ZeroForgeLive on 0G Galileo

@sovereignclaw/inft

ERC-7857 iNFT lifecycle helpers for SovereignClaw — mint an agent as a token, transfer with oracle-mediated re-encryption, record usage events, and irrevocably revoke memory access. Wraps the deployed AgentNFT and MemoryRevocation contracts on 0G Galileo testnet.

Install

pnpm add @sovereignclaw/inft @sovereignclaw/memory ethers

The package imports ABIs from contracts/out/. Run forge build in contracts/ once before building this package — the quickstart covers this.

10-line quickstart

import { Wallet, JsonRpcProvider, randomBytes } from 'ethers';
import { loadDeployment, mintAgentNFT, revokeMemory, OracleClient } from '@sovereignclaw/inft';

const signer = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL!));
const deployment = loadDeployment();
const oracle = new OracleClient({ url: 'http://localhost:8787' });

const minted = await mintAgentNFT({
  agent: { role: 'researcher', getPointer: () => process.env.MEMORY_POINTER! },
  owner: signer,
  wrappedDEK: randomBytes(32),
  deployment,
});
await revokeMemory({ tokenId: minted.tokenId, owner: signer, oracle, deployment });

API

ExportKindPurpose
mintAgentNFTfnMints one iNFT. Commits pointer + wrappedDEK + metadata hash.
transferAgentNFTfnTransfers via oracle re-encryption; updates wrappedDEK atomically.
revokeMemoryfnOwner signs → oracle registry → chain revoke. Irreversible.
recordUsagefnAppend a typed usage record for downstream analytics.
OracleClientclassHTTP client for /oracle/{pubkey,reencrypt,revoke,prove,healthz}.
loadDeploymentfnReads deployments/0g-testnet.json. Throws if missing.
AgentNFTAbi / MemoryRevocationAbiconstEthers-v6-compatible ABIs. Used internally; exposed for callers.
explorerTxUrl / explorerAddressUrlfnFormat chainscan links for mint/transfer/revoke receipts.
digestForOracleProof etc.fnEIP-712 helpers — used by the oracle; exposed for audit tests.
CONTRACT_LIMITSconstOn-chain field maxima (role/pointer/DEK byte lengths).

Errors

All extend InftError:

ErrorWhen
MintErrorPre-flight validation failed or mint tx reverted.
TransferErrorOracle rejected, chain reverted, or post-condition assertion failed.
RevokeErrorOracle rejected, chain reverted, or post-condition assertion failed.
RecordUsageErrorUsage tx reverted or over field-length limit.
OracleClientErrorGeneric oracle transport error (parent).
OracleAuthError401/403 from oracle (auth token mismatch).
OracleRevokedError410 from oracle — token is already revoked.
OracleHttpErrorAny other 4xx/5xx from oracle.
OracleTimeoutError / OracleUnreachableErrorRequest timed out / couldn’t reach oracle.
ContractRevertErrorParsed reason from a contract revert (wraps the underlying tx error).
DeploymentNotFoundErrordeployments/0g-testnet.json missing or malformed.

Trust model

  • The oracle holds one EIP-712 signing key and is **the only entity that

can approve a transfer or a revoke**. On-chain, AgentNFT checks the oracle signature before touching the wrappedDEK or the revoked bit.

  • revokeMemory is irreversible: the oracle flips its in-memory registry

before returning the proof, so any concurrent /oracle/reencrypt for the same token 410s. The chain then permanently zeroes the DEK.

  • A misbehaving oracle cannot mint or transfer to someone else — those

require the owner’s signature as well, enforced on-chain.

Further reading

License

MIT — see the repo root.