erc8004-identity-viewer / tree / scripts/kognai-identity.mjs ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// One command once Kognai publishes the Sepolia test identity (acceptance A5):
//   node scripts/kognai-identity.mjs <agentId>
// 1. writes the agentId into config.js (KOGNAI_TEST_IDENTITY.agentId), 2. reads it live on Base Sepolia while recording
// every RPC answer and the registration file, 3. saves the recording to test/fixtures/kognai-identity.json so the A5
// test replays it offline (Kognai's hidden tests run without network), 4. writes the result into the README.
// Read only: eth_call and HTTPS GETs, no key, no wallet, no spend.
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
import { loadAgent, httpRpc, httpFetchJson } from '../viewer.js';
import { REGISTRIES } from '../config.js';

const agentId = (process.argv[2] || '').trim();
if (!/^\d+$/.test(agentId)) { console.error('usage: node scripts/kognai-identity.mjs <decimal agentId>'); process.exit(2); }
const root = new URL('../', import.meta.url);
const cfgNet = REGISTRIES['base-sepolia'];
const liveRpc = httpRpc(cfgNet.rpcUrl), liveFetch = httpFetchJson();
const rec = { agentId, network: 'base-sepolia', recordedAt: new Date().toISOString(), rpc: [], files: {} };
const rpc = async (method, params) => {
  try { const result = await liveRpc(method, params); rec.rpc.push({ method, params, result }); return result; }
  catch (e) { rec.rpc.push({ method, params, error: { code: e.code ?? null, message: e.message } }); throw e; }
};
const fetchJson = async (url) => { const j = await liveFetch(url); rec.files[url] = j; return j; };
const r = await loadAgent({ agentId, network: 'base-sepolia', identityRegistry: cfgNet.identity, reputationRegistry: cfgNet.reputation, rpc, fetchJson });
rec.result = r;
mkdirSync(new URL('test/fixtures/', root), { recursive: true });
writeFileSync(new URL('test/fixtures/kognai-identity.json', root), JSON.stringify(rec, null, 1) + '\n');

const cfgUrl = new URL('config.js', root);
writeFileSync(cfgUrl, readFileSync(cfgUrl, 'utf8').replace(/(export const KOGNAI_TEST_IDENTITY = \{\s*network: 'base-sepolia',\s*agentId: )[^,\n]+/, `$1'${agentId}'`));

const reg = r.registration || {};
const section = `## Kognai Sepolia test identity result\n\nAgent ${agentId} on Base Sepolia (identity registry ${cfgNet.identity}), read ${rec.recordedAt.slice(0, 10)}: **${r.status}**${r.error ? ' (' + r.error + ')' : ''}.\n\n- Owner: ${r.owner ?? 'none'}\n- tokenURI: ${r.tokenURI ? '`' + String(r.tokenURI).slice(0, 120) + '`' : 'none'}\n- Name: ${reg.name ?? 'none'}\n- Feedback: ${r.feedback ? `${r.feedback.count} entries, average ${r.feedback.average ?? 'none'}` : 'not read'}\n`;
const readmeUrl = new URL('README.md', root);
let readme = readFileSync(readmeUrl, 'utf8');
const rx = /## Kognai Sepolia test identity result\n[\s\S]*?(?=\n## |$)/;
readme = rx.test(readme) ? readme.replace(rx, section) : readme.trimEnd() + '\n\n' + section;
writeFileSync(readmeUrl, readme);
console.log(`agent ${agentId}: status=${r.status}${r.error ? ' error=' + r.error : ''}; fixture, config.js and README updated. Now run: npm test`);
process.exit(r.status === 'ok' ? 0 : 1);

agentgate-source: code mirror on Cloudflare Pages. All repos