
Product
Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.
@powforge/langchain-l402-middleware
Advanced tools
L402 Lightning payment middleware for LangChain.js tools — wrap any async tool function with a pay-per-call Lightning gate backed by LNBits. Works with DynamicTool, StructuredTool, or any plain async function.
L402 Lightning payment middleware for LangChain.js tools. Wrap any async
tool function with a pay-per-call Lightning gate backed by LNBits. Works
with DynamicTool, StructuredTool, or any plain async function.
npm install @powforge/langchain-l402-middleware
Requires Node 18+ (for global fetch).
const { wrapWithL402 } = require('@powforge/langchain-l402-middleware');
const summarize = async (text) => `summary of ${text}`;
const paidSummarize = wrapWithL402(summarize, {
lnbitsUrl: 'https://lnbits.example',
lnbitsApiKey: process.env.LNBITS_INVOICE_KEY,
satsAmount: 21,
});
// First call — no proof, returns a 402 envelope.
const challenge = await paidSummarize('hello world');
// {
// error: 'payment_required',
// invoice: 'lnbc...',
// payment_hash: 'abc123',
// sats: 21,
// next_step: 'Pay the invoice, then re-call with the payment_hash as paymentProof.'
// }
// Pay the invoice externally, then re-call with the payment_hash:
const result = await paidSummarize('hello world', 'abc123');
// "summary of hello world"
const { createL402Tool } = require('@powforge/langchain-l402-middleware');
const { DynamicTool } = require('@langchain/core/tools');
const toolSpec = createL402Tool({
name: 'paid_summary',
description: 'Summarizes any text. Costs 21 sats per call.',
func: async (text) => `summary of ${text}`,
lnbitsUrl: 'https://lnbits.example',
lnbitsApiKey: process.env.LNBITS_INVOICE_KEY,
satsAmount: 21,
});
const tool = new DynamicTool(toolSpec);
Because DynamicTool.func only receives one argument, callers smuggle
the payment proof through a JSON envelope:
await tool.func(JSON.stringify({
__payment_proof__: 'abc123',
__tool_input__: 'hello world',
}));
// "summary of hello world"
{ error: 'payment_required', invoice, payment_hash, sats }.payment_hash as the proof.{ error: 'invoice_not_paid', payment_hash }.| Option | Required | Default | Description |
|---|---|---|---|
lnbitsUrl | yes* | — | LNBits instance base URL |
lnbitsApiKey | yes* | — | Invoice/read key (NOT admin) |
satsAmount | no | 10 | Sats charged per call |
memo | no | langchain-l402 | Invoice memo |
fetchImpl | no | globalThis.fetch | Injectable fetch |
createInvoiceFn | no | LNBits adapter | Override the invoice minter |
checkPaidFn | no | LNBits adapter | Override the paid-check function |
state | no | new in-memory | Shared payment cache |
* Required unless you inject createInvoiceFn + checkPaidFn directly
(useful for tests or non-LNBits backends).
The wrapper never throws on the payment path — it returns a structured object so a LangChain agent can read the error from the tool output.
error | Meaning |
|---|---|
payment_required | No proof; pay the invoice and retry |
invoice_not_paid | Proof points at an unpaid hash |
payment_provider_unavailable | LNBits invoice mint failed |
payment_verifier_unavailable | LNBits paid-check failed |
This package accepts the LNBits payment_hash as the "proof" rather
than the canonical L402 preimage. Trade-off:
@powforge/mcp-l402-gate.MIT
FAQs
L402 Lightning payment middleware for LangChain.js tools — wrap any async tool function with a pay-per-call Lightning gate backed by LNBits. Works with DynamicTool, StructuredTool, or any plain async function.
The npm package @powforge/langchain-l402-middleware receives a total of 2 weekly downloads. As such, @powforge/langchain-l402-middleware popularity was classified as not popular.
We found that @powforge/langchain-l402-middleware demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.

Research
More than 140 Mastra npm packages were compromised in a supply chain attack that used a typosquatted dependency to deliver a cross-platform infostealer during installation.