Skip to content

Commit

Permalink
psbt: expose accessors for inputs taproot internal key
Browse files Browse the repository at this point in the history
  • Loading branch information
jgriffiths committed Jan 11, 2025
1 parent b502072 commit c44a5bb
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 @@ -1420,6 +1420,12 @@ inline int psbt_input_set_signatures(const INPUT& input, const struct wally_map*
return detail::check_ret(__FUNCTION__, ret);
}

template <class INPUT, class PUB_KEY>
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 <class INPUT, class TAP_SIG>
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());
Expand Down
12 changes: 12 additions & 0 deletions include/wally_psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
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 @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
Expand Down Expand Up @@ -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)
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 @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/swig_python/contrib/psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
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 @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]),
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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)]),
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 @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tools/wasm_exports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand Down Expand Up @@ -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' \
Expand Down Expand Up @@ -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' \
Expand Down

0 comments on commit c44a5bb

Please sign in to comment.