Skip to content

Latest commit

 

History

History
401 lines (163 loc) · 12 KB

bitcoin_address.md

File metadata and controls

401 lines (163 loc) · 12 KB

Module 0x3::bitcoin_address

Struct BitcoinAddress

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

Constants

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 P2SH_ADDR_BYTE_LEN: u64 = 21;

const PUBKEY_HASH_LEN: u64 = 20;

const SCRIPT_HASH_LEN: u64 = 20;

Function new_p2pkh

TODO break: rename to p2pkh and add tests

public fun new_p2pkh(pubkey_hash: vector<u8>): bitcoin_address::BitcoinAddress

Function new_p2sh

TODO break: rename to p2sh and add tests

public fun new_p2sh(script_hash: vector<u8>): bitcoin_address::BitcoinAddress

Function new_witness_program

TODO break: make this function private

Function p2tr

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

Function new

public(friend) fun new(bytes: vector<u8>): bitcoin_address::BitcoinAddress

Function is_p2pkh

public fun is_p2pkh(addr: &bitcoin_address::BitcoinAddress): bool

Function is_p2sh

public fun is_p2sh(addr: &bitcoin_address::BitcoinAddress): bool

Function is_witness_program

Function is_empty

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

Function as_bytes

Function into_bytes

Function from_string

Function verify_with_public_key

public fun verify_with_public_key(addr: &string::String, pk: &vector<u8>): bool

Function to_rooch_address

Function verify_bitcoin_address_with_public_key

verify bitcoin address according to the pk bytes, the pk is Secp256k1 public key format.

Function derive_multisig_pubkey_from_pubkeys

Deprecated: this function is deprecated.

public fun derive_multisig_pubkey_from_pubkeys(_public_keys: vector<vector<u8>>, _threshold: u64): vector<u8>

Function derive_bitcoin_taproot_address_from_pubkey