cred402/cli/commands/compliance.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

76 lines
2.0 KiB
TypeScript

/**
* `compliance` command group: KYB / sanctions / jurisdiction screening.
*/
import { type CommandContext, emit, requireArg, UsageError } from "../lib/context.js";
import { color, heading, statusBadge, table } from "../lib/render.js";
interface Check {
name: string;
passed: boolean;
detail: string;
}
interface ComplianceResult {
screen: {
subject: string;
cleared: boolean;
checks: Check[];
};
retention: {
dataClass: string;
retentionDays: number;
containsPii: boolean;
notes: string;
}[];
}
const USAGE = `compliance — agent KYB / sanctions screening
Usage:
cred402 compliance check <agent_id>`;
export async function complianceCommand(ctx: CommandContext): Promise<void> {
const sub = ctx.args[0];
switch (sub) {
case "check":
return check(ctx);
case undefined:
case "--help":
case "-h":
process.stdout.write(USAGE + "\n");
return;
default:
throw new UsageError(`unknown subcommand: compliance ${sub}\n\n${USAGE}`);
}
}
async function check(ctx: CommandContext): Promise<void> {
const id = requireArg(ctx.args, 1, "agent_id");
const r = await ctx.client.get<ComplianceResult>(`/api/compliance/${encodeURIComponent(id)}`);
emit(ctx, r, () => {
const checkRows = r.screen.checks.map((c) => [
c.passed ? statusBadge("passed") : statusBadge("failed"),
c.name,
color.dim(c.detail),
]);
const retRows = r.retention.map((d) => [
d.dataClass,
String(d.retentionDays),
d.containsPii ? color.yellow("yes") : color.green("no"),
color.dim(d.notes),
]);
return (
heading(`Compliance — ${r.screen.subject}`) +
"\n" +
`overall: ${r.screen.cleared ? statusBadge("cleared") : statusBadge("denied")}\n\n` +
table([{ header: "RESULT" }, { header: "CHECK" }, { header: "DETAIL" }], checkRows) +
heading("Data Retention Policy") +
"\n" +
table(
[{ header: "DATA CLASS" }, { header: "DAYS", align: "right" }, { header: "PII" }, { header: "NOTES" }],
retRows,
)
);
});
}