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
25 changes: 0 additions & 25 deletions agentkit/src/schema.ts

This file was deleted.

33 changes: 26 additions & 7 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
5 changes: 2 additions & 3 deletions agentkit/package.json → core/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@worldcoin/agentkit",
"name": "@worldcoin/agentkit-core",
"version": "0.1.6",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
Expand All @@ -23,11 +23,10 @@
"scripts": {
"build": "tsup",
"prepublishOnly": "bun run build",
"publish:npm": "npm publish"
"publish:npm": "bun publish"
},
"dependencies": {
"@scure/base": "^1.2.6",
"@x402/core": "^2.4.0",
"siwe": "^2.3.2",
"tweetnacl": "^1.0.3",
"viem": "^2.46.2",
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 1 addition & 11 deletions agentkit/src/index.ts → core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ export type {
AgentkitExtension,
AgentkitExtensionInfo,
AgentkitExtensionSchema,
AgentkitMode,
AgentkitPayload,
CompleteAgentkitInfo,
DeclareAgentkitOptions,
SignatureScheme,
SignatureType,
AgentkitValidationResult,
Expand All @@ -19,9 +17,7 @@ export type {
SupportedChain,
} from './types'

// Server
export { declareAgentkitExtension } from './declare'
export { agentkitResourceServerExtension } from './server'
// Verification
export { parseAgentkitHeader } from './parse'
export { validateAgentkitMessage } from './validate'
export { verifyAgentkitSignature } from './verify'
Expand All @@ -41,9 +37,3 @@ export {

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

// Storage
export { InMemoryAgentKitStorage, type AgentKitStorage } from './storage'

// Hooks
export { createAgentkitHooks, type CreateAgentkitHooksOptions, type AgentkitHookEvent } from './hooks'
9 changes: 5 additions & 4 deletions agentkit/src/parse.ts → core/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { base64 } from '@scure/base'
import { AgentkitPayloadSchema, type AgentkitPayload } from './types'
import { Base64EncodedRegex, safeBase64Decode } from '@x402/core/utils'

export function parseAgentkitHeader(header: string): AgentkitPayload {
if (!Base64EncodedRegex.test(header)) {
let jsonStr: string
try {
jsonStr = new TextDecoder().decode(base64.decode(header))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept unpadded Base64 headers

parseAgentkitHeader now decodes with @scure/base, which rejects Base64 strings that omit trailing = padding. The previous implementation (Base64EncodedRegex + safeBase64Decode) accepted those headers, and unpadded Base64 is common in non-JS clients and proxies that normalize header values. This change causes valid previously-supported agentkit headers to fail with Invalid agentkit header: not valid base64, breaking interoperability for existing senders unless they add padding explicitly.

Useful? React with 👍 / 👎.

} catch {
throw new Error('Invalid agentkit header: not valid base64')
}

const jsonStr = safeBase64Decode(header)

let rawPayload: unknown
try {
rawPayload = JSON.parse(jsonStr)
Expand Down
27 changes: 27 additions & 0 deletions core/src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { AgentkitExtensionSchema } from './types'

const AGENTKIT_SCHEMA: AgentkitExtensionSchema = {
$schema: 'https://json-schema.org/draft/2020-12/schema',
type: 'object',
properties: {
domain: { type: 'string' },
address: { type: 'string' },
statement: { type: 'string' },
uri: { type: 'string', format: 'uri' },
version: { type: 'string' },
chainId: { type: 'string' },
type: { type: 'string' },
nonce: { type: 'string' },
issuedAt: { type: 'string', format: 'date-time' },
expirationTime: { type: 'string', format: 'date-time' },
notBefore: { type: 'string', format: 'date-time' },
requestId: { type: 'string' },
resources: { type: 'array', items: { type: 'string', format: 'uri' } },
signature: { type: 'string' },
},
required: ['domain', 'address', 'uri', 'version', 'chainId', 'type', 'nonce', 'issuedAt', 'signature'],
}

export function buildAgentkitSchema(): AgentkitExtensionSchema {
return AGENTKIT_SCHEMA
}
File renamed without changes.
15 changes: 0 additions & 15 deletions agentkit/src/types.ts → core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,6 @@ export const AgentkitPayloadSchema = z.object({

export type AgentkitPayload = z.infer<typeof AgentkitPayloadSchema>

export type AgentkitMode =
| { type: 'free' }
| { type: 'free-trial'; uses?: number }
| { type: 'discount'; percent: number; uses?: number }

export interface DeclareAgentkitOptions {
domain?: string
resourceUri?: string
statement?: string
version?: string
network?: string | string[]
expirationSeconds?: number
mode?: AgentkitMode
}

export interface AgentkitValidationResult {
valid: boolean
error?: string
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
"typescript": "^5.8.3"
},
"scripts": {
"build:agentkit": "bun run --cwd agentkit build",
"publish:agentkit": "npm publish --workspace @worldcoin/agentkit"
"build:core": "bun run --cwd core build",
"build:x402": "bun run --cwd x402 build",
"build": "bun run build:core && bun run build:x402",
"publish:core": "bun run --cwd core publish:npm",
"publish:x402": "bun run --cwd x402 publish:npm"
},
"prettier": {
"parser": "@typescript-eslint/parser",
Expand All @@ -26,6 +29,7 @@
},
"private": true,
"workspaces": [
"agentkit"
"core",
"x402"
]
}
2 changes: 2 additions & 0 deletions x402/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
File renamed without changes.
38 changes: 38 additions & 0 deletions x402/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@worldcoin/agentkit",
"version": "0.1.6",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
"types": "./dist/cjs/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
},
"files": ["dist"],
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsup",
"prepublishOnly": "bun run --cwd ../core build && bun run build",
"publish:npm": "bun publish"
},
"dependencies": {
"@worldcoin/agentkit-core": "workspace:^",
"@x402/core": "^2.4.0"
},
"devDependencies": {
"@types/node": "^25.5.0",
"tsup": "^8.5.1",
"tweetnacl": "^1.0.3",
"typescript": "^5.9.3"
}
}
7 changes: 3 additions & 4 deletions agentkit/src/declare.ts → x402/src/declare.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { AGENTKIT } from './types'
import { buildAgentkitSchema } from './schema'
import { AGENTKIT, buildAgentkitSchema } from '@worldcoin/agentkit-core'
import type {
AgentkitExtension,
AgentkitExtensionInfo,
DeclareAgentkitOptions,
SignatureType,
SupportedChain,
} from './types'
} from '@worldcoin/agentkit-core'
import type { DeclareAgentkitOptions } from './types'

export function getSignatureTypes(network: string): SignatureType[] {
return network.startsWith('solana:') ? ['ed25519'] : ['eip191', 'eip1271']
Expand Down
7 changes: 2 additions & 5 deletions agentkit/src/hooks.ts → x402/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { AGENTKIT } from './types'
import { parseAgentkitHeader } from './parse'
import { AGENTKIT, parseAgentkitHeader, verifyAgentkitSignature, validateAgentkitMessage } from '@worldcoin/agentkit-core'
import type { AgentBookVerifier } from '@worldcoin/agentkit-core'
import type { AgentKitStorage } from './storage'
import { verifyAgentkitSignature } from './verify'
import { validateAgentkitMessage } from './validate'
import type { AgentBookVerifier } from './agent-book'
import type { AgentkitMode } from './types'

export type AgentkitHookEvent =
Expand Down
15 changes: 15 additions & 0 deletions x402/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Re-export everything from core
export * from '@worldcoin/agentkit-core'

// x402-specific types
export type { AgentkitMode, DeclareAgentkitOptions } from './types'

// x402 server integration
export { declareAgentkitExtension } from './declare'
export { agentkitResourceServerExtension } from './server'

// Storage
export { InMemoryAgentKitStorage, type AgentKitStorage } from './storage'

// Hooks
export { createAgentkitHooks, type CreateAgentkitHooksOptions, type AgentkitHookEvent } from './hooks'
8 changes: 3 additions & 5 deletions agentkit/src/server.ts → x402/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { AGENTKIT } from './types'
import { AGENTKIT, buildAgentkitSchema } from '@worldcoin/agentkit-core'
import { randomBytes } from 'crypto'
import { buildAgentkitSchema } from './schema'
import { getSignatureTypes, type AgentkitDeclaration } from './declare'
import type { ResourceServerExtension, PaymentRequiredContext } from '@x402/core/types'
import type {
AgentkitExtension,
AgentkitExtensionInfo,
AgentkitMode,
SupportedChain,
DeclareAgentkitOptions,
} from './types'
} from '@worldcoin/agentkit-core'
import type { DeclareAgentkitOptions } from './types'

export const agentkitResourceServerExtension: ResourceServerExtension = {
key: AGENTKIT,
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions x402/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type AgentkitMode =
| { type: 'free' }
| { type: 'free-trial'; uses?: number }
| { type: 'discount'; percent: number; uses?: number }

export interface DeclareAgentkitOptions {
domain?: string
resourceUri?: string
statement?: string
version?: string
network?: string | string[]
expirationSeconds?: number
mode?: AgentkitMode
}
4 changes: 2 additions & 2 deletions agentkit/tests/hooks.test.ts → x402/tests/hooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import nacl from 'tweetnacl'
import { describe, expect, it } from 'bun:test'
import { createAgentkitHooks } from '../src/hooks'
import type { AgentkitPayload } from '../src/types'
import type { AgentkitPayload } from '@worldcoin/agentkit-core'
import type { AgentKitStorage } from '../src/storage'
import { SOLANA_MAINNET, encodeBase58, formatSIWSMessage } from '../src/solana'
import { SOLANA_MAINNET, encodeBase58, formatSIWSMessage } from '@worldcoin/agentkit-core'

function createSignedRequest(url = 'https://agentkit.example/protected') {
const keyPair = nacl.sign.keyPair()
Expand Down
Loading
Loading