Skip to content

Multi-standard token support (STAS, DSTAS, BSV-21) + Back-to-Genesis provenance verification - #61

Merged
sirdeggen merged 3 commits into
bsv-blockchain:masterfrom
MatiasJF:token-integration
Jul 16, 2026
Merged

Multi-standard token support (STAS, DSTAS, BSV-21) + Back-to-Genesis provenance verification#61
sirdeggen merged 3 commits into
bsv-blockchain:masterfrom
MatiasJF:token-integration

Conversation

@MatiasJF

Copy link
Copy Markdown
Contributor

Summary

Adds native wallet support for three token standards — classic STAS, DSTAS, and BSV-21 — on top of the BRC-100 wallet: receive, on-chain transfer (full and partial), peer-to-peer settlement over MessageBox, WhatsOnChain discovery, and Back-to-Genesis provenance verification (counterfeit detection).

The branch is a single squashed commit for review. It is based on 49b4b63 and is currently behind master; a rebase is needed before merge (see Reviewer notes below). GitHub shows the merge-base diff, so Files changed is the token work only.

What it adds

Token engines & registry

  • Per-standard build/sign/broadcast + parsers under src/lib/services/stas, tokens/dstas, tokens/bsv21 (classic-STAS via stas-js, DSTAS via a vendored SDK, BSV-21 ord inscription).
  • TokenProtocolRegistry + *ProtocolAdapter give the address-send path one polymorphic seam.

Discovery — WhatsOnChain, single source

  • woc/WocTokenIndexerClient serves all three standards (STAS by base58, DSTAS by owner hash160, BSV-21 by base58). No third-party fallbacks or feature flags.

Peer settlement (MessageBox)

  • tokens/peer/*PeerTokenClient (imported from the published @bsv/message-box-client) plus per-standard TokenSettlementAdapters with BRC-29 owner derivation.

Back-to-Genesis — counterfeit detection

  • BackToGenesisClient (tri-state verify/trace, fail-safe), TokenVerificationService (cache + worst-verdict card badge), verifyOnReceive (verify at registration), persisted in token_verifications (migration 0004).
  • Token identity is keyed on the resolved genesis outpoint — for classic STAS the tokenId is only the issuer PKH, shared by every token that issuer minted, so genesis is the sole spoof-proof identity. Verified against a real broadcast counterfeit that clones a genuine token's tokenId + amount but has no ancestor → not-authentic.

Persistence, wiring, UI

  • electron/stas-queries + stas-migrations (satellite tables + verifications); fee model set to 250 sat/kb (headroom above the miner floor so token packages don't stall). Assets page (grouped holdings, partial send with instant change, verification badges), Transfers/PeerTokens, Baskets browser.

The one architectural note: two independent send paths

They do not share send code and must not be conflated:

Address path (Assets page) Peer path (Transfers page)
Recipient a plain on-chain address a counterparty identity key
Mechanism registry adapter → *TransferService → broadcast PeerTokenClient*TokenSettlementAdapter → broadcast + MessageBox push
Recipient discovers via WoC discovery on Refresh MessageBox inbox → Accept internalizes the BEEF
Key derivation wallet's own receive key BRC-29 (address derived from identity key)

Both ultimately call the same per-standard on-chain engines.

Testing

  • npm run test:tokens and npm run test:stas — 58 token + 15 STAS tests, plus a migration-0004 roundtrip (npm run test:stas:db, which rebuilds the native module for Electron).
  • Renderer + Electron builds pass.
  • Exercised end-to-end on mainnet: mint → send (full + partial) → receive → verify, across all three standards, including a broadcast counterfeit that the verifier correctly rejects.

Reviewer notes

  • Rebase before merge. Based on 49b4b63; master is ~40 commits ahead with overlap in core files (WalletContext, WalletService, onWalletReady, electron/storage.ts, Menu.tsx, package.json). Happy to rebase once the approach is approved.
  • Apps-API auth model — open question. The HTTP token routes (:3321) are Origin-gated. /stas/transfer also shows a permission modal; /dstas/transfer and /bsv-21/transfer are Origin-only (parity with /peerToken/send, to avoid the 30s bridge-timeout racing a human click). All HTTP token spends currently run under one fixed originator, so per-app spending-authorization would require threading the caller's origin — flagging for a design decision.
  • BSV-21 activation-gating. A freshly minted BSV-21 is invisible to WoC/overlay until GorillaPool activates its token id. Not a wallet bug; Back-to-Genesis still verifies such a token (it walks the chain, independent of the index).

🤖 Generated with Claude Code

https://claude.ai/code/session_01K5d73SoN1pkMac9CbmtX5g

…o-Genesis

Adds native wallet support for three token standards on top of the BRC-100
wallet — receive, on-chain transfer (full + partial), peer-to-peer settlement
over MessageBox, WhatsOnChain discovery, and Back-to-Genesis provenance
verification. Single squashed commit against upstream base 49b4b63; standard
onboarding (the branch's one-click prototype was reverted, net-zero here).

Engines & registry
- src/lib/services/stas, tokens/dstas, tokens/bsv21 — per-standard build/sign/
  broadcast + parsers (classic-STAS, DSTAS via the vendored dxs SDK, BSV-21 ord
  inscription). TokenProtocolRegistry + *ProtocolAdapter give the legacy
  address-send path one polymorphic seam.

Discovery — WhatsOnChain, single source
- woc/WocTokenIndexerClient serves all three standards (no Bitails/relay/1Sat
  fallbacks, no feature flag). Scan loops skip already-held outpoints before any
  per-candidate getRawTx.

Peer settlement (MessageBox)
- tokens/peer/* — PeerTokenClient (imported from @bsv/message-box-client) +
  per-standard TokenSettlementAdapters with BRC-29 owner derivation.

Back-to-Genesis — counterfeit detection
- BackToGenesisClient (tri-state, fail-safe verify/trace), TokenVerificationService
  (session cache + worst-verdict badge), verifyOnReceive (verify at registration),
  persisted in token_verifications (migration 0004). Token identity keys on the
  resolved genesis outpoint — for classic STAS the tokenId is only the issuer PKH,
  so genesis is the sole spoof-proof identity. Proven against a broadcast
  counterfeit (same tokenId+amount as a real token, no ancestor → not-authentic).

Persistence, wiring, UI
- electron/stas-queries + stas-migrations (satellite tables + verifications);
  fee model raised to 250 sat/kb (was on the miner floor). WalletService wires the
  bundle; onWalletReady exposes the HTTP token routes. Assets page (grouped
  holdings, partial send, verification badges), Transfers/PeerTokens.

Tests: test/stas + test/tokens (derivation, discovery, migration incl. 0004,
registration, inscription, dstas-transfer, woc-indexer, back-to-genesis,
token-verification, verify-on-receive). Renderer + Electron builds pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K5d73SoN1pkMac9CbmtX5g
@sirdeggen
sirdeggen force-pushed the token-integration branch from c4d0815 to 6ae8fe2 Compare July 16, 2026 07:34
The Transfers menu item added by the token-integration merge referenced
menu_transfers via t(), but the key didn't exist in translations.ts for
any language, failing the translation-coverage test.
better-sqlite3@12.x and @electron/rebuild@4.x already require Node
>=20/22; the 18.x job only appeared to pass because push.yaml's cache
key hashes only package.json, so PRs that don't touch it get a stale
cache hit and skip npm install (and its postinstall rebuild) entirely.
This PR's dependency changes miss that cache and hit the real, already
pre-existing incompatibility.
@sirdeggen
sirdeggen merged commit f7a31a5 into bsv-blockchain:master Jul 16, 2026
2 checks passed
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.

2 participants