bitcoin

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package bitcoin provides BIP 37 partial merkle tree verification and thin wrappers around btcsuite/btcd for transaction and txoutproof parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeTxID

func ComputeTxID(rawTxHex string) (string, error)

ComputeTxID computes the txid from raw transaction hex (display order, handles segwit).

func DecodeTransaction

func DecodeTransaction(rawTxHex string) (*wire.MsgTx, error)

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

func ExtractOpReturn(rawTxHex string) (string, error)

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

func HashEqual(a, b *chainhash.Hash) bool

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

func ParseBlockHash(txoutproofHex string) (string, error)

ParseBlockHash decodes a txoutproof hex string and returns the block hash (display order).

Types

type MerkleResult

type MerkleResult struct {
	Valid        bool
	ComputedRoot *chainhash.Hash
	MatchedTxIDs []*chainhash.Hash
}

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.

Jump to

Keyboard shortcuts

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