From 1cf9c857ce83ab84e046e81077e8ddd816e804d3 Mon Sep 17 00:00:00 2001 From: Zero-1729 Date: Thu, 7 Sep 2023 13:11:53 +0100 Subject: [PATCH] support parsing tr(KEY) descriptor --- src/descriptors.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/descriptors.ts b/src/descriptors.ts index 2a08e72..a98df3f 100644 --- a/src/descriptors.ts +++ b/src/descriptors.ts @@ -410,6 +410,26 @@ export function DescriptorsFactory(ecc: TinySecp256k1Interface) { payment = p2wpkh({ pubkey, network }); } } + //tr(KEY) - taproot + else if (canonicalExpression.match(RE.rePtrAnchored)) { + isSegwit = true; + const keyExpression = canonicalExpression.match(RE.reKeyExp)?.[0]; + if (!keyExpression) + throw new Error(`Error: keyExpression could not me extracted`); + if (canonicalExpression !== `tr(${keyExpression})`) + throw new Error(`Error: invalid expression ${expression}`); + expandedExpression = 'tr(@0)'; + const pKE = parseKeyExpression({ keyExpression, network, isSegwit }); + expansionMap = { '@0': pKE }; + if (!isCanonicalRanged) { + const pubkey = pKE.pubkey; + if (!pubkey) + throw new Error( + `Error: could not extract a pubkey from ${expression}` + ); + payment = p2tr({ pubkey, network }); + } + } //sh(wsh(miniscript)) else if (canonicalExpression.match(RE.reShWshMiniscriptAnchored)) { isSegwit = true;