Deviant BCH wallet — CashTokens + covenants (Katalogos v1 · chipnet)
Extends services/correspondent/dgb.mjs with the DGB-mainnet P2SH-HTLC
primitives the atomic-swap rail (snapshot 0271) needs. Complements
snapshot 0270's BCH-side covenant triangle (WithdrawalHTLC.cash +
DepositHTLC.cash + Deposit.burn) — same shared preimage on both sides,
so a reveal on either chain settles both.
Redeem script (Bitcoin-lineage HTLC — works on DGB Script without
Taproot):
OP_IF
OP_SHA256 <hashLock> OP_EQUALVERIFY <counterpartyPk> OP_CHECKSIG
OP_ELSE
<refundLockTime> OP_CHECKLOCKTIMEVERIFY OP_DROP <ownerPk> OP_CHECKSIG
OP_ENDIF
New exports (all in dgb.mjs, appended after the bonded-operator rail):
- buildHtlcRedeemScript({ hashLock, counterpartyPubkey, ownerPubkey,
refundLockTime }) → Buffer. 32-byte sha256 hashLock, 33-byte
compressed pubkeys, positive-int CLTV. Rejects malformed inputs.
- htlcAddress(redeemScript, network) → string. DGB P2SH address
(S… prefix; scriptHash 0x3f).
- buildFundHtlcTx({ funder, fromAddress, htlcAddress, amountSats,
… }) → { hex, htlcTxid, htlcVout, htlcAddress, sats, fee }.
Delegates to buildLockTx for the UTXO selection + signing logic;
pins HTLC output at vout 0.
- verifyHtlc({ txid, vout, redeemScript, expectedSats, api }) →
{ ok, confirmations, blockHeight, actualSats, error? }. Verifies
the funded HTLC on-chain via digiexplorer.info; checks output
script matches the P2SH of the redeem script and value matches
expected.
- buildClaimHtlcTx({ htlcTxid, htlcVout, htlcSats, redeemScript,
preimage, claimer, toAddress, feeSatsPerVByte }) →
{ hex, txid, sats, fee }. scriptSig = <sig> <preimage> OP_1
<redeemScript>. Uses SIGHASH_ALL over the redeem script for the
legacy P2SH sighash.
- buildRefundHtlcTx({ htlcTxid, htlcVout, htlcSats, redeemScript,
refundLockTime, owner, toAddress, feeSatsPerVByte }) →
{ hex, txid, sats, fee }. scriptSig = <sig> OP_0 <redeemScript>.
tx.nLockTime = refundLockTime, input sequence = 0xfffffffe so
CLTV is enforced.
Fee defaults are 200 sat/vB (matches the bonded-operator rail default;
DGB min-relay-fee is ~10× BTC's). Fee > HTLC value throws.
test/regtest/dgb-htlc.test.ts — 7/7 passing:
1. Redeem script disassembly matches expected structure (accepts
both OP_CHECKLOCKTIMEVERIFY and its pre-BIP65 name OP_NOP2 — same
opcode; bitcoinjs-lib prints the legacy label).
2. buildHtlcRedeemScript rejects malformed hashLock / pubkey / CLTV.
3. htlcAddress derives a valid DGB P2SH address (S… prefix) that
round-trips through bitcoin.address.toOutputScript.
4. Claim tx scriptSig has 4 chunks: sig, preimage, OP_1,
redeemScript.
5. Refund tx has nLockTime == refundLockTime and sequence 0xfffffffe,
scriptSig has 3 chunks: sig, OP_0, redeemScript.
6. buildClaimHtlcTx throws when fee > HTLC value.
7. sha256(preimage) matches the hashLock embedded at bytes 3..34 of
the redeem script.
Mainnet-live testing (broadcast + mempool acceptance + chipnet-DGB
testnet dry-run of the full swap) is the next lift — snapshot 0272.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
||
|---|---|---|
| .claude | ||
| brand | ||
| contracts | ||
| design | ||
| docs | ||
| KnowledgeBase | ||
| Parameters | ||
| public | ||
| scripts | ||
| services | ||
| shells | ||
| site/deviant | ||
| snapshots | ||
| spike | ||
| src | ||
| telegram-orderbook | ||
| test | ||
| wiki | ||
| .calibration-sweep.json | ||
| .catalytic-sweep.json | ||
| .env.example | ||
| .gitignore | ||
| .kac-extract.txt | ||
| .sim-athenae.json | ||
| adaptive-data.json | ||
| bch-history.json | ||
| bch-market.json | ||
| BCH_Token_Economy_Concept_Paper.md | ||
| bch_wallet_architecture.svg | ||
| CLAUDE.md | ||
| deviant_technical_spec_v2.7.md | ||
| package-lock.json | ||
| package.json | ||
| project-context.md | ||
| README.md | ||
| tsconfig.json | ||
| usdm-historical.json | ||
Deviant
BCH two-tier token economy platform. Pre-implementation. See BCH_Token_Economy_Concept_Paper.md for the full design.
Status
Bootstrap snapshot — protocol swap mechanism is the validation target.
Project map
| Path | Purpose |
|---|---|
BCH_Token_Economy_Concept_Paper.md |
Architecture spec, all [PROPOSED] claims |
CLAUDE.md |
Working agreement for Claude sessions |
src/ |
TypeScript wallet + token logic |
contracts/ |
CashScript source for Architecture A contracts |
test/ |
Unit tests (regtest) + integration plan (chipnet, mainnet) |
scripts/ |
Code-scan, snapshot, compile helpers |
wiki/ |
Living docs: architecture, decisions, testing strategy, code map |
snapshots/ |
Numbered progress snapshots |
Quickstart
npm install
npm run compile:contracts # produces artifacts from contracts/*.cash
npm run test:regtest # runs regtest suite
npm run scan # regenerates wiki/code-map.md
npm run snapshot # appends a new snapshot
Build priorities (active)
- Protocol swap mechanism — most novel claim, needs validation first.
- CashScript enforcement on mainnet — not just theoretical verification.
- tokenId correlation across A/B tiers — edge cases expected.
See wiki/testing-strategy.md for the staged regtest → chipnet → mainnet plan.