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

@sweefi/ap2-adapter

v0.1.1

Published

AP2 (Agent Payments Protocol) adapter for SweeFi — maps AP2 mandates to SweeFi on-chain mandates on Sui

Readme

@sweefi/ap2-adapter

AP2 (Agent Payments Protocol) adapter for SweeFi — maps Google's AP2 mandate types to SweeFi on-chain primitives on Sui.

Apache 2.0 open source. Part of the SweeFi ecosystem.


What this does

AP2 defines what an agent is authorized to buy. SweeFi enforces how it pays on-chain. This adapter bridges the two:

| AP2 Input | SweeFi Output | Mapping Strength | |-----------|---------------|-----------------| | IntentMandate (6 fields) | AgentMandate (9 fields) | Thin — only TTL maps, caller supplies 8 fields | | CartMandate (amount, merchant, expiry) | Invoice (amount, payer, payee) | Strong — structural mapping | | — | PaymentReceipt | Outbound: Sui tx digest → AP2 receipt | | — | PaymentMethodData | Discovery: advertise s402 schemes to AP2 agents |


Install

npm install @sweefi/ap2-adapter

Peer dependencies:

  • @mysten/sui (>=2.0.0) — for Transaction types in the bridge layer

Three layers — use what you need

1. Types only (zero runtime)

import type { AP2IntentMandate, AP2CartMandate, MandateDefaults } from '@sweefi/ap2-adapter';

2. Pure mappers (lightweight — only depends on zod)

import {
  createAgentMandateFromAP2Intent,
  createInvoiceFromAP2Cart,
  toAP2PaymentReceipt,
  toAP2PaymentMethodData,
} from '@sweefi/ap2-adapter';

// IntentMandate → AgentMandate params (caller provides spending limits)
const mandateParams = createAgentMandateFromAP2Intent(ap2Intent, {
  coinType: '0x2::sui::SUI',
  delegator: '0xHUMAN...',
  delegate: '0xAGENT...',
  maxPerTx: '1000000000',     // 1 SUI
  dailyLimit: '5000000000',   // 5 SUI
  weeklyLimit: '20000000000', // 20 SUI
  maxTotal: '100000000000',   // 100 SUI
  level: 2,                   // CAPPED
});

// CartMandate → Invoice params (strong structural mapping)
const invoiceParams = createInvoiceFromAP2Cart(ap2Cart, {
  coinType: '0x2::sui::SUI',
  payer: '0xBUYER...',
  payee: '0xMERCHANT...',
  usdToBaseUnits: 1_000_000n, // 1 USD = 1M base units (USDC-6)
  feeMicroPercent: 10_000,             // 1% facilitator fee
  feeRecipient: '0xFEE...',
});

// Outbound: Sui tx digest → AP2 receipt
const receipt = toAP2PaymentReceipt('ABC123...');

// Discovery: advertise s402 to AP2 agents
const methodData = toAP2PaymentMethodData(); // all 5 schemes

3. Bridge — end-to-end (validate → map → build PTB)

import { buildAgentMandateFromIntent, buildInvoiceFromCart } from '@sweefi/ap2-adapter';
import { testnetConfig } from '@sweefi/sui/ptb';

// Raw AP2 JSON in → unsigned Sui Transaction out
const tx = buildAgentMandateFromIntent(
  rawIntentJson,    // validated at runtime via Zod
  mandateDefaults,  // your spending config
  testnetConfig,    // deployed SweeFi contracts
);

// Sign and execute
const result = await client.signAndExecuteTransaction({ transaction: tx });

Zod schemas (trust boundary validation)

All AP2 data is validated at the trust boundary before mapping:

import {
  intentMandateSchema,
  cartMandateSchema,
  mandateDefaultsSchema,
  invoiceDefaultsSchema,
} from '@sweefi/ap2-adapter';

// Validate raw AP2 JSON
const intent = intentMandateSchema.parse(untrustedJson);

Why the mapping is asymmetric

AP2 IntentMandate is pure authorization intent — "buy headphones under $200." It has zero financial fields. SweeFi AgentMandate is an on-chain enforcement boundary with per-tx caps, daily/weekly limits, and tiered autonomy levels (L0-L3). The adapter is a thin factory where the caller provides 8 of 9 fields.

AP2 CartMandate carries real financial data — amount, currency, merchant, expiry. This maps structurally to a SweeFi Invoice. The adapter converts USD → on-chain base units using the caller's exchange rate.


Ecosystem

| Package | Purpose | |---------|---------| | @sweefi/sui | Sui client + $extend() plugin + contract classes | | @sweefi/server | Chain-agnostic HTTP middleware + fetch wrapper | | @sweefi/mcp | 35 AI payment tools for Claude, Cursor, any MCP client | | s402 | Protocol types + HTTP codec (dual transport: headers + JSON body) |


License

Apache 2.0 — https://github.com/sweeinc/sweefi