Sign In

@bolyra/ai

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bolyra/ai

Bolyra ZKP authentication adapter for Vercel AI SDK — protect AI tool calls with zero-knowledge proofs

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

@bolyra/ai

Bolyra ZKP authentication adapter for the Vercel AI SDK. Protect AI tool calls with zero-knowledge proofs.

Install

npm install @bolyra/ai ai zod

Quick Start

1. Wrap a Language Model (Client Side)

Inject Bolyra auth into outgoing tool calls:

import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { withBolyraAuth } from '@bolyra/ai';

const model = withBolyraAuth(openai('gpt-4o'), {
  credential: agentCredential,
  operatorPrivateKey: process.env.BOLYRA_OPERATOR_KEY!,
  humanIdentity: humanId,
});

// Tool calls now carry Bolyra proof bundles
const result = await streamText({
  model,
  tools: myTools,
  prompt: 'Read the quarterly report',
});

2. Verify Incoming Requests (Server Side)

Gate tool execution behind Bolyra auth:

// app/api/tools/route.ts (Next.js App Router)
import { bolyraAuthMiddleware } from '@bolyra/ai';

const auth = bolyraAuthMiddleware({
  toolPolicy: {
    'read_file': { requireBitmask: 1 },     // READ_DATA
    'send_payment': { requireBitmask: 4 },   // FINANCIAL_SMALL
  },
});

export async function POST(req: Request) {
  const { verified, reason, context } = await auth.verify(req, 'read_file');
  if (!verified) {
    return Response.json({ error: reason }, { status: 401 });
  }
  // context.did, context.permissionBitmask, context.score available
}

3. Add Auth Tools for the LLM

Let the model authenticate and manage credentials programmatically:

import { generateText } from 'ai';
import { createBolyraTools } from '@bolyra/ai';

const bolyraTools = createBolyraTools({
  credential: agentCredential,
  devMode: true,
});

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { ...bolyraTools, ...myAppTools },
  prompt: 'Authenticate, then check if you can read files',
});

Dev Mode

All three APIs support devMode: true for local development without circuit artifacts:

// Client
const model = withBolyraAuth(openai('gpt-4o'), { devMode: true });

// Server
const auth = bolyraAuthMiddleware({ devMode: true });

// Tools
const tools = createBolyraTools({ credential, devMode: true });

Dev mode uses createDevIdentities() from @bolyra/sdk to generate fixed-seed test credentials.

API Reference

withBolyraAuth(model, config)

Wraps a LanguageModelV1 with Bolyra auth middleware. Returns a new LanguageModelV1.

Config:

FieldTypeDescription
credentialAgentCredentialAgent credential for direct proof generation
operatorPrivateKeystring | BufferOperator key for signing
humanIdentityHumanIdentityHuman identity for mutual handshake
gateway{ url, apiKey? }Gateway mode config
toolPermissionsRecord<string, Permission>Per-tool permission requirements
devModebooleanUse mock proofs
networkstringNetwork identifier (default: base-sepolia)

bolyraAuthMiddleware(config)

Creates a server-side verifier. Returns a BolyraVerifier with verify(req, toolName?) and verifyHeader(header, toolName?).

createBolyraTools(config)

Creates four Vercel AI SDK tools:

ToolDescription
bolyra_authenticateGenerate a proof bundle
bolyra_delegateCreate a scoped delegation
bolyra_check_permissionsCheck a specific permission
bolyra_credential_infoReturn credential metadata

Architecture

@bolyra/ai
  src/
    middleware.ts          withBolyraAuth() - model wrapper
    server-middleware.ts   bolyraAuthMiddleware() - request verifier
    tools.ts               createBolyraTools() - tool definitions
    types.ts               Config interfaces
    utils.ts               Bundle encoding, nonce generation
    index.ts               Public exports

License

Apache-2.0

Keywords

bolyra

FAQs

Package last updated on 20 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts