Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

alexandria_btc

Fully qualified path: alexandria_btc

Modules

address
bip322
bip340bip340 implementation
decoder
encoder
hash
keys
legacy_signature
taproot
types

Modules

Modules

address
bip322
bip340bip340 implementation
decoder
encoder
hash
keys
legacy_signature
taproot
types

address

Fully qualified path: alexandria_btc::address

Free functions

private_key_to_addressGenerates a Bitcoin address from a private key for the specified address type. This function derives the public key from the private key and generates…
public_key_to_addressGenerates a Bitcoin address from a public key for the specified address type and network. This is the primary address generation function that handles all Bitcoin address types…
pubkey_hash_to_addressGenerates a Bitcoin address from a public key hash for the specified address type and network. This function generates addresses for address types that can be derived directly from…
create_p2pkh_script_pubkeyCreates a P2PKH script_pubkey from a public key hash. Generates the standard P2PKH script: OP_DUP OP_HASH160 < pubkey_hash> OP_EQUALVERIFY OP_CHECKSIG…
create_p2sh_script_pubkeyCreates a P2SH script_pubkey from a script hash. Generates the standard P2SH script: OP_HASH160 < script_hash> OP_EQUAL…
create_p2wpkh_script_pubkeyCreates a P2WPKH script_pubkey from a public key hash. Generates the standard P2WPKH script: OP_0 < pubkey_hash>…
create_p2wsh_script_pubkeyCreates a P2WSH script_pubkey from a script hash. Generates the standard P2WSH script: OP_0 < script_hash>…
create_p2tr_script_pubkeyCreates a P2TR script_pubkey from an output key. Generates the standard P2TR script: OP_1 < output_key>…
validate_addressValidates a Bitcoin address format for the specified network. Performs basic format validation for both legacy (Base58Check) and SegWit (Bech32/Bech32m) address formats. Checks length, prefixes, and…
decode_addressDecodes a Bitcoin address from ByteArray to a BitcoinAddress type. This function decodes a Bitcoin address based on the specified address type,…

Free functions

Free functions

private_key_to_addressGenerates a Bitcoin address from a private key for the specified address type. This function derives the public key from the private key and generates…
public_key_to_addressGenerates a Bitcoin address from a public key for the specified address type and network. This is the primary address generation function that handles all Bitcoin address types…
pubkey_hash_to_addressGenerates a Bitcoin address from a public key hash for the specified address type and network. This function generates addresses for address types that can be derived directly from…
create_p2pkh_script_pubkeyCreates a P2PKH script_pubkey from a public key hash. Generates the standard P2PKH script: OP_DUP OP_HASH160 < pubkey_hash> OP_EQUALVERIFY OP_CHECKSIG…
create_p2sh_script_pubkeyCreates a P2SH script_pubkey from a script hash. Generates the standard P2SH script: OP_HASH160 < script_hash> OP_EQUAL…
create_p2wpkh_script_pubkeyCreates a P2WPKH script_pubkey from a public key hash. Generates the standard P2WPKH script: OP_0 < pubkey_hash>…
create_p2wsh_script_pubkeyCreates a P2WSH script_pubkey from a script hash. Generates the standard P2WSH script: OP_0 < script_hash>…
create_p2tr_script_pubkeyCreates a P2TR script_pubkey from an output key. Generates the standard P2TR script: OP_1 < output_key>…
validate_addressValidates a Bitcoin address format for the specified network. Performs basic format validation for both legacy (Base58Check) and SegWit (Bech32/Bech32m) address formats. Checks length, prefixes, and…
decode_addressDecodes a Bitcoin address from ByteArray to a BitcoinAddress type. This function decodes a Bitcoin address based on the specified address type,…

private_key_to_address

Generates a Bitcoin address from a private key for the specified address type.

This function derives the public key from the private key and generates the corresponding Bitcoin address based on the specified address type.

Arguments

  • private_key - The Bitcoin private key containing the key data, network, and compression flag
  • address_type - The type of Bitcoin address to generate (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)

Returns

  • BitcoinAddress - Complete address structure with encoded address, script, and metadata

Fully qualified path: alexandria_btc::address::private_key_to_address

pub fn private_key_to_address(
    private_key: BitcoinPrivateKey, address_type: BitcoinAddressType,
) -> BitcoinAddress

public_key_to_address

Generates a Bitcoin address from a public key for the specified address type and network.

This is the primary address generation function that handles all Bitcoin address types including legacy (P2PKH, P2SH) and SegWit (P2WPKH, P2WSH, P2TR) formats.

Arguments

  • public_key - The Bitcoin public key (x, y coordinates and compression flag)
  • address_type - The type of Bitcoin address to generate
  • network - The Bitcoin network (Mainnet, Testnet, or Regtest)

Returns

  • BitcoinAddress - Complete address structure including encoded address and script_pubkey

Fully qualified path: alexandria_btc::address::public_key_to_address

pub fn public_key_to_address(
    public_key: BitcoinPublicKey, address_type: BitcoinAddressType, network: BitcoinNetwork,
) -> BitcoinAddress

pubkey_hash_to_address

Generates a Bitcoin address from a public key hash for the specified address type and network.

This function generates addresses for address types that can be derived directly from a public key hash: P2PKH, P2SH, and P2WPKH. For P2WSH and P2TR, use public_key_to_address instead as they require additional information beyond the pubkey hash.

Arguments

  • pubkey_hash - The 20-byte public key hash (HASH160 of public key)
  • address_type - The type of Bitcoin address to generate (P2PKH, P2SH, or P2WPKH)
  • network - The Bitcoin network (Mainnet, Testnet, or Regtest)

Returns

  • BitcoinAddress - Complete address structure including encoded address and script_pubkey

Panics

Panics if address_type is P2WSH or P2TR (use public_key_to_address for these types)

Fully qualified path: alexandria_btc::address::pubkey_hash_to_address

pub fn pubkey_hash_to_address(
    pubkey_hash: Array<u8>, address_type: BitcoinAddressType, network: BitcoinNetwork,
) -> BitcoinAddress

create_p2pkh_script_pubkey

Creates a P2PKH script_pubkey from a public key hash.

Generates the standard P2PKH script: OP_DUP OP_HASH160 <pubkey_hash> OP_EQUALVERIFY OP_CHECKSIG

Arguments

  • pubkey_hash - The 20-byte public key hash

Returns

  • ByteArray - The script_pubkey as a ByteArray

Fully qualified path: alexandria_btc::address::create_p2pkh_script_pubkey

pub fn create_p2pkh_script_pubkey(pubkey_hash: Array<u8>) -> ByteArray

create_p2sh_script_pubkey

Creates a P2SH script_pubkey from a script hash.

Generates the standard P2SH script: OP_HASH160 <script_hash> OP_EQUAL

Arguments

  • script_hash - The 20-byte script hash

Returns

  • ByteArray - The script_pubkey as a ByteArray

Fully qualified path: alexandria_btc::address::create_p2sh_script_pubkey

pub fn create_p2sh_script_pubkey(script_hash: Array<u8>) -> ByteArray

create_p2wpkh_script_pubkey

Creates a P2WPKH script_pubkey from a public key hash.

Generates the standard P2WPKH script: OP_0 <pubkey_hash>

Arguments

  • pubkey_hash - The 20-byte public key hash

Returns

  • ByteArray - The script_pubkey as a ByteArray

Fully qualified path: alexandria_btc::address::create_p2wpkh_script_pubkey

pub fn create_p2wpkh_script_pubkey(pubkey_hash: Array<u8>) -> ByteArray

create_p2wsh_script_pubkey

Creates a P2WSH script_pubkey from a script hash.

Generates the standard P2WSH script: OP_0 <script_hash>

Arguments

  • script_hash - The 32-byte script hash

Returns

  • ByteArray - The script_pubkey as a ByteArray

Fully qualified path: alexandria_btc::address::create_p2wsh_script_pubkey

pub fn create_p2wsh_script_pubkey(script_hash: Array<u8>) -> ByteArray

create_p2tr_script_pubkey

Creates a P2TR script_pubkey from an output key.

Generates the standard P2TR script: OP_1 <output_key>

Arguments

  • output_key - The 32-byte Taproot output key

Returns

  • ByteArray - The script_pubkey as a ByteArray

Fully qualified path: alexandria_btc::address::create_p2tr_script_pubkey

pub fn create_p2tr_script_pubkey(output_key: Array<u8>) -> ByteArray

validate_address

Validates a Bitcoin address format for the specified network.

Performs basic format validation for both legacy (Base58Check) and SegWit (Bech32/Bech32m) address formats. Checks length, prefixes, and basic structural requirements.

Arguments

  • address - The Bitcoin address string to validate
  • network - The expected Bitcoin network

Returns

  • bool - True if the address format appears valid, false otherwise

Fully qualified path: alexandria_btc::address::validate_address

pub fn validate_address(address: ByteArray, network: BitcoinNetwork) -> bool

decode_address

Decodes a Bitcoin address from ByteArray to a BitcoinAddress type.

This function decodes a Bitcoin address based on the specified address type, validates the checksum, and returns a complete BitcoinAddress structure.

Arguments

  • address - The Bitcoin address as a ByteArray
  • address_type - The type of Bitcoin address to decode

Returns

  • BitcoinAddress - Complete address structure with decoded data and script_pubkey

Fully qualified path: alexandria_btc::address::decode_address

pub fn decode_address(address: ByteArray, address_type: BitcoinAddressType) -> BitcoinAddress

bip322

Fully qualified path: alexandria_btc::bip322

Free functions

Enums

Free functions

Free functions

build_to_spend_tx

Fully qualified path: alexandria_btc::bip322::build_to_spend_tx

pub fn build_to_spend_tx(message: @ByteArray, script_pubkey: @ByteArray) -> BitcoinTransaction

build_to_sign_tx

Fully qualified path: alexandria_btc::bip322::build_to_sign_tx

pub fn build_to_sign_tx(
    to_spend_tx_id: ByteArray, script_pubkey: ByteArray, is_segwit: bool,
) -> BitcoinTransaction

tweak_public_key

Fully qualified path: alexandria_btc::bip322::tweak_public_key

pub fn tweak_public_key(internal_key: u256) -> u256

bip322_msg_hash_p2tr_with_type

Fully qualified path: alexandria_btc::bip322::bip322_msg_hash_p2tr_with_type

pub fn bip322_msg_hash_p2tr_with_type(
    sighash_type: SighashType, pub_key: u256, message: ByteArray,
) -> ByteArray

bip322_msg_hash_p2tr

Fully qualified path: alexandria_btc::bip322::bip322_msg_hash_p2tr

pub fn bip322_msg_hash_p2tr(pub_key: u256, message: ByteArray) -> ByteArray

bip322_msg_hash_p2wpkh_with_type

Fully qualified path: alexandria_btc::bip322::bip322_msg_hash_p2wpkh_with_type

pub fn bip322_msg_hash_p2wpkh_with_type(
    sighash_type: SighashType, public_key: BitcoinPublicKey, message: ByteArray,
) -> ByteArray

bip322_msg_hash_p2wpkh

Fully qualified path: alexandria_btc::bip322::bip322_msg_hash_p2wpkh

pub fn bip322_msg_hash_p2wpkh(public_key: BitcoinPublicKey, message: ByteArray) -> ByteArray

Enums

Enums

SighashType

Fully qualified path: alexandria_btc::bip322::SighashType

pub enum SighashType {
    DEFAULT,
    ALL,
}

Variants

DEFAULT

Fully qualified path: alexandria_btc::bip322::SighashType::DEFAULT

DEFAULT

ALL

Fully qualified path: alexandria_btc::bip322::SighashType::ALL

ALL

bip340

bip340 implementation

Fully qualified path: alexandria_btc::bip340

Free functions

verifyVerifies a signature according to the BIP-340. This function checks if the signature (rx, s) is valid for a message m with respect to the public key px ….
verify_signatureVerifies a signature according to the BIP-340 using Signature struct. This function checks if the signature is valid for a message m with respect to the public key px ….

Free functions

Free functions

verifyVerifies a signature according to the BIP-340. This function checks if the signature (rx, s) is valid for a message m with respect to the public key px ….
verify_signatureVerifies a signature according to the BIP-340 using Signature struct. This function checks if the signature is valid for a message m with respect to the public key px ….

verify

Verifies a signature according to the BIP-340.

This function checks if the signature (rx, s) is valid for a message m with respect to the public key px.

Arguments

  • px: u256 - The x-coordinate of the public key.
  • rx: u256 - The x-coordinate of the R point from the signature.
  • s: u256 - The scalar component of the signature.
  • m: ByteArray - The message for which the signature is being verified.

Returns

  • bool - true if the signature is verified for the message and public key, false otherwise.

Fully qualified path: alexandria_btc::bip340::verify

pub fn verify(px: u256, rx: u256, s: u256, m: ByteArray) -> bool

verify_signature

Verifies a signature according to the BIP-340 using Signature struct.

This function checks if the signature is valid for a message m with respect to the public key px.

Arguments

  • px: u256 - The x-coordinate of the public key.
  • sig: Signature - The signature containing r, s, and y_parity.
  • m: ByteArray - The message for which the signature is being verified.

Returns

  • bool - true if the signature is verified for the message and public key, false otherwise.

Fully qualified path: alexandria_btc::bip340::verify_signature

pub fn verify_signature(px: u256, sig: Signature, m: ByteArray) -> bool

decoder

Fully qualified path: alexandria_btc::decoder

Traits

TransactionDecoderTraitBitcoin transaction decoder trait providing methods to decode raw Bitcoin transaction data. This trait implements the complete Bitcoin transaction format decoder, supporting both…

Impls

TransactionDecoderImplImplementation of the Bitcoin transaction decoder trait. Provides concrete implementations for all Bitcoin transaction decoding operations,…

Traits

Traits

TransactionDecoderTraitBitcoin transaction decoder trait providing methods to decode raw Bitcoin transaction data. This trait implements the complete Bitcoin transaction format decoder, supporting both…

TransactionDecoderTrait

Bitcoin transaction decoder trait providing methods to decode raw Bitcoin transaction data.

This trait implements the complete Bitcoin transaction format decoder, supporting both legacy and SegWit transaction formats according to BIP 141. It handles variable-length encoding (compact size), little-endian integer decoding, and proper transaction structure parsing.

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait

pub trait TransactionDecoderTrait

Trait functions

new

Creates a new Bitcoin transaction decoder from raw transaction data.

Arguments

  • data - Raw Bitcoin transaction data as a ByteArray

Returns

  • BTCDecoder - Initialized decoder context with offset set to 0

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::new

fn new(data: ByteArray) -> BTCDecoder

decode_transaction

Decodes a complete Bitcoin transaction from the current decoder context.

Parses the entire transaction structure including version, inputs, outputs, witness data (if SegWit), and locktime. Automatically detects SegWit transactions by checking for the marker (0x00) and flag (0x01) bytes.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • BitcoinTransaction - Complete decoded transaction structure

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::decode_transaction

fn decode_transaction(ref self: BTCDecoder) -> BitcoinTransaction

decode_input

Decodes a single Bitcoin transaction input from the current position.

Parses input structure: previous TXID (32 bytes), previous output index, script signature with compact size length prefix, and sequence number.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • TransactionInput - Decoded input with all fields populated

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::decode_input

fn decode_input(ref self: BTCDecoder) -> TransactionInput

decode_output

Decodes a single Bitcoin transaction output from the current position.

Parses output structure: value (8 bytes, little-endian) and script public key with compact size length prefix.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • TransactionOutput - Decoded output with value and script

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::decode_output

fn decode_output(ref self: BTCDecoder) -> TransactionOutput

decode_witness

Decodes SegWit witness data for a single input.

Parses witness stack structure: witness item count (compact size) followed by each witness item with its length prefix and data.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • TransactionWitness - Decoded witness data with all stack items

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::decode_witness

fn decode_witness(ref self: BTCDecoder) -> TransactionWitness

read_compact_size

Reads a Bitcoin compact size integer (variable-length encoding).

Implements Bitcoin’s compact size encoding:

  • < 0xfd: 1 byte value
  • 0xfd: 3 bytes (1 + 2 little-endian)
  • 0xfe: 5 bytes (1 + 4 little-endian)
  • 0xff: 9 bytes (1 + 8 little-endian)

Arguments

  • self - Mutable reference to the decoder context

Returns

  • u64 - The decoded integer value

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::read_compact_size

fn read_compact_size(ref self: BTCDecoder) -> u64

read_u8

Reads a single byte from the current position.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • u8 - The byte value at the current position

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::read_u8

fn read_u8(ref self: BTCDecoder) -> u8

read_u32_le

Reads 4 bytes as a little-endian unsigned 32-bit integer.

####### Arguments

  • self - Mutable reference to the decoder context

####### Returns

  • u32 - The decoded little-endian u32 value

Panics

Panics with ‘Not enough bytes for u32’ if fewer than 4 bytes remain.

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::read_u32_le

fn read_u32_le(ref self: BTCDecoder) -> u32

read_u64_le

Reads 8 bytes as a little-endian unsigned 64-bit integer.

####### Arguments

  • self - Mutable reference to the decoder context

####### Returns

  • u64 - The decoded little-endian u64 value
Panics

Panics with ‘Not enough bytes for u64’ if fewer than 8 bytes remain.

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::read_u64_le

fn read_u64_le(ref self: BTCDecoder) -> u64

remaining

Checks if there are sufficient bytes remaining to read from the specified offset.

####### Arguments

  • self - Reference to the decoder context
  • offset - The offset position to check from
  • count - Number of bytes needed

####### Returns

  • bool - True if sufficient bytes remain, false otherwise

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::remaining

fn remaining(self: @BTCDecoder, offset: u32, count: u32) -> bool

Impls

Impls

TransactionDecoderImplImplementation of the Bitcoin transaction decoder trait. Provides concrete implementations for all Bitcoin transaction decoding operations,…

TransactionDecoderImpl

Implementation of the Bitcoin transaction decoder trait.

Provides concrete implementations for all Bitcoin transaction decoding operations, including support for both legacy and SegWit transaction formats.

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl

pub impl TransactionDecoderImpl of TransactionDecoderTrait;

Impl functions

new

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::new

fn new(data: ByteArray) -> BTCDecoder

decode_transaction

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::decode_transaction

fn decode_transaction(ref self: BTCDecoder) -> BitcoinTransaction

decode_input

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::decode_input

fn decode_input(ref self: BTCDecoder) -> TransactionInput

decode_output

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::decode_output

fn decode_output(ref self: BTCDecoder) -> TransactionOutput

decode_witness

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::decode_witness

fn decode_witness(ref self: BTCDecoder) -> TransactionWitness

read_compact_size

Read Bitcoin compact size (variable length integer)

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::read_compact_size

fn read_compact_size(ref self: BTCDecoder) -> u64

read_u8

Read a single byte

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::read_u8

fn read_u8(ref self: BTCDecoder) -> u8

read_u32_le

Read 4 bytes as little-endian u32

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::read_u32_le

fn read_u32_le(ref self: BTCDecoder) -> u32

read_u64_le

Read 8 bytes as little-endian u64

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::read_u64_le

fn read_u64_le(ref self: BTCDecoder) -> u64

remaining

Check if there are enough remaining bytes to read

Fully qualified path: alexandria_btc::decoder::TransactionDecoderImpl::remaining

fn remaining(self: @BTCDecoder, offset: u32, count: u32) -> bool

encoder

Fully qualified path: alexandria_btc::encoder

Traits

TransactionEncoderTraitBitcoin transaction encoder trait providing methods to encode transaction data to raw bytes. This trait implements the complete Bitcoin transaction format encoder, supporting both…

Impls

TransactionEncoderImplImplementation of the Bitcoin transaction encoder trait. Provides concrete implementations for all Bitcoin transaction encoding operations,…

Traits

Traits

TransactionEncoderTraitBitcoin transaction encoder trait providing methods to encode transaction data to raw bytes. This trait implements the complete Bitcoin transaction format encoder, supporting both…

TransactionEncoderTrait

Bitcoin transaction encoder trait providing methods to encode transaction data to raw bytes.

This trait implements the complete Bitcoin transaction format encoder, supporting both legacy and SegWit transaction formats according to BIP 141. It handles variable-length encoding (compact size), little-endian integer encoding, and proper transaction structure serialization.

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait

pub trait TransactionEncoderTrait

Trait functions

new

Creates a new Bitcoin transaction encoder with an empty ByteArray.

Returns

  • BTCEncoder - Initialized encoder context with empty data buffer

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::new

fn new() -> BTCEncoder

encode_transaction

Encodes a complete Bitcoin transaction to raw bytes.

Serializes the entire transaction structure including version, inputs, outputs, witness data (if SegWit), and locktime. Automatically includes SegWit marker (0x00) and flag (0x01) bytes for SegWit transactions.

Arguments

  • self - Mutable reference to the encoder context
  • transaction - Complete Bitcoin transaction structure to encode

Returns

  • ByteArray - Raw transaction bytes ready for broadcast

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::encode_transaction

fn encode_transaction(ref self: BTCEncoder, transaction: BitcoinTransaction) -> ByteArray

encode_input

Encodes a single Bitcoin transaction input to the current position.

Serializes input structure: previous TXID (32 bytes), previous output index, script signature with compact size length prefix, and sequence number.

Arguments

  • self - Mutable reference to the encoder context
  • input - Transaction input to encode

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::encode_input

fn encode_input(ref self: BTCEncoder, input: TransactionInput)

encode_output

Encodes a single Bitcoin transaction output to the current position.

Serializes output structure: value (8 bytes, little-endian) and script public key with compact size length prefix.

Arguments

  • self - Mutable reference to the encoder context
  • output - Transaction output to encode

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::encode_output

fn encode_output(ref self: BTCEncoder, output: TransactionOutput)

encode_witness

Encodes SegWit witness data for a single input.

Serializes witness stack structure: witness item count (compact size) followed by each witness item with its length prefix and data.

Arguments

  • self - Mutable reference to the encoder context
  • witness - Witness data to encode

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::encode_witness

fn encode_witness(ref self: BTCEncoder, witness: TransactionWitness)

write_compact_size

Writes a Bitcoin compact size integer (variable-length encoding).

Implements Bitcoin’s compact size encoding:

  • < 0xfd: 1 byte value
  • 0xfd: 3 bytes (1 + 2 little-endian)
  • 0xfe: 5 bytes (1 + 4 little-endian)
  • 0xff: 9 bytes (1 + 8 little-endian)

Arguments

  • self - Mutable reference to the encoder context
  • value - The integer value to encode

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::write_compact_size

fn write_compact_size(ref self: BTCEncoder, value: u64)

write_u8

Writes a single byte to the current position.

Arguments

  • self - Mutable reference to the encoder context
  • value - The byte value to write

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::write_u8

fn write_u8(ref self: BTCEncoder, value: u8)

write_u32_le

Writes a 32-bit unsigned integer as little-endian bytes.

Arguments

  • self - Mutable reference to the encoder context
  • value - The u32 value to encode

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::write_u32_le

fn write_u32_le(ref self: BTCEncoder, value: u32)

write_u64_le

Writes a 64-bit unsigned integer as little-endian bytes.

Arguments

  • self - Mutable reference to the encoder context
  • value - The u64 value to encode

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::write_u64_le

fn write_u64_le(ref self: BTCEncoder, value: u64)

write_bytes

Writes raw bytes to the current position.

Arguments

  • self - Mutable reference to the encoder context
  • bytes - The ByteArray to append

Fully qualified path: alexandria_btc::encoder::TransactionEncoderTrait::write_bytes

fn write_bytes(ref self: BTCEncoder, bytes: ByteArray)

Impls

Impls

TransactionEncoderImplImplementation of the Bitcoin transaction encoder trait. Provides concrete implementations for all Bitcoin transaction encoding operations,…

TransactionEncoderImpl

Implementation of the Bitcoin transaction encoder trait.

Provides concrete implementations for all Bitcoin transaction encoding operations, including support for both legacy and SegWit transaction formats.

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl

pub impl TransactionEncoderImpl of TransactionEncoderTrait;

Impl functions

new

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::new

fn new() -> BTCEncoder

encode_transaction

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::encode_transaction

fn encode_transaction(ref self: BTCEncoder, transaction: BitcoinTransaction) -> ByteArray

encode_input

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::encode_input

fn encode_input(ref self: BTCEncoder, input: TransactionInput)

encode_output

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::encode_output

fn encode_output(ref self: BTCEncoder, output: TransactionOutput)

encode_witness

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::encode_witness

fn encode_witness(ref self: BTCEncoder, witness: TransactionWitness)

write_compact_size

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::write_compact_size

fn write_compact_size(ref self: BTCEncoder, value: u64)

write_u8

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::write_u8

fn write_u8(ref self: BTCEncoder, value: u8)

write_u32_le

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::write_u32_le

fn write_u32_le(ref self: BTCEncoder, value: u32)

write_u64_le

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::write_u64_le

fn write_u64_le(ref self: BTCEncoder, value: u64)

write_bytes

Fully qualified path: alexandria_btc::encoder::TransactionEncoderImpl::write_bytes

fn write_bytes(ref self: BTCEncoder, bytes: ByteArray)

hash

Fully qualified path: alexandria_btc::hash

Free functions

hash160Computes Bitcoin Hash160 (RIPEMD160(SHA256(data))) from input data. Implements the standard Bitcoin Hash160 function used for address generation…
hash256Computes Bitcoin Hash256 (SHA256(SHA256(data))) from input data. Implements the Bitcoin double SHA256 function used for transaction IDs,…
sha256Computes a single SHA256 hash from input data. Provides a wrapper around the core SHA256 implementation to convert between different data formats and produce byte array output….
checksumCalculates a 4-byte checksum for Base58Check encoding. Computes Hash256 of the input data and returns the first 4 bytes as a checksum for Base58Check encoding used in legacy Bitcoin addresses….
hash160_from_byte_arrayComputes Bitcoin Hash160 directly from ByteArray input. Optimized version of hash160 that works directly with ByteArray data without requiring conversion to Span first….
sha256_from_byte_arrayComputes SHA256 hash directly from ByteArray input. Optimized version of sha256 that works directly with ByteArray data without requiring conversion to Span first….
sha256_byte_arrayComputes SHA256 hash directly from ByteArray input to ByteArray output. Optimized version of sha256 that works directly with ByteArray data without requiring last conversion to ByteArray….
sha256_u256Computes SHA256 hash directly from ByteArray input to u256 output. Optimized version of sha256 that works directly with ByteArray data without requiring last conversion to u256….
hash256_from_byte_arrayComputes Bitcoin Hash256 (double SHA256) directly from ByteArray input. Optimized version of hash256 that works directly with ByteArray data without requiring conversion to Span first….

Free functions

Free functions

hash160Computes Bitcoin Hash160 (RIPEMD160(SHA256(data))) from input data. Implements the standard Bitcoin Hash160 function used for address generation…
hash256Computes Bitcoin Hash256 (SHA256(SHA256(data))) from input data. Implements the Bitcoin double SHA256 function used for transaction IDs,…
sha256Computes a single SHA256 hash from input data. Provides a wrapper around the core SHA256 implementation to convert between different data formats and produce byte array output….
checksumCalculates a 4-byte checksum for Base58Check encoding. Computes Hash256 of the input data and returns the first 4 bytes as a checksum for Base58Check encoding used in legacy Bitcoin addresses….
hash160_from_byte_arrayComputes Bitcoin Hash160 directly from ByteArray input. Optimized version of hash160 that works directly with ByteArray data without requiring conversion to Span first….
sha256_from_byte_arrayComputes SHA256 hash directly from ByteArray input. Optimized version of sha256 that works directly with ByteArray data without requiring conversion to Span first….
sha256_byte_arrayComputes SHA256 hash directly from ByteArray input to ByteArray output. Optimized version of sha256 that works directly with ByteArray data without requiring last conversion to ByteArray….
sha256_u256Computes SHA256 hash directly from ByteArray input to u256 output. Optimized version of sha256 that works directly with ByteArray data without requiring last conversion to u256….
hash256_from_byte_arrayComputes Bitcoin Hash256 (double SHA256) directly from ByteArray input. Optimized version of hash256 that works directly with ByteArray data without requiring conversion to Span first….

hash160

Computes Bitcoin Hash160 (RIPEMD160(SHA256(data))) from input data.

Implements the standard Bitcoin Hash160 function used for address generation and script operations. Applies SHA256 followed by RIPEMD160 to produce a 20-byte hash output.

Arguments

  • data - Input data to hash as a span of bytes

Returns

  • Array<u8> - 20-byte Hash160 result

Fully qualified path: alexandria_btc::hash::hash160

pub fn hash160(data: Span<u8>) -> Array<u8>

hash256

Computes Bitcoin Hash256 (SHA256(SHA256(data))) from input data.

Implements the Bitcoin double SHA256 function used for transaction IDs, block hashes, and Base58Check checksums. Applies SHA256 twice for additional security.

Arguments

  • data - Input data to hash as a span of bytes

Returns

  • Array<u8> - 32-byte Hash256 result

Fully qualified path: alexandria_btc::hash::hash256

pub fn hash256(data: Span<u8>) -> Array<u8>

sha256

Computes a single SHA256 hash from input data.

Provides a wrapper around the core SHA256 implementation to convert between different data formats and produce byte array output.

Arguments

  • data - Input data to hash as a span of bytes

Returns

  • Array<u8> - 32-byte SHA256 hash result

Fully qualified path: alexandria_btc::hash::sha256

pub fn sha256(data: Span<u8>) -> Array<u8>

checksum

Calculates a 4-byte checksum for Base58Check encoding.

Computes Hash256 of the input data and returns the first 4 bytes as a checksum for Base58Check encoding used in legacy Bitcoin addresses.

Arguments

  • data - Input data (version byte + payload) to calculate checksum for

Returns

  • Array<u8> - 4-byte checksum

Fully qualified path: alexandria_btc::hash::checksum

pub fn checksum(data: Span<u8>) -> Array<u8>

hash160_from_byte_array

Computes Bitcoin Hash160 directly from ByteArray input.

Optimized version of hash160 that works directly with ByteArray data without requiring conversion to Span first.

Arguments

  • data - Input data as a ByteArray reference

Returns

  • Array<u8> - 20-byte Hash160 result

Fully qualified path: alexandria_btc::hash::hash160_from_byte_array

pub fn hash160_from_byte_array(data: @ByteArray) -> Array<u8>

sha256_from_byte_array

Computes SHA256 hash directly from ByteArray input.

Optimized version of sha256 that works directly with ByteArray data without requiring conversion to Span first.

Arguments

  • data - Input data as a ByteArray reference

Returns

  • Array<u8> - 32-byte SHA256 hash result

Fully qualified path: alexandria_btc::hash::sha256_from_byte_array

pub fn sha256_from_byte_array(data: @ByteArray) -> Array<u8>

sha256_byte_array

Computes SHA256 hash directly from ByteArray input to ByteArray output.

Optimized version of sha256 that works directly with ByteArray data without requiring last conversion to ByteArray.

Arguments

  • data - Input data as a ByteArray reference

Returns

  • ByteArray - 32-byte SHA256 hash result

Usage

Efficient SHA256 computation when working with ByteArray outputs.

Fully qualified path: alexandria_btc::hash::sha256_byte_array

pub fn sha256_byte_array(data: @ByteArray) -> ByteArray

sha256_u256

Computes SHA256 hash directly from ByteArray input to u256 output.

Optimized version of sha256 that works directly with ByteArray data without requiring last conversion to u256.

Arguments

  • data - Input data as a ByteArray reference

Returns

  • u256 - 32-byte SHA256 hash result

Usage

Efficient SHA256 computation when working with u256 outputs.

Fully qualified path: alexandria_btc::hash::sha256_u256

pub fn sha256_u256(data: @ByteArray) -> u256

hash256_from_byte_array

Computes Bitcoin Hash256 (double SHA256) directly from ByteArray input.

Optimized version of hash256 that works directly with ByteArray data without requiring conversion to Span first.

Arguments

  • data - Input data as a ByteArray reference

Returns

  • Array<u8> - 32-byte Hash256 result

Fully qualified path: alexandria_btc::hash::hash256_from_byte_array

pub fn hash256_from_byte_array(data: @ByteArray) -> Array<u8>

keys

Fully qualified path: alexandria_btc::keys

Free functions

private_key_to_public_keyGenerates a Bitcoin public key from a private key using secp256k1 elliptic curve operations. Performs elliptic curve point multiplication (private_key * G) where G is the…
public_key_to_bytesSerializes a Bitcoin public key to its byte representation. Converts a public key to either compressed (33 bytes) or uncompressed (65 bytes) format according to SEC 1 standard:…
public_key_hashGenerates a Bitcoin public key hash using Hash160 (RIPEMD160 of SHA256). Computes the standard Bitcoin public key hash by serializing the public key…
create_private_keyCreates a Bitcoin private key from a u256 value with validation. Validates that the provided key value is within the secp256k1 curve order…
generate_private_keyGenerates a random Bitcoin private key (placeholder implementation). Creates a private key using a deterministic value for testing purposes….

Free functions

Free functions

private_key_to_public_keyGenerates a Bitcoin public key from a private key using secp256k1 elliptic curve operations. Performs elliptic curve point multiplication (private_key * G) where G is the…
public_key_to_bytesSerializes a Bitcoin public key to its byte representation. Converts a public key to either compressed (33 bytes) or uncompressed (65 bytes) format according to SEC 1 standard:…
public_key_hashGenerates a Bitcoin public key hash using Hash160 (RIPEMD160 of SHA256). Computes the standard Bitcoin public key hash by serializing the public key…
create_private_keyCreates a Bitcoin private key from a u256 value with validation. Validates that the provided key value is within the secp256k1 curve order…
generate_private_keyGenerates a random Bitcoin private key (placeholder implementation). Creates a private key using a deterministic value for testing purposes….

private_key_to_public_key

Generates a Bitcoin public key from a private key using secp256k1 elliptic curve operations.

Performs elliptic curve point multiplication (private_key * G) where G is the secp256k1 generator point to derive the corresponding public key coordinates.

Arguments

  • private_key - The Bitcoin private key containing the scalar value and compression flag

Returns

  • BitcoinPublicKey - Public key with x,y coordinates and compression setting

Fully qualified path: alexandria_btc::keys::private_key_to_public_key

pub fn private_key_to_public_key(private_key: BitcoinPrivateKey) -> BitcoinPublicKey

public_key_to_bytes

Serializes a Bitcoin public key to its byte representation.

Converts a public key to either compressed (33 bytes) or uncompressed (65 bytes) format according to SEC 1 standard:

  • Compressed: 0x02/0x03 prefix + x-coordinate (33 bytes)
  • Uncompressed: 0x04 prefix + x-coordinate + y-coordinate (65 bytes)

Arguments

  • public_key - The Bitcoin public key to serialize

Returns

  • Array<u8> - Serialized public key bytes (33 or 65 bytes)

Fully qualified path: alexandria_btc::keys::public_key_to_bytes

pub fn public_key_to_bytes(public_key: BitcoinPublicKey) -> Array<u8>

public_key_hash

Generates a Bitcoin public key hash using Hash160 (RIPEMD160 of SHA256).

Computes the standard Bitcoin public key hash by serializing the public key and applying the Hash160 function (RIPEMD160(SHA256(pubkey))).

Arguments

  • public_key - The Bitcoin public key to hash

Returns

  • Array<u8> - 20-byte public key hash

Fully qualified path: alexandria_btc::keys::public_key_hash

pub fn public_key_hash(public_key: BitcoinPublicKey) -> Array<u8>

create_private_key

Creates a Bitcoin private key from a u256 value with validation.

Validates that the provided key value is within the secp256k1 curve order and creates a properly formatted Bitcoin private key structure.

Arguments

  • key - The private key scalar value (must be 1 < key < curve_order)
  • network - The Bitcoin network this key will be used on
  • compressed - Whether the corresponding public key should use compressed format

Returns

  • BitcoinPrivateKey - Validated private key structure

Panics

Panics if key is zero or exceeds the secp256k1 curve order.

Fully qualified path: alexandria_btc::keys::create_private_key

pub fn create_private_key(key: u256, network: BitcoinNetwork, compressed: bool) -> BitcoinPrivateKey

generate_private_key

Generates a random Bitcoin private key (placeholder implementation).

Creates a private key using a deterministic value for testing purposes. In production, this should use a cryptographically secure random number generator.

Arguments

  • network - The Bitcoin network for the private key
  • compressed - Whether the corresponding public key should use compressed format

Returns

  • BitcoinPrivateKey - Generated private key structure

Security Note

This implementation is NOT cryptographically secure and should only be used for testing. Production implementations must use proper random number generation.

Fully qualified path: alexandria_btc::keys::generate_private_key

pub fn generate_private_key(network: BitcoinNetwork, compressed: bool) -> BitcoinPrivateKey

legacy_signature

Fully qualified path: alexandria_btc::legacy_signature

Constants

SIGHASH_ALLSIGHASH types for Bitcoin transaction signing
SIGHASH_NONE
SIGHASH_SINGLE
SIGHASH_ANYONECANPAY

Free functions

create_signatureCreate a signature with known y_parity…
verify_ecdsa_signature_coordsVerify a Bitcoin ECDSA signature using Cairo’s built-in verification (legacy coords format) This function uses Cairo’s optimized ECDSA verification through public key recovery….
verify_ecdsa_signatureVerify a Bitcoin ECDSA signature This function works with the new ByteArray-based BitcoinPublicKey structure that properly represents Bitcoin’s 33-byte compressed or 65-byte uncompressed format….
verify_ecdsa_signature_auto_recoveryVerify a Bitcoin ECDSA signature with automatic y_parity detection This function tries both y_parity values (false and true) to find a match…
verify_der_signatureVerify a DER-encoded Bitcoin signature This function parses a DER-encoded signature and verifies it against the provided message hash and public key. Since DER signatures don’t…
parse_der_signatureParse DER-encoded signature using ByteArray utilities…
mod_inverseCalculate modular inverse using Fermat’s little theorem for prime modulus For secp256k1 curve order n (which is prime), we use Fermat’s little theorem:…
create_signature_hashCreate a signature hash for transaction signing using ByteArray…
verify_transaction_signatureVerify a signature against transaction data…

Constants

Constants

SIGHASH_ALLSIGHASH types for Bitcoin transaction signing
SIGHASH_NONE
SIGHASH_SINGLE
SIGHASH_ANYONECANPAY

SIGHASH_ALL

SIGHASH types for Bitcoin transaction signing

Fully qualified path: alexandria_btc::legacy_signature::SIGHASH_ALL

pub const SIGHASH_ALL: u8 = 1;

SIGHASH_NONE

Fully qualified path: alexandria_btc::legacy_signature::SIGHASH_NONE

pub const SIGHASH_NONE: u8 = 2;

SIGHASH_SINGLE

Fully qualified path: alexandria_btc::legacy_signature::SIGHASH_SINGLE

pub const SIGHASH_SINGLE: u8 = 3;

SIGHASH_ANYONECANPAY

Fully qualified path: alexandria_btc::legacy_signature::SIGHASH_ANYONECANPAY

pub const SIGHASH_ANYONECANPAY: u8 = 128;

Free functions

Free functions

create_signatureCreate a signature with known y_parity…
verify_ecdsa_signature_coordsVerify a Bitcoin ECDSA signature using Cairo’s built-in verification (legacy coords format) This function uses Cairo’s optimized ECDSA verification through public key recovery….
verify_ecdsa_signatureVerify a Bitcoin ECDSA signature This function works with the new ByteArray-based BitcoinPublicKey structure that properly represents Bitcoin’s 33-byte compressed or 65-byte uncompressed format….
verify_ecdsa_signature_auto_recoveryVerify a Bitcoin ECDSA signature with automatic y_parity detection This function tries both y_parity values (false and true) to find a match…
verify_der_signatureVerify a DER-encoded Bitcoin signature This function parses a DER-encoded signature and verifies it against the provided message hash and public key. Since DER signatures don’t…
parse_der_signatureParse DER-encoded signature using ByteArray utilities…
mod_inverseCalculate modular inverse using Fermat’s little theorem for prime modulus For secp256k1 curve order n (which is prime), we use Fermat’s little theorem:…
create_signature_hashCreate a signature hash for transaction signing using ByteArray…
verify_transaction_signatureVerify a signature against transaction data…

create_signature

Create a signature with known y_parity

Arguments

  • r - The r component of the signature
  • s - The s component of the signature
  • y_parity - Whether the y-coordinate of the R point is even (false) or odd (true)

Returns

  • Signature - The complete signature structure

Fully qualified path: alexandria_btc::legacy_signature::create_signature

pub fn create_signature(r: u256, s: u256, y_parity: bool) -> Signature

verify_ecdsa_signature_coords

Verify a Bitcoin ECDSA signature using Cairo’s built-in verification (legacy coords format)

This function uses Cairo’s optimized ECDSA verification through public key recovery. It validates the signature by recovering the public key from the signature and message, then comparing it with the expected public key.

Arguments

  • message_hash - The hash of the message that was signed (typically a transaction hash)
  • signature - The ECDSA signature (r, s components and y_parity for recovery)
  • public_key - The public key coordinates to verify against

Returns

  • bool - True if signature is valid, false otherwise

Fully qualified path: alexandria_btc::legacy_signature::verify_ecdsa_signature_coords

pub fn verify_ecdsa_signature_coords(
    message_hash: u256, signature: Signature, public_key: BitcoinPublicKeyCoords,
) -> bool

verify_ecdsa_signature

Verify a Bitcoin ECDSA signature

This function works with the new ByteArray-based BitcoinPublicKey structure that properly represents Bitcoin’s 33-byte compressed or 65-byte uncompressed format.

Arguments

  • message_hash - The hash of the message that was signed
  • signature - The ECDSA signature (r, s components and y_parity for recovery)
  • public_key - The BitcoinPublicKey to verify against

Returns

  • bool - True if signature is valid, false otherwise

Fully qualified path: alexandria_btc::legacy_signature::verify_ecdsa_signature

pub fn verify_ecdsa_signature(
    message_hash: u256, signature: Signature, public_key: BitcoinPublicKey,
) -> bool

verify_ecdsa_signature_auto_recovery

Verify a Bitcoin ECDSA signature with automatic y_parity detection

This function tries both y_parity values (false and true) to find a match with the provided public key. This is useful when the y_parity is unknown or when working with DER signatures that don’t include recovery information.

Arguments

  • message_hash - The hash of the message that was signed
  • r - The r component of the signature
  • s - The s component of the signature
  • public_key - The public key to verify against

Returns

  • bool - True if signature is valid with either y_parity value

Fully qualified path: alexandria_btc::legacy_signature::verify_ecdsa_signature_auto_recovery

pub fn verify_ecdsa_signature_auto_recovery(
    message_hash: u256, r: u256, s: u256, public_key: BitcoinPublicKey,
) -> bool

verify_der_signature

Verify a DER-encoded Bitcoin signature

This function parses a DER-encoded signature and verifies it against the provided message hash and public key. Since DER signatures don’t include recovery information, it automatically tries both y_parity values.

Arguments

  • message_hash - The hash of the message that was signed
  • der_signature - DER-encoded signature bytes
  • public_key - The public key to verify against

Returns

  • bool - True if the DER signature is valid

Fully qualified path: alexandria_btc::legacy_signature::verify_der_signature

pub fn verify_der_signature(
    message_hash: u256, der_signature: Span<u8>, public_key: BitcoinPublicKey,
) -> bool

parse_der_signature

Parse DER-encoded signature using ByteArray utilities

Arguments

  • der_bytes - DER-encoded signature bytes

Returns

  • Option<Signature> - Parsed signature or None if invalid

Fully qualified path: alexandria_btc::legacy_signature::parse_der_signature

pub fn parse_der_signature(der_bytes: Span<u8>) -> Option<Signature>

mod_inverse

Calculate modular inverse using Fermat’s little theorem for prime modulus

For secp256k1 curve order n (which is prime), we use Fermat’s little theorem: If p is prime and a ≢ 0 (mod p), then a^(-1) ≡ a^(p-2) (mod p)

Arguments

  • a - The value to find the modular inverse of
  • m - The modulus (should be prime)

Returns

  • u256 - The modular inverse a^(-1) mod m, or 0 if no inverse exists

Fully qualified path: alexandria_btc::legacy_signature::mod_inverse

pub fn mod_inverse(a: u256, m: u256) -> u256

create_signature_hash

Create a signature hash for transaction signing using ByteArray

Arguments

  • transaction_data - The transaction data to be signed
  • sighash_type - The type of signature hash (SIGHASH_ALL, etc.)

Returns

  • u256 - The hash to be signed

Fully qualified path: alexandria_btc::legacy_signature::create_signature_hash

pub fn create_signature_hash(transaction_data: Span<u8>, sighash_type: u8) -> u256

verify_transaction_signature

Verify a signature against transaction data

Arguments

  • transaction_data - The transaction data that was signed
  • signature - The ECDSA signature
  • public_key - The public key to verify against
  • sighash_type - The signature hash type used

Returns

  • bool - True if signature is valid for the transaction

Fully qualified path: alexandria_btc::legacy_signature::verify_transaction_signature

pub fn verify_transaction_signature(
    transaction_data: Span<u8>,
    signature: Signature,
    public_key: BitcoinPublicKey,
    sighash_type: u8,
) -> bool

taproot

Bitcoin Taproot (BIP-341) Implementation

This module provides Taproot functionality including key tweaking, script trees, and proper P2TR address generation using BIP-340 Schnorr signatures.

Fully qualified path: alexandria_btc::taproot

Free functions

tagged_hashCreate a tagged hash according to BIP-340 tagged hash specification…
tagged_hash_byte_arrayCreate a tagged hash from byte arrays according to BIP-340 tagged hash specification…
tagged_hash_u256Create a tagged hash from byte arrays according to BIP-340 tagged hash specification…
tweak_public_keyTweak a public key for Taproot according to BIP-341…
lift_x_coordinateLift an x-coordinate to a valid secp256k1 point…
u256_to_32_bytes_beConvert u256 to 32-byte array (big-endian)
create_script_treeCreate a Taproot script tree from a single script…
calculate_merkle_rootCalculate the Merkle root of a script tree…
verify_taproot_signatureVerify a BIP-340 Schnorr signature for Taproot…
create_key_path_outputGenerate a key-path only Taproot output…
create_script_path_outputGenerate a script-path Taproot output…

Structs

TweakedPublicKeyTaproot tweaked public key result
ScriptLeafScript tree leaf
TapTreeTaproot script tree (simplified - single leaf for now)

Free functions

Free functions

tagged_hashCreate a tagged hash according to BIP-340 tagged hash specification…
tagged_hash_byte_arrayCreate a tagged hash from byte arrays according to BIP-340 tagged hash specification…
tagged_hash_u256Create a tagged hash from byte arrays according to BIP-340 tagged hash specification…
tweak_public_keyTweak a public key for Taproot according to BIP-341…
lift_x_coordinateLift an x-coordinate to a valid secp256k1 point…
u256_to_32_bytes_beConvert u256 to 32-byte array (big-endian)
create_script_treeCreate a Taproot script tree from a single script…
calculate_merkle_rootCalculate the Merkle root of a script tree…
verify_taproot_signatureVerify a BIP-340 Schnorr signature for Taproot…
create_key_path_outputGenerate a key-path only Taproot output…
create_script_path_outputGenerate a script-path Taproot output…

tagged_hash

Create a tagged hash according to BIP-340 tagged hash specification

Arguments

  • tag - The tag string (e.g., “TapTweak”, “TapLeaf”)
  • data - The data to hash

Returns

  • Array<u8> - The tagged hash (32 bytes)

Fully qualified path: alexandria_btc::taproot::tagged_hash

pub fn tagged_hash(tag: ByteArray, data: Span<u8>) -> Array<u8>

tagged_hash_byte_array

Create a tagged hash from byte arrays according to BIP-340 tagged hash specification

Arguments

  • tag - The tag string (e.g., “TapTweak”, “TapLeaf”)
  • data - The byte array data to hash

Returns

  • ByteArray - The tagged hash as ByteArray array

Fully qualified path: alexandria_btc::taproot::tagged_hash_byte_array

pub fn tagged_hash_byte_array(tag: ByteArray, data: @ByteArray) -> ByteArray

tagged_hash_u256

Create a tagged hash from byte arrays according to BIP-340 tagged hash specification

Arguments

  • tag - The tag string (e.g., “TapTweak”, “TapLeaf”)
  • data - The byte array data to hash

Returns

  • u256 - The tagged hash as u256

Fully qualified path: alexandria_btc::taproot::tagged_hash_u256

pub fn tagged_hash_u256(tag: ByteArray, data: @ByteArray) -> u256

tweak_public_key

Tweak a public key for Taproot according to BIP-341

Arguments

  • internal_key - The internal public key (x-coordinate only)
  • merkle_root - Optional Merkle root of the script tree

Returns

  • TweakedPublicKey - The tweaked output key and parity

Fully qualified path: alexandria_btc::taproot::tweak_public_key

pub fn tweak_public_key(internal_key: u256, merkle_root: Option<u256>) -> Option<TweakedPublicKey>

lift_x_coordinate

Lift an x-coordinate to a valid secp256k1 point

Arguments

  • x - The x-coordinate

Returns

  • Option<Secp256k1Point> - The point if x is valid, None otherwise

Fully qualified path: alexandria_btc::taproot::lift_x_coordinate

pub fn lift_x_coordinate(x: u256) -> Option<Secp256k1Point>

u256_to_32_bytes_be

Convert u256 to 32-byte array (big-endian)

Fully qualified path: alexandria_btc::taproot::u256_to_32_bytes_be

pub fn u256_to_32_bytes_be(mut value: u256) -> Array<u8>

create_script_tree

Create a Taproot script tree from a single script

Arguments

  • script - The script bytes
  • leaf_version - The script version (usually 0xc0)

Returns

  • TapTree - The script tree

Fully qualified path: alexandria_btc::taproot::create_script_tree

pub fn create_script_tree(script: Array<u8>, leaf_version: u8) -> TapTree

calculate_merkle_root

Calculate the Merkle root of a script tree

Arguments

  • tree - The script tree

Returns

  • Option<u256> - The Merkle root if tree has scripts, None for key-path only

Fully qualified path: alexandria_btc::taproot::calculate_merkle_root

pub fn calculate_merkle_root(tree: @TapTree) -> Option<u256>

verify_taproot_signature

Verify a BIP-340 Schnorr signature for Taproot

Arguments

  • signature - The Schnorr signature (64 bytes: r || s)
  • message - The message that was signed
  • public_key - The tweaked public key (x-coordinate only)

Returns

  • bool - True if signature is valid

Fully qualified path: alexandria_btc::taproot::verify_taproot_signature

pub fn verify_taproot_signature(signature: Span<u8>, message: ByteArray, public_key: u256) -> bool

create_key_path_output

Generate a key-path only Taproot output

Arguments

  • internal_key - The internal public key

Returns

  • Option<TweakedPublicKey> - The tweaked key for key-path spending

Fully qualified path: alexandria_btc::taproot::create_key_path_output

pub fn create_key_path_output(internal_key: u256) -> Option<TweakedPublicKey>

create_script_path_output

Generate a script-path Taproot output

Arguments

  • internal_key - The internal public key
  • script_tree - The script tree

Returns

  • Option<TweakedPublicKey> - The tweaked key for script-path spending

Fully qualified path: alexandria_btc::taproot::create_script_path_output

pub fn create_script_path_output(
    internal_key: u256, script_tree: @TapTree,
) -> Option<TweakedPublicKey>

Structs

Structs

TweakedPublicKeyTaproot tweaked public key result
ScriptLeafScript tree leaf
TapTreeTaproot script tree (simplified - single leaf for now)

TweakedPublicKey

Taproot tweaked public key result

Fully qualified path: alexandria_btc::taproot::TweakedPublicKey

[derive(Drop, Copy)]
pub struct TweakedPublicKey {
    pub output_key: u256,
    pub parity: bool,
}

Members

output_key

Fully qualified path: alexandria_btc::taproot::TweakedPublicKey::output_key

pub output_key: u256

parity

Fully qualified path: alexandria_btc::taproot::TweakedPublicKey::parity

pub parity: bool

ScriptLeaf

Script tree leaf

Fully qualified path: alexandria_btc::taproot::ScriptLeaf

[derive(Drop)]
pub struct ScriptLeaf {
    pub script: Array<u8>,
    pub leaf_version: u8,
}

Members

script

Fully qualified path: alexandria_btc::taproot::ScriptLeaf::script

pub script: Array<u8>

leaf_version

Fully qualified path: alexandria_btc::taproot::ScriptLeaf::leaf_version

pub leaf_version: u8

TapTree

Taproot script tree (simplified - single leaf for now)

Fully qualified path: alexandria_btc::taproot::TapTree

[derive(Drop)]
pub struct TapTree {
    pub leaf: Option<ScriptLeaf>,
}

Members

leaf

Fully qualified path: alexandria_btc::taproot::TapTree::leaf

pub leaf: Option<ScriptLeaf>

types

Fully qualified path: alexandria_btc::types

Structs

BitcoinPublicKeyBitcoin public key representation (matches actual Bitcoin format)
BitcoinPublicKeyCoordsLegacy public key representation (for compatibility)
BitcoinAddressBitcoin address structure
BitcoinPrivateKeyPrivate key structure
TransactionInputBitcoin transaction input structure
TransactionOutputBitcoin transaction output structure
TransactionWitnessBitcoin transaction witness data
BitcoinTransactionComplete Bitcoin transaction structure
BTCDecoderBitcoin transaction decoder context
BTCEncoderBitcoin transaction encoder context

Enums

BitcoinNetworkBitcoin network types
BitcoinAddressTypeBitcoin address types

Traits

BitcoinPublicKeyTraitTrait for BitcoinPublicKey operations

Structs

Structs

BitcoinPublicKeyBitcoin public key representation (matches actual Bitcoin format)
BitcoinPublicKeyCoordsLegacy public key representation (for compatibility)
BitcoinAddressBitcoin address structure
BitcoinPrivateKeyPrivate key structure
TransactionInputBitcoin transaction input structure
TransactionOutputBitcoin transaction output structure
TransactionWitnessBitcoin transaction witness data
BitcoinTransactionComplete Bitcoin transaction structure
BTCDecoderBitcoin transaction decoder context
BTCEncoderBitcoin transaction encoder context

BitcoinPublicKey

Bitcoin public key representation (matches actual Bitcoin format)

Fully qualified path: alexandria_btc::types::BitcoinPublicKey

[derive(Clone, Drop, Serde)]
pub struct BitcoinPublicKey {
    pub bytes: ByteArray,
}

Members

bytes

Raw public key bytes (33 bytes compressed or 65 bytes uncompressed)

Fully qualified path: alexandria_btc::types::BitcoinPublicKey::bytes

pub bytes: ByteArray

BitcoinPublicKeyCoords

Legacy public key representation (for compatibility)

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyCoords

[derive(Copy, Drop, Serde)]
pub struct BitcoinPublicKeyCoords {
    pub x: u256,
    pub y: u256,
}

Members

x

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyCoords::x

pub x: u256

y

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyCoords::y

pub y: u256

BitcoinAddress

Bitcoin address structure

Fully qualified path: alexandria_btc::types::BitcoinAddress

#[derive(Drop, Serde)]
pub struct BitcoinAddress {
    pub address: ByteArray,
    pub address_type: BitcoinAddressType,
    pub network: BitcoinNetwork,
    pub script_pubkey: ByteArray,
}

Members

address

Fully qualified path: alexandria_btc::types::BitcoinAddress::address

pub address: ByteArray

address_type

Fully qualified path: alexandria_btc::types::BitcoinAddress::address_type

pub address_type: BitcoinAddressType

network

Fully qualified path: alexandria_btc::types::BitcoinAddress::network

pub network: BitcoinNetwork

script_pubkey

Fully qualified path: alexandria_btc::types::BitcoinAddress::script_pubkey

pub script_pubkey: ByteArray

BitcoinPrivateKey

Private key structure

Fully qualified path: alexandria_btc::types::BitcoinPrivateKey

#[derive(Copy, Drop, Serde)]
pub struct BitcoinPrivateKey {
    pub key: u256,
    pub network: BitcoinNetwork,
    pub compressed: bool,
}

Members

key

Fully qualified path: alexandria_btc::types::BitcoinPrivateKey::key

pub key: u256

network

Fully qualified path: alexandria_btc::types::BitcoinPrivateKey::network

pub network: BitcoinNetwork

compressed

Fully qualified path: alexandria_btc::types::BitcoinPrivateKey::compressed

pub compressed: bool

TransactionInput

Bitcoin transaction input structure

Fully qualified path: alexandria_btc::types::TransactionInput

[derive(Clone, Drop, Serde)]
pub struct TransactionInput {
    pub previous_txid: ByteArray,
    pub previous_vout: u32,
    pub script_sig: ByteArray,
    pub sequence: u32,
}

Members

previous_txid

Previous transaction hash (32 bytes, reversed)

Fully qualified path: alexandria_btc::types::TransactionInput::previous_txid

pub previous_txid: ByteArray

previous_vout

Previous output index

Fully qualified path: alexandria_btc::types::TransactionInput::previous_vout

pub previous_vout: u32

script_sig

Script signature

Fully qualified path: alexandria_btc::types::TransactionInput::script_sig

pub script_sig: ByteArray

sequence

Sequence number

Fully qualified path: alexandria_btc::types::TransactionInput::sequence

pub sequence: u32

TransactionOutput

Bitcoin transaction output structure

Fully qualified path: alexandria_btc::types::TransactionOutput

[derive(Clone, Drop, Serde)]
pub struct TransactionOutput {
    pub value: u64,
    pub script_pubkey: ByteArray,
}

Members

value

Value in satoshis

Fully qualified path: alexandria_btc::types::TransactionOutput::value

pub value: u64

script_pubkey

Script public key

Fully qualified path: alexandria_btc::types::TransactionOutput::script_pubkey

pub script_pubkey: ByteArray

TransactionWitness

Bitcoin transaction witness data

Fully qualified path: alexandria_btc::types::TransactionWitness

[derive(Clone, Drop, Serde)]
pub struct TransactionWitness {
    pub witness_stack: Array<ByteArray>,
}

Members

witness_stack

Array of witness stack items

Fully qualified path: alexandria_btc::types::TransactionWitness::witness_stack

pub witness_stack: Array<ByteArray>

BitcoinTransaction

Complete Bitcoin transaction structure

Fully qualified path: alexandria_btc::types::BitcoinTransaction

[derive(Clone, Drop, Serde)]
pub struct BitcoinTransaction {
    pub version: u32,
    pub inputs: Array<TransactionInput>,
    pub outputs: Array<TransactionOutput>,
    pub locktime: u32,
    pub witness: Array<TransactionWitness>,
    pub is_segwit: bool,
}

Members

version

Transaction version

Fully qualified path: alexandria_btc::types::BitcoinTransaction::version

pub version: u32

inputs

Array of transaction inputs

Fully qualified path: alexandria_btc::types::BitcoinTransaction::inputs

pub inputs: Array<TransactionInput>

outputs

Array of transaction outputs

Fully qualified path: alexandria_btc::types::BitcoinTransaction::outputs

pub outputs: Array<TransactionOutput>

locktime

Lock time

Fully qualified path: alexandria_btc::types::BitcoinTransaction::locktime

pub locktime: u32

witness

Witness data (for SegWit transactions)

Fully qualified path: alexandria_btc::types::BitcoinTransaction::witness

pub witness: Array<TransactionWitness>

is_segwit

Whether this is a SegWit transaction

Fully qualified path: alexandria_btc::types::BitcoinTransaction::is_segwit

pub is_segwit: bool

BTCDecoder

Bitcoin transaction decoder context

Fully qualified path: alexandria_btc::types::BTCDecoder

[derive(Clone, Drop, Serde)]
pub struct BTCDecoder {
    pub data: ByteArray,
    pub offset: u32,
}

Members

data

Raw transaction data

Fully qualified path: alexandria_btc::types::BTCDecoder::data

pub data: ByteArray

offset

Current reading offset

Fully qualified path: alexandria_btc::types::BTCDecoder::offset

pub offset: u32

BTCEncoder

Bitcoin transaction encoder context

Fully qualified path: alexandria_btc::types::BTCEncoder

[derive(Clone, Drop, Serde)]
pub struct BTCEncoder {
    pub data: ByteArray,
}

Members

data

Output transaction data buffer

Fully qualified path: alexandria_btc::types::BTCEncoder::data

pub data: ByteArray

Enums

Enums

BitcoinNetworkBitcoin network types
BitcoinAddressTypeBitcoin address types

BitcoinNetwork

Bitcoin network types

Fully qualified path: alexandria_btc::types::BitcoinNetwork

pub enum BitcoinNetwork {
    Mainnet,
    Testnet,
    Regtest,
}

Variants

Mainnet

Fully qualified path: alexandria_btc::types::BitcoinNetwork::Mainnet

Mainnet

Testnet

Fully qualified path: alexandria_btc::types::BitcoinNetwork::Testnet

Testnet

Regtest

Fully qualified path: alexandria_btc::types::BitcoinNetwork::Regtest

Regtest

BitcoinAddressType

Bitcoin address types

Fully qualified path: alexandria_btc::types::BitcoinAddressType

pub enum BitcoinAddressType {
    P2PKH,
    P2SH,
    P2WPKH,
    P2WSH,
    P2TR,
}

Variants

P2PKH

Fully qualified path: alexandria_btc::types::BitcoinAddressType::P2PKH

P2PKH

P2SH

Fully qualified path: alexandria_btc::types::BitcoinAddressType::P2SH

P2SH

P2WPKH

Fully qualified path: alexandria_btc::types::BitcoinAddressType::P2WPKH

P2WPKH

P2WSH

Fully qualified path: alexandria_btc::types::BitcoinAddressType::P2WSH

P2WSH

P2TR

Fully qualified path: alexandria_btc::types::BitcoinAddressType::P2TR

P2TR

Traits

Traits

BitcoinPublicKeyTraitTrait for BitcoinPublicKey operations

BitcoinPublicKeyTrait

Trait for BitcoinPublicKey operations

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyTrait

pub trait BitcoinPublicKeyTrait

Trait functions

from_x_coordinate

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyTrait::from_x_coordinate

fn from_x_coordinate(x: u256, is_even_y: bool) -> BitcoinPublicKey

from_coordinates

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyTrait::from_coordinates

fn from_coordinates(x: u256, y: u256) -> BitcoinPublicKey

from_hex

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyTrait::from_hex

fn from_hex(hex_string: ByteArray) -> BitcoinPublicKey

is_compressed

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyTrait::is_compressed

fn is_compressed(self: @BitcoinPublicKey) -> bool

get_x_coordinate

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyTrait::get_x_coordinate

fn get_x_coordinate(self: @BitcoinPublicKey) -> u256

get_y_coordinate

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyTrait::get_y_coordinate

fn get_y_coordinate(self: @BitcoinPublicKey) -> Option<u256>

to_coords

Fully qualified path: alexandria_btc::types::BitcoinPublicKeyTrait::to_coords

fn to_coords(self: @BitcoinPublicKey) -> BitcoinPublicKeyCoords