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

66 lines
1.7 KiB
Go

// Package event models the Cred402 protocol event as written to the durable
// NDJSON journal (lib/gateway/persistence.ts). The journal is the system of
// record; the indexer replays it to build queryable projections.
package event
import (
"bufio"
"encoding/json"
"io"
"math/big"
)
// ChainEvent mirrors the TypeScript ChainEvent emitted by the EventBus.
type ChainEvent struct {
Seq int64 `json:"seq"`
Name string `json:"name"`
Contract string `json:"contract"`
DeployHash string `json:"deploy_hash"`
Timestamp int64 `json:"timestamp"`
Data map[string]any `json:"data"`
}
// Str returns a string field from the event data, or "" if absent.
func (e ChainEvent) Str(key string) string {
if v, ok := e.Data[key].(string); ok {
return v
}
return ""
}
// Amount parses a stringified integer field (motes / smallest units) as big.Int.
func (e ChainEvent) Amount(key string) *big.Int {
n := new(big.Int)
if s, ok := e.Data[key].(string); ok {
n.SetString(s, 10)
}
return n
}
// Num returns a numeric field as int64 (JSON numbers decode to float64).
func (e ChainEvent) Num(key string) int64 {
if f, ok := e.Data[key].(float64); ok {
return int64(f)
}
return 0
}
// DecodeJournal streams a newline-delimited JSON journal into events.
func DecodeJournal(r io.Reader) ([]ChainEvent, error) {
var events []ChainEvent
sc := bufio.NewScanner(r)
sc.Buffer(make([]byte, 0, 1024*1024), 16*1024*1024)
for sc.Scan() {
line := sc.Bytes()
if len(line) == 0 {
continue
}
var e ChainEvent
if err := json.Unmarshal(line, &e); err != nil {
return nil, err
}
events = append(events, e)
}
return events, sc.Err()
}