payment

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 13 Imported by: 8

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrTaprootDataIsNil = errors.New("taproot payment data is required to derive taproot addresses")
	ErrNetworkIsNil     = errors.New("network is required to derive taproot addresses")
)

Functions

func Hash160 added in v0.0.4

func Hash160(buf []byte) []byte

Hash160 calculates the hash ripemd160(sha256(b)).

Types

type Payment

type Payment struct {
	Hash          []byte
	WitnessHash   []byte
	Script        []byte
	WitnessScript []byte
	Redeem        *Payment
	PublicKey     *btcec.PublicKey
	BlindingKey   *btcec.PublicKey
	Network       *network.Network
	Taproot       *TaprootPaymentData
}

Payment defines the structure that holds the information different addresses

func FromPayment

func FromPayment(payment *Payment) (*Payment, error)

FromPayment creates a Payment struct from a another Payment

Example

This examples shows how nested payment can be done in order to create non native SegWit(P2SH-P2WPKH) address

_, publicKey := btcec.PrivKeyFromBytes(privateKeyBytes)
p2wpkh := payment.FromPublicKey(publicKey, &network.Regtest, nil)
pay, err := payment.FromPayment(p2wpkh)
p2sh, err := pay.ScriptHash()
if err != nil {
	fmt.Println(err)
}
fmt.Printf("Non native SegWit address %v\n:", p2sh)
Output:

func FromPublicKey

func FromPublicKey(
	pubkey *btcec.PublicKey,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) *Payment

FromPublicKey creates a Payment struct from a btcec.publicKey

Example

This examples shows how standard P2PKH address can be created

_, publicKey := btcec.PrivKeyFromBytes(privateKeyBytes)
pay := payment.FromPublicKey(publicKey, &network.Regtest, nil)
addr, _ := pay.PubKeyHash()
fmt.Printf("P2PKH address %v\n:", addr)
Output:

func FromPublicKeys

func FromPublicKeys(
	pubkeys []*btcec.PublicKey,
	nrequired int,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) (*Payment, error)

FromPublicKeys creates a multi-signature Payment struct from list of public key's

func FromScript

func FromScript(
	outputScript []byte,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) (*Payment, error)

FromScript creates parses a script into a Payment struct

func FromTaprootScriptTree added in v0.4.0

func FromTaprootScriptTree(
	internalKey *btcec.PublicKey,
	tree *taproot.IndexedElementsTapScriptTree,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) (*Payment, error)

FromTaprootScriptTree creates a taproot payment from a merkle script tree and internal key

func FromTaprootScriptTreeHash added in v0.4.0

func FromTaprootScriptTreeHash(
	internalKey *btcec.PublicKey,
	rootHash *chainhash.Hash,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) (*Payment, error)

FromTaprootScriptTreeHash creates a taproot payment from a merkle script tree hash and internal key

func FromTweakedKey added in v0.4.0

func FromTweakedKey(
	tweakedKey *btcec.PublicKey,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) (*Payment, error)

FromTweakedKey creates a P2TR payment from a tweaked output key

func (*Payment) ConfidentialPubKeyHash added in v0.0.2

func (p *Payment) ConfidentialPubKeyHash() (string, error)

ConfidentialPubKeyHash is a method of the Payment struct to derive a base58 confidential p2pkh address

func (*Payment) ConfidentialScriptHash added in v0.0.2

func (p *Payment) ConfidentialScriptHash() (string, error)

ConfidentialScriptHash is a method of the Payment struct to derive a base58 confidential p2sh address

func (*Payment) ConfidentialTaprootAddress added in v0.4.0

func (p *Payment) ConfidentialTaprootAddress() (string, error)

ConfidentialTaprootAddress derives a confidential segwit v1 address from the payment taproot data

func (*Payment) ConfidentialWitnessPubKeyHash added in v0.0.2

func (p *Payment) ConfidentialWitnessPubKeyHash() (string, error)

ConfidentialWitnessPubKeyHash is a method of the Payment struct to derive a confidential blech32 p2wpkh address

func (*Payment) ConfidentialWitnessScriptHash added in v0.0.2

func (p *Payment) ConfidentialWitnessScriptHash() (string, error)

ConfidentialWitnessScriptHash is a method of the Payment struct to derive a confidential blech32 p2wsh address

func (*Payment) PubKeyHash

func (p *Payment) PubKeyHash() (string, error)

PubKeyHash is a method of the Payment struct to derive a base58 p2pkh address

func (*Payment) ScriptHash

func (p *Payment) ScriptHash() (string, error)

ScriptHash is a method of the Payment struct to derive a base58 p2sh address

func (*Payment) TaprootAddress added in v0.4.0

func (p *Payment) TaprootAddress() (string, error)

TaprootAddress derives the unconditional Taproot address from the payment data

func (*Payment) WitnessPubKeyHash

func (p *Payment) WitnessPubKeyHash() (string, error)

WitnessPubKeyHash is a method of the Payment struct to derive a base58 p2wpkh address

func (*Payment) WitnessScriptHash

func (p *Payment) WitnessScriptHash() (string, error)

WitnessScriptHash is a method of the Payment struct to derive a base58 p2wsh address

type TaprootPaymentData added in v0.4.0

type TaprootPaymentData struct {
	XOnlyTweakedKey    []byte
	XOnlyInternalKey   []byte
	RootScriptTreeHash *chainhash.Hash
	ScriptTree         *taproot.IndexedElementsTapScriptTree
}

TaprootPaymentData is included in Payment struct to store Taproot-related data

Jump to

Keyboard shortcuts

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