cred402/lib/casper/deploy.ts
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

65 lines
2.2 KiB
TypeScript

import { toCasperClientArgs, type RuntimeArg } from "./args.js";
/**
* Deploy (transaction) construction for Cred402 contract calls.
*
* A `DeploySpec` is the fully-typed description of a stored-contract entry-point
* call — contract hash, entry point, runtime args, payment, chain, sender. This
* is the part of "going live" that is pure logic and testable offline; signing
* and CL byte serialization are handled by the injected signer (transport.ts).
*/
export interface DeploySpec {
contractHash: string; // "hash-..." package/contract hash
entryPoint: string;
args: RuntimeArg[];
paymentMotes: bigint;
chainName: string;
sender: string; // sender public key hex ("01.." / "02..")
ttlMs?: number;
}
export interface BuildContractCallOptions {
contractHash: string;
entryPoint: string;
args: RuntimeArg[];
paymentMotes: bigint;
chainName: string;
sender: string;
ttlMs?: number;
}
export function buildContractCall(opts: BuildContractCallOptions): DeploySpec {
if (!opts.contractHash) throw new Error("contractHash required");
if (!opts.entryPoint) throw new Error("entryPoint required");
if (opts.paymentMotes <= 0n) throw new Error("paymentMotes must be positive");
return {
contractHash: opts.contractHash,
entryPoint: opts.entryPoint,
args: opts.args,
paymentMotes: opts.paymentMotes,
chainName: opts.chainName,
sender: opts.sender,
ttlMs: opts.ttlMs ?? 30 * 60 * 1000,
};
}
/**
* Render the exact `casper-client put-deploy` invocation for a spec — the same
* command an operator would run, and a faithful, copy-pasteable representation of
* what the signer submits over RPC.
*/
export function toCasperClientCommand(spec: DeploySpec, opts: { nodeAddress: string; secretKeyPath: string }): string {
const hashHex = spec.contractHash.replace(/^hash-/, "");
return [
"casper-client put-deploy",
` --node-address ${opts.nodeAddress}`,
` --chain-name ${spec.chainName}`,
` --secret-key ${opts.secretKeyPath}`,
` --session-hash ${hashHex}`,
` --session-entry-point ${spec.entryPoint}`,
` --payment-amount ${spec.paymentMotes.toString()}`,
...spec.args.map((a) => " " + toCasperClientArgs([a])[0]),
].join(" \\\n");
}