Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ build_wally_release_files:
- cd dist
- tar czf wallycore-wasm.tar.gz --remove-files wallycore.html wallycore.js wallycore.wasm
- cd ..
- EXPORTED_FUNCTIONS="['_malloc','_free','_wally_init','_wally_asset_value_commitment','_wally_asset_generator_from_bytes']" tools/build_wasm.sh
- cd dist
- tar czf esplora-wasm.tar.gz --remove-files wallycore.html wallycore.js wallycore.wasm
- cd ..
- sphinx-build -b html -a -c docs/source docs/source docs/build/html
- cd docs/build
- tar czf ../../wally_dist/apidocs.tar.gz html/
Expand Down
6 changes: 6 additions & 0 deletions include/wally.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,12 @@ inline int map_keypath_bip32_init_alloc(size_t allocation_len, struct wally_map*
return detail::check_ret(__FUNCTION__, ret);
}

template <class MAP_IN, class HDKEY, class OUTPUT>
inline int map_keypath_get_bip32_key_from(const MAP_IN& map_in, size_t index, const HDKEY& hdkey, const OUTPUT& output, size_t* written) {
int ret = ::wally_map_keypath_get_bip32_key_from(detail::get_p(map_in), index, detail::get_p(hdkey), detail::get_p(output), written);
return detail::check_ret(__FUNCTION__, ret);
}

template <class MAP_IN, class HDKEY>
inline int map_keypath_get_bip32_key_from_alloc(const MAP_IN& map_in, size_t index, const HDKEY& hdkey, struct ext_key** output) {
int ret = ::wally_map_keypath_get_bip32_key_from_alloc(detail::get_p(map_in), index, detail::get_p(hdkey), output);
Expand Down
29 changes: 28 additions & 1 deletion include/wally_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,33 @@ WALLY_CORE_API int wally_map_find_bip32_public_key_from(
const struct ext_key *hdkey,
size_t *written);

#ifndef SWIG
/**
* Return a BIP32 derived key matching the keypath of a parent in a map.
*
* :param map_in: The map to search for derived keys of ``hdkey`` in.
* :param index: The zero-based index of the item to start searching from.
* :param hdkey: The BIP32 parent key to derive matches from.
* :param output: Destination for the resulting derived key. If a matching
*| key is not found, ``output`` is zeroed.
* :param written: On success, set to zero if a matching derived key is
*| not found, otherwise the index of the matching key plus one.
*
* .. note:: This function searches for keys in the map that are children
*| of ``hdkey``. If one is found, the corresponding private extended key
*| is derived from ``hdey`` into ``output`` and ``written`` is set
*| to the index of the matching key plus one.
*| If no key is found, ``*output`` is set to ``NULL`` and
*| `WALLY_OK` is returned.
*/
WALLY_CORE_API int wally_map_keypath_get_bip32_key_from(
const struct wally_map *map_in,
size_t index,
const struct ext_key *hdkey,
struct ext_key *output,
size_t *written);
#endif /* SWIG */

/**
* Return a BIP32 derived key matching the keypath of a parent in a map.
*
Expand All @@ -370,7 +397,7 @@ WALLY_CORE_API int wally_map_find_bip32_public_key_from(
* :param output: Destination for the resulting derived key, if any.
*
* .. note:: This function searches for keys in the map that are children
*| of ``hdkey``. If one is found, the resulting privately derived key
*| of ``hdkey``. If one is found, the corresponding privately derived key
*| is returned. If no key is found, ``*output`` is set to ``NULL`` and
*| `WALLY_OK` is returned.
*/
Expand Down
5 changes: 3 additions & 2 deletions include/wally_transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,9 @@ WALLY_CORE_API int wally_tx_get_signature_hash(
*| for. For taproot, the leaf script to sign with if any. Ignored for
*| pre-segwit signing.
* :param script_len: Length of ``script`` in bytes.
* :param key_version: Version of pubkey in tapscript. Must be set
*| to `0x00` or `0x01` for taproot script-path signing.
* :param key_version: For taproot signing, the version of the pubkey
*| in ``script`` when signing with a script path. Currently must be ``1``
*| for this case. For non-taproot or keypath signing, it must be ``0``.
* :param codesep_position: BIP342 codeseparator position
*| or ``WALLY_NO_CODESEPARATOR`` if none. Only used for taproot signing.
* :param annex: BIP341 annex, or NULL if none.
Expand Down
42 changes: 32 additions & 10 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,20 @@ int wally_map_find_bip32_public_key_from(const struct wally_map *map_in, size_t
return ret;
}

int wally_map_keypath_get_bip32_key_from_alloc(const struct wally_map *map_in,
size_t index, const struct ext_key *hdkey,
struct ext_key **output)
int wally_map_keypath_get_bip32_key_from(const struct wally_map *map_in,
size_t index, const struct ext_key *hdkey,
struct ext_key *output, size_t *written)
{
uint32_t path[BIP32_PATH_MAX_LEN];
struct ext_key derived;
size_t i, path_len, idx = 0;
int ret = WALLY_OK;

OUTPUT_CHECK;
if (!map_in || !hdkey)
if (written)
*written = 0;
if (output)
memset(output, 0, sizeof(*output));
if (!map_in || !hdkey || !written || !output)
return WALLY_EINVAL;

if (mem_is_zero(hdkey->chain_code, sizeof(hdkey->chain_code))) {
Expand Down Expand Up @@ -516,14 +519,33 @@ int wally_map_keypath_get_bip32_key_from_alloc(const struct wally_map *map_in,
}
}
if (ret == WALLY_OK && idx) {
/* Found, return the matching key */
*output = wally_calloc(sizeof(struct ext_key));
if (!*output)
/* Found, return the matching key and its 1-based index */
*written = idx;
memcpy(output, hdkey, sizeof(*hdkey));
}
wally_clear(&derived, sizeof(derived));
return ret;
}


int wally_map_keypath_get_bip32_key_from_alloc(const struct wally_map *map_in,
size_t index, const struct ext_key *hdkey,
struct ext_key **output)
{
struct ext_key found;
size_t found_index;
int ret;

OUTPUT_CHECK;
ret = wally_map_keypath_get_bip32_key_from(map_in, index, hdkey,
&found, &found_index);
if (ret == WALLY_OK && found_index) {
if (!(*output = wally_calloc(sizeof(struct ext_key))))
ret = WALLY_ENOMEM;
else
memcpy(*output, hdkey, sizeof(*hdkey));
memcpy(*output, &found, sizeof(found));
}
wally_clear(&derived, sizeof(derived));
wally_clear(&found, sizeof(found));
return ret;
}

Expand Down
1 change: 1 addition & 0 deletions src/swig_java/swig.i
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
%ignore bip32_key_unserialize;
%ignore bip32_key_with_tweak_from_parent_path;
%ignore wally_map_init;
%ignore wally_map_keypath_get_bip32_key_from;
%ignore wally_psbt_blind;
%ignore wally_tx_elements_output_init;
%ignore wally_tx_input_clone;
Expand Down
1 change: 1 addition & 0 deletions src/swig_python/swig.i
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ static void destroy_words(PyObject *obj) { (void)obj; }
%ignore bip32_key_unserialize;
%ignore bip32_key_with_tweak_from_parent_path;
%ignore wally_map_init;
%ignore wally_map_keypath_get_bip32_key_from;
%ignore wally_psbt_blind;
%ignore wally_psbt_get_input_best_utxo;
%ignore wally_tx_elements_output_init;
Expand Down
1 change: 1 addition & 0 deletions src/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ class wally_psbt(Structure):
('wally_map_init_alloc', c_int, [c_size_t, c_void_p, POINTER(POINTER(wally_map))]),
('wally_map_keypath_add', c_int, [POINTER(wally_map), c_void_p, c_size_t, c_void_p, c_size_t, POINTER(c_uint32), c_size_t]),
('wally_map_keypath_bip32_init_alloc', c_int, [c_size_t, POINTER(POINTER(wally_map))]),
('wally_map_keypath_get_bip32_key_from', c_int, [POINTER(wally_map), c_size_t, POINTER(ext_key), POINTER(ext_key), c_size_t_p]),
('wally_map_keypath_get_bip32_key_from_alloc', c_int, [POINTER(wally_map), c_size_t, POINTER(ext_key), POINTER(POINTER(ext_key))]),
('wally_map_keypath_get_item_fingerprint', c_int, [POINTER(wally_map), c_size_t, c_void_p, c_size_t]),
('wally_map_keypath_get_item_path', c_int, [POINTER(wally_map), c_size_t, POINTER(c_uint32), c_size_t, c_size_t_p]),
Expand Down
1 change: 1 addition & 0 deletions src/wasm_package/src/functions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/wasm_package/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export function map_init_noalloc(allocation_len: number, verify_fn: Ref, output:
export function map_keypath_add(map_in: Ref_wally_map, pub_key: Buffer|Uint8Array, fingerprint: Buffer|Uint8Array, child_path: Uint32Array|number[]): void;
export function map_keypath_bip32_init(allocation_len: number): Ref_wally_map;
export function map_keypath_get_bip32_key_from(map_in: Ref_wally_map, index: number, hdkey: Ref_ext_key): Ref_ext_key;
export function map_keypath_get_bip32_key_from_noalloc(map_in: Ref_wally_map, index: number, hdkey: Ref_ext_key, output: Ref_ext_key): number;
export function map_keypath_get_item_fingerprint(map_in: Ref_wally_map, index: number): Buffer;
export function map_keypath_get_item_path_len(map_in: Ref_wally_map, index: number): number;
export function map_keypath_public_key_init(allocation_len: number): Ref_wally_map;
Expand Down
1 change: 1 addition & 0 deletions tools/wasm_exports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \
,'_wally_map_init_alloc' \
,'_wally_map_keypath_add' \
,'_wally_map_keypath_bip32_init_alloc' \
,'_wally_map_keypath_get_bip32_key_from' \
,'_wally_map_keypath_get_bip32_key_from_alloc' \
,'_wally_map_keypath_get_item_fingerprint' \
,'_wally_map_keypath_get_item_path' \
Expand Down
Loading