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>
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
/**
|
|
* `keys` command group: mint scoped API keys via the admin gateway.
|
|
* Requires an admin-scoped key when the server runs with auth enabled
|
|
* (pass `--key <adminKey>`); in development auth is open.
|
|
*/
|
|
import { type CommandContext, emit, requireArg, UsageError } from "../lib/context.js";
|
|
import { idempotencyKey } from "../lib/http.js";
|
|
import { color, heading, keyValues, sym } from "../lib/render.js";
|
|
|
|
const SCOPES = ["read", "write", "admin"] as const;
|
|
|
|
interface ApiKey {
|
|
id: string;
|
|
secret: string;
|
|
scopes: string[];
|
|
}
|
|
|
|
const USAGE = `keys — mint scoped API keys (admin)
|
|
|
|
Usage:
|
|
cred402 keys create <name> <scope...> scopes ∈ ${SCOPES.join(" | ")}
|
|
|
|
Note: requires an admin key when the server enforces auth: --key <adminKey>`;
|
|
|
|
export async function keysCommand(ctx: CommandContext): Promise<void> {
|
|
const sub = ctx.args[0];
|
|
switch (sub) {
|
|
case "create":
|
|
return create(ctx);
|
|
case undefined:
|
|
case "--help":
|
|
case "-h":
|
|
process.stdout.write(USAGE + "\n");
|
|
return;
|
|
default:
|
|
throw new UsageError(`unknown subcommand: keys ${sub}\n\n${USAGE}`);
|
|
}
|
|
}
|
|
|
|
async function create(ctx: CommandContext): Promise<void> {
|
|
const name = requireArg(ctx.args, 1, "name");
|
|
const scopes = ctx.args.slice(2);
|
|
if (scopes.length === 0) throw new UsageError(`at least one scope required: ${SCOPES.join(", ")}`);
|
|
for (const s of scopes) {
|
|
if (!SCOPES.includes(s as (typeof SCOPES)[number])) {
|
|
throw new UsageError(`invalid scope "${s}". Expected one of: ${SCOPES.join(", ")}`);
|
|
}
|
|
}
|
|
|
|
const key = await ctx.client.post<ApiKey>(
|
|
"/v1/admin/api-keys",
|
|
{ name, scopes },
|
|
idempotencyKey("apikey"),
|
|
);
|
|
emit(ctx, key, () =>
|
|
heading(`Created API Key — ${name}`) +
|
|
"\n" +
|
|
keyValues([
|
|
["id", key.id],
|
|
["scopes", key.scopes.join(", ")],
|
|
["secret", color.bold(color.yellow(key.secret))],
|
|
]) +
|
|
`\n\n${sym.info()} ${color.dim("store the secret now — it is shown only once.")}`,
|
|
);
|
|
}
|