wallet

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	P2PK = iota
	P2PKH
	P2MS
	P2SH_P2WPKH
	P2SH_P2WSH
	P2WPKH
	P2WSH
)

Variables

View Source
var (
	ErrMissingNetwork           = fmt.Errorf("missing network")
	ErrMissingMnemonic          = fmt.Errorf("missing mnemonic")
	ErrMissingSigningMasterKey  = fmt.Errorf("missing signing master key")
	ErrMissingBlindingMasterKey = fmt.Errorf("missing blinding master key")
	ErrMissingDerivationPath    = fmt.Errorf("missing derivation path")
	ErrMissingOutputScript      = fmt.Errorf("missing output script")
	ErrMissingPset              = fmt.Errorf("missing pset base64")
	ErrMissingDerivationPaths   = fmt.Errorf("missing derivation path map")

	ErrInvalidEntropySize             = fmt.Errorf("entropy size must be a multiple of 32 in the range [128,256]")
	ErrInvalidMnemonic                = fmt.Errorf("blinding mnemonic is invalid")
	ErrInvalidRootPathLen             = fmt.Errorf("invalid root path length, must be in the form \"m/purpose'/coin_type'\"")
	ErrInvalidRootPath                = fmt.Errorf("root path must contain only hardended values")
	ErrRequiredAbsoluteDerivationPath = fmt.Errorf("path must be an absolute derivation starting with 'm/'")
	ErrInvalidDerivationPathLength    = fmt.Errorf("derivation path must be a relative path in the form \"account'/branch/index\"")
	ErrInvalidDerivationPathAccount   = fmt.Errorf("derivation path's account (first elem) must be hardened (suffix ')")
	ErrInvalidSignatures              = fmt.Errorf("transaction contains invalid signature(s)")

	ErrMalformedDerivationPath         = fmt.Errorf("path must not start or end with a '/'")
	ErrOutOfRangeDerivationPathAccount = fmt.Errorf("account index must be in hardened range [0', %d']", hdkeychain.HardenedKeyStart-1)

	ErrMissingPrevOuts          = fmt.Errorf("missing prevouts")
	ErrInputMissingTxid         = fmt.Errorf("input is missing txid")
	ErrInputInvalidTxid         = fmt.Errorf("invalid input txid length: must be exactly 32 bytes")
	ErrOutputMissingAsset       = fmt.Errorf("output is missing asset")
	ErrOutputInvalidAsset       = fmt.Errorf("invalid output asset length: must be exactly 32 bytes")
	ErrOutputInvalidScript      = fmt.Errorf("invalid output script")
	ErrOutputInvalidBlindingKey = fmt.Errorf("invalid output blinding key")
	ErrMissingInputs            = fmt.Errorf("at least one input is mandatory to create a partial transaction with one or more confidential outputs")
	ErrMissingOwnedInputs       = fmt.Errorf("missing list of owned inputs")
	ErrBlindInvalidInputIndex   = fmt.Errorf("input index to blind is out of range")
	ErrMissingRootPath          = fmt.Errorf("missing root derivation path")
)
View Source
var (
	// DummyFeeAmount is used as the fee amount to cover when coin-selecting the
	// inputs to use to cover the true fee amount, which, instead, is calculated
	// with more precision from the tx size.
	// The real fee amount strictly depends on the number of tx inputs and
	// outputs, and even input types.
	// This value is thought for transactions on TDEX network, whose are composed
	// by at least 3 inputs and 6 outputs.
	// If all inputs are wrapped or native segwit, is shouls be unlikely for the
	// tx virtual size to be higher than 700 vB/sat, taking into account that
	// this pkg supports ONLY native segwit scripts/addresses.
	// For any other case this value can be tweaked at will.
	DummyFeeAmount uint64 = 700
)

Functions

func EstimateFees

func EstimateFees(
	inputs []Input, outputs []Output, millisatsPerByte uint64,
) uint64

EstimateFees estimates the virtual size of the transaciton composed of the given Inputs and Outputs and then returns the corresponding fee amount based on the given mSats/Byte ratio.

func EstimateTxSize

func EstimateTxSize(inputs []Input, outputs []Output) uint64

EstimateTxSize makes an estimation of the virtual size of a transaction for which is required to specify the type of the inputs and outputs according to those of the Bitcoin standard (P2PK, P2PKH, P2MS, P2SH(P2WPKH), P2SH(P2WSH), P2WPKH, P2WSH). The estimation might not be accurate in case of one or more P2MS inputs since the method is not able to retrieve the size of redeem script containg all pubkeys, nor it expects anyone as arg.

func FinalizeAndExtractTransaction

func FinalizeAndExtractTransaction(args FinalizeAndExtractTransactionArgs) (string, string, error)

FinalizeAndExtractTransaction attempts to finalize the provided partial transaction and eventually extracts the final raw transaction, returning it in hex string format, along with its transaction id.

func NewMnemonic

func NewMnemonic(args NewMnemonicArgs) ([]string, error)

NewMnemonic returns a new mnemonic as a list of words:

  • EntropySize: 256 -> 24-words mnemonic.
  • EntropySize: 128 -> 12-words mnemonic.

Types

type BlindPsetWithMasterKeyArgs

type BlindPsetWithMasterKeyArgs struct {
	PsetBase64        string
	ExtraBlindingKeys map[string][]byte
	LastBlinder       bool
}

type BlindPsetWithOwnedInputsArgs

type BlindPsetWithOwnedInputsArgs struct {
	PsetBase64         string
	OwnedInputsByIndex map[uint32]Input
	LastBlinder        bool
}

type CreatePsetArgs

type CreatePsetArgs struct {
	Inputs  []Input
	Outputs []Output
}

type DerivationPath

type DerivationPath []uint32

DerivationPath is the data structure representing an HD path.

func ParseDerivationPath

func ParseDerivationPath(strPath string) (DerivationPath, error)

ParseDerivationPath converts a derivation path in string format to a DerivationPath type.

func ParseRootDerivationPath

func ParseRootDerivationPath(strPath string) (DerivationPath, error)

func (DerivationPath) String

func (path DerivationPath) String() string

type DeriveBlindingKeyPairArgs

type DeriveBlindingKeyPairArgs struct {
	Script []byte
}

type DeriveConfidentialAddressArgs

type DeriveConfidentialAddressArgs struct {
	DerivationPath string
	Network        *network.Network
}

type DeriveSigningKeyPairArgs

type DeriveSigningKeyPairArgs struct {
	DerivationPath string
}

type ExtendedKeyArgs

type ExtendedKeyArgs struct {
	Account uint32
}

type FinalizeAndExtractTransactionArgs

type FinalizeAndExtractTransactionArgs struct {
	PsetBase64 string
}

type Input

type Input struct {
	TxID            string
	TxIndex         uint32
	Value           uint64
	Asset           string
	Script          []byte
	ValueBlinder    []byte
	AssetBlinder    []byte
	ValueCommitment []byte
	AssetCommitment []byte
	Nonce           []byte
	RangeProof      []byte
	SurjectionProof []byte
	DerivationPath  string
}

Input is the data structure representing an input to be added to a partial transaction, therefore including the previous outpoint as long as all the info about the prevout itself (and the derivation path generating its script as extra info).

type NewMnemonicArgs

type NewMnemonicArgs struct {
	EntropySize uint32
}

type NewWalletArgs

type NewWalletArgs struct {
	RootPath string
}

type NewWalletFromMnemonicArgs

type NewWalletFromMnemonicArgs struct {
	RootPath string
	Mnemonic []string
}

type Output

type Output psetv2.OutputArgs

Output is the data structure representing an output to be added to a partial transaction, therefore inclusing asset, amount and address.

type SignPsetArgs

type SignPsetArgs struct {
	PsetBase64        string
	DerivationPathMap map[string]string
	SigHashType       txscript.SigHashType
}

type SignTransactionArgs

type SignTransactionArgs struct {
	TxHex        string
	InputsToSign map[uint32]Input
	SigHashType  txscript.SigHashType
}

type UpdatePsetArgs

type UpdatePsetArgs struct {
	PsetBase64 string
	Inputs     []Input
	Outputs    []Output
}

type Wallet

type Wallet struct {
	// contains filtered or unexported fields
}

Wallet is the data structure representing an HD wallet of an Elements based network.

func NewWallet

func NewWallet(args NewWalletArgs) (*Wallet, error)

NewWallet creates a new HD wallet with a random mnemonic

func NewWalletFromMnemonic

func NewWalletFromMnemonic(args NewWalletFromMnemonicArgs) (*Wallet, error)

NewWalletFromMnemonic creates a new HD wallet with the given mnemonic seed and root path

func (*Wallet) AccountExtendedPrivateKey

func (w *Wallet) AccountExtendedPrivateKey(args ExtendedKeyArgs) (string, error)

AccountExtendedPrivateKey returns the extended private key in base58 format for the given account index.

func (*Wallet) AccountExtendedPublicKey

func (w *Wallet) AccountExtendedPublicKey(args ExtendedKeyArgs) (string, error)

AccountExtendedPublicKey returns the extended public key in base58 format for the given account index.

func (*Wallet) BlindPsetWithMasterKey

func (w *Wallet) BlindPsetWithMasterKey(
	args BlindPsetWithMasterKeyArgs,
) (string, error)

func (*Wallet) BlindPsetWithOwnedInputs

func (w *Wallet) BlindPsetWithOwnedInputs(
	args BlindPsetWithOwnedInputsArgs,
) (string, error)

func (*Wallet) CreatePset

func (w *Wallet) CreatePset(args CreatePsetArgs) (string, error)

CreatePset creates a new partial transaction with given inputs and outputs.

func (*Wallet) DeriveBlindingKeyPair

func (w *Wallet) DeriveBlindingKeyPair(
	args DeriveBlindingKeyPairArgs,
) (*btcec.PrivateKey, *btcec.PublicKey, error)

DeriveBlindingKeyPair derives the SLIP77 blinding key pair from the given output script.

func (*Wallet) DeriveConfidentialAddress

func (w *Wallet) DeriveConfidentialAddress(
	args DeriveConfidentialAddressArgs,
) (string, []byte, error)

DeriveConfidentialAddress derives both the HD signing and the SLIP-77 blinding key-pairs to generate a confidential address.

func (*Wallet) DeriveSigningKeyPair

func (w *Wallet) DeriveSigningKeyPair(args DeriveSigningKeyPairArgs) (
	*btcec.PrivateKey, *btcec.PublicKey, error,
)

DeriveSigningKeyPair derives the key pair from the given derivation path.

func (*Wallet) MasterBlindingKey

func (w *Wallet) MasterBlindingKey() (string, error)

MasterBlindingKey returns the SLIP-77 master blinding key of the wallet in hex format.

func (*Wallet) Mnemonic

func (w *Wallet) Mnemonic() ([]string, error)

Mnemonic returns the mnemonic of the wallet.

func (*Wallet) SignPset

func (w *Wallet) SignPset(args SignPsetArgs) (string, error)

SignPset signs all inputs of a partial transaction matching the given scripts of the derivation path map.

func (*Wallet) SignTransaction

func (w *Wallet) SignTransaction(args SignTransactionArgs) (string, error)

SignTransaction signs all requested inputs of the given raw transaction.

func (*Wallet) UpdatePset

func (w *Wallet) UpdatePset(args UpdatePsetArgs) (string, error)

UpdatesPset adds inputs and outputs to the given partial transaction.

Jump to

Keyboard shortcuts

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