Address Functions
-
int wally_addr_segwit_from_bytes(const unsigned char *bytes, size_t bytes_len, const char *addr_family, uint32_t flags, char **output)
Create a segwit native address from a v0 or later witness program.
- Parameters:
bytes – Witness program bytes, including the version and data push opcode.
bytes_len – Length of
bytes
in bytes. Must beHASH160_LEN
+ 2 orSHA256_LEN
+ 2 for v0 witness programs.addr_family – Address family to generate, e.g. “bc” or “tb”.
flags – For future use. Must be 0.
output – Destination for the resulting segwit native address string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
-
int wally_addr_segwit_to_bytes(const char *addr, const char *addr_family, uint32_t flags, unsigned char *bytes_out, size_t len, size_t *written)
Get a scriptPubKey containing the witness program from a segwit native address.
- Parameters:
addr – Address to fetch the witness program from.
addr_family – Address family to generate, e.g. “bc” or “tb”.
flags – For future use. Must be 0.
bytes_out – Destination for the resulting scriptPubKey (including the version and data push opcode)
len – Size of
bytes_out
. PassingWALLY_SEGWIT_ADDRESS_PUBKEY_MAX_LEN
will ensure the buffer is large enough.written – Destination for the number of bytes written to
bytes_out
.
- Returns:
-
int wally_addr_segwit_n_to_bytes(const char *addr, size_t addr_len, const char *addr_family, size_t addr_family_len, uint32_t flags, unsigned char *bytes_out, size_t len, size_t *written)
Get a scriptPubKey containing the witness program from a known-length segwit native address.
See
wally_addr_segwit_to_bytes
.- Parameters:
len – Size of
bytes_out
. PassingWALLY_SEGWIT_ADDRESS_PUBKEY_MAX_LEN
will ensure the buffer is large enough.
- Returns:
-
int wally_addr_segwit_get_version(const char *addr, const char *addr_family, uint32_t flags, size_t *written)
Get the segwit version of a segwit native address.
- Parameters:
addr – Address to fetch the witness program from.
addr_family – Address family to generate, e.g. “bc” or “tb”.
flags – For future use. Must be 0.
written – Destination for the segwit version from 0 to 16 inclusive.
- Returns:
See Error Codes
-
int wally_addr_segwit_n_get_version(const char *addr, size_t addr_len, const char *addr_family, size_t addr_family_len, uint32_t flags, size_t *written)
Get the segwit version of a known-length segwit native address.
See
wally_addr_segwit_get_version
.- Returns:
See Error Codes
-
int wally_address_to_scriptpubkey(const char *addr, uint32_t network, unsigned char *bytes_out, size_t len, size_t *written)
Infer a scriptPubKey from an address.
- Parameters:
addr – Base58 encoded address to infer the scriptPubKey from. For confidential Liquid addresses first call
wally_confidential_addr_to_addr
.network – Network the address is for. One of the Address network constants.
bytes_out – Destination for the resulting scriptPubKey.
len – Size of
bytes_out
. PassingWALLY_ADDRESS_PUBKEY_MAX_LEN
will ensure the buffer is large enough.written – Destination for the number of bytes written to
bytes_out
.
- Returns:
-
int wally_scriptpubkey_to_address(const unsigned char *scriptpubkey, size_t scriptpubkey_len, uint32_t network, char **output)
Infer an address from a scriptPubKey.
- Parameters:
scriptpubkey – scriptPubKey bytes.
scriptpubkey_len – Length of
scriptpubkey
in bytes.network – Network to generate the address for. One of the Address network constants.
output – Destination for the resulting Base58 encoded address string. The string returned should be freed using
wally_free_string
.
For SegWit addresses, use
wally_addr_segwit_from_bytes
instead. To determine if a scriptPubKey is SegWit, usewally_scriptpubkey_get_type
.- Returns:
See Error Codes
-
int wally_wif_from_bytes(const unsigned char *priv_key, size_t priv_key_len, uint32_t prefix, uint32_t flags, char **output)
Convert a private key to Wallet Import Format.
- Parameters:
priv_key – Private key bytes.
priv_key_len – The length of
priv_key
in bytes. Must beEC_PRIVATE_KEY_LEN
.prefix – Expected prefix byte, e.g.
WALLY_ADDRESS_VERSION_WIF_MAINNET
orWALLY_ADDRESS_VERSION_WIF_TESTNET
.flags – Pass
WALLY_WIF_FLAG_COMPRESSED
if the corresponding pubkey is compressed, otherwiseWALLY_WIF_FLAG_UNCOMPRESSED
.output – Destination for the resulting Wallet Import Format string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
-
int wally_wif_to_bytes(const char *wif, uint32_t prefix, uint32_t flags, unsigned char *bytes_out, size_t len)
Convert a Wallet Import Format string to a private key.
- Parameters:
wif – Private key in Wallet Import Format.
prefix – Prefix byte to use, e.g.
WALLY_ADDRESS_VERSION_WIF_MAINNET
orWALLY_ADDRESS_VERSION_WIF_TESTNET
.flags – Pass
WALLY_WIF_FLAG_COMPRESSED
if the corresponding pubkey is compressed, otherwiseWALLY_WIF_FLAG_UNCOMPRESSED
.bytes_out – Destination for the private key.
len – Size of
bytes_out
. Must beEC_PRIVATE_KEY_LEN
.
- Returns:
See Error Codes
-
int wally_wif_is_uncompressed(const char *wif, size_t *written)
Determine if a private key in Wallet Import Format corresponds to an uncompressed public key.
- Parameters:
wif – Private key in Wallet Import Format to check.
written – 1 if the corresponding public key is uncompressed, 0 if compressed.
- Returns:
See Error Codes
-
int wally_wif_to_public_key(const char *wif, uint32_t prefix, unsigned char *bytes_out, size_t len, size_t *written)
Create a public key corresponding to a private key in Wallet Import Format.
- Parameters:
wif – Private key in Wallet Import Format.
prefix – Expected prefix byte, e.g.
WALLY_ADDRESS_VERSION_WIF_MAINNET
orWALLY_ADDRESS_VERSION_WIF_TESTNET
.bytes_out – Destination for the resulting public key.
len – The length of
bytes_out
.written – Destination for the number of bytes written to
bytes_out
.
- Returns:
-
int wally_bip32_key_to_address(const struct ext_key *hdkey, uint32_t flags, uint32_t version, char **output)
Create a legacy or wrapped SegWit address corresponding to a BIP32 key.
- Parameters:
hdkey – The extended key to use.
flags –
WALLY_ADDRESS_TYPE_P2PKH
for a legacy address,WALLY_ADDRESS_TYPE_P2SH_P2WPKH
for P2SH-wrapped SegWit.version – Address version to generate. One of the Address versions.
output – Destination for the resulting address string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
-
int wally_bip32_key_to_addr_segwit(const struct ext_key *hdkey, const char *addr_family, uint32_t flags, char **output)
Create a native SegWit address corresponding to a BIP32 key.
- Parameters:
hdkey – The extended key to use.
addr_family – Address family to generate, e.g. “bc” or “tb”.
flags – For future use. Must be 0.
output – Destination for the resulting segwit native address string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
-
int wally_wif_to_address(const char *wif, uint32_t prefix, uint32_t version, char **output)
Create a P2PKH address corresponding to a private key in Wallet Import Format.
- Parameters:
wif – Private key in Wallet Import Format.
prefix – Expected prefix byte, e.g.
WALLY_ADDRESS_VERSION_WIF_MAINNET
orWALLY_ADDRESS_VERSION_WIF_TESTNET
.version – Address version to generate. One of the Address versions.
output – Destination for the resulting address string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
-
int wally_confidential_addr_to_addr(const char *address, uint32_t prefix, char **output)
Extract the address from a confidential address.
- Parameters:
address – The base58 encoded confidential address to extract the address from.
prefix – The confidential address prefix byte, e.g.
WALLY_CA_PREFIX_LIQUID
.output – Destination for the resulting address string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
-
int wally_confidential_addr_to_ec_public_key(const char *address, uint32_t prefix, unsigned char *bytes_out, size_t len)
Extract the blinding public key from a confidential address.
- Parameters:
address – The base58 encoded confidential address to extract the public key from.
prefix – The confidential address prefix byte, e.g.
WALLY_CA_PREFIX_LIQUID
.bytes_out – Destination for the public key.
len – Size of
bytes_out
. Must beEC_PUBLIC_KEY_LEN
.
- Returns:
See Error Codes
-
int wally_confidential_addr_from_addr(const char *address, uint32_t prefix, const unsigned char *pub_key, size_t pub_key_len, char **output)
Create a confidential address from an address and blinding public key.
- Parameters:
address – The base58 encoded address to make confidential.
prefix – The confidential address prefix byte, e.g.
WALLY_CA_PREFIX_LIQUID
.pub_key – The blinding public key to associate with
address
.pub_key_len – The length of
pub_key
in bytes. Must beEC_PUBLIC_KEY_LEN
.output – Destination for the resulting address string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
-
int wally_confidential_addr_to_addr_segwit(const char *address, const char *confidential_addr_family, const char *addr_family, char **output)
Extract the segwit native address from a confidential address.
- Parameters:
address – The blech32 encoded confidential address to extract the address from.
confidential_addr_family – The confidential address family of
address
.addr_family – The address family to generate.
output – Destination for the resulting address string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
-
int wally_confidential_addr_segwit_to_ec_public_key(const char *address, const char *confidential_addr_family, unsigned char *bytes_out, size_t len)
Extract the blinding public key from a segwit confidential address.
- Parameters:
address – The blech32 encoded confidential address to extract the public key from.
confidential_addr_family – The confidential address family of
address
.bytes_out – Destination for the public key.
len – Size of
bytes_out
. Must beEC_PUBLIC_KEY_LEN
.
- Returns:
See Error Codes
-
int wally_confidential_addr_from_addr_segwit(const char *address, const char *addr_family, const char *confidential_addr_family, const unsigned char *pub_key, size_t pub_key_len, char **output)
Create a confidential address from a segwit native address and blinding public key.
- Parameters:
address – The bech32 encoded address to make confidential.
addr_family – The address family to generate.
confidential_addr_family – The confidential address family to generate.
pub_key – The blinding public key to associate with
address
.pub_key_len – The length of
pub_key
in bytes. Must beEC_PUBLIC_KEY_LEN
.output – Destination for the resulting address string. The string returned should be freed using
wally_free_string
.
- Returns:
See Error Codes
Address Constants
-
WALLY_WIF_FLAG_COMPRESSED
Corresponding public key compressed
-
WALLY_WIF_FLAG_UNCOMPRESSED
Corresponding public key uncompressed
-
WALLY_CA_PREFIX_LIQUID
Liquid v1 confidential address prefix
-
WALLY_CA_PREFIX_LIQUID_REGTEST
Liquid v1 confidential address prefix for regtest
-
WALLY_CA_PREFIX_LIQUID_TESTNET
Liquid v1 confidential address prefix for testnet
Address network constants
-
WALLY_NETWORK_NONE
Used for miniscript parsing only
-
WALLY_NETWORK_BITCOIN_MAINNET
Bitcoin mainnet
-
WALLY_NETWORK_BITCOIN_REGTEST
Bitcoin regtest: Behaves as testnet except for segwit
-
WALLY_NETWORK_BITCOIN_TESTNET
Bitcoin testnet
-
WALLY_NETWORK_LIQUID
Liquid v1
-
WALLY_NETWORK_LIQUID_REGTEST
Liquid v1 regtest
-
WALLY_NETWORK_LIQUID_TESTNET
Liquid v1 testnet
-
WALLY_ADDRESS_TYPE_P2PKH
P2PKH address (“1…”)
-
WALLY_ADDRESS_TYPE_P2SH_P2WPKH
P2SH-P2WPKH wrapped SegWit address (“3…”)
-
WALLY_ADDRESS_TYPE_P2WPKH
P2WPKH native SegWit address (“bc1…)”
Address versions
-
WALLY_ADDRESS_VERSION_P2PKH_MAINNET
P2PKH address on mainnet
-
WALLY_ADDRESS_VERSION_P2PKH_TESTNET
P2PKH address on testnet
-
WALLY_ADDRESS_VERSION_P2PKH_LIQUID
P2PKH address on liquid v1
-
WALLY_ADDRESS_VERSION_P2PKH_LIQUID_REGTEST
P2PKH address on liquid v1 regtest
-
WALLY_ADDRESS_VERSION_P2PKH_LIQUID_TESTNET
P2PKH address on liquid v1 testnet
-
WALLY_ADDRESS_VERSION_P2SH_MAINNET
P2SH address on mainnet
-
WALLY_ADDRESS_VERSION_P2SH_TESTNET
P2SH address on testnet
-
WALLY_ADDRESS_VERSION_P2SH_LIQUID
P2SH address on liquid v1
-
WALLY_ADDRESS_VERSION_P2SH_LIQUID_REGTEST
P2SH address on liquid v1 regtest
-
WALLY_ADDRESS_VERSION_P2SH_LIQUID_TESTNET
P2SH address on liquid v1 testnet
-
WALLY_ADDRESS_VERSION_WIF_MAINNET
Wallet Import Format on mainnet
-
WALLY_ADDRESS_VERSION_WIF_TESTNET
Wallet Import Format on testnet
-
WALLY_SEGWIT_ADDRESS_PUBKEY_MAX_LEN
OP_[0-16] OP_PUSH_N [up-to-40-bytes witprog]
-
WALLY_ADDRESS_PUBKEY_MAX_LEN
-
WALLY_SEGWIT_V0_ADDRESS_PUBKEY_MAX_LEN
OP_0 OP_PUSH_{20,32} [20 bytes for wpkh, 32 for wsh]
-
WALLY_SEGWIT_V1_ADDRESS_PUBKEY_LEN
OP_1 OP_PUSH_32 [32-bytes x-only pubkey]