Deviant BCH wallet — CashTokens + covenants (Katalogos v1 · chipnet)
Find a file
Local Dev 2fd5b70f80 feat(cross-chain): DGB-side HTLC primitives for the atomic-swap rail
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>
2026-09-16 01:25:02 +02:00
.claude chore(hooks): auto-regenerate snapshots/INDEX.md on snapshot writes 2026-07-07 01:58:15 +02:00
brand brand(landing): clean URLs — wordmark → ./ + deviant_website.html now redirects 2026-08-30 00:30:29 +02:00
contracts feat(potidaea): real Katalogos Publish broadcast · TST431 registered on chipnet 2026-09-06 18:35:41 +02:00
design feat(potidaea): wizard template picker · Static / Shares branch in step 3 2026-09-16 01:18:37 +02:00
docs docs(reorg): rename DEX_Anthemus -> Anthemus_DEX; consolidate both DEX cells + the taxonomy there 2026-07-19 22:29:08 +02:00
KnowledgeBase refactor(taxonomy): regular-form class names + DEA renamed to Direct Emission Asset 2026-09-02 00:02:53 +02:00
Parameters docs(bns): fix Option B prereqs — creds at Argus/, VPS s3d (not local) 2026-09-16 00:52:32 +02:00
public feat(onramp): SideShift Tier-3 in-wallet shift (ADR-0036 amendment) 2026-06-09 20:57:31 +02:00
scripts design(cross-chain): sketch atomic-swap deposit/withdrawal HTLCs 2026-09-06 12:58:45 +02:00
services feat(cross-chain): DGB-side HTLC primitives for the atomic-swap rail 2026-09-16 01:25:02 +02:00
shells feat(anthemus.dex): inline sign-in, header cleanup, full-screen adaptive 2026-09-16 01:21:59 +02:00
site/deviant feat(anthemus.dex): serve DEX-only kiosk at root — no wallet chrome 2026-09-16 01:02:20 +02:00
snapshots design(cross-chain): DGB rail commits to atomic-swap-primary (snapshot 0271) 2026-09-16 01:20:58 +02:00
spike chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP 2026-06-17 01:01:37 +02:00
src feat(wallet): adjustable-fee end-to-end — Artemision + AssetDetail + updateFee 2026-09-02 08:15:40 +02:00
telegram-orderbook chore: sweep in-flight work across all domains 2026-07-29 01:14:33 +02:00
test feat(cross-chain): DGB-side HTLC primitives for the atomic-swap rail 2026-09-16 01:25:02 +02:00
wiki docs(cross-chain): parallel-session handoff for the atomic-swap upgrade 2026-09-07 02:05:29 +02:00
.calibration-sweep.json chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP 2026-06-17 01:01:37 +02:00
.catalytic-sweep.json chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP 2026-06-17 01:01:37 +02:00
.env.example feat(onramp): SideShift Tier-3 in-wallet shift (ADR-0036 amendment) 2026-06-09 20:57:31 +02:00
.gitignore feat(cross-chain): DGB deposit + redeem round-trip live (mainnet ↔ chipnet) 2026-09-04 22:53:35 +02:00
.kac-extract.txt chore: initial project baseline — full Deviant codebase under version control 2026-06-13 20:38:07 +02:00
.sim-athenae.json chore: initial project baseline — full Deviant codebase under version control 2026-06-13 20:38:07 +02:00
adaptive-data.json chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP 2026-06-17 01:01:37 +02:00
bch-history.json chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP 2026-06-17 01:01:37 +02:00
bch-market.json chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP 2026-06-17 01:01:37 +02:00
BCH_Token_Economy_Concept_Paper.md chore: initial project baseline — full Deviant codebase under version control 2026-06-13 20:38:07 +02:00
bch_wallet_architecture.svg chore: initial project baseline — full Deviant codebase under version control 2026-06-13 20:38:07 +02:00
CLAUDE.md feat(asm): Potidaea swap-relay + tally refresh to 52,998 2026-08-14 01:39:41 +02:00
deviant_technical_spec_v2.7.md chore: checkpoint in-flight work across shell, contracts, and docs 2026-07-07 02:02:05 +02:00
package-lock.json chore: sweep in-flight work across all domains 2026-07-29 01:14:33 +02:00
package.json chore: sweep in-flight work across all domains 2026-07-29 01:14:33 +02:00
project-context.md feat(asm): Potidaea swap-relay + tally refresh to 52,998 2026-08-14 01:39:41 +02:00
README.md chore: initial project baseline — full Deviant codebase under version control 2026-06-13 20:38:07 +02:00
tsconfig.json chore: initial project baseline — full Deviant codebase under version control 2026-06-13 20:38:07 +02:00
usdm-historical.json chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP 2026-06-17 01:01:37 +02:00

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)

  1. Protocol swap mechanism — most novel claim, needs validation first.
  2. CashScript enforcement on mainnet — not just theoretical verification.
  3. tokenId correlation across A/B tiers — edge cases expected.

See wiki/testing-strategy.md for the staged regtest → chipnet → mainnet plan.