Skip to content

Commit 5e4d603

Browse files
committed
psbt: add a flags argument to psbt_get_input_signature_hash for future use
1 parent 3d006d1 commit 5e4d603

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

include/wally.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,8 @@ inline int psbt_get_input_scriptcode_len(const PSBT& psbt, size_t index, const S
988988
}
989989

990990
template <class PSBT, class TX, class SCRIPT, class BYTES_OUT>
991-
inline int psbt_get_input_signature_hash(const PSBT& psbt, size_t index, const TX& tx, const SCRIPT& script, BYTES_OUT& bytes_out) {
992-
int ret = ::wally_psbt_get_input_signature_hash(detail::get_p(psbt), index, detail::get_p(tx), script.data(), script.size(), bytes_out.data(), bytes_out.size());
991+
inline int psbt_get_input_signature_hash(const PSBT& psbt, size_t index, const TX& tx, const SCRIPT& script, uint32_t flags, BYTES_OUT& bytes_out) {
992+
int ret = ::wally_psbt_get_input_signature_hash(detail::get_p(psbt), index, detail::get_p(tx), script.data(), script.size(), flags, bytes_out.data(), bytes_out.size());
993993
return ret;
994994
}
995995

include/wally_psbt.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,13 +2115,14 @@ WALLY_CORE_API int wally_psbt_get_input_scriptcode(
21152115
size_t *written);
21162116

21172117
/**
2118-
* Create a BTC transaction for signing a PSBT input and return its hash.
2118+
* Create a transaction for signing a PSBT input and return its hash.
21192119
*
2120-
* :param psbt: The PSBT containing the input to compute a signing hash for.
2120+
* :param psbt: The PSBT containing the input to compute a signature hash for.
21212121
* :param index: The zero-based index of the PSBT input to sign.
21222122
* :param tx: The transaction to generate the signature hash from.
21232123
* :param script: The (unprefixed) scriptCode for the input being signed.
21242124
* :param script_len: Length of ``script`` in bytes.
2125+
* :param flags: Flags controlling signature hash generation. Must be 0.
21252126
* :param bytes_out: Destination for the signature hash.
21262127
* FIXED_SIZED_OUTPUT(len, bytes_out, SHA256_LEN)
21272128
*/
@@ -2131,6 +2132,7 @@ WALLY_CORE_API int wally_psbt_get_input_signature_hash(
21312132
const struct wally_tx *tx,
21322133
const unsigned char *script,
21332134
size_t script_len,
2135+
uint32_t flags,
21342136
unsigned char *bytes_out,
21352137
size_t len);
21362138

src/psbt.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4009,15 +4009,16 @@ int wally_psbt_get_input_scriptcode(const struct wally_psbt *psbt, size_t index,
40094009
int wally_psbt_get_input_signature_hash(struct wally_psbt *psbt, size_t index,
40104010
const struct wally_tx *tx,
40114011
const unsigned char *script, size_t script_len,
4012+
uint32_t flags,
40124013
unsigned char *bytes_out, size_t len)
40134014
{
40144015
const struct wally_psbt_input *inp = psbt_get_input(psbt, index);
40154016
uint64_t satoshi;
4016-
uint32_t sighash, flags;
4017+
uint32_t sighash, sig_flags;
40174018
size_t is_pset;
40184019
int ret;
40194020

4020-
if (!inp || !tx)
4021+
if (!inp || !tx || flags)
40214022
return WALLY_EINVAL;
40224023

40234024
if ((ret = wally_psbt_is_elements(psbt, &is_pset)) != WALLY_OK)
@@ -4026,7 +4027,7 @@ int wally_psbt_get_input_signature_hash(struct wally_psbt *psbt, size_t index,
40264027
sighash = inp->sighash ? inp->sighash : WALLY_SIGHASH_ALL;
40274028
if (sighash & 0xffffff00)
40284029
return WALLY_EINVAL;
4029-
flags = inp->witness_utxo ? WALLY_TX_FLAG_USE_WITNESS : 0;
4030+
sig_flags = inp->witness_utxo ? WALLY_TX_FLAG_USE_WITNESS : 0;
40304031

40314032
if (is_pset) {
40324033
if (!inp->witness_utxo)
@@ -4036,14 +4037,15 @@ int wally_psbt_get_input_signature_hash(struct wally_psbt *psbt, size_t index,
40364037
script, script_len,
40374038
inp->witness_utxo->value,
40384039
inp->witness_utxo->value_len,
4039-
sighash, flags, bytes_out, len);
4040+
sighash, sig_flags, bytes_out,
4041+
len);
40404042
#else
40414043
return WALLY_EINVAL; /* Unsupported */
40424044
#endif /* BUILD_ELEMENTS */
40434045
}
40444046
satoshi = inp->witness_utxo ? inp->witness_utxo->satoshi : 0;
40454047
return wally_tx_get_btc_signature_hash(tx, index, script, script_len,
4046-
satoshi, sighash, flags,
4048+
satoshi, sighash, sig_flags,
40474049
bytes_out, len);
40484050
}
40494051

@@ -4139,7 +4141,7 @@ int wally_psbt_sign_bip32(struct wally_psbt *psbt,
41394141
if (ret == WALLY_OK)
41404142
ret = wally_psbt_get_input_signature_hash(psbt, i, tx,
41414143
scriptcode, scriptcode_len,
4142-
txhash, sizeof(txhash));
4144+
0, txhash, sizeof(txhash));
41434145
/* Sign the input */
41444146
if (ret == WALLY_OK)
41454147
ret = wally_psbt_sign_input_bip32(psbt, i, subindex,

src/test/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class wally_psbt(Structure):
398398
('wally_psbt_get_input_bip32_key_from_alloc', c_int, [POINTER(wally_psbt), c_size_t, c_size_t, c_uint32, POINTER(ext_key), POINTER(POINTER(ext_key))]),
399399
('wally_psbt_get_input_scriptcode', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_void_p, c_size_t, c_size_t_p]),
400400
('wally_psbt_get_input_scriptcode_len', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_size_t_p]),
401-
('wally_psbt_get_input_signature_hash', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_tx), c_void_p, c_size_t, c_void_p, c_size_t]),
401+
('wally_psbt_get_input_signature_hash', c_int, [POINTER(wally_psbt), c_size_t, POINTER(wally_tx), c_void_p, c_size_t, c_uint32, c_void_p, c_size_t]),
402402
('wally_psbt_get_input_signing_script', c_int, [POINTER(wally_psbt), c_size_t, c_void_p, c_size_t, c_size_t_p]),
403403
('wally_psbt_get_input_signing_script_len', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]),
404404
('wally_psbt_get_length', c_int, [POINTER(wally_psbt), c_uint32, c_size_t_p]),

src/wasm_package/functions.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/wasm_package/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export function psbt_get_input_required_locktime(psbt: Ref_wally_psbt, index: nu
276276
export function psbt_get_input_scriptcode_len(psbt: Ref_wally_psbt, index: number, script: Buffer|Uint8Array): number;
277277
export function psbt_get_input_sequence(psbt: Ref_wally_psbt, index: number): number;
278278
export function psbt_get_input_sighash(psbt: Ref_wally_psbt, index: number): number;
279-
export function psbt_get_input_signature_hash(psbt: Ref_wally_psbt, index: number, tx: Ref_wally_tx, script: Buffer|Uint8Array): Buffer;
279+
export function psbt_get_input_signature_hash(psbt: Ref_wally_psbt, index: number, tx: Ref_wally_tx, script: Buffer|Uint8Array, flags: number): Buffer;
280280
export function psbt_get_input_signature_len(psbt: Ref_wally_psbt, index: number, subindex: number): number;
281281
export function psbt_get_input_signatures_size(psbt: Ref_wally_psbt, index: number): number;
282282
export function psbt_get_input_signing_script_len(psbt: Ref_wally_psbt, index: number): number;

0 commit comments

Comments
 (0)