npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@delegare/sdk

v0.2.1

Published

Trustless payment delegation for AI agents

Readme

@delegare/sdk

The official TypeScript SDK for Delegare – Trustless payment delegation for AI agents.

Delegare empowers AI agents to spend money on behalf of users across the web without requiring a human-in-the-loop or a wallet popup for every transaction.

This SDK allows developers to:

  1. Merchants: Accept programmatic AP2 Intent Mandates (SD-JWT-VC) as payment from agents.
  2. Agents: Seamlessly satisfy x402 Payment Required paywalls using a pre-authorized budget.

Installation

npm install @delegare/sdk
# or
pnpm add @delegare/sdk
# or
yarn add @delegare/sdk

1. Agent Autonomy: x402 Auto-Payments

When building an AI agent, you often need to fetch data or invoke tools from monetized APIs (e.g., APIs protected by the x402 protocol or Google's Agentic Commerce Protocol).

Instead of halting the agent to prompt the user for payment, the Delegare SDK provides a drop-in replacement for the native fetch function. If the server returns a 402 Payment Required challenge, Delegare automatically signs an EIP-3009 authorization under the hood using the user's spending mandate, and retries the request seamlessly.

import { Delegare } from '@delegare/sdk';

// Initialize the client
const delegare = new Delegare({
  merchantId: 'm_your_agent_platform_id',
  apiKey: process.env.DELEGARE_API_KEY
});

// The user's pre-authorized spending token (SD-JWT-VC)
const intentMandate = "eyJhbGciOiJIUzI1Ni... (truncated)";

// 1. Fetch a resource that might be paywalled
// If the server returns 402, Delegare intercepts it, checks the required price 
// against the user's monthly budget, signs the payment, and fetches the data.
const response = await delegare.fetch(
  'https://api.premium-data-provider.com/weather',
  { method: 'GET' },
  intentMandate // Automatically authorize if x402 paywall is hit
);

const data = await response.json();
console.log(data); // Returns the premium data!

2. Merchants: Accept AP2 Intent Mandates

If you are a merchant, store, or service provider, you can use the SDK to charge an AI agent that visits your platform with a valid spending mandate.

import { Delegare } from '@delegare/sdk';

const delegare = new Delegare({
  merchantId: process.env.DELEGARE_MERCHANT_ID,
  apiKey: process.env.DELEGARE_API_KEY
});

// An AI agent sends you their intentMandate to buy something
app.post('/api/checkout', async (req, res) => {
  const { intentMandate, orderId } = req.body;

  try {
    const receipt = await delegare.charge({
      intentMandate,
      amountCents: 1500, // $15.00
      currency: 'usd',
      description: 'Premium AI API Call',
      idempotencyKey: orderId // Prevents double-charging
    });

    if (receipt.status === 'completed') {
      res.json({ success: true, orderId });
    } else {
      res.status(402).json({ error: 'Payment failed (limit exceeded or declined)' });
    }
  } catch (error) {
    res.status(400).json({ error: error.message });
  }
});

Core API Reference

delegare.fetch(url, init?, intentMandate?)

A wrapper around the native fetch API. If a 402 response is returned with X-PAYMENT requirements, it signs the payment securely and retries the request.

delegare.charge(params)

Execute a payment against a given AP2 intent mandate.

delegare.getBalance(intentMandate)

Query the remaining monthly limit for a specific mandate.

const balance = await delegare.getBalance('mandate_id_here');
console.log(`Remaining monthly budget: $${balance.remainingMonthlyBudgetCents / 100}`);

delegare.createSetupSession(params)

Generates a URL where your human users can safely authorize a spending budget for their agents.

const session = await delegare.createSetupSession({
  maxPerTxCents: 5000,          // $50 max per transaction
  maxMonthlySpendCents: 20000,  // $200 max per month
  rail: 'both'                  // Support fiat (Stripe) and crypto (Base USDC)
});
console.log(`Direct user to: ${session.setupUrl}`);

delegare.waitForSetup(sessionToken)

Polls the setup session until the user completes the flow in their browser, returning the newly minted intentMandate to be given to the agent.

const intentMandate = await delegare.waitForSetup(session.sessionToken);

Environments

By default, the SDK points to the Delegare production API. For testing, supply the sandbox baseUrl during initialization:

const delegare = new Delegare({
  merchantId: 'm_test_...',
  apiKey: 'dk_test_...',
  baseUrl: 'https://api.sandbox.delegare.dev/v1'
});

Links