From cabd1867239c72b2054280b6c6d108fa85ee09e9 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 8 Jan 2025 15:22:15 +1300 Subject: [PATCH 1/4] base64: add known-length calls for base64_to_bytes/get_maximum_length --- include/wally.hpp | 12 ++++++++++ include/wally_core.h | 24 ++++++++++++++++++++ include/wally_map.h | 2 +- src/base_64.c | 35 ++++++++++++++++++++---------- src/swig_java/swig.i | 2 ++ src/swig_python/python_extra.py_in | 1 + src/test/test_base64.py | 15 +++++++++++++ src/test/util.py | 2 ++ src/wasm_package/src/functions.js | 2 ++ src/wasm_package/src/index.d.ts | 2 ++ tools/wasm_exports.sh | 2 ++ 11 files changed, 87 insertions(+), 12 deletions(-) diff --git a/include/wally.hpp b/include/wally.hpp index fbfe4b0ce..c75b4b4a0 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -463,6 +463,18 @@ inline int base64_get_maximum_length(const STR_IN& str_in, uint32_t flags, size_ return detail::check_ret(__FUNCTION__, ret); } +template +inline int base64_n_get_maximum_length(const STR_IN& str_in, size_t str_len, uint32_t flags, size_t* written) { + int ret = ::wally_base64_n_get_maximum_length(detail::get_p(str_in), str_len, flags, written); + return detail::check_ret(__FUNCTION__, ret); +} + +template +inline int base64_n_to_bytes(const STR_IN& str_in, size_t str_len, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_base64_n_to_bytes(detail::get_p(str_in), str_len, flags, bytes_out.data(), bytes_out.size(), written); + return detail::check_ret(__FUNCTION__, ret); +} + template inline int base64_to_bytes(const STR_IN& str_in, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { int ret = ::wally_base64_to_bytes(detail::get_p(str_in), flags, bytes_out.data(), bytes_out.size(), written); diff --git a/include/wally_core.h b/include/wally_core.h index 658722c46..7bf1f65ca 100644 --- a/include/wally_core.h +++ b/include/wally_core.h @@ -350,6 +350,19 @@ WALLY_CORE_API int wally_base64_to_bytes( size_t len, size_t *written); +/** + * Decode a known-length base64 encoded string back into into binary data. + * + * See `wally_base64_to_bytes`. + */ +WALLY_CORE_API int wally_base64_n_to_bytes( + const char *str_in, + size_t str_len, + uint32_t flags, + unsigned char *bytes_out, + size_t len, + size_t *written); + /** * Return the maximum length of a base64 encoded string once decoded into bytes. * @@ -369,6 +382,17 @@ WALLY_CORE_API int wally_base64_get_maximum_length( uint32_t flags, size_t *written); +/** + * Return the maximum length of a known-length base64 encoded string once decoded into bytes. + * + * See `wally_base64_get_maximum_length`. + */ +WALLY_CORE_API int wally_base64_n_get_maximum_length( + const char *str_in, + size_t str_len, + uint32_t flags, + size_t *written); + #ifndef SWIG /** The type of an overridable function to allocate memory */ diff --git a/include/wally_map.h b/include/wally_map.h index 61886a4f1..e5b496ba3 100644 --- a/include/wally_map.h +++ b/include/wally_map.h @@ -333,7 +333,7 @@ WALLY_CORE_API int wally_map_combine( /** * Replace a maps contents with another map. * - * :param map_in: the destination to combine into. + * :param map_in: the destination to assign to. * :param source: the source to copy items from. * * .. note:: If this call fails, ``map_in`` is left untouched. diff --git a/src/base_64.c b/src/base_64.c index 6816e0398..27a5bc069 100644 --- a/src/base_64.c +++ b/src/base_64.c @@ -25,42 +25,55 @@ int wally_base64_from_bytes(const unsigned char *bytes, size_t bytes_len, return WALLY_OK; } -int wally_base64_get_maximum_length(const char *str_in, uint32_t flags, size_t *written) +int wally_base64_n_get_maximum_length(const char *str_in, size_t str_len, uint32_t flags, size_t *written) { if (written) *written = 0; - if (!str_in || !*str_in || flags || !written) + if (!str_in || !str_len || flags || !written) return WALLY_EINVAL; - *written = base64_decoded_length(strlen(str_in)); + *written = base64_decoded_length(str_len); return WALLY_OK; } -int wally_base64_to_bytes(const char *str_in, uint32_t flags, - unsigned char *bytes_out, size_t len, - size_t *written) +int wally_base64_get_maximum_length(const char *str_in, uint32_t flags, size_t *written) +{ + size_t str_len = str_in ? strlen(str_in) : 0; + return wally_base64_n_get_maximum_length(str_in, str_len, flags, written); +} + +int wally_base64_n_to_bytes(const char *str_in, size_t str_len, uint32_t flags, + unsigned char *bytes_out, size_t len, + size_t *written) { - size_t decode_len, str_in_len; + size_t decode_len; ssize_t actual_len; if (written) *written = 0; - if (!str_in || flags || !bytes_out || !len || !written) + if (!str_in || !str_len || flags || !bytes_out || !len || !written) return WALLY_EINVAL; - str_in_len = strlen(str_in); - decode_len = base64_decoded_length(str_in_len); + decode_len = base64_decoded_length(str_len); if (len < decode_len) { /* Not enough space; return the amount required */ *written = decode_len; return WALLY_OK; } - actual_len = base64_decode((char *)bytes_out, decode_len, str_in, str_in_len); + actual_len = base64_decode((char *)bytes_out, decode_len, str_in, str_len); if (actual_len < 0) return WALLY_EINVAL; /* Invalid base64 data */ *written = actual_len; return WALLY_OK; } + +int wally_base64_to_bytes(const char *str_in, uint32_t flags, + unsigned char *bytes_out, size_t len, + size_t *written) +{ + size_t str_len = str_in ? strlen(str_in) : 0; + return wally_base64_n_to_bytes(str_in, str_len, flags, bytes_out, len, written); +} diff --git a/src/swig_java/swig.i b/src/swig_java/swig.i index 37d6aca82..24a1258fb 100644 --- a/src/swig_java/swig.i +++ b/src/swig_java/swig.i @@ -551,7 +551,9 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %returns_size_t(wally_base58_n_to_bytes); %returns_string(wally_base64_from_bytes); %returns_size_t(wally_base64_to_bytes); +%returns_size_t(wally_base64_n_to_bytes); %returns_size_t(wally_base64_get_maximum_length); +%returns_size_t(wally_base64_n_get_maximum_length); %returns_string(wally_bip32_key_to_address); %returns_string(wally_bip32_key_to_addr_segwit); %returns_array_(wally_bip340_tagged_hash, 4, 5, SHA256_LEN); diff --git a/src/swig_python/python_extra.py_in b/src/swig_python/python_extra.py_in index 2be4d700a..a3eb630ef 100644 --- a/src/swig_python/python_extra.py_in +++ b/src/swig_python/python_extra.py_in @@ -119,6 +119,7 @@ aes_cbc = _wrap_bin(aes_cbc, aes_cbc_get_maximum_length, resize=True) aes_cbc_with_ecdh_key = _wrap_bin(aes_cbc_with_ecdh_key, aes_cbc_with_ecdh_key_get_maximum_length, resize=True) base58_n_to_bytes = _wrap_bin(base58_n_to_bytes, base58_n_to_bytes_len, resize=True) base58_to_bytes = _wrap_bin(base58_to_bytes, base58_to_bytes_len, resize=True) +base64_n_to_bytes = _wrap_bin(base64_n_to_bytes, base64_n_get_maximum_length, resize=True) base64_to_bytes = _wrap_bin(base64_to_bytes, base64_get_maximum_length, resize=True) bip32_key_from_base58 = bip32_key_from_base58_alloc bip32_key_from_base58_n = bip32_key_from_base58_n_alloc diff --git a/src/test/test_base64.py b/src/test/test_base64.py index 2cda1df6e..014de1ec6 100755 --- a/src/test/test_base64.py +++ b/src/test/test_base64.py @@ -35,12 +35,19 @@ def test_vectors(self): self.assertEqual(ret, WALLY_OK) self.assertTrue(max_len >= len(str_in)) + ret, max_len_n = wally_base64_n_get_maximum_length(b64_in, len(b64_in), 0) + self.assertEqual(ret, WALLY_OK) + self.assertEqual(max_len, max_len_n) + ret, b64_out = wally_base64_from_bytes(utf8(str_in), len(str_in), 0) self.assertEqual((ret, b64_out), (WALLY_OK, b64_in)) ret, written = wally_base64_to_bytes(utf8(b64_in), 0, buf, max_len) self.assertEqual((ret, buf[:written]), (WALLY_OK, utf8(str_in))) + ret, written = wally_base64_n_to_bytes(utf8(b64_in), len(b64_in), 0, buf, max_len) + self.assertEqual((ret, buf[:written]), (WALLY_OK, utf8(str_in))) + def test_get_maximum_length(self): # Invalid args valid_b64 = utf8(ROUND_TRIP_CASES[0][1]) @@ -69,6 +76,7 @@ def test_base64_to_bytes(self): # Invalid args buf, buf_len = make_cbuffer('00' * 1024) valid_b64 = utf8(ROUND_TRIP_CASES[0][1]) + valid_len = len(valid_b64) _, max_len = wally_base64_get_maximum_length(valid_b64, 0) for args in [ @@ -80,6 +88,13 @@ def test_base64_to_bytes(self): ret, written = wally_base64_to_bytes(*args) self.assertEqual((ret, written), (WALLY_EINVAL, 0)) + for args in [ + (None, valid_len, 0, buf, max_len), # NULL base64 string, non-0 length + (valid_b64, 0, 0, buf, max_len), # Non-NULL base64 string, 0 length + ]: + ret, written = wally_base64_n_to_bytes(*args) + self.assertEqual((ret, written), (WALLY_EINVAL, 0)) + # Too short output length returns the number of bytes needed ret, written = wally_base64_to_bytes(valid_b64, 0, buf, max_len-1) self.assertEqual((ret, written), (WALLY_OK, max_len)) diff --git a/src/test/util.py b/src/test/util.py index c2f709d26..da67f19f1 100755 --- a/src/test/util.py +++ b/src/test/util.py @@ -300,6 +300,8 @@ class wally_psbt(Structure): ('wally_base58_to_bytes', c_int, [c_char_p, c_uint32, c_void_p, c_size_t, c_size_t_p]), ('wally_base64_from_bytes', c_int, [c_void_p, c_size_t, c_uint32, c_char_p_p]), ('wally_base64_get_maximum_length', c_int, [c_char_p, c_uint32, c_size_t_p]), + ('wally_base64_n_get_maximum_length', c_int, [c_char_p, c_size_t, c_uint32, c_size_t_p]), + ('wally_base64_n_to_bytes', c_int, [c_char_p, c_size_t, c_uint32, c_void_p, c_size_t, c_size_t_p]), ('wally_base64_to_bytes', c_int, [c_char_p, c_uint32, c_void_p, c_size_t, c_size_t_p]), ('wally_bip32_key_to_addr_segwit', c_int, [POINTER(ext_key), c_char_p, c_uint32, c_char_p_p]), ('wally_bip32_key_to_address', c_int, [POINTER(ext_key), c_uint32, c_uint32, c_char_p_p]), diff --git a/src/wasm_package/src/functions.js b/src/wasm_package/src/functions.js index 692b43a62..2feb1c952 100644 --- a/src/wasm_package/src/functions.js +++ b/src/wasm_package/src/functions.js @@ -96,6 +96,7 @@ export const base58_get_length = wrap('wally_base58_get_length', [T.String, T.De export const base58_n_get_length = wrap('wally_base58_n_get_length', [T.String, T.Int32, T.DestPtr(T.Int32)]); export const base64_from_bytes = wrap('wally_base64_from_bytes', [T.Bytes, T.Int32, T.DestPtrPtr(T.String)]); export const base64_get_maximum_length = wrap('wally_base64_get_maximum_length', [T.String, T.Int32, T.DestPtr(T.Int32)]); +export const base64_n_get_maximum_length = wrap('wally_base64_n_get_maximum_length', [T.String, T.Int32, T.Int32, T.DestPtr(T.Int32)]); export const bip32_key_free = wrap('bip32_key_free', [T.OpaqueRef]); export const bip32_key_from_base58 = wrap('bip32_key_from_base58_alloc', [T.String, T.DestPtrPtr(T.OpaqueRef)]); export const bip32_key_from_base58_n = wrap('bip32_key_from_base58_n_alloc', [T.String, T.Int32, T.DestPtrPtr(T.OpaqueRef)]); @@ -781,6 +782,7 @@ export const asset_pak_whitelistproof = wrap('wally_asset_pak_whitelistproof', [ export const asset_surjectionproof = wrap('wally_asset_surjectionproof', [T.Bytes, T.Bytes, T.Bytes, T.Bytes, T.Bytes, T.Bytes, T.Bytes, T.DestPtrVarLen(T.Bytes, asset_surjectionproof_len, false)]); export const base58_n_to_bytes = wrap('wally_base58_n_to_bytes', [T.String, T.Int32, T.Int32, T.DestPtrVarLen(T.Bytes, base58_n_to_bytes_len, true)]); export const base58_to_bytes = wrap('wally_base58_to_bytes', [T.String, T.Int32, T.DestPtrVarLen(T.Bytes, base58_to_bytes_len, true)]); +export const base64_n_to_bytes = wrap('wally_base64_n_to_bytes', [T.String, T.Int32, T.Int32, T.DestPtrVarLen(T.Bytes, base64_n_get_maximum_length, true)]); export const base64_to_bytes = wrap('wally_base64_to_bytes', [T.String, T.Int32, T.DestPtrVarLen(T.Bytes, base64_get_maximum_length, true)]); export const descriptor_get_key_child_path_str = wrap('wally_descriptor_get_key_child_path_str', [T.OpaqueRef, T.Int32, T.DestPtrPtr(T.String)]); export const descriptor_get_key_origin_path_str = wrap('wally_descriptor_get_key_origin_path_str', [T.OpaqueRef, T.Int32, T.DestPtrPtr(T.String)]); diff --git a/src/wasm_package/src/index.d.ts b/src/wasm_package/src/index.d.ts index 707338a53..8345a4731 100644 --- a/src/wasm_package/src/index.d.ts +++ b/src/wasm_package/src/index.d.ts @@ -56,6 +56,7 @@ export function base58_get_length(str_in: string): number; export function base58_n_get_length(str_in: string, str_len: number): number; export function base64_from_bytes(bytes: Buffer|Uint8Array, flags: number): string; export function base64_get_maximum_length(str_in: string, flags: number): number; +export function base64_n_get_maximum_length(str_in: string, str_len: number, flags: number): number; export function bip32_key_free(hdkey: Ref_ext_key): void; export function bip32_key_from_base58(base58: string): Ref_ext_key; export function bip32_key_from_base58_n(base58: string, base58_len: number): Ref_ext_key; @@ -741,6 +742,7 @@ export function asset_pak_whitelistproof(online_keys: Buffer|Uint8Array, offline export function asset_surjectionproof(output_asset: Buffer|Uint8Array, output_abf: Buffer|Uint8Array, output_generator: Buffer|Uint8Array, bytes: Buffer|Uint8Array, asset: Buffer|Uint8Array, abf: Buffer|Uint8Array, generator: Buffer|Uint8Array): Buffer; export function base58_n_to_bytes(str_in: string, str_len: number, flags: number): Buffer; export function base58_to_bytes(str_in: string, flags: number): Buffer; +export function base64_n_to_bytes(str_in: string, str_len: number, flags: number): Buffer; export function base64_to_bytes(str_in: string, flags: number): Buffer; export function descriptor_get_key_child_path_str(descriptor: Ref_wally_descriptor, index: number): string; export function descriptor_get_key_origin_path_str(descriptor: Ref_wally_descriptor, index: number): string; diff --git a/tools/wasm_exports.sh b/tools/wasm_exports.sh index d2a91c79f..a3c2d2a11 100644 --- a/tools/wasm_exports.sh +++ b/tools/wasm_exports.sh @@ -75,6 +75,8 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_base58_to_bytes' \ ,'_wally_base64_from_bytes' \ ,'_wally_base64_get_maximum_length' \ +,'_wally_base64_n_get_maximum_length' \ +,'_wally_base64_n_to_bytes' \ ,'_wally_base64_to_bytes' \ ,'_wally_bip32_key_to_addr_segwit' \ ,'_wally_bip32_key_to_address' \ From b5020721248ed958eeb21b10a5c7dc49233df209 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 8 Jan 2025 17:48:27 +1300 Subject: [PATCH 2/4] psbt: add a known-length call for psbt_from_base64 --- include/wally.hpp | 12 +++++++++--- include/wally_psbt.h | 17 ++++++++++++++--- src/psbt.c | 13 ++++++++++--- src/swig_java/swig.i | 1 + src/test/test_psbt.py | 8 +++++++- src/test/util.py | 1 + src/wasm_package/src/functions.js | 1 + src/wasm_package/src/index.d.ts | 3 ++- tools/wasm_exports.sh | 1 + 9 files changed, 46 insertions(+), 11 deletions(-) diff --git a/include/wally.hpp b/include/wally.hpp index c75b4b4a0..1d7a0f969 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -1214,9 +1214,15 @@ inline int psbt_free(struct wally_psbt* psbt) { return detail::check_ret(__FUNCTION__, ret); } -template -inline int psbt_from_base64(const BASE64& base64, uint32_t flags, struct wally_psbt** output) { - int ret = ::wally_psbt_from_base64(detail::get_p(base64), flags, output); +template +inline int psbt_from_base64(const STR_IN& str_in, uint32_t flags, struct wally_psbt** output) { + int ret = ::wally_psbt_from_base64(detail::get_p(str_in), flags, output); + return detail::check_ret(__FUNCTION__, ret); +} + +template +inline int psbt_from_base64_n(const STR_IN& str_in, size_t str_len, uint32_t flags, struct wally_psbt** output) { + int ret = ::wally_psbt_from_base64_n(detail::get_p(str_in), str_len, flags, output); return detail::check_ret(__FUNCTION__, ret); } diff --git a/include/wally_psbt.h b/include/wally_psbt.h index 98e95d925..b8016406f 100644 --- a/include/wally_psbt.h +++ b/include/wally_psbt.h @@ -2363,14 +2363,25 @@ WALLY_CORE_API int wally_psbt_to_bytes( size_t *written); /** - * Create a PSBT from its serialized base64 string. + * Create a PSBT from a serialized base64 string. * - * :param base64: Base64 string to create the PSBT from. + * :param str_in: Base64 string to create the PSBT from. * :param flags: `WALLY_PSBT_PARSE_FLAG_STRICT` or 0. * :param output: Destination for the resulting PSBT. */ WALLY_CORE_API int wally_psbt_from_base64( - const char *base64, + const char *str_in, + uint32_t flags, + struct wally_psbt **output); + +/** + * Create a PSBT from a known-length serialized base64 string. + * + * See `wally_psbt_from_base64`. + */ +WALLY_CORE_API int wally_psbt_from_base64_n( + const char *str_in, + size_t str_len, uint32_t flags, struct wally_psbt **output); diff --git a/src/psbt.c b/src/psbt.c index cfdd644c0..03a715827 100644 --- a/src/psbt.c +++ b/src/psbt.c @@ -3357,14 +3357,14 @@ int wally_psbt_to_bytes(const struct wally_psbt *psbt, uint32_t flags, return WALLY_OK; } -int wally_psbt_from_base64(const char *base64, uint32_t flags, struct wally_psbt **output) +int wally_psbt_from_base64_n(const char *str_in, size_t str_len, uint32_t flags, struct wally_psbt **output) { unsigned char *decoded; size_t max_len, written; int ret; OUTPUT_CHECK; - if ((ret = wally_base64_get_maximum_length(base64, 0, &max_len)) != WALLY_OK) + if ((ret = wally_base64_n_get_maximum_length(str_in, str_len, 0, &max_len)) != WALLY_OK) return ret; /* Allocate the buffer to decode into */ @@ -3372,7 +3372,8 @@ int wally_psbt_from_base64(const char *base64, uint32_t flags, struct wally_psbt return WALLY_ENOMEM; /* Decode the base64 psbt into binary */ - if ((ret = wally_base64_to_bytes(base64, 0, decoded, max_len, &written)) != WALLY_OK) + ret = wally_base64_n_to_bytes(str_in, str_len, 0, decoded, max_len, &written); + if (ret != WALLY_OK) goto done; if (written <= sizeof(PSBT_MAGIC)) { @@ -3392,6 +3393,12 @@ int wally_psbt_from_base64(const char *base64, uint32_t flags, struct wally_psbt return ret; } +int wally_psbt_from_base64(const char *str_in, uint32_t flags, struct wally_psbt **output) +{ + size_t str_len = str_in ? strlen(str_in) : 0; + return wally_psbt_from_base64_n(str_in, str_len, flags, output); +} + int wally_psbt_to_base64(const struct wally_psbt *psbt, uint32_t flags, char **output) { unsigned char *buff; diff --git a/src/swig_java/swig.i b/src/swig_java/swig.i index 24a1258fb..fbb729dc1 100644 --- a/src/swig_java/swig.i +++ b/src/swig_java/swig.i @@ -731,6 +731,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %returns_size_t(wally_psbt_find_global_scalar); %returns_void__(wally_psbt_free); %returns_struct(wally_psbt_from_base64, wally_psbt); +%returns_struct(wally_psbt_from_base64_n, wally_psbt); %returns_struct(wally_psbt_from_bytes, wally_psbt); %returns_struct(wally_psbt_from_tx, wally_psbt); %returns_void__(wally_psbt_generate_input_explicit_proofs); diff --git a/src/test/test_psbt.py b/src/test/test_psbt.py index 8c5226201..a114adb1c 100644 --- a/src/test/test_psbt.py +++ b/src/test/test_psbt.py @@ -320,13 +320,19 @@ def test_invalid_args(self): # psbt_from_base64 src_base64 = JSON['valid'][0]['psbt'] + src_len = len(src_base64) for args in [(None, 0, psbt), # NULL base64 ('', 0, psbt), # Empty base64 (src_base64, 0xff, psbt), # Invalid flags (src_base64, 0, None)]: # NULL dest self.assertEqual(WALLY_EINVAL, wally_psbt_from_base64(*args)) - self.assertEqual(WALLY_OK, wally_psbt_from_base64(JSON['valid'][0]['psbt'], 0, psbt)) + for args in [(None, src_len, 0, psbt), # NULL base64 string, non-0 length + (src_base64, 0, 0, psbt)]: # Non-NULL base64 string, 0 length + self.assertEqual(WALLY_EINVAL, wally_psbt_from_base64_n(*args)) + + self.assertEqual(WALLY_OK, wally_psbt_from_base64(src_base64, 0, psbt)) + self.assertEqual(WALLY_OK, wally_psbt_from_base64_n(src_base64, src_len, 0, psbt)) # psbt_clone_alloc clone = pointer(wally_psbt()) diff --git a/src/test/util.py b/src/test/util.py index da67f19f1..393406837 100755 --- a/src/test/util.py +++ b/src/test/util.py @@ -448,6 +448,7 @@ class wally_psbt(Structure): ('wally_psbt_find_input_spending_utxo', c_int, [POINTER(wally_psbt), c_void_p, c_size_t, c_uint32, c_size_t_p]), ('wally_psbt_free', c_int, [POINTER(wally_psbt)]), ('wally_psbt_from_base64', c_int, [c_char_p, c_uint32, POINTER(POINTER(wally_psbt))]), + ('wally_psbt_from_base64_n', c_int, [c_char_p, c_size_t, c_uint32, POINTER(POINTER(wally_psbt))]), ('wally_psbt_from_bytes', c_int, [c_void_p, c_size_t, c_uint32, POINTER(POINTER(wally_psbt))]), ('wally_psbt_from_tx', c_int, [POINTER(wally_tx), c_uint32, c_uint32, POINTER(POINTER(wally_psbt))]), ('wally_psbt_get_id', c_int, [POINTER(wally_psbt), c_uint32, c_void_p, c_size_t]), diff --git a/src/wasm_package/src/functions.js b/src/wasm_package/src/functions.js index 2feb1c952..be25e8907 100644 --- a/src/wasm_package/src/functions.js +++ b/src/wasm_package/src/functions.js @@ -318,6 +318,7 @@ export const psbt_find_output_keypath = wrap('wally_psbt_find_output_keypath', [ export const psbt_find_output_unknown = wrap('wally_psbt_find_output_unknown', [T.OpaqueRef, T.Int32, T.Bytes, T.DestPtr(T.Int32)]); export const psbt_free = wrap('wally_psbt_free', [T.OpaqueRef]); export const psbt_from_base64 = wrap('wally_psbt_from_base64', [T.String, T.Int32, T.DestPtrPtr(T.OpaqueRef)]); +export const psbt_from_base64_n = wrap('wally_psbt_from_base64_n', [T.String, T.Int32, T.Int32, T.DestPtrPtr(T.OpaqueRef)]); export const psbt_from_bytes = wrap('wally_psbt_from_bytes', [T.Bytes, T.Int32, T.DestPtrPtr(T.OpaqueRef)]); export const psbt_from_tx = wrap('wally_psbt_from_tx', [T.OpaqueRef, T.Int32, T.Int32, T.DestPtrPtr(T.OpaqueRef)]); export const psbt_generate_input_explicit_proofs = wrap('wally_psbt_generate_input_explicit_proofs', [T.OpaqueRef, T.Int32, T.Int64, T.Bytes, T.Bytes, T.Bytes, T.Bytes]); diff --git a/src/wasm_package/src/index.d.ts b/src/wasm_package/src/index.d.ts index 8345a4731..03f602fa0 100644 --- a/src/wasm_package/src/index.d.ts +++ b/src/wasm_package/src/index.d.ts @@ -277,7 +277,8 @@ export function psbt_find_input_unknown(psbt: Ref_wally_psbt, index: number, key export function psbt_find_output_keypath(psbt: Ref_wally_psbt, index: number, key: Buffer|Uint8Array): number; export function psbt_find_output_unknown(psbt: Ref_wally_psbt, index: number, key: Buffer|Uint8Array): number; export function psbt_free(psbt: Ref_wally_psbt): void; -export function psbt_from_base64(base64: string, flags: number): Ref_wally_psbt; +export function psbt_from_base64(str_in: string, flags: number): Ref_wally_psbt; +export function psbt_from_base64_n(str_in: string, str_len: number, flags: number): Ref_wally_psbt; export function psbt_from_bytes(bytes: Buffer|Uint8Array, flags: number): Ref_wally_psbt; export function psbt_from_tx(tx: Ref_wally_tx, version: number, flags: number): Ref_wally_psbt; export function psbt_generate_input_explicit_proofs(psbt: Ref_wally_psbt, index: number, satoshi: bigint, asset: Buffer|Uint8Array, abf: Buffer|Uint8Array, vbf: Buffer|Uint8Array, entropy: Buffer|Uint8Array): void; diff --git a/tools/wasm_exports.sh b/tools/wasm_exports.sh index a3c2d2a11..bb5581480 100644 --- a/tools/wasm_exports.sh +++ b/tools/wasm_exports.sh @@ -211,6 +211,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_psbt_find_output_unknown' \ ,'_wally_psbt_free' \ ,'_wally_psbt_from_base64' \ +,'_wally_psbt_from_base64_n' \ ,'_wally_psbt_from_bytes' \ ,'_wally_psbt_from_tx' \ ,'_wally_psbt_get_fallback_locktime' \ From c44a5bbcaf68e3ab1d3ace7e9a564f6bcca486ab Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Fri, 10 Jan 2025 14:28:48 +1300 Subject: [PATCH 3/4] psbt: expose accessors for inputs taproot internal key --- include/wally.hpp | 6 ++++++ include/wally_psbt.h | 12 ++++++++++++ include/wally_psbt_members.h | 3 +++ src/psbt.c | 2 ++ src/swig_java/swig.i | 4 ++++ src/swig_python/contrib/psbt.py | 4 ++++ src/swig_python/python_extra.py_in | 1 + src/test/util.py | 4 ++++ src/wasm_package/src/functions.js | 4 ++++ src/wasm_package/src/index.d.ts | 4 ++++ tools/wasm_exports.sh | 4 ++++ 11 files changed, 48 insertions(+) diff --git a/include/wally.hpp b/include/wally.hpp index 1d7a0f969..0e384da53 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -1420,6 +1420,12 @@ inline int psbt_input_set_signatures(const INPUT& input, const struct wally_map* return detail::check_ret(__FUNCTION__, ret); } +template +inline int psbt_input_set_taproot_internal_key(const INPUT& input, const PUB_KEY& pub_key) { + int ret = ::wally_psbt_input_set_taproot_internal_key(detail::get_p(input), pub_key.data(), pub_key.size()); + return detail::check_ret(__FUNCTION__, ret); +} + template inline int psbt_input_set_taproot_signature(const INPUT& input, const TAP_SIG& tap_sig) { int ret = ::wally_psbt_input_set_taproot_signature(detail::get_p(input), tap_sig.data(), tap_sig.size()); diff --git a/include/wally_psbt.h b/include/wally_psbt.h index b8016406f..c261c2a27 100644 --- a/include/wally_psbt.h +++ b/include/wally_psbt.h @@ -354,6 +354,18 @@ WALLY_CORE_API int wally_psbt_input_set_taproot_signature( const unsigned char *tap_sig, size_t tap_sig_len); +/** + * Set the taproot internal public key in an input. + * + * :param input: The input to update. + * :param pub_key: The x-only internal public key for this input. + * :param pub_key_len: The length of ``pub_key`` in bytes. Must be `EC_XONLY_PUBLIC_KEY_LEN`. + */ +WALLY_CORE_API int wally_psbt_input_set_taproot_internal_key( + struct wally_psbt_input *input, + const unsigned char *pub_key, + size_t pub_key_len); + /** * Find a partial signature matching a pubkey in an input. * diff --git a/include/wally_psbt_members.h b/include/wally_psbt_members.h index 8ffb0fb8c..d426a8b71 100644 --- a/include/wally_psbt_members.h +++ b/include/wally_psbt_members.h @@ -52,6 +52,8 @@ WALLY_CORE_API int wally_psbt_get_input_signature(const struct wally_psbt *psbt, WALLY_CORE_API int wally_psbt_get_input_signature_len(const struct wally_psbt *psbt, size_t index, size_t subindex, size_t *written); WALLY_CORE_API int wally_psbt_get_input_taproot_signature(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written); WALLY_CORE_API int wally_psbt_get_input_taproot_signature_len(const struct wally_psbt *psbt, size_t index, size_t *written); +WALLY_CORE_API int wally_psbt_get_input_taproot_internal_key(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written); +WALLY_CORE_API int wally_psbt_get_input_taproot_internal_key_len(const struct wally_psbt *psbt, size_t index, size_t *written); WALLY_CORE_API int wally_psbt_get_input_unknowns_size(const struct wally_psbt *psbt, size_t index, size_t *written); WALLY_CORE_API int wally_psbt_find_input_unknown(const struct wally_psbt *psbt, size_t index, const unsigned char *key, size_t key_len, size_t *written); WALLY_CORE_API int wally_psbt_get_input_unknown(const struct wally_psbt *psbt, size_t index, size_t subindex, unsigned char *bytes_out, size_t len, size_t *written); @@ -79,6 +81,7 @@ WALLY_CORE_API int wally_psbt_set_input_final_witness(struct wally_psbt *psbt, s WALLY_CORE_API int wally_psbt_set_input_keypaths(struct wally_psbt *psbt, size_t index, const struct wally_map *map_in); WALLY_CORE_API int wally_psbt_set_input_signatures(struct wally_psbt *psbt, size_t index, const struct wally_map *map_in); WALLY_CORE_API int wally_psbt_set_input_taproot_signature(struct wally_psbt *psbt, size_t index, const unsigned char *sig, size_t sig_len); +WALLY_CORE_API int wally_psbt_set_input_taproot_internal_key(struct wally_psbt *psbt, size_t index, const unsigned char *pub_key, size_t pub_key_len); WALLY_CORE_API int wally_psbt_add_input_signature(struct wally_psbt *psbt, size_t index, const unsigned char *pub_key, size_t pub_key_len, const unsigned char *sig, size_t sig_len); WALLY_CORE_API int wally_psbt_set_input_unknowns(struct wally_psbt *psbt, size_t index, const struct wally_map *map_in); WALLY_CORE_API int wally_psbt_set_input_sighash(struct wally_psbt *psbt, size_t index, uint32_t sighash); diff --git a/src/psbt.c b/src/psbt.c index 03a715827..dacdf19d2 100644 --- a/src/psbt.c +++ b/src/psbt.c @@ -389,6 +389,7 @@ MAP_INNER_FIELD(input, redeem_script, PSBT_IN_REDEEM_SCRIPT, psbt_fields) MAP_INNER_FIELD(input, witness_script, PSBT_IN_WITNESS_SCRIPT, psbt_fields) MAP_INNER_FIELD(input, final_scriptsig, PSBT_IN_FINAL_SCRIPTSIG, psbt_fields) MAP_INNER_FIELD(input, taproot_signature, PSBT_IN_TAP_KEY_SIG, psbt_fields) +MAP_INNER_FIELD(input, taproot_internal_key, PSBT_IN_TAP_INTERNAL_KEY, psbt_fields) SET_STRUCT(wally_psbt_input, final_witness, wally_tx_witness_stack, wally_tx_witness_stack_clone_alloc, wally_tx_witness_stack_free) SET_MAP(wally_psbt_input, keypath,) @@ -5574,6 +5575,7 @@ PSBT_FIELD(input, redeem_script, PSBT_0) PSBT_FIELD(input, witness_script, PSBT_0) PSBT_FIELD(input, final_scriptsig, PSBT_0) PSBT_FIELD(input, taproot_signature, PSBT_0) +PSBT_FIELD(input, taproot_internal_key, PSBT_0) PSBT_GET_S(input, final_witness, wally_tx_witness_stack, wally_tx_witness_stack_clone_alloc) PSBT_GET_M(input, keypath) PSBT_GET_M(input, signature) diff --git a/src/swig_java/swig.i b/src/swig_java/swig.i index fbb729dc1..c4644fa9e 100644 --- a/src/swig_java/swig.i +++ b/src/swig_java/swig.i @@ -802,6 +802,8 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %returns_size_t(wally_psbt_get_input_signature_hash); %returns_size_t(wally_psbt_get_input_signature_len); %returns_size_t(wally_psbt_get_input_sighash); +%returns_size_t(wally_psbt_get_input_taproot_internal_key); +%returns_size_t(wally_psbt_get_input_taproot_internal_key_len); %returns_size_t(wally_psbt_get_input_taproot_signature); %returns_size_t(wally_psbt_get_input_taproot_signature_len); %returns_size_t(wally_psbt_get_input_unknown); @@ -913,6 +915,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %returns_void__(wally_psbt_set_input_sighash); %returns_void__(wally_psbt_set_input_signatures); %returns_void__(wally_psbt_set_input_taproot_signature); +%returns_void__(wally_psbt_set_input_taproot_internal_key); %returns_void__(wally_psbt_set_input_unknowns); %returns_void__(wally_psbt_set_input_utxo); %returns_void__(wally_psbt_set_input_utxo_rangeproof); @@ -1292,6 +1295,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %ignore wally_psbt_input_get_inflation_keys_blinding_rangeproof_len; %ignore wally_psbt_input_set_inflation_keys_blinding_rangeproof; %ignore wally_psbt_input_clear_inflation_keys_blinding_rangeproof; +%ignore wally_psbt_input_set_taproot_internal_key; %ignore wally_psbt_input_set_taproot_signature; %ignore wally_psbt_input_get_utxo_rangeproof; %ignore wally_psbt_input_get_utxo_rangeproof_len; diff --git a/src/swig_python/contrib/psbt.py b/src/swig_python/contrib/psbt.py index 66cdcc5e7..0c9755b17 100644 --- a/src/swig_python/contrib/psbt.py +++ b/src/swig_python/contrib/psbt.py @@ -336,6 +336,7 @@ def test_psbt(self): dummy_sig_tap_default = TAPROOT_SIG_BYTES # SIGHASH_DEFAULT dummy_sig_tap_all = TAPROOT_SIG_BYTES + bytearray(b'\x01') # SIGHASH_ALL dummy_sig_tap_single = TAPROOT_SIG_BYTES + bytearray(b'\x03') # SIGHASH_SINGLE + dummy_tap_internal_key = bytearray(b'\x01' * 32) # Untweaked x-only pubkey if is_elements_build(): dummy_nonce = bytearray(b'\x00' * WALLY_TX_ASSET_CT_NONCE_LEN) dummy_bf = bytearray(b'\x00' * BLINDING_FACTOR_LEN) @@ -493,6 +494,9 @@ def test_psbt(self): self._try_get_set_b(psbt_set_input_taproot_signature, psbt_get_input_taproot_signature, None, psbt, dummy_sig_tap_default) + self._try_get_set_b(psbt_set_input_taproot_internal_key, + psbt_get_input_taproot_internal_key, + None, psbt, dummy_tap_internal_key) # Test finding the UXTO an input spends by txid/vout utxo_txhash = psbt_get_input_previous_txid(psbt, 0) utxo_index = psbt_get_input_output_index(psbt, 0) diff --git a/src/swig_python/python_extra.py_in b/src/swig_python/python_extra.py_in index a3eb630ef..ef8184807 100644 --- a/src/swig_python/python_extra.py_in +++ b/src/swig_python/python_extra.py_in @@ -197,6 +197,7 @@ psbt_get_input_scriptcode = _wrap_bin(psbt_get_input_scriptcode, psbt_get_input_ psbt_get_input_signature = _wrap_bin(psbt_get_input_signature, psbt_get_input_signature_len) psbt_get_input_signature_hash = _wrap_bin(psbt_get_input_signature_hash, SHA256_LEN) psbt_get_input_signing_script = _wrap_bin(psbt_get_input_signing_script, psbt_get_input_signing_script_len) +psbt_get_input_taproot_internal_key = _wrap_bin(psbt_get_input_taproot_internal_key, psbt_get_input_taproot_internal_key_len) psbt_get_input_taproot_signature = _wrap_bin(psbt_get_input_taproot_signature, psbt_get_input_taproot_signature_len) psbt_get_input_unknown = _wrap_bin(psbt_get_input_unknown, psbt_get_input_unknown_len) psbt_get_input_utxo = psbt_get_input_utxo_alloc diff --git a/src/test/util.py b/src/test/util.py index 393406837..5ee5f5d8e 100755 --- a/src/test/util.py +++ b/src/test/util.py @@ -548,6 +548,7 @@ class wally_psbt(Structure): ('wally_psbt_input_set_sequence', c_int, [POINTER(wally_psbt_input), c_uint32]), ('wally_psbt_input_set_sighash', c_int, [POINTER(wally_psbt_input), c_uint32]), ('wally_psbt_input_set_signatures', c_int, [POINTER(wally_psbt_input), POINTER(wally_map)]), + ('wally_psbt_input_set_taproot_internal_key', c_int, [POINTER(wally_psbt_input), c_void_p, c_size_t]), ('wally_psbt_input_set_taproot_signature', c_int, [POINTER(wally_psbt_input), c_void_p, c_size_t]), ('wally_psbt_input_set_unknowns', c_int, [POINTER(wally_psbt_input), POINTER(wally_map)]), ('wally_psbt_input_set_utxo', c_int, [POINTER(wally_psbt_input), POINTER(wally_tx)]), @@ -839,6 +840,8 @@ class wally_psbt(Structure): ('wally_psbt_get_input_signature', c_int, [POINTER(wally_psbt), c_size_t, c_size_t, c_void_p, c_size_t, c_size_t_p]), ('wally_psbt_get_input_signature_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t, c_size_t_p]), ('wally_psbt_get_input_signatures_size', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]), + ('wally_psbt_get_input_taproot_internal_key', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_size_t_p]), + ('wally_psbt_get_input_taproot_internal_key_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]), ('wally_psbt_get_input_taproot_signature', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_size_t_p]), ('wally_psbt_get_input_taproot_signature_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]), ('wally_psbt_get_input_unknown', c_int, [POINTER(wally_psbt), c_size_t, c_size_t, c_void_p, c_size_t, c_size_t_p]), @@ -922,6 +925,7 @@ class wally_psbt(Structure): ('wally_psbt_set_input_sequence', c_int, [POINTER(wally_psbt), c_size_t, c_uint32]), ('wally_psbt_set_input_sighash', c_int, [POINTER(wally_psbt), c_size_t, c_uint32]), ('wally_psbt_set_input_signatures', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_map)]), + ('wally_psbt_set_input_taproot_internal_key', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]), ('wally_psbt_set_input_taproot_signature', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]), ('wally_psbt_set_input_unknowns', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_map)]), ('wally_psbt_set_input_utxo', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_tx)]), diff --git a/src/wasm_package/src/functions.js b/src/wasm_package/src/functions.js index be25e8907..b15ac488f 100644 --- a/src/wasm_package/src/functions.js +++ b/src/wasm_package/src/functions.js @@ -364,6 +364,7 @@ export const psbt_get_input_signature_hash = wrap('wally_psbt_get_input_signatur export const psbt_get_input_signature_len = wrap('wally_psbt_get_input_signature_len', [T.OpaqueRef, T.Int32, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_input_signatures_size = wrap('wally_psbt_get_input_signatures_size', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_input_signing_script_len = wrap('wally_psbt_get_input_signing_script_len', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); +export const psbt_get_input_taproot_internal_key_len = wrap('wally_psbt_get_input_taproot_internal_key_len', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_input_taproot_signature_len = wrap('wally_psbt_get_input_taproot_signature_len', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_input_unknown_len = wrap('wally_psbt_get_input_unknown_len', [T.OpaqueRef, T.Int32, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_input_unknowns_size = wrap('wally_psbt_get_input_unknowns_size', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); @@ -475,6 +476,7 @@ export const psbt_input_set_required_locktime = wrap('wally_psbt_input_set_requi export const psbt_input_set_sequence = wrap('wally_psbt_input_set_sequence', [T.OpaqueRef, T.Int32]); export const psbt_input_set_sighash = wrap('wally_psbt_input_set_sighash', [T.OpaqueRef, T.Int32]); export const psbt_input_set_signatures = wrap('wally_psbt_input_set_signatures', [T.OpaqueRef, T.OpaqueRef]); +export const psbt_input_set_taproot_internal_key = wrap('wally_psbt_input_set_taproot_internal_key', [T.OpaqueRef, T.Bytes]); export const psbt_input_set_taproot_signature = wrap('wally_psbt_input_set_taproot_signature', [T.OpaqueRef, T.Bytes]); export const psbt_input_set_unknowns = wrap('wally_psbt_input_set_unknowns', [T.OpaqueRef, T.OpaqueRef]); export const psbt_input_set_utxo = wrap('wally_psbt_input_set_utxo', [T.OpaqueRef, T.OpaqueRef]); @@ -561,6 +563,7 @@ export const psbt_set_input_required_locktime = wrap('wally_psbt_set_input_requi export const psbt_set_input_sequence = wrap('wally_psbt_set_input_sequence', [T.OpaqueRef, T.Int32, T.Int32]); export const psbt_set_input_sighash = wrap('wally_psbt_set_input_sighash', [T.OpaqueRef, T.Int32, T.Int32]); export const psbt_set_input_signatures = wrap('wally_psbt_set_input_signatures', [T.OpaqueRef, T.Int32, T.OpaqueRef]); +export const psbt_set_input_taproot_internal_key = wrap('wally_psbt_set_input_taproot_internal_key', [T.OpaqueRef, T.Int32, T.Bytes]); export const psbt_set_input_taproot_signature = wrap('wally_psbt_set_input_taproot_signature', [T.OpaqueRef, T.Int32, T.Bytes]); export const psbt_set_input_unknowns = wrap('wally_psbt_set_input_unknowns', [T.OpaqueRef, T.Int32, T.OpaqueRef]); export const psbt_set_input_utxo = wrap('wally_psbt_set_input_utxo', [T.OpaqueRef, T.Int32, T.OpaqueRef]); @@ -814,6 +817,7 @@ export const psbt_get_input_redeem_script = wrap('wally_psbt_get_input_redeem_sc export const psbt_get_input_scriptcode = wrap('wally_psbt_get_input_scriptcode', [T.OpaqueRef, T.Int32, T.Bytes, T.DestPtrVarLen(T.Bytes, psbt_get_input_scriptcode_len, false)]); export const psbt_get_input_signature = wrap('wally_psbt_get_input_signature', [T.OpaqueRef, T.Int32, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_input_signature_len, false)]); export const psbt_get_input_signing_script = wrap('wally_psbt_get_input_signing_script', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_input_signing_script_len, false)]); +export const psbt_get_input_taproot_internal_key = wrap('wally_psbt_get_input_taproot_internal_key', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_input_taproot_internal_key_len, false)]); export const psbt_get_input_taproot_signature = wrap('wally_psbt_get_input_taproot_signature', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_input_taproot_signature_len, false)]); export const psbt_get_input_unknown = wrap('wally_psbt_get_input_unknown', [T.OpaqueRef, T.Int32, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_input_unknown_len, false)]); export const psbt_get_input_utxo_rangeproof = wrap('wally_psbt_get_input_utxo_rangeproof', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_input_utxo_rangeproof_len, false)]); diff --git a/src/wasm_package/src/index.d.ts b/src/wasm_package/src/index.d.ts index 03f602fa0..669005f1f 100644 --- a/src/wasm_package/src/index.d.ts +++ b/src/wasm_package/src/index.d.ts @@ -324,6 +324,7 @@ export function psbt_get_input_signature_hash(psbt: Ref_wally_psbt, index: numbe export function psbt_get_input_signature_len(psbt: Ref_wally_psbt, index: number, subindex: number): number; export function psbt_get_input_signatures_size(psbt: Ref_wally_psbt, index: number): number; export function psbt_get_input_signing_script_len(psbt: Ref_wally_psbt, index: number): number; +export function psbt_get_input_taproot_internal_key_len(psbt: Ref_wally_psbt, index: number): number; export function psbt_get_input_taproot_signature_len(psbt: Ref_wally_psbt, index: number): number; export function psbt_get_input_unknown_len(psbt: Ref_wally_psbt, index: number, subindex: number): number; export function psbt_get_input_unknowns_size(psbt: Ref_wally_psbt, index: number): number; @@ -435,6 +436,7 @@ export function psbt_input_set_required_locktime(input: Ref_wally_psbt_input, re export function psbt_input_set_sequence(input: Ref_wally_psbt_input, sequence: number): void; export function psbt_input_set_sighash(input: Ref_wally_psbt_input, sighash: number): void; export function psbt_input_set_signatures(input: Ref_wally_psbt_input, map_in: Ref_wally_map): void; +export function psbt_input_set_taproot_internal_key(input: Ref_wally_psbt_input, pub_key: Buffer|Uint8Array): void; export function psbt_input_set_taproot_signature(input: Ref_wally_psbt_input, tap_sig: Buffer|Uint8Array): void; export function psbt_input_set_unknowns(input: Ref_wally_psbt_input, map_in: Ref_wally_map): void; export function psbt_input_set_utxo(input: Ref_wally_psbt_input, utxo: Ref_wally_tx): void; @@ -521,6 +523,7 @@ export function psbt_set_input_required_locktime(psbt: Ref_wally_psbt, index: nu export function psbt_set_input_sequence(psbt: Ref_wally_psbt, index: number, sequence: number): void; export function psbt_set_input_sighash(psbt: Ref_wally_psbt, index: number, sighash: number): void; export function psbt_set_input_signatures(psbt: Ref_wally_psbt, index: number, map_in: Ref_wally_map): void; +export function psbt_set_input_taproot_internal_key(psbt: Ref_wally_psbt, index: number, pub_key: Buffer|Uint8Array): void; export function psbt_set_input_taproot_signature(psbt: Ref_wally_psbt, index: number, sig: Buffer|Uint8Array): void; export function psbt_set_input_unknowns(psbt: Ref_wally_psbt, index: number, map_in: Ref_wally_map): void; export function psbt_set_input_utxo(psbt: Ref_wally_psbt, index: number, utxo: Ref_wally_tx): void; @@ -774,6 +777,7 @@ export function psbt_get_input_redeem_script(psbt: Ref_wally_psbt, index: number export function psbt_get_input_scriptcode(psbt: Ref_wally_psbt, index: number, script: Buffer|Uint8Array): Buffer; export function psbt_get_input_signature(psbt: Ref_wally_psbt, index: number, subindex: number): Buffer; export function psbt_get_input_signing_script(psbt: Ref_wally_psbt, index: number): Buffer; +export function psbt_get_input_taproot_internal_key(psbt: Ref_wally_psbt, index: number): Buffer; export function psbt_get_input_taproot_signature(psbt: Ref_wally_psbt, index: number): Buffer; export function psbt_get_input_unknown(psbt: Ref_wally_psbt, index: number, subindex: number): Buffer; export function psbt_get_input_utxo_rangeproof(psbt: Ref_wally_psbt, index: number): Buffer; diff --git a/tools/wasm_exports.sh b/tools/wasm_exports.sh index bb5581480..853fc6dd0 100644 --- a/tools/wasm_exports.sh +++ b/tools/wasm_exports.sh @@ -242,6 +242,8 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_psbt_get_input_signatures_size' \ ,'_wally_psbt_get_input_signing_script' \ ,'_wally_psbt_get_input_signing_script_len' \ +,'_wally_psbt_get_input_taproot_internal_key' \ +,'_wally_psbt_get_input_taproot_internal_key_len' \ ,'_wally_psbt_get_input_taproot_signature' \ ,'_wally_psbt_get_input_taproot_signature_len' \ ,'_wally_psbt_get_input_unknown' \ @@ -296,6 +298,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_psbt_input_set_sequence' \ ,'_wally_psbt_input_set_sighash' \ ,'_wally_psbt_input_set_signatures' \ +,'_wally_psbt_input_set_taproot_internal_key' \ ,'_wally_psbt_input_set_taproot_signature' \ ,'_wally_psbt_input_set_unknowns' \ ,'_wally_psbt_input_set_utxo' \ @@ -332,6 +335,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_psbt_set_input_sequence' \ ,'_wally_psbt_set_input_sighash' \ ,'_wally_psbt_set_input_signatures' \ +,'_wally_psbt_set_input_taproot_internal_key' \ ,'_wally_psbt_set_input_taproot_signature' \ ,'_wally_psbt_set_input_unknowns' \ ,'_wally_psbt_set_input_utxo' \ From 1fffafa23c67fd2264a27bc5c4352e3b512197d0 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Sat, 11 Jan 2025 22:17:04 +1300 Subject: [PATCH 4/4] psbt: expose accessors for outputs taproot internal key --- include/wally.hpp | 6 ++++++ include/wally_psbt.h | 13 +++++++++++++ include/wally_psbt_members.h | 3 +++ src/psbt.c | 2 ++ src/swig_java/swig.i | 4 ++++ src/swig_python/contrib/psbt.py | 3 +++ src/swig_python/python_extra.py_in | 1 + src/test/util.py | 4 ++++ src/wasm_package/src/functions.js | 4 ++++ src/wasm_package/src/index.d.ts | 4 ++++ tools/wasm_exports.sh | 4 ++++ 11 files changed, 48 insertions(+) diff --git a/include/wally.hpp b/include/wally.hpp index 0e384da53..5c49cef21 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -1533,6 +1533,12 @@ inline int psbt_output_set_script(const OUTPUT& output, const SCRIPT& script) { return detail::check_ret(__FUNCTION__, ret); } +template +inline int psbt_output_set_taproot_internal_key(const OUTPUT& output, const PUB_KEY& pub_key) { + int ret = ::wally_psbt_output_set_taproot_internal_key(detail::get_p(output), pub_key.data(), pub_key.size()); + return detail::check_ret(__FUNCTION__, ret); +} + template inline int psbt_output_set_unknowns(const OUTPUT& output, const struct wally_map* map_in) { int ret = ::wally_psbt_output_set_unknowns(detail::get_p(output), map_in); diff --git a/include/wally_psbt.h b/include/wally_psbt.h index c261c2a27..18593efdf 100644 --- a/include/wally_psbt.h +++ b/include/wally_psbt.h @@ -1434,6 +1434,19 @@ WALLY_CORE_API int wally_psbt_output_set_script( const unsigned char *script, size_t script_len); +/** + * Set the taproot internal public key in an output. + * + * :param output: The output to update. + * :param pub_key: The x-only internal public key for this output. + * :param pub_key_len: The length of ``pub_key`` in bytes. Must be `EC_XONLY_PUBLIC_KEY_LEN`. + */ +WALLY_CORE_API int wally_psbt_output_set_taproot_internal_key( + struct wally_psbt_output *output, + const unsigned char *pub_key, + size_t pub_key_len); + + #ifndef WALLY_ABI_NO_ELEMENTS /** * Set the input blinder index in an output. diff --git a/include/wally_psbt_members.h b/include/wally_psbt_members.h index d426a8b71..6e3965f2f 100644 --- a/include/wally_psbt_members.h +++ b/include/wally_psbt_members.h @@ -186,6 +186,8 @@ WALLY_CORE_API int wally_psbt_get_output_script(const struct wally_psbt *psbt, s WALLY_CORE_API int wally_psbt_get_output_script_len(const struct wally_psbt *psbt, size_t index, size_t *written); WALLY_CORE_API int wally_psbt_get_output_amount(const struct wally_psbt *psbt, size_t index, uint64_t *value_out); WALLY_CORE_API int wally_psbt_has_output_amount(const struct wally_psbt *psbt, size_t index, size_t *written); +WALLY_CORE_API int wally_psbt_get_output_taproot_internal_key(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written); +WALLY_CORE_API int wally_psbt_get_output_taproot_internal_key_len(const struct wally_psbt *psbt, size_t index, size_t *written); WALLY_CORE_API int wally_psbt_set_output_redeem_script(struct wally_psbt *psbt, size_t index, const unsigned char *script, size_t script_len); WALLY_CORE_API int wally_psbt_set_output_witness_script(struct wally_psbt *psbt, size_t index, const unsigned char *script, size_t script_len); @@ -194,6 +196,7 @@ WALLY_CORE_API int wally_psbt_set_output_unknowns(struct wally_psbt *psbt, size_ WALLY_CORE_API int wally_psbt_set_output_script(struct wally_psbt *psbt, size_t index, const unsigned char *script, size_t script_len); WALLY_CORE_API int wally_psbt_set_output_amount(struct wally_psbt *psbt, size_t index, uint64_t amount); WALLY_CORE_API int wally_psbt_clear_output_amount(struct wally_psbt *psbt, size_t index); +WALLY_CORE_API int wally_psbt_set_output_taproot_internal_key(struct wally_psbt *psbt, size_t index, const unsigned char *pub_key, size_t pub_key_len); #ifndef WALLY_ABI_NO_ELEMENTS WALLY_CORE_API int wally_psbt_get_output_blinder_index(const struct wally_psbt *psbt, size_t index, uint32_t *value_out); diff --git a/src/psbt.c b/src/psbt.c index dacdf19d2..ccc26441b 100644 --- a/src/psbt.c +++ b/src/psbt.c @@ -871,6 +871,7 @@ static int psbt_input_free(struct wally_psbt_input *input, bool free_parent) MAP_INNER_FIELD(output, redeem_script, PSBT_OUT_REDEEM_SCRIPT, psbt_fields) MAP_INNER_FIELD(output, witness_script, PSBT_OUT_WITNESS_SCRIPT, psbt_fields) +MAP_INNER_FIELD(output, taproot_internal_key, PSBT_OUT_TAP_INTERNAL_KEY, psbt_fields) SET_MAP(wally_psbt_output, keypath,) ADD_KEYPATH(wally_psbt_output) ADD_TAP_KEYPATH(wally_psbt_output) @@ -5712,6 +5713,7 @@ int wally_psbt_clear_input_required_lockheight(struct wally_psbt *psbt, size_t i if (!psbt || psbt->version != PSBT_2) return WALLY_EINVAL; return wally_psbt_input_clear_required_lockheight(psbt_get_input(psbt, index)); } +PSBT_FIELD(output, taproot_internal_key, PSBT_0) #ifndef WALLY_ABI_NO_ELEMENTS PSBT_GET_I_PSET(input, amount, uint64_t, PSBT_2) diff --git a/src/swig_java/swig.i b/src/swig_java/swig.i index c4644fa9e..f9b45595a 100644 --- a/src/swig_java/swig.i +++ b/src/swig_java/swig.i @@ -845,6 +845,8 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %returns_size_t(wally_psbt_get_output_redeem_script_len); %returns_size_t(wally_psbt_get_output_script); %returns_size_t(wally_psbt_get_output_script_len); +%returns_size_t(wally_psbt_get_output_taproot_internal_key); +%returns_size_t(wally_psbt_get_output_taproot_internal_key_len); %returns_size_t(wally_psbt_get_output_unknown); %returns_size_t(wally_psbt_get_output_unknown_len); %returns_size_t(wally_psbt_get_output_unknowns_size); @@ -934,6 +936,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %returns_void__(wally_psbt_set_output_keypaths); %returns_void__(wally_psbt_set_output_redeem_script); %returns_void__(wally_psbt_set_output_script); +%returns_void__(wally_psbt_set_output_taproot_internal_key); %returns_void__(wally_psbt_set_output_unknowns); %returns_void__(wally_psbt_set_output_value_blinding_rangeproof); %returns_void__(wally_psbt_set_output_value_commitment); @@ -1352,6 +1355,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %ignore wally_psbt_output_set_asset_blinding_surjectionproof; %ignore wally_psbt_output_clear_asset_blinding_surjectionproof; %ignore wally_psbt_output_get_blinding_status; +%ignore wally_psbt_output_set_taproot_internal_key; %include "../include/wally_core.h" %include "../include/wally_address.h" diff --git a/src/swig_python/contrib/psbt.py b/src/swig_python/contrib/psbt.py index 0c9755b17..3b8d669d4 100644 --- a/src/swig_python/contrib/psbt.py +++ b/src/swig_python/contrib/psbt.py @@ -655,6 +655,9 @@ def test_psbt(self): psbt_get_output_unknown, psbt_find_output_unknown, p, dummy_unknowns, dummy_unknown_key) + self._try_get_set_b(psbt_set_output_taproot_internal_key, + psbt_get_output_taproot_internal_key, + None, psbt, dummy_tap_internal_key) # # Outputs: PSBT V2 diff --git a/src/swig_python/python_extra.py_in b/src/swig_python/python_extra.py_in index ef8184807..a8cf554b7 100644 --- a/src/swig_python/python_extra.py_in +++ b/src/swig_python/python_extra.py_in @@ -206,6 +206,7 @@ psbt_get_input_witness_utxo = psbt_get_input_witness_utxo_alloc psbt_get_output_keypath = _wrap_bin(psbt_get_output_keypath, psbt_get_output_keypath_len) psbt_get_output_redeem_script = _wrap_bin(psbt_get_output_redeem_script, psbt_get_output_redeem_script_len) psbt_get_output_script = _wrap_bin(psbt_get_output_script, psbt_get_output_script_len) +psbt_get_output_taproot_internal_key = _wrap_bin(psbt_get_output_taproot_internal_key, psbt_get_output_taproot_internal_key_len) psbt_get_output_unknown = _wrap_bin(psbt_get_output_unknown, psbt_get_output_unknown_len) psbt_get_output_witness_script = _wrap_bin(psbt_get_output_witness_script, psbt_get_output_witness_script_len) psbt_init = psbt_init_alloc diff --git a/src/test/util.py b/src/test/util.py index 5ee5f5d8e..5b37098c3 100755 --- a/src/test/util.py +++ b/src/test/util.py @@ -604,6 +604,7 @@ class wally_psbt(Structure): ('wally_psbt_output_set_keypaths', c_int, [POINTER(wally_psbt_output), POINTER(wally_map)]), ('wally_psbt_output_set_redeem_script', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]), ('wally_psbt_output_set_script', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]), + ('wally_psbt_output_set_taproot_internal_key', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]), ('wally_psbt_output_set_unknowns', c_int, [POINTER(wally_psbt_output), POINTER(wally_map)]), ('wally_psbt_output_set_value_blinding_rangeproof', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]), ('wally_psbt_output_set_value_commitment', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]), @@ -877,6 +878,8 @@ class wally_psbt(Structure): ('wally_psbt_get_output_redeem_script_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]), ('wally_psbt_get_output_script', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_size_t_p]), ('wally_psbt_get_output_script_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]), + ('wally_psbt_get_output_taproot_internal_key', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_size_t_p]), + ('wally_psbt_get_output_taproot_internal_key_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]), ('wally_psbt_get_output_unknown', c_int, [POINTER(wally_psbt), c_size_t, c_size_t, c_void_p, c_size_t, c_size_t_p]), ('wally_psbt_get_output_unknown_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t, c_size_t_p]), ('wally_psbt_get_output_unknowns_size', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]), @@ -944,6 +947,7 @@ class wally_psbt(Structure): ('wally_psbt_set_output_keypaths', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_map)]), ('wally_psbt_set_output_redeem_script', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]), ('wally_psbt_set_output_script', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]), + ('wally_psbt_set_output_taproot_internal_key', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]), ('wally_psbt_set_output_unknowns', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_map)]), ('wally_psbt_set_output_value_blinding_rangeproof', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]), ('wally_psbt_set_output_value_commitment', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]), diff --git a/src/wasm_package/src/functions.js b/src/wasm_package/src/functions.js index b15ac488f..ba4b54a09 100644 --- a/src/wasm_package/src/functions.js +++ b/src/wasm_package/src/functions.js @@ -389,6 +389,7 @@ export const psbt_get_output_keypath_len = wrap('wally_psbt_get_output_keypath_l export const psbt_get_output_keypaths_size = wrap('wally_psbt_get_output_keypaths_size', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_output_redeem_script_len = wrap('wally_psbt_get_output_redeem_script_len', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_output_script_len = wrap('wally_psbt_get_output_script_len', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); +export const psbt_get_output_taproot_internal_key_len = wrap('wally_psbt_get_output_taproot_internal_key_len', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_output_unknown_len = wrap('wally_psbt_get_output_unknown_len', [T.OpaqueRef, T.Int32, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_output_unknowns_size = wrap('wally_psbt_get_output_unknowns_size', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); export const psbt_get_output_value_blinding_rangeproof_len = wrap('wally_psbt_get_output_value_blinding_rangeproof_len', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]); @@ -523,6 +524,7 @@ export const psbt_output_set_ecdh_public_key = wrap('wally_psbt_output_set_ecdh_ export const psbt_output_set_keypaths = wrap('wally_psbt_output_set_keypaths', [T.OpaqueRef, T.OpaqueRef]); export const psbt_output_set_redeem_script = wrap('wally_psbt_output_set_redeem_script', [T.OpaqueRef, T.Bytes]); export const psbt_output_set_script = wrap('wally_psbt_output_set_script', [T.OpaqueRef, T.Bytes]); +export const psbt_output_set_taproot_internal_key = wrap('wally_psbt_output_set_taproot_internal_key', [T.OpaqueRef, T.Bytes]); export const psbt_output_set_unknowns = wrap('wally_psbt_output_set_unknowns', [T.OpaqueRef, T.OpaqueRef]); export const psbt_output_set_value_blinding_rangeproof = wrap('wally_psbt_output_set_value_blinding_rangeproof', [T.OpaqueRef, T.Bytes]); export const psbt_output_set_value_commitment = wrap('wally_psbt_output_set_value_commitment', [T.OpaqueRef, T.Bytes]); @@ -582,6 +584,7 @@ export const psbt_set_output_ecdh_public_key = wrap('wally_psbt_set_output_ecdh_ export const psbt_set_output_keypaths = wrap('wally_psbt_set_output_keypaths', [T.OpaqueRef, T.Int32, T.OpaqueRef]); export const psbt_set_output_redeem_script = wrap('wally_psbt_set_output_redeem_script', [T.OpaqueRef, T.Int32, T.Bytes]); export const psbt_set_output_script = wrap('wally_psbt_set_output_script', [T.OpaqueRef, T.Int32, T.Bytes]); +export const psbt_set_output_taproot_internal_key = wrap('wally_psbt_set_output_taproot_internal_key', [T.OpaqueRef, T.Int32, T.Bytes]); export const psbt_set_output_unknowns = wrap('wally_psbt_set_output_unknowns', [T.OpaqueRef, T.Int32, T.OpaqueRef]); export const psbt_set_output_value_blinding_rangeproof = wrap('wally_psbt_set_output_value_blinding_rangeproof', [T.OpaqueRef, T.Int32, T.Bytes]); export const psbt_set_output_value_commitment = wrap('wally_psbt_set_output_value_commitment', [T.OpaqueRef, T.Int32, T.Bytes]); @@ -831,6 +834,7 @@ export const psbt_get_output_ecdh_public_key = wrap('wally_psbt_get_output_ecdh_ export const psbt_get_output_keypath = wrap('wally_psbt_get_output_keypath', [T.OpaqueRef, T.Int32, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_output_keypath_len, false)]); export const psbt_get_output_redeem_script = wrap('wally_psbt_get_output_redeem_script', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_output_redeem_script_len, false)]); export const psbt_get_output_script = wrap('wally_psbt_get_output_script', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_output_script_len, false)]); +export const psbt_get_output_taproot_internal_key = wrap('wally_psbt_get_output_taproot_internal_key', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_output_taproot_internal_key_len, false)]); export const psbt_get_output_unknown = wrap('wally_psbt_get_output_unknown', [T.OpaqueRef, T.Int32, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_output_unknown_len, false)]); export const psbt_get_output_value_blinding_rangeproof = wrap('wally_psbt_get_output_value_blinding_rangeproof', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_output_value_blinding_rangeproof_len, false)]); export const psbt_get_output_value_commitment = wrap('wally_psbt_get_output_value_commitment', [T.OpaqueRef, T.Int32, T.DestPtrVarLen(T.Bytes, psbt_get_output_value_commitment_len, false)]); diff --git a/src/wasm_package/src/index.d.ts b/src/wasm_package/src/index.d.ts index 669005f1f..44e54addc 100644 --- a/src/wasm_package/src/index.d.ts +++ b/src/wasm_package/src/index.d.ts @@ -349,6 +349,7 @@ export function psbt_get_output_keypath_len(psbt: Ref_wally_psbt, index: number, export function psbt_get_output_keypaths_size(psbt: Ref_wally_psbt, index: number): number; export function psbt_get_output_redeem_script_len(psbt: Ref_wally_psbt, index: number): number; export function psbt_get_output_script_len(psbt: Ref_wally_psbt, index: number): number; +export function psbt_get_output_taproot_internal_key_len(psbt: Ref_wally_psbt, index: number): number; export function psbt_get_output_unknown_len(psbt: Ref_wally_psbt, index: number, subindex: number): number; export function psbt_get_output_unknowns_size(psbt: Ref_wally_psbt, index: number): number; export function psbt_get_output_value_blinding_rangeproof_len(psbt: Ref_wally_psbt, index: number): number; @@ -483,6 +484,7 @@ export function psbt_output_set_ecdh_public_key(output: Ref_wally_psbt_output, p export function psbt_output_set_keypaths(output: Ref_wally_psbt_output, map_in: Ref_wally_map): void; export function psbt_output_set_redeem_script(output: Ref_wally_psbt_output, script: Buffer|Uint8Array): void; export function psbt_output_set_script(output: Ref_wally_psbt_output, script: Buffer|Uint8Array): void; +export function psbt_output_set_taproot_internal_key(output: Ref_wally_psbt_output, pub_key: Buffer|Uint8Array): void; export function psbt_output_set_unknowns(output: Ref_wally_psbt_output, map_in: Ref_wally_map): void; export function psbt_output_set_value_blinding_rangeproof(output: Ref_wally_psbt_output, rangeproof: Buffer|Uint8Array): void; export function psbt_output_set_value_commitment(output: Ref_wally_psbt_output, commitment: Buffer|Uint8Array): void; @@ -542,6 +544,7 @@ export function psbt_set_output_ecdh_public_key(psbt: Ref_wally_psbt, index: num export function psbt_set_output_keypaths(psbt: Ref_wally_psbt, index: number, map_in: Ref_wally_map): void; export function psbt_set_output_redeem_script(psbt: Ref_wally_psbt, index: number, script: Buffer|Uint8Array): void; export function psbt_set_output_script(psbt: Ref_wally_psbt, index: number, script: Buffer|Uint8Array): void; +export function psbt_set_output_taproot_internal_key(psbt: Ref_wally_psbt, index: number, pub_key: Buffer|Uint8Array): void; export function psbt_set_output_unknowns(psbt: Ref_wally_psbt, index: number, map_in: Ref_wally_map): void; export function psbt_set_output_value_blinding_rangeproof(psbt: Ref_wally_psbt, index: number, rangeproof: Buffer|Uint8Array): void; export function psbt_set_output_value_commitment(psbt: Ref_wally_psbt, index: number, commitment: Buffer|Uint8Array): void; @@ -791,6 +794,7 @@ export function psbt_get_output_ecdh_public_key(psbt: Ref_wally_psbt, index: num export function psbt_get_output_keypath(psbt: Ref_wally_psbt, index: number, subindex: number): Buffer; export function psbt_get_output_redeem_script(psbt: Ref_wally_psbt, index: number): Buffer; export function psbt_get_output_script(psbt: Ref_wally_psbt, index: number): Buffer; +export function psbt_get_output_taproot_internal_key(psbt: Ref_wally_psbt, index: number): Buffer; export function psbt_get_output_unknown(psbt: Ref_wally_psbt, index: number, subindex: number): Buffer; export function psbt_get_output_value_blinding_rangeproof(psbt: Ref_wally_psbt, index: number): Buffer; export function psbt_get_output_value_commitment(psbt: Ref_wally_psbt, index: number): Buffer; diff --git a/tools/wasm_exports.sh b/tools/wasm_exports.sh index 853fc6dd0..afcab56d9 100644 --- a/tools/wasm_exports.sh +++ b/tools/wasm_exports.sh @@ -265,6 +265,8 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_psbt_get_output_redeem_script_len' \ ,'_wally_psbt_get_output_script' \ ,'_wally_psbt_get_output_script_len' \ +,'_wally_psbt_get_output_taproot_internal_key' \ +,'_wally_psbt_get_output_taproot_internal_key_len' \ ,'_wally_psbt_get_output_unknown' \ ,'_wally_psbt_get_output_unknown_len' \ ,'_wally_psbt_get_output_unknowns_size' \ @@ -317,6 +319,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_psbt_output_set_keypaths' \ ,'_wally_psbt_output_set_redeem_script' \ ,'_wally_psbt_output_set_script' \ +,'_wally_psbt_output_set_taproot_internal_key' \ ,'_wally_psbt_output_set_unknowns' \ ,'_wally_psbt_output_set_witness_script' \ ,'_wally_psbt_output_taproot_keypath_add' \ @@ -346,6 +349,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_psbt_set_output_keypaths' \ ,'_wally_psbt_set_output_redeem_script' \ ,'_wally_psbt_set_output_script' \ +,'_wally_psbt_set_output_taproot_internal_key' \ ,'_wally_psbt_set_output_unknowns' \ ,'_wally_psbt_set_output_witness_script' \ ,'_wally_psbt_set_tx_modifiable_flags' \