Description: Educational Taproot script-path spend demo in TypeScript. Implements tagged hashing, TapLeaf/TapBranch/TapTweak, internal→output key tweaking, control block construction, and a minimal script serializer for a OP_CHECKSIG tapleaf. Uses noble-curves for BIP340 Schnorr.
Not a full PSBT or tx builder; this focuses on the cryptographic plumbing of Taproot key- and script-paths. Educational only.
- BIP340 tagged hash helper
- Taproot tapleaf hash (
TapLeaf = sha256(tag="TapLeaf", ver||len||script)) - Merkle root for script tree (
TapBranch) - Key tweak:
Q = P + H_tapTweak(P || merkle_root)·G - Build control block for script-path spend
- Minimal script encoder and a single-leaf
(xonly_pub) OP_CHECKSIGscript - Schnorr sign (BIP340) with tweaked key
npm i
npm run build
node dist/demo.jssrc/taproot.ts— Taproot primitives (tagged hash, tweak, leaf, branch)src/script.ts— Minimal Bitcoin script serializer & helperssrc/demo.ts— Builds a 1-leaf tree (OP_CHECKSIG) and prints tweaked pubkey & control block
- This does not build or sign full Bitcoin transactions or PSBTs.
- No bech32m encoding (address); we output the x-only pubkey for P2TR.
- Verified against the spec formulas; use a full library for production.