cred402/scripts/sidecar_watch.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

41 lines
1.6 KiB
TypeScript

/**
* sidecar_watch.ts — stream live events from a Casper Sidecar (`/events` SSE).
*
* Wires `casper-network/casper-sidecar`: connect to a real Sidecar and print
* decoded events + any contract-emitted messages (the production source for the
* WatchdogAgent / indexer). Set CRED402_SIDECAR_URL, then:
*
* CRED402_SIDECAR_URL=http://127.0.0.1:19999 npm run casper:sidecar
*
* Run a Sidecar against Testnet per casper-network/casper-sidecar USAGE.md.
*/
import { sidecarFromEnv, extractContractMessages } from "../lib/casper/sidecar.js";
async function main(): Promise<void> {
const client = sidecarFromEnv();
if (!client) {
console.log("Sidecar not configured. Set CRED402_SIDECAR_URL (e.g. http://127.0.0.1:19999).");
console.log("In-process EventBus remains the default event source.");
return;
}
console.log(`Streaming Casper Sidecar events from ${process.env.CRED402_SIDECAR_URL}/events …\n`);
const controller = new AbortController();
process.on("SIGINT", () => controller.abort());
let count = 0;
for await (const e of client.streamEvents(controller.signal)) {
count++;
const tag = e.id ? `#${e.id}` : `#${count}`;
console.log(`${tag} ${e.kind}`);
for (const m of extractContractMessages(e)) {
console.log(` contract ${m.entity_addr.slice(0, 24)}… topic=${m.topic_name} payload=${JSON.stringify(m.payload)}`);
}
if (e.kind === "Shutdown") console.log(" (node shutdown — Sidecar will attempt to reconnect)");
}
}
main().catch((err) => {
console.error("sidecar watch failed:", (err as Error).message);
process.exit(1);
});