cred402/docs/p8.md
caelum0x 2d43618725 feat: real integrations (Casper Testnet, x402/EIP-712, MCP, RealFi, cross-chain), wallet sign-in, branding
Replace the design-note docs (p1–p7) with the implemented "make it real" phase
docs (p8–p10) and wire production-grade, env-gated real integrations:

- p8 Casper Testnet: byte-exact deploys + WASM install via casper-js-sdk; live
  node reads (node.testnet.casper.network); CRED402_CHAIN=sim|testnet transport.
- p9 x402 + data + MCP: real EIP-712 typed-data digests (@casper-ecosystem/
  casper-eip-712); casper-x402 facilitator client (x402 V2); live Open-Meteo GHI;
  official @modelcontextprotocol/sdk server; casper-sidecar SSE event feed.
- p10 RealFi + cross-chain: real Stripe test-mode webhooks (HMAC-verified) and
  Plaid sandbox → privacy-preserving on-chain envelopes; Base Sepolia EVM deploy
  (Foundry); reachable via /api/realfi/* and /api/x402/facilitator routes.
- Sign-in with Casper Wallet: real extension provider + challenge/ed25519/session
  flow (/v1/auth/wallet/*), console connect + sign-in button.
- Branding: Cred402 logo mark, favicon, OG image; Vercel config for the console.

All env-gated with sim/free-API fallbacks; full suite green, all toolchains
(TS/Rust/Go/Solidity) build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 00:37:36 +03:00

4.3 KiB

p8 — Real Casper Testnet

Make it real, phase 1. The protocol's canonical layer stops being a simulation: Cred402 now builds, signs, and submits byte-exact Casper 2.0 deploys with casper-js-sdk, reads live state from a real Testnet node, and installs the Odra contracts on chain. Simulation stays the default so the deterministic demo and the test suite never need a node or a key.

This closes the one write-path seam called out in PRODUCTION.md §8.

What became real

Capability Before Now (p8)
Node reads (status, state root, query, deploy result) dependency-free JSON-RPC unchanged — already real (lib/casper/rpc.ts)
Deploy serialization + signature hand-rolled canonical hash (lib/casper/signer.ts) byte-exact via casper-js-sdk (lib/casper/sdk_signer.ts)
Contract installation dry-run plan only real ModuleBytes install (lib/casper/install.ts)
Transport selection sim only CRED402_CHAIN=sim|testnet switch (lib/casper/factory.ts)
Default Testnet node dead rpc.testnet.casperlabs.io live node.testnet.casper.network (Casper 2.0, protocol 2.2.1)

The write path

casper-js-sdk@5 (the Casper 2.0 transaction model) produces a genuine deploy: a DeployHeader bound to the chain name + signer public key, a StoredContractByHash session (or ModuleBytes for installation), standardPayment, then Deploy.makeDeploy(...) → deploy.sign(privateKey). The deploy hash is a real blake2b over the CL byte serialization and the approval is a real ed25519 (or secp256k1) signature.

RuntimeArg[]  ──toArgs()──▶  Args(CLValue…)
                                  │
DeployHeader(chain, ttl, pubkey)  │   ExecutableDeployItem.standardPayment(motes)
        └───────────── Deploy.makeDeploy(header, payment, session) ──────────────┐
                                                                                  ▼
                                                        deploy.sign(privateKey)  →  account_put_deploy

Build + sign are fully offline. Only signAndSubmit / installContract touch the network, so test/casper_sdk.test.ts constructs and self-validates real signed deploys (deploy.validate() === true) with an ephemeral key and no node — proving the integration is real crypto, not a mock.

CLType → CLValue mapping

lib/casper/args.ts RuntimeArgs map 1:1 to byte-exact CLValues:

Cred402 CLType casper-js-sdk
String CLValue.newCLString
Bool CLValue.newCLValueBool
U64 CLValue.newCLUint64
U512 CLValue.newCLUInt512
Key CLValue.newCLKey(Key.newKey("hash-…"))
PublicKey CLValue.newCLPublicKey(PublicKey.fromHex)
ByteArray CLValue.newCLByteArray

Run it

# Reads only — hits the real Casper 2.0 Testnet node, no key needed:
npm run casper:health
#   ✓ reachable — chain "casper-test", build 2.2.1-…
#   ✓ state root hash: 1284d433…

# Dry run — prints the casper-client plan + writes deploys.testnet.json:
npm run deploy:testnet

# LIVE deploy — build WASM, fund a key, then:
cd contracts && cargo build --release --target wasm32-unknown-unknown && cd ..
export CRED402_CHAIN=testnet
export CRED402_NODE=https://node.testnet.casper.network/rpc
export CRED402_SECRET_KEY=/path/to/funded/secret_key.pem
npm run deploy:testnet     # installs each Odra contract, writes real hashes

A funded Testnet key comes from the faucet at https://testnet.cspr.live/tools/faucet. See .env.example for every variable.

Why the SDK is isolated

casper-js-sdk is CommonJS and heavy, so it is imported only in sdk_signer.ts / install.ts, which are loaded lazily by factory.ts on the testnet path. The default sim path — and therefore the whole 87-test suite and the deterministic demo — never loads the SDK. Going live is a transport swap, exactly as docs/architecture.md promised.

Safety

  • No secrets in source: the key is read from CRED402_SECRET_KEY (a PEM path), .env is gitignored, and missing config fails loud rather than degrading.
  • Every constructed deploy is validate()d before submission.
  • Sim remains default, so CI and the demo are deterministic and key-free.