Skip to content

Taproot script-path spend demo in TypeScript. Implements tagged hashing, TapLeaf/TapBranch/TapTweak, key tweak (internal→output), control block build, and a minimal <xonly_pub> OP_CHECKSIG leaf. BIP340 Schnorr via noble. Educational only.

Notifications You must be signed in to change notification settings

onurnaim/taproot-script-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

taproot-script-demo

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.

Features

  • 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_CHECKSIG script
  • Schnorr sign (BIP340) with tweaked key

Quickstart

npm i
npm run build
node dist/demo.js

Files

  • src/taproot.ts — Taproot primitives (tagged hash, tweak, leaf, branch)
  • src/script.ts — Minimal Bitcoin script serializer & helpers
  • src/demo.ts — Builds a 1-leaf tree (OP_CHECKSIG) and prints tweaked pubkey & control block

Notes

  • 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.

About

Taproot script-path spend demo in TypeScript. Implements tagged hashing, TapLeaf/TapBranch/TapTweak, key tweak (internal→output), control block build, and a minimal <xonly_pub> OP_CHECKSIG leaf. BIP340 Schnorr via noble. Educational only.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published