Skip to content

Add the BLAKE2b chains xbt and txbt4, signing with SIGHASH_UNIFIED - #48

Merged
melvincarvalho merged 1 commit into
gh-pagesfrom
blake2b-chains
Sep 23, 2026
Merged

melvincarvalho merged 1 commit into
gh-pagesfrom
blake2b-chains

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Closes #47.

What changes

  • Two new chains in CHAINS:
    • xbt: the BLAKE2b fork of Bitcoin, from block 961,640, using https://mempool.kilombino.com/api.
    • txbt4: the BLAKE2b fork of testnet4, from block 150,308, using https://mempool.guide/testnet4/api.
  • Address prefix per chain. Each entry now carries its hrp, replacing chain === 'btc' ? 'bc' : 'tb', so xbt gets bc1p… addresses.
  • Replay-protected signing on both chains. buildTransaction takes { unified }. When set, it signs the unified message with SIGHASH_ALL|SIGHASH_UNIFIED (0x21), producing a 65-byte signature. SHA256d nodes reject it, so a mark that spends a pre-fork coin can't be replayed onto the original chain. The other four chains are unchanged and keep 64-byte BIP341 signatures.
  • lib/unified-sighash.js is the implementation from bitcoin-blake/blaketest. The spec is unified-sighash.md.
  • Docs: a chains table in the README, and the chain codes in URI.md.

Testing

  • npm test: 49 pass, 0 fail. New tests:
    • all 166 Knots unified sighash vectors (test/unified_sighash.json)
    • xbt and txbt4 addresses match btc and tbtc4
    • the chain registry flags
    • default signing still gives a 64-byte signature; unified signing gives 65 bytes ending 0x21, which verifies against the unified message and not against a BIP341 one
  • git mark init --chain xbt and --chain txbt4 run offline and print bc1p… and tb1p… addresses; an unknown chain is still refused.
  • Both explorer APIs answer (/blocks/tip/height: xbt 973,814, txbt4 151,579).
  • Not yet tested on chain. The first end-to-end run on txbt4 will be funded by a melchain peg-out, and I'll add the result here.

xbt (the BLAKE2b fork of Bitcoin) and txbt4 (the BLAKE2b fork of
testnet4) join the chain table, with Kilombino and mempool.guide as
explorers. Each chain now carries its bech32 prefix, so xbt gets bc1p
addresses instead of falling through to tb.

On both, marks are signed with SIGHASH_ALL|SIGHASH_UNIFIED: a 65-byte
signature over the unified message, which SHA256d nodes reject, so a
mark spending a pre-fork coin cannot be replayed onto the original
chain. lib/unified-sighash.js is the implementation from
bitcoin-blake/blaketest and passes Knots's 166 test vectors, now in
test/unified_sighash.json.

Closes #47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The new chain registry entries, unified sighash implementation, and signing integration are covered by deterministic unit tests (including the full Knots vector set) and appear consistent with the stated replay-protection goals.

Review effort: Lite
Findings: None

What changed in this PR

This PR adds support for the BLAKE2b fork chains xbt and txbt4 to gitmark, including replay-protected Taproot signing using SIGHASH_UNIFIED to prevent pre-fork UTXO spends from being replayed onto the SHA256d Bitcoin chains.

Changes:

  • Added xbt and txbt4 to the chain registry, including per-chain Bech32m HRPs (bc/tb) and a unified flag to opt into unified sighash signing.
  • Implemented Unified opt-in sighash (and parsing utilities) in lib/unified-sighash.js, and wired buildTransaction(..., { unified }) to produce 65-byte signatures with hash type 0x21 when enabled.
  • Added documentation and test coverage: chain tables in docs plus full Knots unified sighash vector verification and signature behavior tests.
File Description
URI.md Documents the new chain codes used in txo:<chain>:<txid>:<vout> URIs.
README.md Adds a chains table and explains SIGHASH_UNIFIED replay protection for xbt/txbt4.
lib/​unified-sighash.js Adds Unified sighash implementation + transaction parser used for testing and signing.
bin/​git-mark.js Extends CHAINS with xbt/txbt4, adds per-chain HRP, and enables unified signing via buildTransaction({ unified }).
test/​unified_sighash.json Adds 166 Knots unified sighash test vectors.
test/​git-mark.test.js Adds tests for new chain registry entries, address HRPs, vector verification, and 64-byte vs 65-byte signature behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@melvincarvalho
melvincarvalho merged commit 00553d3 into gh-pages Sep 23, 2026
1 check passed
@melvincarvalho
melvincarvalho deleted the blake2b-chains branch September 23, 2026 16:47
@melvincarvalho

Copy link
Copy Markdown
Contributor Author

Tested end to end on txbt4 with 0.0.78. The voucher came from a melchain peg-out, and both spends are signed with SIGHASH_UNIFIED: 65-byte witnesses ending 0x21, accepted by mempool.guide and by a local Knots node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support the BLAKE2b chains: xbt and txbt4, with replay-protected signing

2 participants