Documentation
¶
Overview ¶
Package bitcoin provides BIP 37 partial merkle tree verification and thin wrappers around btcsuite/btcd for transaction and txoutproof parsing.
Index ¶
- func ComputeTxID(rawTxHex string) (string, error)
- func DecodeTransaction(rawTxHex string) (*wire.MsgTx, error)
- func DecodeTxOutProof(txoutproofHex string) (*wire.MsgMerkleBlock, error)
- func ExtractOpReturn(rawTxHex string) (string, error)
- func HashEqual(a, b *chainhash.Hash) bool
- func ParseBlockHash(txoutproofHex string) (string, error)
- type MerkleResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeTxID ¶
ComputeTxID computes the txid from raw transaction hex (display order, handles segwit).
func DecodeTransaction ¶
DecodeTransaction decodes raw transaction hex into a wire.MsgTx.
func DecodeTxOutProof ¶
func DecodeTxOutProof(txoutproofHex string) (*wire.MsgMerkleBlock, error)
DecodeTxOutProof decodes a txoutproof hex string into a wire.MsgMerkleBlock.
func ExtractOpReturn ¶
ExtractOpReturn parses a raw transaction and returns the OP_RETURN data as hex.
Appendix E.19 of the whitepaper fixes the selection rule: the payload is the push data of the FIRST output whose script begins with 0x6a. Selection is therefore on the leading opcode alone, not on txscript.IsNullData, which additionally enforces a single push and the 80-byte MaxDataCarrierSize policy limit. Once that output is chosen the parse runs on it and nothing else — scanning past a malformed or oversized first OP_RETURN to a later, well-formed one would let a crafted transaction present a payload generation never emitted.
func HashEqual ¶ added in v0.12.0
HashEqual reports whether two Bitcoin hashes are equal, in constant time.
btcd's (*chainhash.Hash).IsEqual compares the underlying [32]byte with Go array equality, which lowers to runtime.memequal and short-circuits on the first differing byte. Appendix E.4 of the whitepaper makes every hash and digest comparison constant-time without qualification, so the CLI wraps btcd rather than forking it and applies one rule everywhere — including the CVE-2012-2459 duplicate check, where both operands are public and the uniformity is the point rather than a live side channel. Nil handling is identical to IsEqual.
func ParseBlockHash ¶
ParseBlockHash decodes a txoutproof hex string and returns the block hash (display order).
Types ¶
type MerkleResult ¶
MerkleResult holds the result of a partial merkle tree verification.
func VerifyPartialMerkleTree ¶
func VerifyPartialMerkleTree( hashes []*chainhash.Hash, flagBytes []byte, totalTxs uint32, expectedRoot *chainhash.Hash, ) MerkleResult
VerifyPartialMerkleTree verifies a Bitcoin BIP 37 partial merkle tree. Takes the hashes and raw flag bytes from wire.MsgMerkleBlock directly.