Skip to content

Commit 1fffafa

Browse files
committed
psbt: expose accessors for outputs taproot internal key
1 parent c44a5bb commit 1fffafa

File tree

11 files changed

+48
-0
lines changed

11 files changed

+48
-0
lines changed

include/wally.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,12 @@ inline int psbt_output_set_script(const OUTPUT& output, const SCRIPT& script) {
15331533
return detail::check_ret(__FUNCTION__, ret);
15341534
}
15351535

1536+
template <class OUTPUT, class PUB_KEY>
1537+
inline int psbt_output_set_taproot_internal_key(const OUTPUT& output, const PUB_KEY& pub_key) {
1538+
int ret = ::wally_psbt_output_set_taproot_internal_key(detail::get_p(output), pub_key.data(), pub_key.size());
1539+
return detail::check_ret(__FUNCTION__, ret);
1540+
}
1541+
15361542
template <class OUTPUT>
15371543
inline int psbt_output_set_unknowns(const OUTPUT& output, const struct wally_map* map_in) {
15381544
int ret = ::wally_psbt_output_set_unknowns(detail::get_p(output), map_in);

include/wally_psbt.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,19 @@ WALLY_CORE_API int wally_psbt_output_set_script(
14341434
const unsigned char *script,
14351435
size_t script_len);
14361436

1437+
/**
1438+
* Set the taproot internal public key in an output.
1439+
*
1440+
* :param output: The output to update.
1441+
* :param pub_key: The x-only internal public key for this output.
1442+
* :param pub_key_len: The length of ``pub_key`` in bytes. Must be `EC_XONLY_PUBLIC_KEY_LEN`.
1443+
*/
1444+
WALLY_CORE_API int wally_psbt_output_set_taproot_internal_key(
1445+
struct wally_psbt_output *output,
1446+
const unsigned char *pub_key,
1447+
size_t pub_key_len);
1448+
1449+
14371450
#ifndef WALLY_ABI_NO_ELEMENTS
14381451
/**
14391452
* Set the input blinder index in an output.

include/wally_psbt_members.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ WALLY_CORE_API int wally_psbt_get_output_script(const struct wally_psbt *psbt, s
186186
WALLY_CORE_API int wally_psbt_get_output_script_len(const struct wally_psbt *psbt, size_t index, size_t *written);
187187
WALLY_CORE_API int wally_psbt_get_output_amount(const struct wally_psbt *psbt, size_t index, uint64_t *value_out);
188188
WALLY_CORE_API int wally_psbt_has_output_amount(const struct wally_psbt *psbt, size_t index, size_t *written);
189+
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);
190+
WALLY_CORE_API int wally_psbt_get_output_taproot_internal_key_len(const struct wally_psbt *psbt, size_t index, size_t *written);
189191

190192
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);
191193
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_
194196
WALLY_CORE_API int wally_psbt_set_output_script(struct wally_psbt *psbt, size_t index, const unsigned char *script, size_t script_len);
195197
WALLY_CORE_API int wally_psbt_set_output_amount(struct wally_psbt *psbt, size_t index, uint64_t amount);
196198
WALLY_CORE_API int wally_psbt_clear_output_amount(struct wally_psbt *psbt, size_t index);
199+
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);
197200

198201
#ifndef WALLY_ABI_NO_ELEMENTS
199202
WALLY_CORE_API int wally_psbt_get_output_blinder_index(const struct wally_psbt *psbt, size_t index, uint32_t *value_out);

src/psbt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ static int psbt_input_free(struct wally_psbt_input *input, bool free_parent)
871871

872872
MAP_INNER_FIELD(output, redeem_script, PSBT_OUT_REDEEM_SCRIPT, psbt_fields)
873873
MAP_INNER_FIELD(output, witness_script, PSBT_OUT_WITNESS_SCRIPT, psbt_fields)
874+
MAP_INNER_FIELD(output, taproot_internal_key, PSBT_OUT_TAP_INTERNAL_KEY, psbt_fields)
874875
SET_MAP(wally_psbt_output, keypath,)
875876
ADD_KEYPATH(wally_psbt_output)
876877
ADD_TAP_KEYPATH(wally_psbt_output)
@@ -5712,6 +5713,7 @@ int wally_psbt_clear_input_required_lockheight(struct wally_psbt *psbt, size_t i
57125713
if (!psbt || psbt->version != PSBT_2) return WALLY_EINVAL;
57135714
return wally_psbt_input_clear_required_lockheight(psbt_get_input(psbt, index));
57145715
}
5716+
PSBT_FIELD(output, taproot_internal_key, PSBT_0)
57155717

57165718
#ifndef WALLY_ABI_NO_ELEMENTS
57175719
PSBT_GET_I_PSET(input, amount, uint64_t, PSBT_2)

src/swig_java/swig.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,8 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
845845
%returns_size_t(wally_psbt_get_output_redeem_script_len);
846846
%returns_size_t(wally_psbt_get_output_script);
847847
%returns_size_t(wally_psbt_get_output_script_len);
848+
%returns_size_t(wally_psbt_get_output_taproot_internal_key);
849+
%returns_size_t(wally_psbt_get_output_taproot_internal_key_len);
848850
%returns_size_t(wally_psbt_get_output_unknown);
849851
%returns_size_t(wally_psbt_get_output_unknown_len);
850852
%returns_size_t(wally_psbt_get_output_unknowns_size);
@@ -934,6 +936,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
934936
%returns_void__(wally_psbt_set_output_keypaths);
935937
%returns_void__(wally_psbt_set_output_redeem_script);
936938
%returns_void__(wally_psbt_set_output_script);
939+
%returns_void__(wally_psbt_set_output_taproot_internal_key);
937940
%returns_void__(wally_psbt_set_output_unknowns);
938941
%returns_void__(wally_psbt_set_output_value_blinding_rangeproof);
939942
%returns_void__(wally_psbt_set_output_value_commitment);
@@ -1352,6 +1355,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
13521355
%ignore wally_psbt_output_set_asset_blinding_surjectionproof;
13531356
%ignore wally_psbt_output_clear_asset_blinding_surjectionproof;
13541357
%ignore wally_psbt_output_get_blinding_status;
1358+
%ignore wally_psbt_output_set_taproot_internal_key;
13551359

13561360
%include "../include/wally_core.h"
13571361
%include "../include/wally_address.h"

src/swig_python/contrib/psbt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ def test_psbt(self):
655655
psbt_get_output_unknown,
656656
psbt_find_output_unknown,
657657
p, dummy_unknowns, dummy_unknown_key)
658+
self._try_get_set_b(psbt_set_output_taproot_internal_key,
659+
psbt_get_output_taproot_internal_key,
660+
None, psbt, dummy_tap_internal_key)
658661

659662
#
660663
# Outputs: PSBT V2

src/swig_python/python_extra.py_in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ psbt_get_input_witness_utxo = psbt_get_input_witness_utxo_alloc
206206
psbt_get_output_keypath = _wrap_bin(psbt_get_output_keypath, psbt_get_output_keypath_len)
207207
psbt_get_output_redeem_script = _wrap_bin(psbt_get_output_redeem_script, psbt_get_output_redeem_script_len)
208208
psbt_get_output_script = _wrap_bin(psbt_get_output_script, psbt_get_output_script_len)
209+
psbt_get_output_taproot_internal_key = _wrap_bin(psbt_get_output_taproot_internal_key, psbt_get_output_taproot_internal_key_len)
209210
psbt_get_output_unknown = _wrap_bin(psbt_get_output_unknown, psbt_get_output_unknown_len)
210211
psbt_get_output_witness_script = _wrap_bin(psbt_get_output_witness_script, psbt_get_output_witness_script_len)
211212
psbt_init = psbt_init_alloc

src/test/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ class wally_psbt(Structure):
604604
('wally_psbt_output_set_keypaths', c_int, [POINTER(wally_psbt_output), POINTER(wally_map)]),
605605
('wally_psbt_output_set_redeem_script', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]),
606606
('wally_psbt_output_set_script', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]),
607+
('wally_psbt_output_set_taproot_internal_key', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]),
607608
('wally_psbt_output_set_unknowns', c_int, [POINTER(wally_psbt_output), POINTER(wally_map)]),
608609
('wally_psbt_output_set_value_blinding_rangeproof', c_int, [POINTER(wally_psbt_output), c_void_p, c_size_t]),
609610
('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):
877878
('wally_psbt_get_output_redeem_script_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]),
878879
('wally_psbt_get_output_script', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_size_t_p]),
879880
('wally_psbt_get_output_script_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]),
881+
('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]),
882+
('wally_psbt_get_output_taproot_internal_key_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]),
880883
('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]),
881884
('wally_psbt_get_output_unknown_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t, c_size_t_p]),
882885
('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):
944947
('wally_psbt_set_output_keypaths', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_map)]),
945948
('wally_psbt_set_output_redeem_script', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]),
946949
('wally_psbt_set_output_script', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]),
950+
('wally_psbt_set_output_taproot_internal_key', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]),
947951
('wally_psbt_set_output_unknowns', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_map)]),
948952
('wally_psbt_set_output_value_blinding_rangeproof', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]),
949953
('wally_psbt_set_output_value_commitment', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]),

src/wasm_package/src/functions.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/wasm_package/src/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ export function psbt_get_output_keypath_len(psbt: Ref_wally_psbt, index: number,
349349
export function psbt_get_output_keypaths_size(psbt: Ref_wally_psbt, index: number): number;
350350
export function psbt_get_output_redeem_script_len(psbt: Ref_wally_psbt, index: number): number;
351351
export function psbt_get_output_script_len(psbt: Ref_wally_psbt, index: number): number;
352+
export function psbt_get_output_taproot_internal_key_len(psbt: Ref_wally_psbt, index: number): number;
352353
export function psbt_get_output_unknown_len(psbt: Ref_wally_psbt, index: number, subindex: number): number;
353354
export function psbt_get_output_unknowns_size(psbt: Ref_wally_psbt, index: number): number;
354355
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
483484
export function psbt_output_set_keypaths(output: Ref_wally_psbt_output, map_in: Ref_wally_map): void;
484485
export function psbt_output_set_redeem_script(output: Ref_wally_psbt_output, script: Buffer|Uint8Array): void;
485486
export function psbt_output_set_script(output: Ref_wally_psbt_output, script: Buffer|Uint8Array): void;
487+
export function psbt_output_set_taproot_internal_key(output: Ref_wally_psbt_output, pub_key: Buffer|Uint8Array): void;
486488
export function psbt_output_set_unknowns(output: Ref_wally_psbt_output, map_in: Ref_wally_map): void;
487489
export function psbt_output_set_value_blinding_rangeproof(output: Ref_wally_psbt_output, rangeproof: Buffer|Uint8Array): void;
488490
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
542544
export function psbt_set_output_keypaths(psbt: Ref_wally_psbt, index: number, map_in: Ref_wally_map): void;
543545
export function psbt_set_output_redeem_script(psbt: Ref_wally_psbt, index: number, script: Buffer|Uint8Array): void;
544546
export function psbt_set_output_script(psbt: Ref_wally_psbt, index: number, script: Buffer|Uint8Array): void;
547+
export function psbt_set_output_taproot_internal_key(psbt: Ref_wally_psbt, index: number, pub_key: Buffer|Uint8Array): void;
545548
export function psbt_set_output_unknowns(psbt: Ref_wally_psbt, index: number, map_in: Ref_wally_map): void;
546549
export function psbt_set_output_value_blinding_rangeproof(psbt: Ref_wally_psbt, index: number, rangeproof: Buffer|Uint8Array): void;
547550
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
791794
export function psbt_get_output_keypath(psbt: Ref_wally_psbt, index: number, subindex: number): Buffer;
792795
export function psbt_get_output_redeem_script(psbt: Ref_wally_psbt, index: number): Buffer;
793796
export function psbt_get_output_script(psbt: Ref_wally_psbt, index: number): Buffer;
797+
export function psbt_get_output_taproot_internal_key(psbt: Ref_wally_psbt, index: number): Buffer;
794798
export function psbt_get_output_unknown(psbt: Ref_wally_psbt, index: number, subindex: number): Buffer;
795799
export function psbt_get_output_value_blinding_rangeproof(psbt: Ref_wally_psbt, index: number): Buffer;
796800
export function psbt_get_output_value_commitment(psbt: Ref_wally_psbt, index: number): Buffer;

0 commit comments

Comments
 (0)