cred402/scripts/near_keygen.ts
caelum0x 7fdc321d79 feat: live-wire Casper writes, add marketing homepage, fix cold-start UX
Round 1 against STRATEGY-2026-10-23.md's backlog:

- Wire register_agent/stake/set_credit_score/deposit_liquidity to the real
  Casper Testnet contracts (lib/casper/live_bridge.ts), verified live against
  the real RPC node with a freshly generated (unfunded) keypair
  (npm run casper:keygen). Honesty flags built in for the Odra payable
  calling convention and the admin-gated set_credit_score call.
- Unblock NEAR's paid x402 route (npm run near:keygen generates a real
  implicit account id); QIE stays correctly flagged as blocked on unconfirmed
  external facts (asset contract, facilitator), not env plumbing.
- New public Home tab: live-stats hero, how-it-works, a real competitor
  comparison table, and a "90-second proof" that calls the real API live in
  the browser (verified end-to-end with gstack browse).
- Cold-start UX: visible retry state in X402Playground + the TS SDK, plus a
  keep-warm self-ping (lib/services/keepalive.ts) so the free Render dyno
  rarely idles out from under a real first-time caller.
- New GET /v1/credit-score/:agentId alias + docs/integrations/ samples for
  Skyfire/Nevermined/Coinbase x402.
- Self-hosting quickstart: root docker-compose.yml + scripts/bootstrap.sh,
  both run for real; fixed a real EACCES crash-loop bug in infra/Dockerfile
  (non-root user never owned the /data volume mount) found while verifying.

450/450 tests pass, typecheck clean, frontend build clean.
2026-10-23 19:57:40 +03:00

57 lines
2.6 KiB
TypeScript

/**
* near_keygen.ts — generate a fresh NEAR Testnet ed25519 keypair entirely
* offline (no network call, spends nothing).
*
* NEAR has "implicit accounts": the 64-hex-char encoding of the ed25519
* public key IS a valid account id, and it becomes a real on-chain account
* automatically the first time it receives a transfer — no separate
* registration step. That means the public key derived here can go straight
* into CRED402_NEAR_PAY_TO once funded.
*
* npm run near:keygen
* # then, as the owner: fund the printed implicit account at
* # https://near-faucet.io (free testnet NEAR, no real funds)
* # then set CRED402_NEAR_PAY_TO to the implicit account id.
*/
import { mkdirSync, writeFileSync, existsSync } from "node:fs";
import { join } from "node:path";
import { KeyPair } from "near-api-js";
const SECRETS_DIR = join(process.cwd(), ".secrets");
const OUT_PATH = join(SECRETS_DIR, "near_testnet_credentials.json");
function main(): void {
if (existsSync(OUT_PATH) && !process.argv.includes("--force")) {
console.log(`A key already exists at ${OUT_PATH} — pass --force to overwrite (this would orphan any funds sent to the old account).`);
process.exit(1);
}
mkdirSync(SECRETS_DIR, { recursive: true });
const keyPair = KeyPair.fromRandom("ed25519");
const publicKey = keyPair.getPublicKey();
const implicitAccountId = Buffer.from(publicKey.data).toString("hex");
const credentials = {
account_id: implicitAccountId,
public_key: publicKey.toString(),
private_key: keyPair.toString(),
};
writeFileSync(OUT_PATH, JSON.stringify(credentials, null, 2), { mode: 0o600 });
console.log("Generated a fresh NEAR Testnet ed25519 keypair (offline — nothing broadcast, nothing spent).");
console.log(` credentials (gitignored): ${OUT_PATH}`);
console.log(` implicit account id: ${implicitAccountId}`);
console.log(` public key: ${publicKey.toString()}`);
console.log("");
console.log("OWNER STEP (captcha-gated, cannot be automated):");
console.log(" 1. Open https://near-faucet.io");
console.log(` 2. Paste the implicit account id above and claim free Testnet NEAR (no payment, no real funds).`);
console.log(" This both funds AND creates the account on-chain in one step.");
console.log(" 3. Once funded, set in your .env (or the Render dashboard):");
console.log(` CRED402_NEAR_PAY_TO=${implicitAccountId}`);
console.log(" CRED402_NEAR_NETWORK=testnet");
console.log(" 4. Restart the API. GET /v1/x402/near/status will report ready:true once reachable + funded.");
}
main();