From ce6cc0ae3766df7c87217aa4de3f5561bcf9c29a Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Mar 2026 16:53:06 -0700 Subject: [PATCH] split to core and x402 --- agentkit/src/schema.ts | 25 -------------- bun.lock | 33 ++++++++++++++---- {agentkit => core}/.gitignore | 0 {agentkit => core}/package.json | 5 ++- {agentkit => core}/src/agent-book.ts | 0 {agentkit => core}/src/evm.ts | 0 {agentkit => core}/src/index.ts | 12 +------ {agentkit => core}/src/parse.ts | 9 ++--- core/src/schema.ts | 27 +++++++++++++++ {agentkit => core}/src/solana.ts | 0 {agentkit => core}/src/types.ts | 15 -------- {agentkit => core}/src/validate.ts | 0 {agentkit => core}/src/verify.ts | 0 {agentkit => core}/src/viem-client.ts | 0 {agentkit => core}/tests/agent-book.test.ts | 0 {agentkit => core}/tests/validate.test.ts | 0 {agentkit => core}/tsconfig.json | 0 {agentkit => core}/tsup.config.ts | 0 package.json | 10 ++++-- x402/.gitignore | 2 ++ {agentkit => x402}/DOCS.md | 0 x402/package.json | 38 +++++++++++++++++++++ {agentkit => x402}/src/declare.ts | 7 ++-- {agentkit => x402}/src/hooks.ts | 7 ++-- x402/src/index.ts | 15 ++++++++ {agentkit => x402}/src/server.ts | 8 ++--- {agentkit => x402}/src/storage.ts | 0 x402/src/types.ts | 14 ++++++++ {agentkit => x402}/tests/hooks.test.ts | 4 +-- x402/tsconfig.json | 18 ++++++++++ x402/tsup.config.ts | 25 ++++++++++++++ 31 files changed, 190 insertions(+), 84 deletions(-) delete mode 100644 agentkit/src/schema.ts rename {agentkit => core}/.gitignore (100%) rename {agentkit => core}/package.json (88%) rename {agentkit => core}/src/agent-book.ts (100%) rename {agentkit => core}/src/evm.ts (100%) rename {agentkit => core}/src/index.ts (73%) rename {agentkit => core}/src/parse.ts (81%) create mode 100644 core/src/schema.ts rename {agentkit => core}/src/solana.ts (100%) rename {agentkit => core}/src/types.ts (87%) rename {agentkit => core}/src/validate.ts (100%) rename {agentkit => core}/src/verify.ts (100%) rename {agentkit => core}/src/viem-client.ts (100%) rename {agentkit => core}/tests/agent-book.test.ts (100%) rename {agentkit => core}/tests/validate.test.ts (100%) rename {agentkit => core}/tsconfig.json (100%) rename {agentkit => core}/tsup.config.ts (100%) create mode 100644 x402/.gitignore rename {agentkit => x402}/DOCS.md (100%) create mode 100644 x402/package.json rename {agentkit => x402}/src/declare.ts (88%) rename {agentkit => x402}/src/hooks.ts (96%) create mode 100644 x402/src/index.ts rename {agentkit => x402}/src/server.ts (92%) rename {agentkit => x402}/src/storage.ts (100%) create mode 100644 x402/src/types.ts rename {agentkit => x402}/tests/hooks.test.ts (97%) create mode 100644 x402/tsconfig.json create mode 100644 x402/tsup.config.ts diff --git a/agentkit/src/schema.ts b/agentkit/src/schema.ts deleted file mode 100644 index bfef59a..0000000 --- a/agentkit/src/schema.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { AgentkitExtensionSchema } from './types' - -export function buildAgentkitSchema(): AgentkitExtensionSchema { - return { - $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'], - } -} diff --git a/bun.lock b/bun.lock index 69c8523..2982ec4 100644 --- a/bun.lock +++ b/bun.lock @@ -11,12 +11,11 @@ "typescript": "^5.8.3", }, }, - "agentkit": { - "name": "@worldcoin/agentkit", - "version": "0.0.1", + "core": { + "name": "@worldcoin/agentkit-core", + "version": "0.1.5", "dependencies": { "@scure/base": "^1.2.6", - "@x402/core": "^2.4.0", "siwe": "^2.3.2", "tweetnacl": "^1.0.3", "viem": "^2.46.2", @@ -27,6 +26,20 @@ "typescript": "^5.9.3", }, }, + "x402": { + "name": "@worldcoin/agentkit", + "version": "0.1.5", + "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", + }, + }, }, "packages": { "@adraffy/ens-normalize": ["@adraffy/ens-normalize@1.10.1", "", {}, "sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw=="], @@ -191,7 +204,7 @@ "@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="], - "@types/node": ["@types/node@22.7.5", "", { "dependencies": { "undici-types": "~6.19.2" } }, "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ=="], + "@types/node": ["@types/node@25.5.0", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw=="], "@typescript-eslint/parser": ["@typescript-eslint/parser@8.56.1", "", { "dependencies": { "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/types": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1", "debug": "^4.4.3" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "sha512-klQbnPAAiGYFyI02+znpBRLyjL4/BrBd0nyWkdC0s/6xFLkXYQ8OoRrSkqacS1ddVxf/LDyODIKbQ5TgKAf/Fg=="], @@ -207,7 +220,9 @@ "@typescript-eslint/visitor-keys": ["@typescript-eslint/visitor-keys@8.56.1", "", { "dependencies": { "@typescript-eslint/types": "8.56.1", "eslint-visitor-keys": "^5.0.0" } }, "sha512-KiROIzYdEV85YygXw6BI/Dx4fnBlFQu6Mq4QE4MOH9fFnhohw6wX/OAvDY2/C+ut0I3RSPKenvZJIVYqJNkhEw=="], - "@worldcoin/agentkit": ["@worldcoin/agentkit@workspace:agentkit"], + "@worldcoin/agentkit": ["@worldcoin/agentkit@workspace:x402"], + + "@worldcoin/agentkit-core": ["@worldcoin/agentkit-core@workspace:core"], "@x402/core": ["@x402/core@2.4.0", "", { "dependencies": { "zod": "^3.24.2" } }, "sha512-g4K5dAVjevQftxCcpFlUDjO2AHE43FkO43VxwLCQ8ET3ki4aj2fzCcgvnXEj2eloJoocFS/Evt4pSTnP/4cFJw=="], @@ -415,7 +430,7 @@ "ufo": ["ufo@1.6.3", "", {}, "sha512-yDJTmhydvl5lJzBmy/hyOAA0d+aqCBuwl818haVdYCRrWV84o7YyeVm4QlVHStqNrrJSTb6jKuFAVqAFsr+K3Q=="], - "undici-types": ["undici-types@6.19.8", "", {}, "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="], + "undici-types": ["undici-types@7.18.2", "", {}, "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="], "uri-js": ["uri-js@4.4.1", "", { "dependencies": { "punycode": "^2.1.0" } }, "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg=="], @@ -439,6 +454,8 @@ "ethers/@noble/hashes": ["@noble/hashes@1.3.2", "", {}, "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ=="], + "ethers/@types/node": ["@types/node@22.7.5", "", { "dependencies": { "undici-types": "~6.19.2" } }, "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ=="], + "ethers/ws": ["ws@8.17.1", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ=="], "ox/@adraffy/ens-normalize": ["@adraffy/ens-normalize@1.11.1", "", {}, "sha512-nhCBV3quEgesuf7c7KYfperqSS14T8bYuvJ8PcLJp6znkZpFc0AuW4qBtr8eKVyPPe/8RSr7sglCWPU5eaxwKQ=="], @@ -446,5 +463,7 @@ "prettier-plugin-sort-imports-desc/prettier": ["prettier@2.8.8", "", { "bin": { "prettier": "bin-prettier.js" } }, "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q=="], "prettier-plugin-sort-imports-desc/typescript": ["typescript@4.9.5", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g=="], + + "ethers/@types/node/undici-types": ["undici-types@6.19.8", "", {}, "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="], } } diff --git a/agentkit/.gitignore b/core/.gitignore similarity index 100% rename from agentkit/.gitignore rename to core/.gitignore diff --git a/agentkit/package.json b/core/package.json similarity index 88% rename from agentkit/package.json rename to core/package.json index 4503b06..70228dd 100644 --- a/agentkit/package.json +++ b/core/package.json @@ -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", @@ -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", diff --git a/agentkit/src/agent-book.ts b/core/src/agent-book.ts similarity index 100% rename from agentkit/src/agent-book.ts rename to core/src/agent-book.ts diff --git a/agentkit/src/evm.ts b/core/src/evm.ts similarity index 100% rename from agentkit/src/evm.ts rename to core/src/evm.ts diff --git a/agentkit/src/index.ts b/core/src/index.ts similarity index 73% rename from agentkit/src/index.ts rename to core/src/index.ts index a1253d3..9e34e0f 100644 --- a/agentkit/src/index.ts +++ b/core/src/index.ts @@ -7,10 +7,8 @@ export type { AgentkitExtension, AgentkitExtensionInfo, AgentkitExtensionSchema, - AgentkitMode, AgentkitPayload, CompleteAgentkitInfo, - DeclareAgentkitOptions, SignatureScheme, SignatureType, AgentkitValidationResult, @@ -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' @@ -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' diff --git a/agentkit/src/parse.ts b/core/src/parse.ts similarity index 81% rename from agentkit/src/parse.ts rename to core/src/parse.ts index 578efc4..8a9aac0 100644 --- a/agentkit/src/parse.ts +++ b/core/src/parse.ts @@ -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)) + } catch { throw new Error('Invalid agentkit header: not valid base64') } - const jsonStr = safeBase64Decode(header) - let rawPayload: unknown try { rawPayload = JSON.parse(jsonStr) diff --git a/core/src/schema.ts b/core/src/schema.ts new file mode 100644 index 0000000..bcec865 --- /dev/null +++ b/core/src/schema.ts @@ -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 +} diff --git a/agentkit/src/solana.ts b/core/src/solana.ts similarity index 100% rename from agentkit/src/solana.ts rename to core/src/solana.ts diff --git a/agentkit/src/types.ts b/core/src/types.ts similarity index 87% rename from agentkit/src/types.ts rename to core/src/types.ts index ca16ed5..1c83e6d 100644 --- a/agentkit/src/types.ts +++ b/core/src/types.ts @@ -73,21 +73,6 @@ export const AgentkitPayloadSchema = z.object({ export type AgentkitPayload = z.infer -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 diff --git a/agentkit/src/validate.ts b/core/src/validate.ts similarity index 100% rename from agentkit/src/validate.ts rename to core/src/validate.ts diff --git a/agentkit/src/verify.ts b/core/src/verify.ts similarity index 100% rename from agentkit/src/verify.ts rename to core/src/verify.ts diff --git a/agentkit/src/viem-client.ts b/core/src/viem-client.ts similarity index 100% rename from agentkit/src/viem-client.ts rename to core/src/viem-client.ts diff --git a/agentkit/tests/agent-book.test.ts b/core/tests/agent-book.test.ts similarity index 100% rename from agentkit/tests/agent-book.test.ts rename to core/tests/agent-book.test.ts diff --git a/agentkit/tests/validate.test.ts b/core/tests/validate.test.ts similarity index 100% rename from agentkit/tests/validate.test.ts rename to core/tests/validate.test.ts diff --git a/agentkit/tsconfig.json b/core/tsconfig.json similarity index 100% rename from agentkit/tsconfig.json rename to core/tsconfig.json diff --git a/agentkit/tsup.config.ts b/core/tsup.config.ts similarity index 100% rename from agentkit/tsup.config.ts rename to core/tsup.config.ts diff --git a/package.json b/package.json index 8a31624..378aa4a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -26,6 +29,7 @@ }, "private": true, "workspaces": [ - "agentkit" + "core", + "x402" ] } diff --git a/x402/.gitignore b/x402/.gitignore new file mode 100644 index 0000000..de4d1f0 --- /dev/null +++ b/x402/.gitignore @@ -0,0 +1,2 @@ +dist +node_modules diff --git a/agentkit/DOCS.md b/x402/DOCS.md similarity index 100% rename from agentkit/DOCS.md rename to x402/DOCS.md diff --git a/x402/package.json b/x402/package.json new file mode 100644 index 0000000..6dabd68 --- /dev/null +++ b/x402/package.json @@ -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" + } +} diff --git a/agentkit/src/declare.ts b/x402/src/declare.ts similarity index 88% rename from agentkit/src/declare.ts rename to x402/src/declare.ts index 63ae64d..9ef2f92 100644 --- a/agentkit/src/declare.ts +++ b/x402/src/declare.ts @@ -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'] diff --git a/agentkit/src/hooks.ts b/x402/src/hooks.ts similarity index 96% rename from agentkit/src/hooks.ts rename to x402/src/hooks.ts index 6c617a8..74849f3 100644 --- a/agentkit/src/hooks.ts +++ b/x402/src/hooks.ts @@ -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 = diff --git a/x402/src/index.ts b/x402/src/index.ts new file mode 100644 index 0000000..1c14081 --- /dev/null +++ b/x402/src/index.ts @@ -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' diff --git a/agentkit/src/server.ts b/x402/src/server.ts similarity index 92% rename from agentkit/src/server.ts rename to x402/src/server.ts index fea5ffe..962e1e1 100644 --- a/agentkit/src/server.ts +++ b/x402/src/server.ts @@ -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, diff --git a/agentkit/src/storage.ts b/x402/src/storage.ts similarity index 100% rename from agentkit/src/storage.ts rename to x402/src/storage.ts diff --git a/x402/src/types.ts b/x402/src/types.ts new file mode 100644 index 0000000..2f864ff --- /dev/null +++ b/x402/src/types.ts @@ -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 +} diff --git a/agentkit/tests/hooks.test.ts b/x402/tests/hooks.test.ts similarity index 97% rename from agentkit/tests/hooks.test.ts rename to x402/tests/hooks.test.ts index 87d3dc4..f3c2b12 100644 --- a/agentkit/tests/hooks.test.ts +++ b/x402/tests/hooks.test.ts @@ -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() diff --git a/x402/tsconfig.json b/x402/tsconfig.json new file mode 100644 index 0000000..03acab7 --- /dev/null +++ b/x402/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "ES2020", + "lib": ["ES2020"], + "moduleResolution": "bundler", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true + }, + "include": ["src"], + "exclude": ["dist", "node_modules"] +} diff --git a/x402/tsup.config.ts b/x402/tsup.config.ts new file mode 100644 index 0000000..f243bbe --- /dev/null +++ b/x402/tsup.config.ts @@ -0,0 +1,25 @@ +import { defineConfig } from "tsup"; + +const baseConfig = { + entry: { + index: "src/index.ts", + }, + dts: true, + sourcemap: true, + target: "es2020", +}; + +export default defineConfig([ + { + ...baseConfig, + format: "esm", + outDir: "dist/esm", + clean: true, + }, + { + ...baseConfig, + format: "cjs", + outDir: "dist/cjs", + clean: false, + }, +]);