Documentation ¶
Overview ¶
Package payment is an abstract for working with all kind of addresses in Liquid network.
It can be used for the creation of p2pkh, p2ms, p2sh, non-native SegWit and native SegWit addresses.
It also provides support for confidential payments.
Index ¶
- func Hash160(buf []byte) []byte
- type Payment
- func FromPayment(payment *Payment) (*Payment, error)
- func FromPublicKey(pubkey *btcec.PublicKey, net *network.Network, blindingKey *btcec.PublicKey) *Payment
- func FromPublicKeys(pubkeys []*btcec.PublicKey, nrequired int, net *network.Network, ...) (*Payment, error)
- func FromScript(script []byte, net *network.Network, blindingKey *btcec.PublicKey) (*Payment, error)
- func (p *Payment) ConfidentialPubKeyHash() (string, error)
- func (p *Payment) ConfidentialScriptHash() (string, error)
- func (p *Payment) ConfidentialWitnessPubKeyHash() (string, error)
- func (p *Payment) ConfidentialWitnessScriptHash() (string, error)
- func (p *Payment) PubKeyHash() (string, error)
- func (p *Payment) ScriptHash() (string, error)
- func (p *Payment) WitnessPubKeyHash() (string, error)
- func (p *Payment) WitnessScriptHash() (string, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 }
Payment defines the structure that holds the information different addresses
func FromPayment ¶
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
package main import ( "encoding/hex" "fmt" "github.com/btcsuite/btcd/btcec" "github.com/yenkuanlee/go-elements/network" "github.com/yenkuanlee/go-elements/payment" ) const privateKeyHex = "1cc080a4cd371eafcad489a29664af6a7276b362fe783443ce036552482b971d" var privateKeyBytes, _ = hex.DecodeString(privateKeyHex) func main() { _, publicKey := btcec.PrivKeyFromBytes(btcec.S256(), 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
package main import ( "encoding/hex" "fmt" "github.com/btcsuite/btcd/btcec" "github.com/yenkuanlee/go-elements/network" "github.com/yenkuanlee/go-elements/payment" ) const privateKeyHex = "1cc080a4cd371eafcad489a29664af6a7276b362fe783443ce036552482b971d" var privateKeyBytes, _ = hex.DecodeString(privateKeyHex) func main() { _, publicKey := btcec.PrivKeyFromBytes(btcec.S256(), 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( script []byte, net *network.Network, blindingKey *btcec.PublicKey, ) (*Payment, error)
FromScript creates parses a script into a Payment struct
func (*Payment) ConfidentialPubKeyHash ¶
ConfidentialPubKeyHash is a method of the Payment struct to derive a base58 confidential p2pkh address
func (*Payment) ConfidentialScriptHash ¶
ConfidentialScriptHash is a method of the Payment struct to derive a base58 confidential p2sh address
func (*Payment) ConfidentialWitnessPubKeyHash ¶
ConfidentialWitnessPubKeyHash is a method of the Payment struct to derive a confidential blech32 p2wpkh address
func (*Payment) ConfidentialWitnessScriptHash ¶
ConfidentialWitnessScriptHash is a method of the Payment struct to derive a confidential blech32 p2wsh address
func (*Payment) PubKeyHash ¶
PubKeyHash is a method of the Payment struct to derive a base58 p2pkh address
func (*Payment) ScriptHash ¶
ScriptHash is a method of the Payment struct to derive a base58 p2sh address
func (*Payment) WitnessPubKeyHash ¶
WitnessPubKeyHash is a method of the Payment struct to derive a base58 p2wpkh address
func (*Payment) WitnessScriptHash ¶
WitnessScriptHash is a method of the Payment struct to derive a base58 p2wsh address