Skip to content

Commit e638df0

Browse files
authored
Create example-taproot-verify.js
1 parent 13aea8c commit e638df0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/example-taproot-verify.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Example: Simple Taproot signature verification using bitcoinjs-lib
3+
* Demonstrates how to import a transaction and verify a signature.
4+
*/
5+
6+
import * as bitcoin from 'bitcoinjs-lib';
7+
8+
export function verifyTaprootSignature(txHex, signature, pubkey) {
9+
try {
10+
const tx = bitcoin.Transaction.fromHex(txHex);
11+
const hash = tx.hashForWitnessV1(0, [pubkey], [bitcoin.Transaction.SIGHASH_ALL]);
12+
return bitcoin.script.signature.decode(signature).toString('hex') === hash.toString('hex');
13+
} catch (err) {
14+
console.error('Verification failed:', err);
15+
return false;
16+
}
17+
}

0 commit comments

Comments
 (0)