Skip to content

Commit c44a5bb

Browse files
committed
psbt: expose accessors for inputs taproot internal key
1 parent b502072 commit c44a5bb

File tree

11 files changed

+48
-0
lines changed

11 files changed

+48
-0
lines changed

include/wally.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,12 @@ inline int psbt_input_set_signatures(const INPUT& input, const struct wally_map*
14201420
return detail::check_ret(__FUNCTION__, ret);
14211421
}
14221422

1423+
template <class INPUT, class PUB_KEY>
1424+
inline int psbt_input_set_taproot_internal_key(const INPUT& input, const PUB_KEY& pub_key) {
1425+
int ret = ::wally_psbt_input_set_taproot_internal_key(detail::get_p(input), pub_key.data(), pub_key.size());
1426+
return detail::check_ret(__FUNCTION__, ret);
1427+
}
1428+
14231429
template <class INPUT, class TAP_SIG>
14241430
inline int psbt_input_set_taproot_signature(const INPUT& input, const TAP_SIG& tap_sig) {
14251431
int ret = ::wally_psbt_input_set_taproot_signature(detail::get_p(input), tap_sig.data(), tap_sig.size());

include/wally_psbt.h

+12
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,18 @@ WALLY_CORE_API int wally_psbt_input_set_taproot_signature(
354354
const unsigned char *tap_sig,
355355
size_t tap_sig_len);
356356

357+
/**
358+
* Set the taproot internal public key in an input.
359+
*
360+
* :param input: The input to update.
361+
* :param pub_key: The x-only internal public key for this input.
362+
* :param pub_key_len: The length of ``pub_key`` in bytes. Must be `EC_XONLY_PUBLIC_KEY_LEN`.
363+
*/
364+
WALLY_CORE_API int wally_psbt_input_set_taproot_internal_key(
365+
struct wally_psbt_input *input,
366+
const unsigned char *pub_key,
367+
size_t pub_key_len);
368+
357369
/**
358370
* Find a partial signature matching a pubkey in an input.
359371
*

include/wally_psbt_members.h

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ WALLY_CORE_API int wally_psbt_get_input_signature(const struct wally_psbt *psbt,
5252
WALLY_CORE_API int wally_psbt_get_input_signature_len(const struct wally_psbt *psbt, size_t index, size_t subindex, size_t *written);
5353
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);
5454
WALLY_CORE_API int wally_psbt_get_input_taproot_signature_len(const struct wally_psbt *psbt, size_t index, size_t *written);
55+
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);
56+
WALLY_CORE_API int wally_psbt_get_input_taproot_internal_key_len(const struct wally_psbt *psbt, size_t index, size_t *written);
5557
WALLY_CORE_API int wally_psbt_get_input_unknowns_size(const struct wally_psbt *psbt, size_t index, size_t *written);
5658
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);
5759
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
7981
WALLY_CORE_API int wally_psbt_set_input_keypaths(struct wally_psbt *psbt, size_t index, const struct wally_map *map_in);
8082
WALLY_CORE_API int wally_psbt_set_input_signatures(struct wally_psbt *psbt, size_t index, const struct wally_map *map_in);
8183
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);
84+
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);
8285
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);
8386
WALLY_CORE_API int wally_psbt_set_input_unknowns(struct wally_psbt *psbt, size_t index, const struct wally_map *map_in);
8487
WALLY_CORE_API int wally_psbt_set_input_sighash(struct wally_psbt *psbt, size_t index, uint32_t sighash);

src/psbt.c

+2
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ MAP_INNER_FIELD(input, redeem_script, PSBT_IN_REDEEM_SCRIPT, psbt_fields)
389389
MAP_INNER_FIELD(input, witness_script, PSBT_IN_WITNESS_SCRIPT, psbt_fields)
390390
MAP_INNER_FIELD(input, final_scriptsig, PSBT_IN_FINAL_SCRIPTSIG, psbt_fields)
391391
MAP_INNER_FIELD(input, taproot_signature, PSBT_IN_TAP_KEY_SIG, psbt_fields)
392+
MAP_INNER_FIELD(input, taproot_internal_key, PSBT_IN_TAP_INTERNAL_KEY, psbt_fields)
392393
SET_STRUCT(wally_psbt_input, final_witness, wally_tx_witness_stack,
393394
wally_tx_witness_stack_clone_alloc, wally_tx_witness_stack_free)
394395
SET_MAP(wally_psbt_input, keypath,)
@@ -5574,6 +5575,7 @@ PSBT_FIELD(input, redeem_script, PSBT_0)
55745575
PSBT_FIELD(input, witness_script, PSBT_0)
55755576
PSBT_FIELD(input, final_scriptsig, PSBT_0)
55765577
PSBT_FIELD(input, taproot_signature, PSBT_0)
5578+
PSBT_FIELD(input, taproot_internal_key, PSBT_0)
55775579
PSBT_GET_S(input, final_witness, wally_tx_witness_stack, wally_tx_witness_stack_clone_alloc)
55785580
PSBT_GET_M(input, keypath)
55795581
PSBT_GET_M(input, signature)

src/swig_java/swig.i

+4
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
802802
%returns_size_t(wally_psbt_get_input_signature_hash);
803803
%returns_size_t(wally_psbt_get_input_signature_len);
804804
%returns_size_t(wally_psbt_get_input_sighash);
805+
%returns_size_t(wally_psbt_get_input_taproot_internal_key);
806+
%returns_size_t(wally_psbt_get_input_taproot_internal_key_len);
805807
%returns_size_t(wally_psbt_get_input_taproot_signature);
806808
%returns_size_t(wally_psbt_get_input_taproot_signature_len);
807809
%returns_size_t(wally_psbt_get_input_unknown);
@@ -913,6 +915,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
913915
%returns_void__(wally_psbt_set_input_sighash);
914916
%returns_void__(wally_psbt_set_input_signatures);
915917
%returns_void__(wally_psbt_set_input_taproot_signature);
918+
%returns_void__(wally_psbt_set_input_taproot_internal_key);
916919
%returns_void__(wally_psbt_set_input_unknowns);
917920
%returns_void__(wally_psbt_set_input_utxo);
918921
%returns_void__(wally_psbt_set_input_utxo_rangeproof);
@@ -1292,6 +1295,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
12921295
%ignore wally_psbt_input_get_inflation_keys_blinding_rangeproof_len;
12931296
%ignore wally_psbt_input_set_inflation_keys_blinding_rangeproof;
12941297
%ignore wally_psbt_input_clear_inflation_keys_blinding_rangeproof;
1298+
%ignore wally_psbt_input_set_taproot_internal_key;
12951299
%ignore wally_psbt_input_set_taproot_signature;
12961300
%ignore wally_psbt_input_get_utxo_rangeproof;
12971301
%ignore wally_psbt_input_get_utxo_rangeproof_len;

src/swig_python/contrib/psbt.py

+4
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ def test_psbt(self):
336336
dummy_sig_tap_default = TAPROOT_SIG_BYTES # SIGHASH_DEFAULT
337337
dummy_sig_tap_all = TAPROOT_SIG_BYTES + bytearray(b'\x01') # SIGHASH_ALL
338338
dummy_sig_tap_single = TAPROOT_SIG_BYTES + bytearray(b'\x03') # SIGHASH_SINGLE
339+
dummy_tap_internal_key = bytearray(b'\x01' * 32) # Untweaked x-only pubkey
339340
if is_elements_build():
340341
dummy_nonce = bytearray(b'\x00' * WALLY_TX_ASSET_CT_NONCE_LEN)
341342
dummy_bf = bytearray(b'\x00' * BLINDING_FACTOR_LEN)
@@ -493,6 +494,9 @@ def test_psbt(self):
493494
self._try_get_set_b(psbt_set_input_taproot_signature,
494495
psbt_get_input_taproot_signature,
495496
None, psbt, dummy_sig_tap_default)
497+
self._try_get_set_b(psbt_set_input_taproot_internal_key,
498+
psbt_get_input_taproot_internal_key,
499+
None, psbt, dummy_tap_internal_key)
496500
# Test finding the UXTO an input spends by txid/vout
497501
utxo_txhash = psbt_get_input_previous_txid(psbt, 0)
498502
utxo_index = psbt_get_input_output_index(psbt, 0)

src/swig_python/python_extra.py_in

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ psbt_get_input_scriptcode = _wrap_bin(psbt_get_input_scriptcode, psbt_get_input_
197197
psbt_get_input_signature = _wrap_bin(psbt_get_input_signature, psbt_get_input_signature_len)
198198
psbt_get_input_signature_hash = _wrap_bin(psbt_get_input_signature_hash, SHA256_LEN)
199199
psbt_get_input_signing_script = _wrap_bin(psbt_get_input_signing_script, psbt_get_input_signing_script_len)
200+
psbt_get_input_taproot_internal_key = _wrap_bin(psbt_get_input_taproot_internal_key, psbt_get_input_taproot_internal_key_len)
200201
psbt_get_input_taproot_signature = _wrap_bin(psbt_get_input_taproot_signature, psbt_get_input_taproot_signature_len)
201202
psbt_get_input_unknown = _wrap_bin(psbt_get_input_unknown, psbt_get_input_unknown_len)
202203
psbt_get_input_utxo = psbt_get_input_utxo_alloc

src/test/util.py

+4
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ class wally_psbt(Structure):
548548
('wally_psbt_input_set_sequence', c_int, [POINTER(wally_psbt_input), c_uint32]),
549549
('wally_psbt_input_set_sighash', c_int, [POINTER(wally_psbt_input), c_uint32]),
550550
('wally_psbt_input_set_signatures', c_int, [POINTER(wally_psbt_input), POINTER(wally_map)]),
551+
('wally_psbt_input_set_taproot_internal_key', c_int, [POINTER(wally_psbt_input), c_void_p, c_size_t]),
551552
('wally_psbt_input_set_taproot_signature', c_int, [POINTER(wally_psbt_input), c_void_p, c_size_t]),
552553
('wally_psbt_input_set_unknowns', c_int, [POINTER(wally_psbt_input), POINTER(wally_map)]),
553554
('wally_psbt_input_set_utxo', c_int, [POINTER(wally_psbt_input), POINTER(wally_tx)]),
@@ -839,6 +840,8 @@ class wally_psbt(Structure):
839840
('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]),
840841
('wally_psbt_get_input_signature_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t, c_size_t_p]),
841842
('wally_psbt_get_input_signatures_size', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]),
843+
('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]),
844+
('wally_psbt_get_input_taproot_internal_key_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]),
842845
('wally_psbt_get_input_taproot_signature', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_size_t_p]),
843846
('wally_psbt_get_input_taproot_signature_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]),
844847
('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):
922925
('wally_psbt_set_input_sequence', c_int, [POINTER(wally_psbt), c_size_t, c_uint32]),
923926
('wally_psbt_set_input_sighash', c_int, [POINTER(wally_psbt), c_size_t, c_uint32]),
924927
('wally_psbt_set_input_signatures', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_map)]),
928+
('wally_psbt_set_input_taproot_internal_key', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]),
925929
('wally_psbt_set_input_taproot_signature', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t]),
926930
('wally_psbt_set_input_unknowns', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_map)]),
927931
('wally_psbt_set_input_utxo', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_tx)]),

src/wasm_package/src/functions.js

+4
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

+4
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ export function psbt_get_input_signature_hash(psbt: Ref_wally_psbt, index: numbe
324324
export function psbt_get_input_signature_len(psbt: Ref_wally_psbt, index: number, subindex: number): number;
325325
export function psbt_get_input_signatures_size(psbt: Ref_wally_psbt, index: number): number;
326326
export function psbt_get_input_signing_script_len(psbt: Ref_wally_psbt, index: number): number;
327+
export function psbt_get_input_taproot_internal_key_len(psbt: Ref_wally_psbt, index: number): number;
327328
export function psbt_get_input_taproot_signature_len(psbt: Ref_wally_psbt, index: number): number;
328329
export function psbt_get_input_unknown_len(psbt: Ref_wally_psbt, index: number, subindex: number): number;
329330
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
435436
export function psbt_input_set_sequence(input: Ref_wally_psbt_input, sequence: number): void;
436437
export function psbt_input_set_sighash(input: Ref_wally_psbt_input, sighash: number): void;
437438
export function psbt_input_set_signatures(input: Ref_wally_psbt_input, map_in: Ref_wally_map): void;
439+
export function psbt_input_set_taproot_internal_key(input: Ref_wally_psbt_input, pub_key: Buffer|Uint8Array): void;
438440
export function psbt_input_set_taproot_signature(input: Ref_wally_psbt_input, tap_sig: Buffer|Uint8Array): void;
439441
export function psbt_input_set_unknowns(input: Ref_wally_psbt_input, map_in: Ref_wally_map): void;
440442
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
521523
export function psbt_set_input_sequence(psbt: Ref_wally_psbt, index: number, sequence: number): void;
522524
export function psbt_set_input_sighash(psbt: Ref_wally_psbt, index: number, sighash: number): void;
523525
export function psbt_set_input_signatures(psbt: Ref_wally_psbt, index: number, map_in: Ref_wally_map): void;
526+
export function psbt_set_input_taproot_internal_key(psbt: Ref_wally_psbt, index: number, pub_key: Buffer|Uint8Array): void;
524527
export function psbt_set_input_taproot_signature(psbt: Ref_wally_psbt, index: number, sig: Buffer|Uint8Array): void;
525528
export function psbt_set_input_unknowns(psbt: Ref_wally_psbt, index: number, map_in: Ref_wally_map): void;
526529
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
774777
export function psbt_get_input_scriptcode(psbt: Ref_wally_psbt, index: number, script: Buffer|Uint8Array): Buffer;
775778
export function psbt_get_input_signature(psbt: Ref_wally_psbt, index: number, subindex: number): Buffer;
776779
export function psbt_get_input_signing_script(psbt: Ref_wally_psbt, index: number): Buffer;
780+
export function psbt_get_input_taproot_internal_key(psbt: Ref_wally_psbt, index: number): Buffer;
777781
export function psbt_get_input_taproot_signature(psbt: Ref_wally_psbt, index: number): Buffer;
778782
export function psbt_get_input_unknown(psbt: Ref_wally_psbt, index: number, subindex: number): Buffer;
779783
export function psbt_get_input_utxo_rangeproof(psbt: Ref_wally_psbt, index: number): Buffer;

tools/wasm_exports.sh

+4
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \
242242
,'_wally_psbt_get_input_signatures_size' \
243243
,'_wally_psbt_get_input_signing_script' \
244244
,'_wally_psbt_get_input_signing_script_len' \
245+
,'_wally_psbt_get_input_taproot_internal_key' \
246+
,'_wally_psbt_get_input_taproot_internal_key_len' \
245247
,'_wally_psbt_get_input_taproot_signature' \
246248
,'_wally_psbt_get_input_taproot_signature_len' \
247249
,'_wally_psbt_get_input_unknown' \
@@ -296,6 +298,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \
296298
,'_wally_psbt_input_set_sequence' \
297299
,'_wally_psbt_input_set_sighash' \
298300
,'_wally_psbt_input_set_signatures' \
301+
,'_wally_psbt_input_set_taproot_internal_key' \
299302
,'_wally_psbt_input_set_taproot_signature' \
300303
,'_wally_psbt_input_set_unknowns' \
301304
,'_wally_psbt_input_set_utxo' \
@@ -332,6 +335,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \
332335
,'_wally_psbt_set_input_sequence' \
333336
,'_wally_psbt_set_input_sighash' \
334337
,'_wally_psbt_set_input_signatures' \
338+
,'_wally_psbt_set_input_taproot_internal_key' \
335339
,'_wally_psbt_set_input_taproot_signature' \
336340
,'_wally_psbt_set_input_unknowns' \
337341
,'_wally_psbt_set_input_utxo' \

0 commit comments

Comments
 (0)