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

89 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Command-line interface for the Cred402 risk + fraud engine.
Fetches live data from the Cred402 API and prints results as formatted JSON.
Usage::
python3 cli.py score <agent_id>
python3 cli.py fraud <agent_id>
python3 cli.py portfolio
Environment:
CRED402_API base URL of the Cred402 API (default http://localhost:4021)
"""
from __future__ import annotations
import json
import os
import sys
# Make the package importable when run as `python3 cli.py` from anywhere.
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from cred402_risk.client import Cred402APIError, Cred402Client # noqa: E402
from cred402_risk.server import fraud_agent, portfolio, score_agent # noqa: E402
USAGE = """\
cred402-risk — advisory risk + fraud scoring CLI
usage:
python3 cli.py score <agent_id> probability-of-default credit assessment
python3 cli.py fraud <agent_id> receipt-graph fraud assessment
python3 cli.py portfolio leaderboard of all agents
env:
CRED402_API Cred402 API base URL (default http://localhost:4021)
"""
def _emit(obj) -> None:
print(json.dumps(obj, indent=2, sort_keys=False))
def main(argv: list[str] | None = None) -> int:
argv = list(sys.argv[1:] if argv is None else argv)
if not argv or argv[0] in ("-h", "--help", "help"):
print(USAGE)
return 0 if argv else 1
command = argv[0]
client = Cred402Client()
try:
agents, receipts = client.fetch_all()
except Cred402APIError as exc:
print(f"error: {exc}", file=sys.stderr)
print(f" (is the Cred402 API running at {client.base_url}?)", file=sys.stderr)
return 2
if command == "portfolio":
_emit(portfolio(agents, receipts))
return 0
if command in ("score", "fraud"):
if len(argv) < 2:
print(f"error: '{command}' requires an <agent_id>", file=sys.stderr)
return 1
agent_id = argv[1]
if command == "score":
result = score_agent(agent_id, agents, receipts)
else:
result = fraud_agent(agent_id, agents, receipts)
if result is None:
print(f"error: agent '{agent_id}' not found", file=sys.stderr)
known = sorted(a.get("agent_id", "?") for a in agents)
print(f" known agents: {', '.join(known)}", file=sys.stderr)
return 3
_emit(result)
return 0
print(f"error: unknown command '{command}'\n", file=sys.stderr)
print(USAGE, file=sys.stderr)
return 1
if __name__ == "__main__":
raise SystemExit(main())