Skip to content

Commit

Permalink
support parsing tr(KEY) descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
Zero-1729 committed May 16, 2024
1 parent ccbc520 commit 1cf9c85
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1cf9c85

Please sign in to comment.