diff --git a/btcutil/psbt/bip32.go b/btcutil/psbt/bip32.go index 6b22dc06..2fe6afa2 100644 --- a/btcutil/psbt/bip32.go +++ b/btcutil/psbt/bip32.go @@ -36,10 +36,10 @@ func (s Bip32Sorter) Less(i, j int) bool { return bytes.Compare(s[i].PubKey, s[j].PubKey) < 0 } -// readBip32Derivation deserializes a byte slice containing chunks of 4 byte +// ReadBip32Derivation deserializes a byte slice containing chunks of 4 byte // little endian encodings of uint32 values, the first of which is the // masterkeyfingerprint and the remainder of which are the derivation path. -func readBip32Derivation(path []byte) (uint32, []uint32, error) { +func ReadBip32Derivation(path []byte) (uint32, []uint32, error) { // BIP-0174 defines the derivation path being encoded as // "<32-bit uint> <32-bit uint>*" // with the asterisk meaning 0 to n times. Which in turn means that an diff --git a/btcutil/psbt/partial_input.go b/btcutil/psbt/partial_input.go index 7686c451..5128f1fc 100644 --- a/btcutil/psbt/partial_input.go +++ b/btcutil/psbt/partial_input.go @@ -174,7 +174,9 @@ func (pi *PInput) deserialize(r io.Reader) error { if !validatePubkey(keydata) { return ErrInvalidPsbtFormat } - master, derivationPath, err := readBip32Derivation(value) + master, derivationPath, err := ReadBip32Derivation( + value, + ) if err != nil { return err } @@ -322,7 +324,7 @@ func (pi *PInput) deserialize(r io.Reader) error { return ErrInvalidKeydata } - taprootDerivation, err := readTaprootBip32Derivation( + taprootDerivation, err := ReadTaprootBip32Derivation( keydata, value, ) if err != nil { @@ -538,7 +540,7 @@ func (pi *PInput) serialize(w io.Writer) error { ) }) for _, derivation := range pi.TaprootBip32Derivation { - value, err := serializeTaprootBip32Derivation( + value, err := SerializeTaprootBip32Derivation( derivation, ) if err != nil { diff --git a/btcutil/psbt/partial_output.go b/btcutil/psbt/partial_output.go index 33b5ff99..f0e90406 100644 --- a/btcutil/psbt/partial_output.go +++ b/btcutil/psbt/partial_output.go @@ -74,7 +74,9 @@ func (po *POutput) deserialize(r io.Reader) error { if !validatePubkey(keydata) { return ErrInvalidKeydata } - master, derivationPath, err := readBip32Derivation(value) + master, derivationPath, err := ReadBip32Derivation( + value, + ) if err != nil { return err } @@ -123,7 +125,7 @@ func (po *POutput) deserialize(r io.Reader) error { return ErrInvalidKeydata } - taprootDerivation, err := readTaprootBip32Derivation( + taprootDerivation, err := ReadTaprootBip32Derivation( keydata, value, ) if err != nil { @@ -211,7 +213,7 @@ func (po *POutput) serialize(w io.Writer) error { ) }) for _, derivation := range po.TaprootBip32Derivation { - value, err := serializeTaprootBip32Derivation( + value, err := SerializeTaprootBip32Derivation( derivation, ) if err != nil { diff --git a/btcutil/psbt/taproot.go b/btcutil/psbt/taproot.go index 4d0619ec..b9df860c 100644 --- a/btcutil/psbt/taproot.go +++ b/btcutil/psbt/taproot.go @@ -2,6 +2,7 @@ package psbt import ( "bytes" + "github.com/btcsuite/btcd/btcec/v2/schnorr" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" @@ -92,10 +93,10 @@ func (s *TaprootBip32Derivation) SortBefore(other *TaprootBip32Derivation) bool return bytes.Compare(s.XOnlyPubKey, other.XOnlyPubKey) < 0 } -// readTaprootBip32Derivation deserializes a byte slice containing the Taproot +// ReadTaprootBip32Derivation deserializes a byte slice containing the Taproot // BIP32 derivation info that consists of a list of leaf hashes as well as the // normal BIP32 derivation info. -func readTaprootBip32Derivation(xOnlyPubKey, +func ReadTaprootBip32Derivation(xOnlyPubKey, value []byte) (*TaprootBip32Derivation, error) { // The taproot key BIP 32 derivation path is defined as: @@ -141,7 +142,7 @@ func readTaprootBip32Derivation(xOnlyPubKey, } // Read the BIP32 derivation info. - fingerprint, path, err := readBip32Derivation(leftoverBuf.Bytes()) + fingerprint, path, err := ReadBip32Derivation(leftoverBuf.Bytes()) if err != nil { return nil, err } @@ -152,9 +153,9 @@ func readTaprootBip32Derivation(xOnlyPubKey, return &derivation, nil } -// serializeTaprootBip32Derivation serializes a TaprootBip32Derivation to its +// SerializeTaprootBip32Derivation serializes a TaprootBip32Derivation to its // raw byte representation. -func serializeTaprootBip32Derivation(d *TaprootBip32Derivation) ([]byte, +func SerializeTaprootBip32Derivation(d *TaprootBip32Derivation) ([]byte, error) { var buf bytes.Buffer