Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agentkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@worldcoin/agentkit",
"version": "0.1.4",
"version": "0.1.5",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
"types": "./dist/cjs/index.d.ts",
Expand Down
14 changes: 3 additions & 11 deletions agentkit/src/agent-book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const WORLD_MAINNET = 'eip155:480' as const

const AGENT_BOOK_ADDRESS: `0x${string}` = '0xA23aB2712eA7BBa896930544C7d6636a96b944dA'

export type AgentBookNetwork = 'world'

const AGENT_BOOK_ABI = [
{
inputs: [{ internalType: 'address', name: '', type: 'address' }],
Expand All @@ -21,26 +19,20 @@ const AGENT_BOOK_ABI = [
export interface AgentBookOptions {
/** Custom viem PublicClient. Overrides automatic client creation. */
client?: PublicClient
/** Custom contract address. Overrides the built-in network → address mapping. */
/** Custom contract address. Overrides the built-in World Chain deployment. */
contractAddress?: `0x${string}`
/** Custom RPC URL. Defaults to the chain's default RPC. */
rpcUrl?: string
/** Pin lookup to the built-in World Chain AgentBook deployment. */
network?: AgentBookNetwork
}

export function createAgentBookVerifier(options: AgentBookOptions = {}) {
function resolveLookupChainId(): typeof WORLD_MAINNET {
return WORLD_MAINNET
}

function getClient(chainId: string): PublicClient {
if (options.client) return options.client

const numericId =
options.contractAddress && options.rpcUrl && !options.network
options.contractAddress && options.rpcUrl
? extractEVMChainId(chainId)
: extractEVMChainId(resolveLookupChainId())
: extractEVMChainId(WORLD_MAINNET)

return getPublicClient(numericId, options.rpcUrl)
}
Expand Down
7 changes: 1 addition & 6 deletions agentkit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ export {
} from './solana'

// AgentBook
export {
createAgentBookVerifier,
type AgentBookVerifier,
type AgentBookOptions,
type AgentBookNetwork,
} from './agent-book'
export { createAgentBookVerifier, type AgentBookVerifier, type AgentBookOptions } from './agent-book'

// Storage
export { InMemoryAgentKitStorage, type AgentKitStorage } from './storage'
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@worldcoin/agentkit-cli",
"version": "0.1.5",
"version": "0.1.6",
"description": "Register agent wallets with World ID-verified humans via AgentBook.",
"type": "module",
"main": "dist/index.js",
Expand Down
32 changes: 8 additions & 24 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import qrcode from 'qrcode-terminal'

// ─── Config ──────────────────────────────────────────────────────────────────

const NETWORKS = {
world: { chain: worldchain, address: '0xA23aB2712eA7BBa896930544C7d6636a96b944dA' as const },
} as const

const NETWORK_NAMES = Object.keys(NETWORKS) as [keyof typeof NETWORKS, ...Array<keyof typeof NETWORKS>]
const AGENT_BOOK_CONTRACT = '0xA23aB2712eA7BBa896930544C7d6636a96b944dA' as const

const AGENT_BOOK_ABI = [
{
Expand All @@ -29,9 +25,7 @@ const AGENT_BOOK_ABI = [

const APP_ID = 'app_a7c3e2b6b83927251a0db5345bd7146a'
const ACTION = 'agentbook-registration'
const DEFAULT_AUTO_API_URLS: Partial<Record<keyof typeof NETWORKS, string>> = {
world: 'https://x402-worldchain.vercel.app',
}
const DEFAULT_API_URL = 'https://x402-worldchain.vercel.app'

// ─── CLI ─────────────────────────────────────────────────────────────────────

Expand All @@ -46,11 +40,10 @@ cli.command('register', {
address: z.string().regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address').describe('Agent wallet address'),
}),
options: z.object({
network: z.enum(NETWORK_NAMES).default('world').describe('Target network'),
auto: z.boolean().default(true).describe('Submit registration to the default relay or API_URL override'),
manual: z.boolean().optional().describe('Print manual call data instead of submitting through a relay'),
}),
alias: { network: 'n', auto: 'a', manual: 'm' },
alias: { auto: 'a', manual: 'm' },
env: z.object({
API_URL: z
.string()
Expand All @@ -64,23 +57,21 @@ cli.command('register', {
nullifierHash: z.string(),
proof: z.array(z.string()),
contract: z.string(),
network: z.string(),
txHash: z.string().optional(),
}),
examples: [
{ args: { address: '0x1234567890abcdef1234567890abcdef12345678' }, description: 'Register on World Chain' },
],
async run(c) {
const agentAddress = c.args.address as `0x${string}`
const deployment = NETWORKS[c.options.network]
const shouldAuto = c.options.manual ? false : c.options.auto

// 1. Read next nonce from AgentBook contract
if (!c.agent) console.log(`Looking up next nonce for ${agentAddress}...`)

const client = createPublicClient({ chain: deployment.chain, transport: http() })
const client = createPublicClient({ chain: worldchain, transport: http() })
const nonce = await client.readContract({
address: deployment.address,
address: AGENT_BOOK_CONTRACT,
abi: AGENT_BOOK_ABI,
functionName: 'getNextNonce',
args: [agentAddress],
Expand Down Expand Up @@ -142,16 +133,15 @@ cli.command('register', {
nonce: nonce.toString(),
nullifierHash: completion.proof.nullifier_hash,
proof,
contract: deployment.address,
network: c.options.network,
contract: AGENT_BOOK_CONTRACT,
}

if (!shouldAuto) {
if (!c.agent) {
console.log()
console.log('Submit this transaction on-chain:')
console.log()
console.log(`Contract: ${deployment.address}`)
console.log(`Contract: ${AGENT_BOOK_CONTRACT}`)
console.log(
'Function: register(address agent, uint256 root, uint256 nonce, uint256 nullifierHash, uint256[8] proof)'
)
Expand All @@ -160,13 +150,7 @@ cli.command('register', {
return registration
}

const apiUrl = c.env.API_URL ?? DEFAULT_AUTO_API_URLS[c.options.network]
if (!apiUrl) {
return c.error({
code: 'MISSING_API_URL',
message: `No default registration relay is configured for network ${c.options.network}. Set API_URL to use --auto on this network.`,
})
}
const apiUrl = c.env.API_URL ?? DEFAULT_API_URL

const registerUrl = `${apiUrl.replace(/\/$/, '')}/register`

Expand Down
Loading