From e638df00c7ab25f2bfd1ce48a9ce0cbf7dee6325 Mon Sep 17 00:00:00 2001 From: kilfoigo12 Date: Thu, 6 Nov 2025 00:18:17 +0100 Subject: [PATCH] Create example-taproot-verify.js --- src/example-taproot-verify.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/example-taproot-verify.js diff --git a/src/example-taproot-verify.js b/src/example-taproot-verify.js new file mode 100644 index 000000000..a1dc9d344 --- /dev/null +++ b/src/example-taproot-verify.js @@ -0,0 +1,17 @@ +/** + * Example: Simple Taproot signature verification using bitcoinjs-lib + * Demonstrates how to import a transaction and verify a signature. + */ + +import * as bitcoin from 'bitcoinjs-lib'; + +export function verifyTaprootSignature(txHex, signature, pubkey) { + try { + const tx = bitcoin.Transaction.fromHex(txHex); + const hash = tx.hashForWitnessV1(0, [pubkey], [bitcoin.Transaction.SIGHASH_ALL]); + return bitcoin.script.signature.decode(signature).toString('hex') === hash.toString('hex'); + } catch (err) { + console.error('Verification failed:', err); + return false; + } +}