Skip to content

Commit 9b582ef

Browse files
committed
taproot: support generating elements p2tr scripts
Elements uses a different tagged hash for tweaking the internal key.
1 parent b27dc40 commit 9b582ef

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/wally_script.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ WALLY_CORE_API int wally_witness_p2wpkh_from_der(
301301
* :param bytes: Compressed or x-only public key to create a scriptPubkey for.
302302
* :param bytes_len: The length of ``bytes`` in bytes. Must be ``EC_PUBLIC_KEY_LEN``
303303
*| or ``EC_XONLY_PUBLIC_KEY_LEN``.
304-
* :param flags: Must be 0.
304+
* :param flags: Must be 0 or EC_FLAG_ELEMENTS to create an elements p2tr sctipt.
305305
* :param bytes_out: Destination for the resulting scriptPubkey.
306306
* MAX_SIZED_OUTPUT(len, bytes_out, WALLY_SCRIPTPUBKEY_P2TR_LEN)
307307
* :param written: Destination for the number of bytes written to ``bytes_out``.

src/script.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,13 @@ int wally_scriptpubkey_p2tr_from_bytes(const unsigned char *bytes, size_t bytes_
13051305
if (written)
13061306
*written = 0;
13071307

1308-
/* FIXME: Support EC_FLAG_ELEMENTS for Elements P2TR */
1309-
if (!bytes || flags || !bytes_out || !written)
1308+
if (!bytes || !bytes_out || !written)
1309+
return WALLY_EINVAL;
1310+
#ifdef BUILD_ELEMENTS
1311+
if (flags & ~EC_FLAG_ELEMENTS)
1312+
#else
1313+
if (flags)
1314+
#endif
13101315
return WALLY_EINVAL;
13111316

13121317
if (len < WALLY_SCRIPTPUBKEY_P2TR_LEN) {
@@ -1318,7 +1323,7 @@ int wally_scriptpubkey_p2tr_from_bytes(const unsigned char *bytes, size_t bytes_
13181323
if (bytes_len == EC_PUBLIC_KEY_LEN) {
13191324
/* An untweaked public key, tweak it */
13201325
int ret = wally_ec_public_key_bip341_tweak(bytes, bytes_len, NULL, 0,
1321-
0, tweaked, sizeof(tweaked));
1326+
flags, tweaked, sizeof(tweaked));
13221327
if (ret != WALLY_OK)
13231328
return ret;
13241329
bytes = tweaked + 1; /* Convert to x-only */

0 commit comments

Comments
 (0)