Snapshot of the shared working tree's outstanding changes (multiple concurrent workstreams), excluding generated runtime state files (.football-tote-state.json, .tote-platform-state.json, .usdm-historical-chart.html). Spans: wallet shell (connect/, keystore MultiKeyStore+vault, screens, currency picker, sign-message), verify artifacts, new Potidaea/DRA/tote contracts + regtest suites, cross-chain/T6 + WalletConnect Parameters, a telegram-orderbook subproject, design mockups, and docs. See shells/app/WALLET-COORDINATION.md for the per-file ownership split. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
71 lines
3.6 KiB
TypeScript
71 lines
3.6 KiB
TypeScript
/**
|
|
* bch-namespace.ts — wire constants shared by the WalletConnect (wc2-bch-bcr) and
|
|
* CashConnect (CashRPC) responder handlers.
|
|
*
|
|
* Both protocols ride the SAME WC2 relay and use the SAME namespace name (`bch`);
|
|
* they differ in proposal shape (CashConnect adds `protocol: 'CashRPC:0'` +
|
|
* `template` + `allowedTokens`), method names (`_V0`-suffixed for CC), and wire
|
|
* encoding. See ADR-0043 + wiki/connector.md for the full design rationale.
|
|
*/
|
|
import type { BchChain } from './index';
|
|
|
|
/** Account string layout for wc2-bch-bcr: `bch:<network>:<cashaddr>`. */
|
|
export type WcAccount = `${BchChain}:${string}`;
|
|
|
|
/** Account string layout for CashConnect: `bch:<network>:<pubkeyHex>`. The wallet
|
|
* exposes the **public key** (33-byte compressed, hex), NOT a cashaddr — confirmed
|
|
* in cashconnect@0.0.25 (`CashConnectWallet.onSessionProposal`, lines ~1483 of the
|
|
* installed dist: `accounts: ['${chain}:${network}:${binToHex(sandboxedPublicKey)}']`).
|
|
* Snapshot 0062 finding 1. */
|
|
export type CcAccount = `${BchChain}:${string}`;
|
|
|
|
// ─── WalletConnect (wc2-bch-bcr) ──────────────────────────────────────────
|
|
/** WalletConnect methods the responder MUST handle. Mirrors the proposer
|
|
* (src/connect/proposer.ts) and snapshot 0057's validated co-sign. */
|
|
export const WC_METHODS = [
|
|
'bch_getAddresses',
|
|
'bch_signMessage',
|
|
'bch_signTransaction',
|
|
] as const;
|
|
export type WcMethod = (typeof WC_METHODS)[number];
|
|
|
|
// ─── CashConnect (CashRPC) ────────────────────────────────────────────────
|
|
/** CashConnect methods the responder MAY handle. CashConnect V0 is
|
|
* wallet-orchestrated (it builds the tx from instructions, runs a VM verify, and
|
|
* signs) — so the responder routes signTransaction to the cashconnect package's
|
|
* exported `CashRPC_V0` class. CC cannot co-sign Deviant covenant txs at V0; those
|
|
* flows route through WC (ADR-0043 §2.3 + snapshot 0062 Finding 3). */
|
|
export const CC_METHODS = [
|
|
'wc_authRequest',
|
|
'bch_getBalance_V0',
|
|
'bch_getChangeLockingBytecode_V0',
|
|
'bch_getTokens_V0',
|
|
'bch_signMessage_V0',
|
|
'bch_signTransaction_V0',
|
|
] as const;
|
|
export type CcMethod = (typeof CC_METHODS)[number];
|
|
|
|
/** CashConnect's protocol marker on the `bch` namespace at session proposal. Used
|
|
* by `classifier.classifyProposal` to distinguish CC sessions from plain WC ones. */
|
|
export const CC_PROTOCOL = 'CashRPC:0' as const;
|
|
|
|
/** CashConnect emits `balancesChanged`; plain WC emits nothing. */
|
|
export const CC_EVENTS = ['balancesChanged'] as const;
|
|
|
|
/** Chains supported by both protocols (per cashconnect's `SupportedChains` and the
|
|
* proposer's namespace). The shell's `ALLOWED_NETWORKS` may further restrict this
|
|
* at runtime (chipnet-only beta builds, etc.). */
|
|
export const SUPPORTED_CHAINS: readonly BchChain[] = ['bch:bchtest', 'bch:bitcoincash'];
|
|
|
|
/** Map a `BchChain` to the libauth network token used by the noble crypto shim and
|
|
* cashscript's `ElectrumNetworkProvider`. `bch:bchreg` is not exposed in the shell. */
|
|
export function chainToNetwork(chain: BchChain): 'chipnet' | 'mainnet' {
|
|
return chain === 'bch:bchtest' ? 'chipnet' : 'mainnet';
|
|
}
|
|
|
|
/** Inverse: a network → its chain id. */
|
|
export function networkToChain(network: 'chipnet' | 'mainnet' | 'testnet4'): BchChain {
|
|
// testnet4 has no canonical BCH WC chain id; surface as chipnet for transport
|
|
// purposes (no live dApps speak testnet4 anyway). Document this in connector.md.
|
|
return network === 'mainnet' ? 'bch:bitcoincash' : 'bch:bchtest';
|
|
}
|