Skip to content

Commit dc27ce4

Browse files
committed
taproot: support elements tx TapLeaf/TapSighash hashing
1 parent e0ca55a commit dc27ce4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/transaction.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ static const unsigned char DUMMY_SIG[EC_SIGNATURE_DER_MAX_LEN + 1]; /* +1 for si
3535

3636
#define EXT_FLAG_BIP342 0x1 /* Indicates BIP342 tapscript message extension */
3737

38+
#ifdef BUILD_ELEMENTS
39+
#define TAPLEAF(is_elements) (is_elements) ? "TapLeaf/elements" : "TapLeaf"
40+
#define TAPSIGHASH(is_elements) (is_elements) ? "TapSighash/elements" : "TapSighash"
41+
#else
42+
#define TAPLEAF(is_elements) "TapLeaf"
43+
#define TAPSIGHASH(is_elements) "TapSighash"
44+
#endif
45+
46+
3847
/* Extra options when serializing for hashing */
3948
struct tx_serialize_opts
4049
{
@@ -2531,7 +2540,8 @@ static inline int tx_to_bip341_bytes(const struct wally_tx *tx,
25312540
buff_p[0] = 0xC0; /* leaf_version */
25322541
tmp_p = buff_p + 1;
25332542
tmp_p += varbuff_to_bytes(opts->tapleaf_script, opts->tapleaf_script_len, tmp_p);
2534-
ret = wally_bip340_tagged_hash(buff_p, tmp_p - buff_p, "TapLeaf", p, SHA256_LEN);
2543+
ret = wally_bip340_tagged_hash(buff_p, tmp_p - buff_p,
2544+
TAPLEAF(is_elements), p, SHA256_LEN);
25352545
if (ret != WALLY_OK)
25362546
goto error;
25372547
p += SHA256_LEN;
@@ -3398,7 +3408,7 @@ int wally_tx_get_btc_taproot_signature_hash(
33983408
if (n != n2)
33993409
ret = WALLY_ERROR; /* tx_get_length/tx_to_bytes mismatch, should not happen! */
34003410
else
3401-
ret = wally_bip340_tagged_hash(buff, n, "TapSighash", bytes_out, len);
3411+
ret = wally_bip340_tagged_hash(buff, n, TAPSIGHASH(false), bytes_out, len);
34023412
}
34033413
wally_clear(buff, n);
34043414
return ret;

0 commit comments

Comments
 (0)