Skip to content

Commit

Permalink
psbt: expose accessors for outputs taproot internal key
Browse files Browse the repository at this point in the history
  • Loading branch information
jgriffiths committed Jan 11, 2025
1 parent c44a5bb commit 1fffafa
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/wally.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,12 @@ inline int psbt_output_set_script(const OUTPUT& output, const SCRIPT& script) {
return detail::check_ret(__FUNCTION__, ret);
}

template <class OUTPUT, class PUB_KEY>
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 <class OUTPUT>
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);
Expand Down
13 changes: 13 additions & 0 deletions include/wally_psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions include/wally_psbt_members.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/swig_java/swig.i
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/swig_python/contrib/psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/swig_python/python_extra.py_in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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]),
Expand Down
4 changes: 4 additions & 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.

4 changes: 4 additions & 0 deletions src/wasm_package/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tools/wasm_exports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand Down Expand Up @@ -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' \
Expand Down Expand Up @@ -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' \
Expand Down

0 comments on commit 1fffafa

Please sign in to comment.