Bip32 Functions

int bip32_key_free(const struct ext_key *hdkey)

Free a key allocated by bip32_key_from_seed_alloc or bip32_key_unserialize_alloc.

Parameters:
  • hdkey – Key to free.
Returns:

WALLY_OK or an error code.

Return type:

int

int bip32_key_init_alloc(uint32_t version, uint32_t depth, uint32_t child_num, const unsigned char *chain_code, size_t chain_code_len, const unsigned char *pub_key, size_t pub_key_len, const unsigned char *priv_key, size_t priv_key_len, const unsigned char *hash160, size_t hash160_len, const unsigned char *parent160, size_t parent160_len, struct ext_key **output)
Returns:WALLY_OK or an error code.
Return type:int
int bip32_key_from_seed(const unsigned char *bytes, size_t bytes_len, uint32_t version, uint32_t flags, struct ext_key *output)

Create a new master extended key from entropy.

This creates a new master key, i.e. the root of a new HD tree. The entropy passed in may produce an invalid key. If this happens, WALLY_ERROR will be returned and the caller should retry with new entropy.

Parameters:
  • bytes – Entropy to use.
  • bytes_len – Size of bytes in bytes. Must be one of BIP32_ENTROPY_LEN_128, BIP32_ENTROPY_LEN_256 or BIP32_ENTROPY_LEN_512.
  • version – Either BIP32_VER_MAIN_PRIVATE or BIP32_VER_TEST_PRIVATE, indicating mainnet or testnet/regtest respectively.
  • flags – Either BIP32_FLAG_SKIP_HASH to skip hash160 calculation, or 0.
  • output – Destination for the resulting master extended key.
Returns:

WALLY_OK or an error code.

Return type:

int

int bip32_key_from_seed_alloc(const unsigned char *bytes, size_t bytes_len, uint32_t version, uint32_t flags, struct ext_key **output)

As per bip32_key_from_seed, but allocates the key.

Note

The returned key should be freed with bip32_key_free.

Returns:WALLY_OK or an error code.
Return type:int
int bip32_key_serialize(const struct ext_key *hdkey, uint32_t flags, unsigned char *bytes_out, size_t len)

Serialize an extended key to memory using BIP32 format.

Parameters:
  • hdkey – The extended key to serialize.
  • flagsBIP32_FLAG_KEY_ Flags indicating which key to serialize. You can not serialize a private extended key from a public extended key.
  • bytes_out – Destination for the serialized key.
  • len – Size of bytes_out in bytes. Must be BIP32_SERIALIZED_LEN.
Returns:

WALLY_OK or an error code.

Return type:

int

int bip32_key_unserialize(const unsigned char *bytes, size_t bytes_len, struct ext_key *output)

Un-serialize an extended key from memory.

Parameters:
  • bytes – Storage holding the serialized key.
  • bytes_len – Size of bytes in bytes. Must be BIP32_SERIALIZED_LEN.
  • output – Destination for the resulting extended key.
Returns:

WALLY_OK or an error code.

Return type:

int

int bip32_key_unserialize_alloc(const unsigned char *bytes, size_t bytes_len, struct ext_key **output)

As per bip32_key_unserialize, but allocates the key.

Note

The returned key should be freed with bip32_key_free.

Returns:WALLY_OK or an error code.
Return type:int
int bip32_key_from_parent(const struct ext_key *hdkey, uint32_t child_num, uint32_t flags, struct ext_key *output)

Create a new child extended key from a parent extended key.

Parameters:
  • hdkey – The parent extended key.
  • child_num – The child number to create. Numbers greater than or equal to BIP32_INITIAL_HARDENED_CHILD represent hardened keys that cannot be created from public parent extended keys.
  • flagsBIP32_FLAG_KEY_ Flags indicating the type of derivation wanted. You can not derive a private child extended key from a public parent extended key.
  • output – Destination for the resulting child extended key.
Returns:

WALLY_OK or an error code.

Return type:

int

int bip32_key_from_parent_alloc(const struct ext_key *hdkey, uint32_t child_num, uint32_t flags, struct ext_key **output)

As per bip32_key_from_parent, but allocates the key.

Note

The returned key should be freed with bip32_key_free.

Returns:WALLY_OK or an error code.
Return type:int
int bip32_key_from_parent_path(const struct ext_key *hdkey, const uint32_t *child_path, size_t child_path_len, uint32_t flags, struct ext_key *output)

Create a new child extended key from a parent extended key and a path.

Parameters:
  • hdkey – The parent extended key.
  • child_path – The path of child numbers to create.
  • child_path_len – The number of child numbers in child_path.
  • flagsBIP32_KEY_ Flags indicating the type of derivation wanted.
  • output – Destination for the resulting child extended key.
Returns:

WALLY_OK or an error code.

Return type:

int

int bip32_key_from_parent_path_alloc(const struct ext_key *hdkey, const uint32_t *child_path, size_t child_path_len, uint32_t flags, struct ext_key **output)

As per bip32_key_from_parent_path, but allocates the key.

Note

The returned key should be freed with bip32_key_free.

Returns:WALLY_OK or an error code.
Return type:int
int bip32_key_to_base58(const struct ext_key *hdkey, uint32_t flags, char **output)

Convert an extended key to base58.

Parameters:
  • hdkey – The extended key.
  • flagsBIP32_FLAG_KEY_ Flags indicating which key to serialize. You can not serialize a private extended key from a public extended key.
  • output – Destination for the resulting key in base58.
Returns:

WALLY_OK or an error code.

Return type:

int

int bip32_key_from_base58(const char *base58, struct ext_key *output)

Convert a base58 encoded extended key to an extended key.

Parameters:
  • base58 – The extended key in base58.
  • output – Destination for the resulting extended key.
Returns:

WALLY_OK or an error code.

Return type:

int

int bip32_key_from_base58_alloc(const char *base58, struct ext_key **output)

As per bip32_key_from_base58, but allocates the key.

Note

The returned key should be freed with bip32_key_free.

Returns:WALLY_OK or an error code.
Return type:int