Skip to main content

@helixid/langchain

HelixID middleware for LangChain and LangGraph — injects a signed presentation into tool calls, and filters the tool list by the scopes the agent actually holds.

npm install @helixid/langchain

@langchain/core is declared as an optional peer dependency.

Exports

ExportPurpose
HelixIDMiddleware(options)Returns a LangChain callback config that injects _helixVP into object tool input before tool start.
HelixIDToolWrapper(tool, options)Wraps a structured tool and injects _helixVP before calling the original _call.
filterToolsByScope(tools, walletFilePath, walletPassphrase)Filters tools by tool.metadata.requiredScope or tool name against the wallet's VC scopes.
encodeBase64UrlJson(value)Encodes a VP or object as base64url JSON.
selectVC(wallet, targetService)Picks the matching credential for a target service, falling back to the first VC.
ensureObjectInput(input)Validates that tool input is an object.

Options

OptionRequiredPurpose
walletPassphraseYesPassphrase for the encrypted wallet file
walletFilePathYesPath to the wallet
targetServiceYesBinds the VP to one verifier
userDidNoThe user on whose behalf the agent is acting

Usage

import { HelixIDMiddleware } from '@helixid/langchain';

const middleware = HelixIDMiddleware({
walletPassphrase: process.env.WALLET_PASSPHRASE!,
walletFilePath: './agent-wallet.enc',
userDid: 'did:web:user.example.com',
targetService: 'orders',
});

filterToolsByScope() is worth using alongside the middleware: it keeps tools the agent has no scope for out of the model's choices entirely, so the model never proposes a call that is going to be refused. See LangChain Integration.