{"_id":"@bolyra/ai","name":"@bolyra/ai","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@bolyra/ai","version":"0.1.0","description":"Bolyra ZKP authentication adapter for Vercel AI SDK — protect AI tool calls with zero-knowledge proofs","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"build":"tsc","test":"jest --passWithNoTests","typecheck":"tsc --noEmit"},"dependencies":{"@bolyra/sdk":"^0.5.0","@bolyra/mcp":"~0.6.0"},"peerDependencies":{"ai":">=3.0.0","zod":">=3.0.0"},"peerDependenciesMeta":{"ai":{"optional":false},"zod":{"optional":false}},"devDependencies":{"@types/jest":"^30.0.0","@types/node":"^25.9.1","ai":"^4.3.0","jest":"^30.4.2","ts-jest":"^29.2.0","typescript":"^5.5.0","zod":"^3.25.0"},"repository":{"type":"git","url":"git+https://github.com/bolyra/bolyra.git"},"publishConfig":{"access":"public"},"keywords":["bolyra","vercel-ai-sdk","ai","zkp","agent-authentication","zero-knowledge","tool-calling","middleware"],"license":"Apache-2.0","gitHead":"bfe31b5c84e22442fd21d3f82f52349d97fe55cd","_id":"@bolyra/ai@0.1.0","bugs":{"url":"https://github.com/bolyra/bolyra/issues"},"homepage":"https://github.com/bolyra/bolyra#readme","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-TOJ/z0qkpmjwJ5U5C4ATy+AL+NFMez7wzauUKFVW8Cg9eV5azM1cWWPyatY/s/Mo4f3BXkFy/5pSzkp9iCYBIQ==","shasum":"567546dfafe4bebaa291316baebe381302c1b43b","tarball":"https://registry.npmjs.org/@bolyra/ai/-/ai-0.1.0.tgz","fileCount":22,"unpackedSize":86915,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDFNA9tAybAlCiXA0PFLrIcnYmDtYDre8gRpKj8lI/jEgIgdpGwIwGJ9PGFECnjycYjf0zS+3cW2xjyGFSmtwvKnHA="}]},"_npmUser":{"name":"saneguy","email":"kondojuviswanadha@gmail.com"},"directories":{},"maintainers":[{"name":"saneguy","email":"kondojuviswanadha@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ai_0.1.0_1781931817992_0.9116846915934194"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-20T05:03:37.768Z","0.1.0":"2026-06-20T05:03:38.145Z","modified":"2026-06-20T05:03:38.450Z"},"maintainers":[{"name":"saneguy","email":"kondojuviswanadha@gmail.com"}],"description":"Bolyra ZKP authentication adapter for Vercel AI SDK — protect AI tool calls with zero-knowledge proofs","homepage":"https://github.com/bolyra/bolyra#readme","keywords":["bolyra","vercel-ai-sdk","ai","zkp","agent-authentication","zero-knowledge","tool-calling","middleware"],"repository":{"type":"git","url":"git+https://github.com/bolyra/bolyra.git"},"bugs":{"url":"https://github.com/bolyra/bolyra/issues"},"license":"Apache-2.0","readme":"# @bolyra/ai\n\nBolyra ZKP authentication adapter for the [Vercel AI SDK](https://sdk.vercel.ai). Protect AI tool calls with zero-knowledge proofs.\n\n## Install\n\n```bash\nnpm install @bolyra/ai ai zod\n```\n\n## Quick Start\n\n### 1. Wrap a Language Model (Client Side)\n\nInject Bolyra auth into outgoing tool calls:\n\n```typescript\nimport { streamText } from 'ai';\nimport { openai } from '@ai-sdk/openai';\nimport { withBolyraAuth } from '@bolyra/ai';\n\nconst model = withBolyraAuth(openai('gpt-4o'), {\n  credential: agentCredential,\n  operatorPrivateKey: process.env.BOLYRA_OPERATOR_KEY!,\n  humanIdentity: humanId,\n});\n\n// Tool calls now carry Bolyra proof bundles\nconst result = await streamText({\n  model,\n  tools: myTools,\n  prompt: 'Read the quarterly report',\n});\n```\n\n### 2. Verify Incoming Requests (Server Side)\n\nGate tool execution behind Bolyra auth:\n\n```typescript\n// app/api/tools/route.ts (Next.js App Router)\nimport { bolyraAuthMiddleware } from '@bolyra/ai';\n\nconst auth = bolyraAuthMiddleware({\n  toolPolicy: {\n    'read_file': { requireBitmask: 1 },     // READ_DATA\n    'send_payment': { requireBitmask: 4 },   // FINANCIAL_SMALL\n  },\n});\n\nexport async function POST(req: Request) {\n  const { verified, reason, context } = await auth.verify(req, 'read_file');\n  if (!verified) {\n    return Response.json({ error: reason }, { status: 401 });\n  }\n  // context.did, context.permissionBitmask, context.score available\n}\n```\n\n### 3. Add Auth Tools for the LLM\n\nLet the model authenticate and manage credentials programmatically:\n\n```typescript\nimport { generateText } from 'ai';\nimport { createBolyraTools } from '@bolyra/ai';\n\nconst bolyraTools = createBolyraTools({\n  credential: agentCredential,\n  devMode: true,\n});\n\nconst result = await generateText({\n  model: openai('gpt-4o'),\n  tools: { ...bolyraTools, ...myAppTools },\n  prompt: 'Authenticate, then check if you can read files',\n});\n```\n\n## Dev Mode\n\nAll three APIs support `devMode: true` for local development without circuit artifacts:\n\n```typescript\n// Client\nconst model = withBolyraAuth(openai('gpt-4o'), { devMode: true });\n\n// Server\nconst auth = bolyraAuthMiddleware({ devMode: true });\n\n// Tools\nconst tools = createBolyraTools({ credential, devMode: true });\n```\n\nDev mode uses `createDevIdentities()` from `@bolyra/sdk` to generate fixed-seed test credentials.\n\n## API Reference\n\n### `withBolyraAuth(model, config)`\n\nWraps a `LanguageModelV1` with Bolyra auth middleware. Returns a new `LanguageModelV1`.\n\n**Config:**\n\n| Field | Type | Description |\n|---|---|---|\n| `credential` | `AgentCredential` | Agent credential for direct proof generation |\n| `operatorPrivateKey` | `string \\| Buffer` | Operator key for signing |\n| `humanIdentity` | `HumanIdentity` | Human identity for mutual handshake |\n| `gateway` | `{ url, apiKey? }` | Gateway mode config |\n| `toolPermissions` | `Record<string, Permission>` | Per-tool permission requirements |\n| `devMode` | `boolean` | Use mock proofs |\n| `network` | `string` | Network identifier (default: `base-sepolia`) |\n\n### `bolyraAuthMiddleware(config)`\n\nCreates a server-side verifier. Returns a `BolyraVerifier` with `verify(req, toolName?)` and `verifyHeader(header, toolName?)`.\n\n### `createBolyraTools(config)`\n\nCreates four Vercel AI SDK tools:\n\n| Tool | Description |\n|---|---|\n| `bolyra_authenticate` | Generate a proof bundle |\n| `bolyra_delegate` | Create a scoped delegation |\n| `bolyra_check_permissions` | Check a specific permission |\n| `bolyra_credential_info` | Return credential metadata |\n\n## Architecture\n\n```\n@bolyra/ai\n  src/\n    middleware.ts          withBolyraAuth() - model wrapper\n    server-middleware.ts   bolyraAuthMiddleware() - request verifier\n    tools.ts               createBolyraTools() - tool definitions\n    types.ts               Config interfaces\n    utils.ts               Bundle encoding, nonce generation\n    index.ts               Public exports\n```\n\n## License\n\nApache-2.0\n","readmeFilename":"README.md","_rev":"1-9a8b4a307923cb4d52fabbb1505202bf"}