- Struct
BitcoinAddress
- Constants
- Function
new_p2pkh
- Function
new_p2sh
- Function
new_witness_program
- Function
p2tr
- Function
new
- Function
is_p2pkh
- Function
is_p2sh
- Function
is_witness_program
- Function
is_empty
- Function
as_bytes
- Function
into_bytes
- Function
from_string
- Function
verify_with_public_key
- Function
to_rooch_address
- Function
verify_bitcoin_address_with_public_key
- Function
derive_multisig_pubkey_from_pubkeys
- Function
derive_bitcoin_taproot_address_from_pubkey
use 0x1::option;
use 0x1::string;
use 0x1::vector;
use 0x2::bcs;
use 0x2::hash;
BitcoinAddress is a struct that represents a Bitcoin address. We just keep the raw bytes of the address and do care about the network.
#[data_struct]
struct BitcoinAddress has copy, drop, store
const ErrorArgNotVectorU8: u64 = 2;
const ErrorDeprecated: u64 = 6;
const ErrorInvalidAddress: u64 = 1;
const ErrorInvalidKeyEggContext: u64 = 5;
const ErrorInvalidPublicKey: u64 = 3;
const ErrorInvalidThreshold: u64 = 4;
const P2PKH_ADDR_BYTE_LEN: u64 = 21;
const P2PKH_ADDR_DECIMAL_PREFIX_MAIN: u8 = 0;
const P2PKH_ADDR_DECIMAL_PREFIX_TEST: u8 = 111;
const P2SH_ADDR_BYTE_LEN: u64 = 21;
const P2SH_ADDR_DECIMAL_PREFIX_MAIN: u8 = 5;
const P2SH_ADDR_DECIMAL_PREFIX_TEST: u8 = 196;
const PAY_LOAD_TYPE_PUBKEY_HASH: u8 = 0;
const PAY_LOAD_TYPE_SCRIPT_HASH: u8 = 1;
const PAY_LOAD_TYPE_WITNESS_PROGRAM: u8 = 2;
const PUBKEY_HASH_LEN: u64 = 20;
const SCRIPT_HASH_LEN: u64 = 20;
TODO break: rename to p2pkh and add tests
public fun new_p2pkh(pubkey_hash: vector<u8>): bitcoin_address::BitcoinAddress
TODO break: rename to p2sh and add tests
public fun new_p2sh(script_hash: vector<u8>): bitcoin_address::BitcoinAddress
TODO break: make this function private
public fun new_witness_program(program: vector<u8>): bitcoin_address::BitcoinAddress
Derive a Bitcoin address from a internal public key and a merkle root. The internal public key is a secp256k1 public key or x-only public key.
public fun p2tr(internal_pubkey: &vector<u8>, merkle_root: option::Option<address>): bitcoin_address::BitcoinAddress
public(friend) fun new(bytes: vector<u8>): bitcoin_address::BitcoinAddress
public fun is_p2pkh(addr: &bitcoin_address::BitcoinAddress): bool
public fun is_p2sh(addr: &bitcoin_address::BitcoinAddress): bool
public fun is_witness_program(addr: &bitcoin_address::BitcoinAddress): bool
Empty address is a special address that is used to if we parse address failed from script.
public fun is_empty(addr: &bitcoin_address::BitcoinAddress): bool
public fun as_bytes(addr: &bitcoin_address::BitcoinAddress): &vector<u8>
public fun into_bytes(addr: bitcoin_address::BitcoinAddress): vector<u8>
public fun from_string(addr: &string::String): bitcoin_address::BitcoinAddress
public fun verify_with_public_key(addr: &string::String, pk: &vector<u8>): bool
public fun to_rooch_address(addr: &bitcoin_address::BitcoinAddress): address
verify bitcoin address according to the pk bytes, the pk is Secp256k1 public key format.
public fun verify_bitcoin_address_with_public_key(bitcoin_addr: &bitcoin_address::BitcoinAddress, pk: &vector<u8>): bool
Deprecated: this function is deprecated.
public fun derive_multisig_pubkey_from_pubkeys(_public_keys: vector<vector<u8>>, _threshold: u64): vector<u8>
public fun derive_bitcoin_taproot_address_from_pubkey(pubkey: &vector<u8>): bitcoin_address::BitcoinAddress