psetv2

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 24 Imported by: 7

Documentation

Index

Constants

View Source
const (
	//Per output types: BIP 174, 370, 371
	GlobalXpub             = 0x01 //BIP 174
	GlobalTxVersion        = 0x02 //BIP 370
	GlobalFallbackLocktime = 0x03 //BIP 370
	GlobalInputCount       = 0x04 //BIP 370
	GlobalOutputCount      = 0x05 //BIP 370
	GlobalTxModifiable     = 0x06 //BIP 370
	GlobalVersion          = 0xFB //BIP 174

	//Elements Proprietary types
	GlobalScalar     = 0x00
	GlobalModifiable = 0x01
)
View Source
const (
	//Per input types: BIP 127, 174, 370, 371
	InputNonWitnessUtxo         = 0x00 //BIP 174
	InputWitnessUtxo            = 0x01 //BIP 174
	InputPartialSig             = 0x02 //BIP 174
	InputSighashType            = 0x03 //BIP 174
	InputRedeemScript           = 0x04 //BIP 174
	InputWitnessScript          = 0x05 //BIP 174
	InputBip32Derivation        = 0x06 //BIP 174
	InputFinalScriptsig         = 0x07 //BIP 174
	InputFinalScriptwitness     = 0x08 //BIP 174
	InputPorCommitment          = 0x09 //BIP 127
	InputRipemd160              = 0x0a //BIP 174
	InputSha256                 = 0x0b //BIP 174
	InputHash160                = 0x0c //BIP 174
	InputHash256                = 0x0d //BIP 174
	InputPreviousTxid           = 0x0e //BIP 370
	InputPreviousTxIndex        = 0x0f //BIP 370
	InputSequence               = 0x10 //BIP 370
	InputRequiredTimeLocktime   = 0x11 //BIP 370
	InputRequiredHeightLocktime = 0x12 //BIP 370
	InputTapKeySig              = 0x13 //BIP 371
	InputTapScriptSig           = 0x14 //BIP 371
	InputTapLeafScript          = 0x15 //BIP 371
	InputTapBip32Derivation     = 0x16 //BIP 371
	InputTapInternalKey         = 0x17 //BIP 371
	InputTapMerkleRoot          = 0x18 //BIP 371

	//Elements Proprietary types
	InputIssuanceValue                   = 0x00
	InputIssuanceValueCommitment         = 0x01
	InputIssuanceValueRangeproof         = 0x02
	InputIssuanceInflationKeysRangeproof = 0x03
	InputPeginTx                         = 0x04
	InputPeginTxoutProof                 = 0x05
	InputPeginGenesis                    = 0x06
	InputPeginClaimScript                = 0x07
	InputPeginValue                      = 0x08
	InputPeginWitness                    = 0x09
	InputIssuanceInflationKeys           = 0x0a
	InputIssuanceInflationKeysCommitment = 0x0b
	InputIssuanceBlindingNonce           = 0x0c
	InputIssuanceAssetEntropy            = 0x0d
	InputUtxoRangeProof                  = 0x0e
	InputIssuanceBlindValueProof         = 0x0f
	InputIssuanceBlindInflationKeysProof = 0x10
	InputExplicitValue                   = 0x11
	InputValueProof                      = 0x12
	InputExplicitAsset                   = 0x13
	InputAssetProof                      = 0x14
	InputBlindedIssuanceValue            = 0x15
)
View Source
const (
	//Per output types: BIP 174, 370, 371
	OutputRedeemScript       = 0x00 //BIP 174
	OutputWitnessScript      = 0x01 //BIP 174
	OutputBip32Derivation    = 0x02 //BIP 174
	OutputAmount             = 0x03 //BIP 370
	OutputScript             = 0x04 //BIP 370
	OutputTapInternalKey     = 0x05 //BIP 371
	OutputTapTree            = 0x06 //BIP 371
	OutputTapLeafScript      = 0x06 //BIP 371 //TODO is duplicate key type allowed?
	OutputTapBip32Derivation = 0x07 //BIP 371

	//Elements Proprietary types
	OutputValueCommitment      = 0x01
	OutputAsset                = 0x02
	OutputAssetCommitment      = 0x03
	OutputValueRangeproof      = 0x04
	OutputAssetSurjectionProof = 0x05
	OutputBlindingPubkey       = 0x06
	OutputEcdhPubkey           = 0x07
	OutputBlinderIndex         = 0x08
	OutputBlindValueProof      = 0x09
	OutputBlindAssetProof      = 0x0a
)
View Source
const (
	NonConfidentialReissuanceTokenFlag = uint(0)
	ConfidentialReissuanceTokenFlag    = uint(1)
)
View Source
const (
	PsetProprietary = 0xfc
)

Variables

View Source
var (

	// Output errors
	ErrOutMissingBlindingKey = fmt.Errorf(
		"cannot blind an output that misses blinding pubkey",
	)
	ErrOutMissingNonce                = fmt.Errorf("missing output ecdh pubkey")
	ErrOutMissingNonceCommitment      = fmt.Errorf("missing output nonce commitment")
	ErrOutMissingAssetBlinder         = fmt.Errorf("missing output asset blinder")
	ErrOutMissingAssetCommitment      = fmt.Errorf("missing output asset commitment")
	ErrOutMissingAssetSurjectionProof = fmt.Errorf("missing output asset surjetcion proof")
	ErrOutMissingAssetBlindProof      = fmt.Errorf("missing output asset commitment or blind proof")
	ErrOutMissingValueBlinder         = fmt.Errorf("missing output value blinder")
	ErrOutMissingValueCommitment      = fmt.Errorf("missing output value commitment")
	ErrOutMissingValueRangeProof      = fmt.Errorf("missing output value range proof")
	ErrOutMissingValueBlindProof      = fmt.Errorf("missing output value commitment or blind proof")
	ErrOutInvalidNonce                = fmt.Errorf("invalid output ecdh pubkey length")
	ErrOutInvalidNonceCommitment      = fmt.Errorf("invalid output nonce commitment length")
	ErrOutInvalidValueBlinder         = fmt.Errorf("invalid output value blinder length")
	ErrOutInvalidAssetBlinder         = fmt.Errorf("invalid output asset blinder length")
	ErrOutInvalidAssetCommitment      = fmt.Errorf("invalid output asset commitment length")
	ErrOutInvalidValueCommitment      = fmt.Errorf("invalid output value commitment length")

	// Input issuance errors
	ErrInIssuanceMissingValueBlinder    = fmt.Errorf("missing issuance value blinder")
	ErrInIssuanceMissingValueCommitment = fmt.Errorf("missing issuance value commitment")
	ErrInIssuanceMissingValueRangeProof = fmt.Errorf("missing issuance value range proof")
	ErrInIssuanceMissingValueBlindProof = fmt.Errorf("missing issuance value blind proof")
	ErrInIssuanceMissingTokenBlinder    = fmt.Errorf("missing issuance token value blinder")
	ErrInIssuanceMissingTokenCommitment = fmt.Errorf("missing issuance token value commitment")
	ErrInIssuanceMissingTokenRangeProof = fmt.Errorf("missing issuance token value range proof")
	ErrInIssuanceMissingTokenBlindProof = fmt.Errorf("missing issuance token value blind proof")
	ErrInIssuanceInvalidValueBlinder    = fmt.Errorf("invalid issuance value blinder length")
	ErrInIssuanceInvalidValueCommitment = fmt.Errorf("invalid issuance value commitment length")
	ErrInIssuanceInvalidTokenBlinder    = fmt.Errorf("invalid issuance token value blinder length")
	ErrInIssuanceInvalidTokenCommitment = fmt.Errorf("invalid issuance token value commitment length")

	// Input errors
	ErrOwnedInMissingValue        = fmt.Errorf("missing input value")
	ErrOwnedInMissingAsset        = fmt.Errorf("missing input asset")
	ErrOwnedInMissingValueBlinder = fmt.Errorf("missing input value blinder")
	ErrOwnedInMissingAssetBlinder = fmt.Errorf("missing input asset blinder")
	ErrOwnedInInvalidAsset        = fmt.Errorf("invalid input asset length")
	ErrOwnedInInvalidAssetFormat  = fmt.Errorf("input asset must be a string in hex format")
	ErrOwnedInInvalidValueBlinder = fmt.Errorf("invalid input value blinder length")
	ErrOwnedInInvalidAssetBlinder = fmt.Errorf("invalid input asset blinder length")

	// Blinder errors
	ErrBlinderForbiddenBlinding  = fmt.Errorf("provided pset does not need to be blinded")
	ErrBlinderMissingOwnedInputs = fmt.Errorf("missing list of owned inputs")
	ErrBlinderMissingValidator   = fmt.Errorf("missing blinding validator")
	ErrBlinderMissingGenerator   = fmt.Errorf("missing blinding generator")
)
View Source
var (
	// Input errors
	ErrInMissingTxid       = fmt.Errorf("missing input txid")
	ErrInInvalidTxidFormat = fmt.Errorf("input txid must be in hex format")
	ErrInInvalidTxid       = fmt.Errorf("invalid input txid length")

	// Output errors
	ErrOutMissingAsset       = fmt.Errorf("missing output asset")
	ErrOutInvalidAssetFormat = fmt.Errorf("output asset must be in hex format")
	ErrOutInvalidAsset       = fmt.Errorf("invalid output asset length")
	ErrOutInvalidAddress     = fmt.Errorf("invalid output address")
)
View Source
var (
	ErrFinalizerInvalidSigHashFlags   = fmt.Errorf("invalid sighash flags")
	ErrFinalizerForbiddenFinalization = fmt.Errorf("pset is not finalizable")
	ErrFinalizerAlreadyFinalized      = fmt.Errorf(
		"cannot finalize pset, finalized scriptSig or scriptWitnes already exists",
	)
)
View Source
var (
	ErrGlobalInvalidXPubLen               = fmt.Errorf("invalid global xpub value length")
	ErrGlobalInvalidXPubDerivationPathLen = fmt.Errorf("invalid global xpub derivation path value length")
	ErrGlobalInvalidTxVersionLen          = fmt.Errorf("invalid global tx version value length")
	ErrGlobalInvalidTxVersion             = fmt.Errorf("invalid global tx version value")
	ErrGlobalInvalidFallbackLocktimeLen   = fmt.Errorf("invalid global fallback locktime value length")
	ErrGlobalInvalidInputCountLen         = fmt.Errorf("invalid global input count value length")
	ErrGlobalInvalidOutputCountLen        = fmt.Errorf("invalid global output count value length")
	ErrGlobalInvalidTxModifiableLen       = fmt.Errorf("invalid global tx modifiable value length")
	ErrGlobalInvalidTxModifiable          = fmt.Errorf("invalid global tx modifiable value")
	ErrGlobalInvalidVersionLen            = fmt.Errorf("invalid global version value length")
	ErrGlobalInvalidVersion               = fmt.Errorf("invalid global version value")
	ErrGlobalInvalidScalarLen             = fmt.Errorf("invalid global scalar length")
	ErrGlobalInvalidModifiableLen         = fmt.Errorf("invalid global pset modifiable length")
	ErrGlobalInvalidModifiable            = fmt.Errorf("invalid global pset modifiable value")
	ErrGlobalDuplicatedField              = func(field string) error {
		return fmt.Errorf("duplicated global %s", field)
	}
)
View Source
var (
	ErrInInvalidPartialSignature = fmt.Errorf(
		"invalid input partial signature",
	)
	ErrInInvalidSigHash = fmt.Errorf(
		"invalid input sighash length",
	)
	ErrInInvalidPubKey = fmt.Errorf(
		"invalid input pubkey length",
	)
	ErrInInvalidPreviousTxid = fmt.Errorf(
		"invalid input prev txid length",
	)
	ErrInInvalidPreviousTxIndex = fmt.Errorf(
		"invalid input prev tx index length",
	)
	ErrInInvalidSequence = fmt.Errorf(
		"invalid input sequence length",
	)
	ErrInInvalidRequiredLocktime = fmt.Errorf(
		"invalid input required locktime length",
	)
	ErrInInvalidRequiredHeightLocktime = fmt.Errorf(
		"invalid input required height locktime length",
	)
	ErrInInvalidTapKeySig = fmt.Errorf(
		"invalid input taproot key signature length",
	)
	ErrInInvalidTapScriptSigKeyData = fmt.Errorf(
		"invalid input taproot script signature key data length",
	)
	ErrInInvalidTapScriptSigSignature = fmt.Errorf(
		"invalid input taproot script signature",
	)
	ErrInInvalidTapLeafScriptKeyData = fmt.Errorf(
		"invalid input taproot leaf script key data length",
	)
	ErrInInvalidTapLeafScriptVersion = fmt.Errorf(
		"invalid input taproot leaf script version",
	)
	ErrInInvalidTapLeafScript = fmt.Errorf(
		"invalid input taproot leaf script",
	)
	ErrInInvalidTapBip32DerivationKeyData = fmt.Errorf(
		"invalid input taproot bip32 derivation pubkey length",
	)
	ErrInInvalidTapBip32Derivation = fmt.Errorf(
		"invalid input taproot bip32 derivation",
	)
	ErrInInvalidTapInternalKey = fmt.Errorf(
		"invalid input taproot internal key",
	)
	ErrInInvalidTapMerkleRoot = fmt.Errorf(
		"invalid input taproot merkle root",
	)
	ErrInInvalidIssuanceValue = fmt.Errorf(
		"invalid input issuance value length",
	)
	ErrInInvalidIssuanceCommitment = fmt.Errorf(
		"invalid input issuance value commitment length",
	)
	ErrInInvalidPeginGenesisHash = fmt.Errorf(
		"invalid input pegin genesis hash length",
	)
	ErrInInvalidPeginValue = fmt.Errorf(
		"invalid input pegin value length",
	)
	ErrInInvalidIssuanceInflationKeys = fmt.Errorf(
		"invalid input issuance inflation keys length",
	)
	ErrInInvalidIssuanceInflationKeysCommitment = fmt.Errorf(
		"invalid input issuance inflation keys commitment length",
	)
	ErrInInvalidIssuanceBlindingNonce = fmt.Errorf(
		"invalid input issuance blinding nonce length",
	)
	ErrInInvalidIssuanceAssetEntropy = fmt.Errorf(
		"invalid input issuance asset entropy length",
	)
	ErrInInvalidWitnessScript = fmt.Errorf(
		"input witness script cannot be set if witness utxo is unset",
	)
	ErrInInvalidFinalScriptWitness = fmt.Errorf(
		"input final script witness cannot be set if witness utxo is unset",
	)
	ErrInMissingIssuanceBlindValueProof = fmt.Errorf(
		"missing input issuance value commitment or blind proof",
	)
	ErrInMissingIssuanceBlindInflationKeysProof = fmt.Errorf(
		"missing input issuance inflation keys commitment or blind proof",
	)
	ErrInInvalidLocktime       = fmt.Errorf("invalid input locktime")
	ErrInInvalidNonWitnessUtxo = fmt.Errorf(
		"non-witness utxo hash does not match input txid",
	)
	ErrInInvalidPeginWitness = fmt.Errorf("invalid input pegin witness")
	ErrInInvalidPeginTx      = fmt.Errorf("invalid input pegin tx")
	ErrInDuplicatedField     = func(field string) error {
		return fmt.Errorf("duplicated input %s", field)
	}
	ErrInInvalidExplicitValue        = fmt.Errorf("invalid input explicit value")
	ErrInInvalidExplicitAsset        = fmt.Errorf("invalid input explicit asset")
	ErrInInvalidBlindedIssuanceValue = fmt.Errorf("invalid input blinded issuance value")
)
View Source
var (
	ErrKeyInvalidSize               = fmt.Errorf("invalid key size")
	ErrProprietaryInvalidKey        = fmt.Errorf("invalid ProprietaryData key")
	ErrProprietaryInvalidIdentifier = fmt.Errorf("invalid ProprietaryData identifier")
)
View Source
var (
	ErrOutInvalidBlinding = fmt.Errorf(
		"output is partially blinded while it must be either unblinded or " +
			"fully blinded",
	)
	ErrOutInvalidBlinderIndexState = fmt.Errorf(
		"blinder index must be unset for fully blinded output",
	)
	ErrOutInvalidValue          = fmt.Errorf("invalid output value length")
	ErrOutInvalidPubKey         = fmt.Errorf("invalid output pubkey length")
	ErrOutInvalidBlindingPubKey = fmt.Errorf(
		"invalid output blinding pubkey length",
	)
	ErrOutInvalidBlinderIndex = fmt.Errorf("invalid output blinder index length")
	ErrOutDuplicatedField     = func(field string) error {
		return fmt.Errorf("duplicated output %s", field)
	}
)
View Source
var (
	ErrInvalidPsbtFormat        = fmt.Errorf("invalid PSBT serialization format")
	ErrNoMoreKeyPairs           = fmt.Errorf("no more key-pairs")
	ErrInvalidMagicBytes        = fmt.Errorf("invalid magic bytes")
	ErrPsetMissingBlindedOutput = fmt.Errorf(
		"pset has blinded inputs, at least one output must be blinded",
	)
	ErrPsetInvalidGlobablModifiableState = fmt.Errorf(
		"global modifiable flag must be unset for fully blinded pset",
	)
	ErrPsetForbiddenInputsModification = fmt.Errorf(
		"pset locked for modifications on inputs",
	)
	ErrPsetForbiddenOutputsModification = fmt.Errorf(
		"pset locked for modifications on outputs",
	)
	ErrPartialSignatureMissingPubKey = fmt.Errorf(
		"input partial signature is missing pubkey",
	)
)
View Source
var (
	ErrSignerForbiddenSigning                       = fmt.Errorf("pset is not fully blinded")
	ErrSignerForbiddenTaprootKeySigHasTapscriptSigs = fmt.Errorf("pset input has tapscript signatures")
	ErrSignerForbiddenTaprootScriptSigHasKeySig     = fmt.Errorf("pset input has taproot key signature")
)
View Source
var (
	ErrInputIndexOutOfRange              = fmt.Errorf("provided input index is out of range")
	ErrOutputIndexOutOfRange             = fmt.Errorf("provided output index is out of range")
	ErrInvalidSignatureForInput          = fmt.Errorf("signature does not correspond to this input")
	ErrInIssuanceMissingAssetAddress     = fmt.Errorf("missing destination address for asset to (re)issue")
	ErrInIssuanceMissingTokenAddress     = fmt.Errorf("missing destination address for token to (re)issue")
	ErrInIssuanceAddressesMismatch       = fmt.Errorf("asset and token destination addresses must both be confidential or non-confidential")
	ErrPsetMissingInputForIssuance       = fmt.Errorf("pset must contain at least one input to add issuance to")
	ErrPsetMissingEmptyInputsForIssuance = fmt.Errorf("transaction does not contain any input with empty issuance")
	ErrInReissuanceMissingPrevout        = fmt.Errorf("either WitnessUtxo or NonWitnessUtxo must be defined")
	ErrInReissuanceInvalidTokenBlinder   = fmt.Errorf("invalid token prevout blinder length")
	ErrInReissuanceZeroTokenBlinder      = fmt.Errorf("token prevout blinder must not be a zero blinder")
	ErrInReissuanceInvalidAssetAmount    = fmt.Errorf("invalid reissuance asset amount")
	ErrInReissuanceInvalidTokenAmount    = fmt.Errorf("invalid reissuance token amount")
)
View Source
var (
	ErrExtractorForbiddenExtraction = fmt.Errorf(
		"pset must be complete to extract final transaction",
	)
)

Functions

func Extract

func Extract(p *Pset) (*transaction.Transaction, error)

func Finalize

func Finalize(p *Pset, inIndex int) error

Finalize assumes that the provided pset.Pset struct has all partial signatures and redeem scripts/witness scripts already prepared for the specified input, and so removes all temporary data and replaces them with completed sigScript and witness fields, which are stored in key-types 07 and 08. The witness/non-witness utxo fields in the inputs (key-types 00 and 01) are left intact as they may be needed for validation (?). If there is any invalid or incomplete data, an error is returned.

func FinalizeAll

func FinalizeAll(p *Pset) error

FinalizeAll finalizes all inputs of a partial elements transaction by calling the Finalize function for every partial input

func MaybeFinalize

func MaybeFinalize(p *Pset, inIndex int) (bool, error)

MaybeFinalize attempts to finalize the input at index inIndex in the PSET p, returning true with no error if it succeeds, OR if the input has already been finalized.

func MaybeFinalizeAll

func MaybeFinalizeAll(p *Pset) error

MaybeFinalizeAll attempts to finalize all inputs of the pset.Pset that are not already finalized, and returns an error if it fails to do so.

func SerializeBIP32Derivation

func SerializeBIP32Derivation(masterKeyFingerprint uint32,
	bip32Path []uint32) []byte

SerializeBIP32Derivation takes a master key fingerprint as defined in BIP32, along with a path specified as a list of uint32 values, and returns a bytestring specifying the derivation in the format required by BIP174: // master key fingerprint (4) || child index (4) || child index (4) || ....

Types

type AddInIssuanceArgs

type AddInIssuanceArgs struct {
	Precision       uint
	Contract        *transaction.IssuanceContract
	AssetAmount     uint64
	TokenAmount     uint64
	AssetAddress    string
	TokenAddress    string
	BlindedIssuance bool
}

AddInIssuanceArgs is a struct encapsulating all the issuance data that can be attached to any specific transaction of the PSBT.

type AddInReissuanceArgs

type AddInReissuanceArgs struct {
	TokenPrevOutBlinder []byte
	Entropy             string
	AssetAmount         uint64
	AssetAddress        string
	TokenAmount         uint64
	TokenAddress        string
}

AddInReissuanceArgs defines the mandatory fields that one needs to pass to the AddInReissuance method of the *Updater type

PrevOutHash: the prevout hash of the token that will be added as input to the tx
PrevOutIndex: the prevout index of the token that will be added as input to the tx
PrevOutBlinder: the asset blinder used to blind the prevout token
WitnessUtxo: the prevout token in case it is a witness one
NonWitnessUtxo: the prevout tx that include the token output in case it is a non-witness one
Entropy: the entropy used to generate token and asset
AssetAmount: the amount of asset to re-issue
TokenAmount: the same unblinded amount of the prevout token
AssetAddress: the destination address of the re-issuing asset
TokenAddress: the destination address of the re-issuance token

type Bip32Sorter

type Bip32Sorter []*DerivationPathWithPubKey

Bip32Sorter implements sort.Interface for the DerivationPathWithPubKey struct.

func (Bip32Sorter) Len

func (s Bip32Sorter) Len() int

func (Bip32Sorter) Less

func (s Bip32Sorter) Less(i, j int) bool

func (Bip32Sorter) Swap

func (s Bip32Sorter) Swap(i, j int)

type BitSet

type BitSet []byte

func NewBitSet

func NewBitSet() BitSet

func NewBitSetFromBuffer

func NewBitSetFromBuffer(buf byte) (BitSet, error)

func (BitSet) Clear

func (s BitSet) Clear()

func (BitSet) Reset

func (s BitSet) Reset(index int)

func (BitSet) Set

func (s BitSet) Set(index int)

func (BitSet) String

func (s BitSet) String() string

func (BitSet) Test

func (s BitSet) Test(index int) bool

func (BitSet) Uint8

func (s BitSet) Uint8() uint8

type Blinder

type Blinder struct {
	Pset        *Pset
	OwnedInputs []OwnedInput
	// contains filtered or unexported fields
}

func NewBlinder

func NewBlinder(
	p *Pset, ownedInputs []OwnedInput,
	validator BlindingValidator, generator BlindingGenerator,
) (*Blinder, error)

func (*Blinder) BlindLast

func (b *Blinder) BlindLast(
	inIssuanceBlindingArgs []InputIssuanceBlindingArgs,
	outBlindingArgs []OutputBlindingArgs,
) error

func (*Blinder) BlindNonLast

func (b *Blinder) BlindNonLast(
	inIssuanceBlindingArgs []InputIssuanceBlindingArgs,
	outBlindingArgs []OutputBlindingArgs,
) error

type BlindingGenerator

type BlindingGenerator interface {
	// Scalar methods
	ComputeAndAddToScalarOffset(
		scalar []byte, value uint64, assetBlinder, valueBlinder []byte,
	) ([]byte, error)
	SubtractScalars(inputScalar, outputScalar []byte) ([]byte, error)
	// Last blinder methods
	LastValueCommitment(value uint64, asset, blinder []byte) ([]byte, error)
	LastBlindValueProof(
		value uint64, valueCommitment, assetCommitment, blinder []byte,
	) ([]byte, error)
	LastValueRangeProof(
		value uint64, asset, assetBlinder, valueCommitment, valueBlinder,
		scriptPubkey, nonce []byte,
	) ([]byte, error)
}

type BlindingValidator

type BlindingValidator interface {
	VerifyValueRangeProof(
		valueCommitment, assetCommitment, script, proof []byte,
	) bool
	VerifyAssetSurjectionProof(
		inAssets, inAssetBlinders [][]byte,
		outAsset, outAssetBlinder, proof []byte,
	) bool
	VerifyBlindValueProof(
		value uint64, valueCommitment, assetCommitment, proof []byte,
	) bool
	VerifyBlindAssetProof(asset, assetCommitment, proof []byte) bool
}

type DerivationPath

type DerivationPath []uint32

func (DerivationPath) String

func (p DerivationPath) String() string

type DerivationPathWithPubKey

type DerivationPathWithPubKey struct {
	// PubKey is the raw pubkey serialized in compressed format.
	PubKey []byte

	// MasterKeyFingerprint is the finger print of the master pubkey.
	MasterKeyFingerprint uint32

	// Bip32Path is the BIP 32 path with child index as a distinct integer.
	Bip32Path []uint32
}

DerivationPathWithPubKey encapsulates the data for the input and output DerivationPathWithPubKey key-value fields.

type Global

type Global struct {
	Xpubs            []Xpub
	TxVersion        uint32
	FallbackLocktime *uint32
	InputCount       uint64
	OutputCount      uint64
	TxModifiable     BitSet
	Version          uint32
	Scalars          [][]byte
	Modifiable       BitSet
	ProprietaryData  []ProprietaryData
	Unknowns         []KeyPair
}

func (*Global) SanityCheck

func (g *Global) SanityCheck() error

type Input

type Input struct {
	NonWitnessUtxo                  *transaction.Transaction
	WitnessUtxo                     *transaction.TxOutput
	PartialSigs                     []PartialSig
	SigHashType                     txscript.SigHashType
	RedeemScript                    []byte
	WitnessScript                   []byte
	Bip32Derivation                 []DerivationPathWithPubKey
	FinalScriptSig                  []byte
	FinalScriptWitness              []byte
	Ripemd160Preimages              map[[20]byte][]byte
	Sha256Preimages                 map[[32]byte][]byte
	Hash160Preimages                map[[20]byte][]byte
	Hash256Preimages                map[[32]byte][]byte
	PreviousTxid                    []byte
	PreviousTxIndex                 uint32
	Sequence                        uint32
	RequiredTimeLocktime            uint32
	RequiredHeightLocktime          uint32
	IssuanceValue                   uint64
	IssuanceValueCommitment         []byte
	IssuanceValueRangeproof         []byte
	IssuanceInflationKeysRangeproof []byte
	PeginTx                         *wire.MsgTx
	PeginTxoutProof                 []byte
	PeginGenesisHash                []byte
	PeginClaimScript                []byte
	PeginValue                      uint64
	PeginWitness                    [][]byte
	IssuanceInflationKeys           uint64
	IssuanceInflationKeysCommitment []byte
	IssuanceBlindingNonce           []byte
	IssuanceAssetEntropy            []byte
	UtxoRangeProof                  []byte
	IssuanceBlindValueProof         []byte
	IssuanceBlindInflationKeysProof []byte
	ExplicitValue                   uint64
	ValueProof                      []byte
	ExplicitAsset                   []byte
	AssetProof                      []byte
	BlindedIssuance                 *bool
	ProprietaryData                 []ProprietaryData
	TapKeySig                       []byte
	TapScriptSig                    []TapScriptSig
	TapLeafScript                   []TapLeafScript
	TapBip32Derivation              []TapDerivationPathWithPubKey
	TapInternalKey                  []byte
	TapMerkleRoot                   []byte
	Unknowns                        []KeyPair
}

func (*Input) GetIssuanceAssetHash

func (i *Input) GetIssuanceAssetHash() []byte

func (*Input) GetIssuanceInflationKeysHash

func (i *Input) GetIssuanceInflationKeysHash() []byte

func (*Input) GetUtxo

func (i *Input) GetUtxo() *transaction.TxOutput

func (*Input) HasIssuance

func (i *Input) HasIssuance() bool

func (*Input) HasIssuanceBlinded

func (i *Input) HasIssuanceBlinded() bool

func (*Input) HasReissuance

func (i *Input) HasReissuance() bool

func (*Input) SanityCheck

func (i *Input) SanityCheck() error

type InputArgs

type InputArgs struct {
	Txid       string
	TxIndex    uint32
	Sequence   uint32
	HeightLock uint32
	TimeLock   uint32
}

type InputIssuanceBlindingArgs

type InputIssuanceBlindingArgs struct {
	Index                   uint32
	IssuanceAsset           []byte
	IssuanceToken           []byte
	IssuanceValueCommitment []byte
	IssuanceTokenCommitment []byte
	IssuanceValueRangeProof []byte
	IssuanceTokenRangeProof []byte
	IssuanceValueBlindProof []byte
	IssuanceTokenBlindProof []byte
	IssuanceValueBlinder    []byte
	IssuanceTokenBlinder    []byte
}

type Key

type Key struct {
	KeyType uint8
	KeyData []byte
}

type KeyPair

type KeyPair struct {
	Key   Key
	Value []byte
}

keyPair format: <keypair> := <key> <value> <key> := <keylen> <keytype> <keydata> <value> := <valuelen> <valuedata>

type Output

type Output struct {
	RedeemScript         []byte
	WitnessScript        []byte
	Bip32Derivation      []DerivationPathWithPubKey
	Value                uint64
	Script               []byte
	ValueCommitment      []byte
	Asset                []byte
	AssetCommitment      []byte
	ValueRangeproof      []byte
	AssetSurjectionProof []byte
	BlindingPubkey       []byte
	EcdhPubkey           []byte
	BlinderIndex         uint32
	BlindValueProof      []byte
	BlindAssetProof      []byte
	ProprietaryData      []ProprietaryData
	Unknowns             []KeyPair
}

func (*Output) IsFullyBlinded

func (o *Output) IsFullyBlinded() bool

func (*Output) IsPartiallyBlinded

func (o *Output) IsPartiallyBlinded() bool

func (*Output) NeedsBlinding

func (o *Output) NeedsBlinding() bool

func (*Output) SanityCheck

func (o *Output) SanityCheck() error

type OutputArgs

type OutputArgs struct {
	Asset        string
	Amount       uint64
	Script       []byte
	BlindingKey  []byte
	BlinderIndex uint32
}

type OutputBlindingArgs

type OutputBlindingArgs struct {
	Index                uint32
	Nonce                []byte
	NonceCommitment      []byte
	ValueCommitment      []byte
	AssetCommitment      []byte
	ValueRangeProof      []byte
	AssetSurjectionProof []byte
	ValueBlindProof      []byte
	AssetBlindProof      []byte
	ValueBlinder         []byte
	AssetBlinder         []byte
}

type OwnedInput

type OwnedInput struct {
	Index        uint32
	Value        uint64
	Asset        string
	ValueBlinder []byte
	AssetBlinder []byte
}

type PartialSig

type PartialSig struct {
	PubKey    []byte
	Signature []byte
}

PartialSig encapsulate a (BTC public key, ECDSA signature) pair, note that the fields are stored as byte slices, not btcec.PublicKey or btcec.Signature (because manipulations will be with the former not the latter, here); compliance with consensus serialization is enforced with .checkValid()

type PartialSigSorter

type PartialSigSorter []*PartialSig

PartialSigSorter implements sort.Interface for PartialSig.

func (PartialSigSorter) Len

func (s PartialSigSorter) Len() int

func (PartialSigSorter) Less

func (s PartialSigSorter) Less(i, j int) bool

func (PartialSigSorter) Swap

func (s PartialSigSorter) Swap(i, j int)

type ProprietaryData

type ProprietaryData struct {
	Identifier []byte
	Subtype    uint8
	KeyData    []byte
	Value      []byte
}

type Pset

type Pset struct {
	Global  Global
	Inputs  []Input
	Outputs []Output
}

Pset - Partially Signed Elements Transaction Format: <pset> := <magic> <global-map> <input-map>* <output-map>* <magic> := 0x70 0x73 0x65 0x74 0xFF -> pset starts with magic bytes, after which goes global map followed by more input-map's and output-map's <global-map> := <keypair>* 0x00 -> there is one global-map, there can be many keypair's, global map ends with separator <input-map> := <keypair>* 0x00 -> there can be many input-map's, there can be many keypair's, input map ends with separator <output-map> := <keypair>* 0x00 -> there can be many output-map's, there can be many keypair's, output map ends with separator <keypair> := <key> <value> <key> := <keylen> <keytype> <keydata> <value> := <valuelen> <valuedata> Each map can contain ProprietaryData data and unknowns keypair's Full spec: https://github.com/ElementsProject/elements/blob/master/doc/pset.mediawiki

func New

func New(
	ins []InputArgs, outs []OutputArgs, locktime *uint32,
) (*Pset, error)

func NewPsetFromBase64

func NewPsetFromBase64(psetBase64 string) (*Pset, error)

func NewPsetFromBuffer

func NewPsetFromBuffer(buf *bytes.Buffer) (*Pset, error)

func (*Pset) Copy

func (p *Pset) Copy() *Pset

func (*Pset) HasSighashSingle

func (p *Pset) HasSighashSingle() bool

func (*Pset) InputsModifiable

func (p *Pset) InputsModifiable() bool

func (*Pset) IsComplete

func (p *Pset) IsComplete() bool

func (*Pset) IsFullyBlinded

func (p *Pset) IsFullyBlinded() bool

func (*Pset) Locktime

func (p *Pset) Locktime() uint32

func (*Pset) NeedsBlinding

func (p *Pset) NeedsBlinding() bool

func (*Pset) OutputsModifiable

func (p *Pset) OutputsModifiable() bool

func (*Pset) SanityCheck

func (p *Pset) SanityCheck() error

func (*Pset) ToBase64

func (p *Pset) ToBase64() (string, error)

func (*Pset) UnsignedTx

func (p *Pset) UnsignedTx() (*transaction.Transaction, error)

func (*Pset) ValidateAllSignatures

func (p *Pset) ValidateAllSignatures() (bool, error)

func (*Pset) ValidateInputSignatures

func (p *Pset) ValidateInputSignatures(
	inputIndex int,
) (bool, error)

type Signer

type Signer = Updater

func NewSigner

func NewSigner(pset *Pset) (*Signer, error)

func (*Signer) SignInput

func (s *Signer) SignInput(
	inIndex int, sig, pubKey, redeemScript, witnessScript []byte,
) error

SignInput allows the caller to sign a PSET at a particular input; they must provide a signature and a pubkey, both as byte slices; they can also optionally provide both witnessScript and/or redeemScript, otherwise these arguments must be set as nil (and in that case, they must already be present in the PSBT if required for signing to succeed).

This serves as a wrapper around UpdaterRole.addPartialSignature; it ensures that the redeemScript and witnessScript are updated as needed (note that the UpdaterRole is allowed to add redeemScripts and witnessScripts independently, before signing), and ensures that the right form of utxo field (NonWitnessUtxo or WitnessUtxo) is included in the input so that signature insertion (and then finalization) can take place.

func (*Signer) SignTaprootInputKeySig added in v0.4.7

func (s *Signer) SignTaprootInputKeySig(
	inIndex int, sig []byte,
) error

SignTaprootInputKeySig adds a taproot key-path signature to the input at inIndex it returns an error if the input has tapscript signatures or if the input is already signed with key signature

func (*Signer) SignTaprootInputTapscriptSig added in v0.4.7

func (s *Signer) SignTaprootInputTapscriptSig(
	inIndex int, tapscriptSig TapScriptSig,
) error

SignTaprootInputTapscriptSig adds a taproot tapscript signature to the input at inIndex it returns an error if the input is signed with key-path signature

type TapDerivationPathWithPubKey added in v0.4.7

type TapDerivationPathWithPubKey struct {
	DerivationPathWithPubKey
	LeafHashes [][]byte
}

type TapLeafScript added in v0.4.7

type TapLeafScript struct {
	taproot.TapElementsLeaf
	ControlBlock taproot.ControlBlock
}

func NewTapLeafScript added in v0.4.7

func NewTapLeafScript(leafProof taproot.TapscriptElementsProof, internalKey *secp256k1.PublicKey) TapLeafScript

type TapScriptSig added in v0.4.7

type TapScriptSig struct {
	PartialSig
	LeafHash []byte
}

type Updater

type Updater struct {
	Pset *Pset
}

Updater encapsulates the role 'Updater' as specified in BIP174; it accepts Psbt structs and has methods to add fields to the inputs and outputs.

func NewUpdater

func NewUpdater(p *Pset) (*Updater, error)

NewUpdater returns a new instance of Updater, if the passed Psbt struct is in a valid form, else an error.a

func (*Updater) AddInBip32Derivation

func (u *Updater) AddInBip32Derivation(
	inIndex int, bip32Derivation DerivationPathWithPubKey,
) error

AddInBip32Derivation takes a master key fingerprint as defined in BIP32, a BIP32 path as a slice of uint32 values, and a serialized pubkey as a byte slice, along with the integer index of the input, and inserts this data into that input.

NOTE: This can be called multiple times for the same input. An error is returned if addition of this key-value pair to the Psbt fails.

func (*Updater) AddInExplicitAsset added in v0.4.3

func (u *Updater) AddInExplicitAsset(inIndex int, asset, proof []byte) error

AddInExplicitAsset adds the unconfidential asset hash and related blinding proof to the given confidential input. The proof should be calculate with confidential.CreateBlindAssetProof API.

func (*Updater) AddInExplicitValue added in v0.4.3

func (u *Updater) AddInExplicitValue(inIndex int, value uint64, proof []byte) error

AddInExplicitValue adds the unconfidential value and related blinding proof to the given confidential input. The proof should be calculate with confidential.CreateBlindValueProof API.

func (*Updater) AddInIssuance

func (u *Updater) AddInIssuance(inputIndex int, arg AddInIssuanceArgs) error

AddInIssuance adds an unblinded issuance to the transaction

func (*Updater) AddInNonWitnessUtxo

func (u *Updater) AddInNonWitnessUtxo(inIndex int, tx *transaction.Transaction) error

AddInNonWitnessUtxo adds the utxo information for an input which is non-witness. This requires provision of a full transaction (which is the source of the corresponding prevOut), and the input index. If addition of this key-value pair to the Psbt fails, an error is returned.

func (*Updater) AddInRedeemScript

func (u *Updater) AddInRedeemScript(inIndex int, redeemScript []byte) error

AddInRedeemScript adds the redeem script information for an input. The redeem script is passed serialized, as a byte slice, along with the index of the input. An error is returned if addition of this key-value pair to the Psbt fails.

func (*Updater) AddInReissuance

func (u *Updater) AddInReissuance(inputIndex int, arg AddInReissuanceArgs) error

AddInReissuance takes care of adding an input (the prevout token) and 2 outputs to the partial transaction. It also creates a new (re)issuance with the provided entropy, blinder and amounts and attaches it to the new input. NOTE: This transaction must be blinded later so that a new token blinding nonce is generated for the new token output

func (*Updater) AddInSighashType

func (u *Updater) AddInSighashType(
	inIndex int, sighashType txscript.SigHashType,
) error

AddInSighashType adds the sighash type information for an input. The sighash type is passed as a 32 bit unsigned integer, along with the index for the input. .

func (*Updater) AddInTapBip32Derivation added in v0.4.7

func (u *Updater) AddInTapBip32Derivation(inIndex int, tapBip32Derivation TapDerivationPathWithPubKey) error

AddInTapBip32Derivation adds TapBip32Derivation to the input at index inIndex.

func (*Updater) AddInTapInternalKey added in v0.4.7

func (u *Updater) AddInTapInternalKey(inIndex int, internalKey []byte) error

AddInTapInternalKey adds a taproot internal key to the input at index inIndex. it returns an error if the input has already a TapInternalKey.

func (*Updater) AddInTapLeafScript added in v0.4.7

func (u *Updater) AddInTapLeafScript(inIndex int, tapLeafScript TapLeafScript) error

AddInTapLeafScript adds TapLeafScript to the input at index inIndex. It returns an error if the input has already a TapLeafScript with the same TapHash.

func (*Updater) AddInTapMerkleRoot added in v0.4.7

func (u *Updater) AddInTapMerkleRoot(inIndex int, tapMerkleRoot []byte) error

AddInTapMerkleRoot adds the taproot tree root to the input at index inIndex. it returns an error if the input has already a TapMerkleRoot.

func (*Updater) AddInUtxoRangeProof

func (u *Updater) AddInUtxoRangeProof(
	inIndex int, proof []byte,
) error

AddInUtxoRangeProof adds the prevout rangeproof for an input.

func (*Updater) AddInWitnessScript

func (u *Updater) AddInWitnessScript(inIndex int, witnessScript []byte) error

AddInWitnessScript adds the witness script information for an input. The witness script is passed serialized, as a byte slice, along with the index of the input. An error is returned if addition of this key-value pair to the Psbt fails.

func (*Updater) AddInWitnessUtxo

func (u *Updater) AddInWitnessUtxo(inIndex int, txout *transaction.TxOutput) error

AddInWitnessUtxo adds the utxo information for an input which is witness. This requires provision of a full transaction *output* (which is the source of the corresponding prevOut); not the full transaction because BIP143 means the output information is sufficient, and the input index. If addition of this key-value pair to the Psbt fails, an error is returned.

func (*Updater) AddInputs

func (u *Updater) AddInputs(inputs []InputArgs) error

AddInputs adds the provided inputs to the Pset

func (*Updater) AddOutBip32Derivation

func (u *Updater) AddOutBip32Derivation(
	outIndex int, bip32Derivation DerivationPathWithPubKey,
) error

AddOutBip32Derivation takes a master key fingerprint as defined in BIP32, a BIP32 path as a slice of uint32 values, and a serialized pubkey as a byte slice, along with the integer index of the output, and inserts this data into that output.

NOTE: That this can be called multiple times for the same output. An error is returned if addition of this key-value pair to the Psbt fails.

func (*Updater) AddOutRedeemScript

func (u *Updater) AddOutRedeemScript(outIndex int, redeemScript []byte) error

AddOutRedeemScript takes a redeem script as a byte slice and appends it to the output at index outIndex.

func (*Updater) AddOutWitnessScript

func (u *Updater) AddOutWitnessScript(outIndex int, witnessScript []byte) error

AddOutWitnessScript takes a witness script as a byte slice and appends it to the output at index outIndex.

func (*Updater) AddOutputs

func (u *Updater) AddOutputs(outputs []OutputArgs) error

AddOutput adds the provided outputs to the Pset

type Xpub

type Xpub struct {
	ExtendedKey       []byte
	MasterFingerprint uint32
	DerivationPath    DerivationPath
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL