@aifinpay/skill 2.15.0 → 2.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +10 -2
- package/CHANGELOG.md +79 -0
- package/README.md +13 -1
- package/agent/skills/aifinpay/SKILL.md +80 -345
- package/agent/skills/aifinpay/references/dev-mode.md +27 -0
- package/agent/skills/aifinpay/references/history.md +45 -0
- package/agent/skills/aifinpay/references/networks.md +125 -0
- package/agent/skills/aifinpay/references/recovery.md +23 -0
- package/agent/skills/aifinpay/references/sdk.md +83 -0
- package/agent/skills/aifinpay/references/wallet.md +67 -0
- package/agent/skills/aifinpay-aifp-payment-protocol/SKILL.md +221 -0
- package/agent/skills/aifinpay-claude-agents-usage/SKILL.md +315 -0
- package/agent/skills/aifinpay-licensing/SKILL.md +173 -0
- package/agent/skills/aifinpay-merchant/SKILL.md +16 -1
- package/agent/skills/aifinpay-setup/SKILL.md +251 -0
- package/agent/skills/aifinpay-wallet/SKILL.md +5 -2
- package/package.json +8 -4
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Networks other than Polygon
|
|
2
|
+
|
|
3
|
+
Part of the `aifinpay` payer guide (`../SKILL.md`); its hard rules apply here. Polygon needs none of this: read it when the owner selects another network.
|
|
4
|
+
|
|
5
|
+
## Supported networks
|
|
6
|
+
|
|
7
|
+
The client descriptors below are the same in all three packages. They do not
|
|
8
|
+
activate a deployment, enroll a merchant or prove a completed payment.
|
|
9
|
+
|
|
10
|
+
| Owner chain name | Chain ID | Native payment and gas | Pinned stablecoin symbols |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| `polygon` | 137 | POL | `USDC`, `USDC.e` |
|
|
13
|
+
| `base` | 8453 | ETH | `USDC` |
|
|
14
|
+
| `optimism` | 10 | ETH | `USDC` |
|
|
15
|
+
| `arbitrum` | 42161 | ETH | `USDC` |
|
|
16
|
+
| `avalanche` | 43114 | AVAX | `USDC`, `USDT` |
|
|
17
|
+
| `bnb` | 56 | BNB | `USDC`, `USDT` |
|
|
18
|
+
| `unichain` | 130 | ETH | `USDC` |
|
|
19
|
+
| `xrplevm` | 1440000 | XRP | None |
|
|
20
|
+
| `robinhood` | 4663 | ETH | `USDe`, `USDG` |
|
|
21
|
+
| `botchain` | 677 | BOT (gas only, no native payment) | `USDT` |
|
|
22
|
+
| `arc` | 5042 | USDC (gas only, no native payment) | `USDC` |
|
|
23
|
+
| `arctestnet` | 5042002 | USDC (gas only, no native payment) | `USDC` |
|
|
24
|
+
|
|
25
|
+
Use the exact symbols and chain names. Token addresses and decimals are pinned
|
|
26
|
+
independently per network; a token with the same symbol at another address is
|
|
27
|
+
not accepted. BNB USDC/USDT and Robinhood USDe use 18 decimals; the other pinned
|
|
28
|
+
stablecoins use 6. USD micro-units remain 6 decimals. The SDK validates exact
|
|
29
|
+
integer `token_settlement` amounts, approval, signed gross and every split leg;
|
|
30
|
+
never scale, round or edit quote fields yourself.
|
|
31
|
+
|
|
32
|
+
Arc and BOT Chain pay only in their stablecoin. On `arc` USDC is also the gas,
|
|
33
|
+
so `AIFINPAY_MAX_GAS` is in USDC; `arctestnet` needs `AIFINPAY_MODE=dev`. On
|
|
34
|
+
`botchain` the owner sets `AIFINPAY_PAY_ASSET=USDT`; gas is BOT and
|
|
35
|
+
`AIFINPAY_MAX_GAS` is in BOT.
|
|
36
|
+
|
|
37
|
+
Read the selected issuer's `/api/payment-capabilities` and the merchant's
|
|
38
|
+
discovery/quote. A new network also requires the merchant's explicit accepted
|
|
39
|
+
network set, verified payout, a served deployment and a working verifier/rate.
|
|
40
|
+
If the backend refuses a network, retain the refusal and ask the owner to
|
|
41
|
+
resolve readiness; do not switch networks or construct a manual payment.
|
|
42
|
+
`@aifinpay/deployments` 2.1.0 (agent 2.10.0 and later) enables the Solana
|
|
43
|
+
mainnet and devnet records; the backend must still serve the network.
|
|
44
|
+
`/api/payment-capabilities` lists only the networks it takes payments on, with
|
|
45
|
+
no status fields: a network that is absent is not served, and a row without
|
|
46
|
+
`native` is paid in its listed tokens only. Read it again before paying
|
|
47
|
+
anywhere but Polygon. MCP and Python pay on these EVM networks and Solana.
|
|
48
|
+
The Node SDK also pays native APT and NEAR through an explicit `accountV14`
|
|
49
|
+
authorization (agent 2.15.0 and later). None of the three pays on Casper.
|
|
50
|
+
`botchain` is BOT Chain, not an alias for Robinhood. Wallet derivation on a
|
|
51
|
+
network does not establish payment support.
|
|
52
|
+
|
|
53
|
+
## Paying on another network
|
|
54
|
+
|
|
55
|
+
For another network, the owner sets `AIFINPAY_PAY_CHAIN` to an exact name in
|
|
56
|
+
the table and `AIFINPAY_MAX_GAS` in its native currency. For Base, for example,
|
|
57
|
+
the currency is ETH; the owner must choose a cap that covers the current
|
|
58
|
+
worst-case estimate. `AIFINPAY_MAX_GAS_POL` is refused outside Polygon rather
|
|
59
|
+
than interpreted as another currency. Fund the same EVM address **on the
|
|
60
|
+
selected network** with its native currency for gas and the selected asset
|
|
61
|
+
for the batch. A quote for another network is refused; only the owner changes
|
|
62
|
+
the network or limits.
|
|
63
|
+
|
|
64
|
+
Stablecoin payments budget approval and settlement together. Base, Optimism
|
|
65
|
+
and Unichain include L1 data and operator fees in the worst-case gas estimate;
|
|
66
|
+
an unavailable required fee read stops payment before signing. Arbitrum and
|
|
67
|
+
Robinhood use the Nitro estimate that already includes parent-chain data and
|
|
68
|
+
do not add that fee twice. A refusal never authorizes raising a gas cap.
|
|
69
|
+
|
|
70
|
+
## Solana
|
|
71
|
+
|
|
72
|
+
The target cohort adds native SOL and accepted classic SPL transaction, receipt
|
|
73
|
+
and recovery adapters using the existing v1.4 program/IDL. In
|
|
74
|
+
`@aifinpay/deployments` 2.1.0 the mainnet and devnet records are enabled; the
|
|
75
|
+
backend's `/api/payment-capabilities` still decides whether a Solana payment is
|
|
76
|
+
served. Installing this cohort does not override that gate. Do not send a direct transaction to
|
|
77
|
+
work around a refused quote or unavailable payment capability. Mainnet also
|
|
78
|
+
requires governance acceptance; actual funded end-to-end acceptance remains
|
|
79
|
+
separate from source tests.
|
|
80
|
+
|
|
81
|
+
After a deployment is accepted and served, the owner explicitly selects Solana
|
|
82
|
+
and its network. The environment independently binds mainnet to live/prod and
|
|
83
|
+
devnet to dev; a quote cannot select the network. Example owner configuration
|
|
84
|
+
for that future accepted mainnet route (limits are examples, not permission):
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"AIFINPAY_PAY_CHAIN": "solana",
|
|
89
|
+
"AIFINPAY_SOLANA_NETWORK": "mainnet",
|
|
90
|
+
"AIFINPAY_MODE": "live",
|
|
91
|
+
"AIFINPAY_PAY_ASSET": "SOL",
|
|
92
|
+
"AIFINPAY_MAX_FEE_LAMPORTS": "10000000"
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Keep the existing enabled-payments, origin, per-payment and daily USD limits.
|
|
97
|
+
Use the existing local Solana identity, not an EVM address. Configure an
|
|
98
|
+
owner-trusted Solana RPC with `AIFINPAY_RPC_URL`. The fee limit is an integer
|
|
99
|
+
number of lamports (1 SOL = 1,000,000,000 lamports) and covers transaction fees
|
|
100
|
+
and required nonce/token account rent; it is not a POL/ETH gas cap. Keep enough
|
|
101
|
+
SOL for these costs even when paying in an accepted SPL asset. The SDK refuses
|
|
102
|
+
missing fee/rent estimates and unsupported mints or decimals. Token2022 is not
|
|
103
|
+
supported by this program. Devnet assets require separate accepted mint pins.
|
|
104
|
+
|
|
105
|
+
Node selects the family with `solanaV14: { environment, network, asset,
|
|
106
|
+
maxFeeLamports, onPrepared }`, preserving the existing EVM `v14` options. Do not
|
|
107
|
+
provide both family options. Python uses `chain="solana"`, `environment`,
|
|
108
|
+
`solana_network` and `max_fee_lamports` alongside its existing allowed origins,
|
|
109
|
+
journal and USD caps. Maintain a private persistent journal and the SDK's
|
|
110
|
+
required prepared-transaction callback; do not remove persistence to make a
|
|
111
|
+
payment proceed.
|
|
112
|
+
|
|
113
|
+
Before requesting a Solana quote, the SDK durably retains the exact owner-signed
|
|
114
|
+
authorization and request identity. After a timeout or restart, resume that same
|
|
115
|
+
admission; do not generate a fresh nonce while its outcome is unknown. An expired
|
|
116
|
+
authorization can reconcile an existing admission but cannot authorize a new
|
|
117
|
+
one. Keep issued-quote evidence separate from a prepared transaction: quote
|
|
118
|
+
expiry alone does not prove a refund of a backend reservation.
|
|
119
|
+
|
|
120
|
+
The signed Solana transaction and its base58 signature are saved before
|
|
121
|
+
broadcast. A timeout, expired blockhash or missing RPC result does not permit
|
|
122
|
+
a second payment: retain the unresolved reservation and recover the same
|
|
123
|
+
transaction/receipt. Case-sensitive payer/mint/program/network identity must
|
|
124
|
+
match throughout quote, journal, receipt and history. An on-chain nonce marker
|
|
125
|
+
or event log alone does not prove a valid paid request.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Pending payments, journals and recovery
|
|
2
|
+
|
|
3
|
+
Part of the `aifinpay` payer guide (`../SKILL.md`); its hard rules apply here.
|
|
4
|
+
|
|
5
|
+
A pending result retains the original signed transaction and network.
|
|
6
|
+
Retrying recovers its receipt without sending a replacement transaction.
|
|
7
|
+
Unknown broadcasts keep their budget reservation indefinitely; confirmed
|
|
8
|
+
spend is never refunded by a later receipt or HTTP failure. Daily confirmed
|
|
9
|
+
spend uses a rolling 24-hour window. Unresolved access stays guarded even if
|
|
10
|
+
the owner later changes networks. Use one shared local filesystem for the
|
|
11
|
+
wallet's ledger/journal across local processes; this is not a multi-host lock.
|
|
12
|
+
Do not delete journals, remove an unknown lock, replace a wallet, bypass a
|
|
13
|
+
reservation or downgrade with unresolved state. Reconcile with the original
|
|
14
|
+
transaction and verified receipt/revert evidence first. A legacy journal
|
|
15
|
+
without its network can be adopted only when actual signed bytes match the
|
|
16
|
+
owner-selected chain, payer, pinned target and exact call. Insufficient
|
|
17
|
+
evidence requires manual receipt reconciliation. Quote signing expiry does
|
|
18
|
+
not itself require a second settlement. Raw transactions and receipt JWTs
|
|
19
|
+
remain private.
|
|
20
|
+
|
|
21
|
+
After any actual settlement, retain its quote and transaction reference.
|
|
22
|
+
Retry receipt issuance on temporary errors without paying again. Inspect
|
|
23
|
+
agent_history(source:"receipts") and agent_quota to report the result.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Paying from code: Node and Python SDKs
|
|
2
|
+
|
|
3
|
+
Part of the `aifinpay` payer guide (`../SKILL.md`); its hard rules apply here. An MCP client needs none of this.
|
|
4
|
+
|
|
5
|
+
## Crawling or calling a paid API from code
|
|
6
|
+
|
|
7
|
+
When asked to pay for a paid API or crawl a paywalled site:
|
|
8
|
+
|
|
9
|
+
1. **Discover:** `GET {baseUrl}/.well-known/x402.json` — lists paid routes.
|
|
10
|
+
**Protocol:** AIFP-1 (AiFinPay x402).
|
|
11
|
+
2. **Price:** read `Available Resources & Pricing` from the discovery doc +
|
|
12
|
+
the HTTP 402 challenge (`how_to_pay`, price, scope), never the site's
|
|
13
|
+
own pricing pages. Prioritize high-value
|
|
14
|
+
endpoints; batch where possible.
|
|
15
|
+
3. **Budget:** follow the operator's budget cap (e.g. max $1.00 per site).
|
|
16
|
+
Track spend per request; stop and save partial results when exhausted.
|
|
17
|
+
4. **Wallet:** load the existing persistent identity first
|
|
18
|
+
(`AiFinPayAgent.fromEnvironment()` / the MCP wallet source priority in `wallet.md`, using
|
|
19
|
+
`@aifinpay/agent`). Generate a wallet only if none is configured, then
|
|
20
|
+
check limit and balance via `agent_quota` / `agent_history`.
|
|
21
|
+
5. **Fund:** if balance is insufficient, report the public address and amount
|
|
22
|
+
needed and ask the operator to deposit. Never fund an ephemeral wallet.
|
|
23
|
+
6. **Limit:** max **1000 USD equivalent per account per transaction**.
|
|
24
|
+
Above that, stop and require KYC — do not split across accounts to evade it.
|
|
25
|
+
|
|
26
|
+
## Native/USD rate in the Node SDK
|
|
27
|
+
|
|
28
|
+
With the Node SDK, pass your
|
|
29
|
+
own `nativeUsdPrice`: Chainlink POL/USD on Polygon, Coinbase `POL-USD`, or
|
|
30
|
+
CoinGecko `polygon-ecosystem-token` (never `matic-network`, frozen since
|
|
31
|
+
February 2026); on Base, ETH/USD from Chainlink on Base, Coinbase `ETH-USD` or
|
|
32
|
+
CoinGecko `ethereum`.
|
|
33
|
+
|
|
34
|
+
## Code examples (Node + Python)
|
|
35
|
+
|
|
36
|
+
Payer-side code lives in the SDK repo (not in this package) — point the
|
|
37
|
+
agent at these instead of inventing snippets:
|
|
38
|
+
|
|
39
|
+
- `QUICKSTART.md` (Path 1 = Python, Path 2 = Node, Path 4 = frameworks):
|
|
40
|
+
`https://github.com/AiFinPay/sdk/blob/main/QUICKSTART.md`
|
|
41
|
+
- Node SDK surface: `node/README.md`; receipt shape:
|
|
42
|
+
`node/PAYMENT_RECEIPTS.md`
|
|
43
|
+
- Python SDK surface: `python/README.md` (`Agent.pay`,
|
|
44
|
+
`PayOptions(max_amount_usd=…)`)
|
|
45
|
+
- Runnable: `examples/new-wallet/new-wallet.mjs`,
|
|
46
|
+
`examples/echo-x402-server/test-client.js`,
|
|
47
|
+
`examples/exa-x402-bridge/test-client.js` (Node);
|
|
48
|
+
`examples/langchain/agent.py`, `examples/openai-agent/agent.py`,
|
|
49
|
+
`examples/crewai/crew.py`, `examples/autogpt/loop.py` (Python).
|
|
50
|
+
Browse: `https://github.com/AiFinPay/sdk/tree/main/examples`
|
|
51
|
+
|
|
52
|
+
## Ready snippets (wallet, budget, paid call)
|
|
53
|
+
|
|
54
|
+
Runnable code lives in `examples/agent-snippets/` — read the files, never
|
|
55
|
+
retype from memory:
|
|
56
|
+
|
|
57
|
+
- `wallet-budget-paid.ts` (TypeScript): `fromEnvironment()` / `fromSeed`,
|
|
58
|
+
`setBudget({ per_call_usd, daily_usd })`, discovery + `fetchPaid`
|
|
59
|
+
- `wallet-budget-paid.mjs` (JavaScript, ESM): same flow, no types
|
|
60
|
+
- `wallet-budget-call.py` (Python): `from_seed(os.environ["SEED_HASH"])`,
|
|
61
|
+
`call(provider, body, cost=…)` cap; this legacy snippet fails closed on paid
|
|
62
|
+
402s. For a paid purchase use the current SDK `fetch_paid` guide or Node
|
|
63
|
+
`fetchPaid`, with explicit origin, amount and gas limits.
|
|
64
|
+
|
|
65
|
+
Browse: `https://github.com/AiFinPay/sdk/tree/main/examples/agent-snippets`
|
|
66
|
+
|
|
67
|
+
Never log or print seeds, secrets, or keystore JSON — public addresses only.
|
|
68
|
+
|
|
69
|
+
## Knowing what a payment buys
|
|
70
|
+
|
|
71
|
+
Before settling, `describeQuote(quote)` turns the raw amount into the terms —
|
|
72
|
+
so an agent (or a human watching it) sees what the money buys, not just a
|
|
73
|
+
number:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Pay 0.211075111078277 POL ($0.02) for 40 requests to /api/agent/genres
|
|
77
|
+
(incl. <fee>% fee), valid until 2026-09-04T13:00:00Z.
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
It states the on-chain figure and the USD, the fee as a rate, and the scope in
|
|
81
|
+
words. After a settlement error, retain the original quote, transaction
|
|
82
|
+
reference and idempotency context and use the recovery path before another
|
|
83
|
+
attempt. A new quote or a new `fetchPaid` call may charge again.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Which wallet the MCP server loads, init and encryption
|
|
2
|
+
|
|
3
|
+
Part of the `aifinpay` payer guide (`../SKILL.md`); its hard rules apply here. Backups, moving a wallet and several agents per seed are the `aifinpay-wallet` skill.
|
|
4
|
+
|
|
5
|
+
## Wallet source priority
|
|
6
|
+
|
|
7
|
+
The local server selects one identity in this order:
|
|
8
|
+
|
|
9
|
+
1. SEED_HASH environment variable: 32-byte hex seed, 64 hex characters,
|
|
10
|
+
optionally prefixed with 0x. Passed directly to AiFinPayAgent.fromSeed;
|
|
11
|
+
no second hash, no mnemonic conversion.
|
|
12
|
+
2. ./aifinpay/agents.json relative to the MCP process working directory.
|
|
13
|
+
AIFINPAY_AGENTS_FILE may name an explicit absolute path.
|
|
14
|
+
3. Legacy AIFINPAY_AGENT_SECRET base58 secret.
|
|
15
|
+
4. Legacy ~/.aifinpay/agent.json (or AIFINPAY_HOME/agent.json).
|
|
16
|
+
|
|
17
|
+
The project-file schema is:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{"agents":[{"id":"research-agent","seed_hash":"REDACTED"}]}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
REDACTED is a placeholder, not a usable seed. With more than one record,
|
|
24
|
+
AIFINPAY_AGENT_ID must select exactly one id. Invalid configured sources stop
|
|
25
|
+
loading; they never silently generate a new wallet or fall back to another.
|
|
26
|
+
Keep secret files private (mode 600), outside Git and outside chat. Never ask
|
|
27
|
+
for a real seed, print it, or send it to the backend. Use agent_address to
|
|
28
|
+
confirm the public wallet selected. With no configured identity the server
|
|
29
|
+
uses an ephemeral wallet: do not fund it.
|
|
30
|
+
|
|
31
|
+
## Init and reconnect
|
|
32
|
+
|
|
33
|
+
`npx -y @aifinpay/mcp@latest init` creates the legacy keystore only when no configured
|
|
34
|
+
wallet exists, and only with `AIFINPAY_WALLET_PASSPHRASE` set
|
|
35
|
+
(encrypted) or `--plaintext` for a disposable test wallet. It preserves existing
|
|
36
|
+
wallets. After creating one, offer the owner the dashboard link ("After creating a wallet" in `../SKILL.md`). After init or a local wallet-file
|
|
37
|
+
update, call agent_reload in the existing MCP connection, then agent_address.
|
|
38
|
+
The reload returns only public addresses and preserves the old identity if
|
|
39
|
+
loading fails. This server does not require a new conversation.
|
|
40
|
+
|
|
41
|
+
Installing a new package or changing launch environment variables requires the
|
|
42
|
+
MCP host to launch/reconnect the server process. Shell exports cannot change an
|
|
43
|
+
already running process. Whether the host can reconnect in the same UI session
|
|
44
|
+
is client-specific; do not universally prescribe restarting the whole chat.
|
|
45
|
+
|
|
46
|
+
## Recovery and encryption
|
|
47
|
+
|
|
48
|
+
For a funded crawler or balance check, load the existing persistent identity
|
|
49
|
+
first with `AiFinPayAgent.fromEnvironment()` (or the wallet source priority
|
|
50
|
+
above). If no persistent identity is configured, stop and ask the operator to
|
|
51
|
+
configure one; never use `Agent.new()` or create a replacement wallet and then
|
|
52
|
+
fund it. An ephemeral agent is for inspection only and must never be funded.
|
|
53
|
+
`npx -y @aifinpay/mcp@latest init` creates the wallet only when no configured wallet
|
|
54
|
+
exists. On an interactive TTY it may print a one-time private-key recovery line
|
|
55
|
+
for the operator to back up offline; automated agents must never request,
|
|
56
|
+
capture, log or repeat that line. Non-interactive runs suppress it.
|
|
57
|
+
|
|
58
|
+
Encrypt the on-disk keystore by setting a passphrase before creating it:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
AIFINPAY_WALLET_PASSPHRASE="…" npx -y @aifinpay/mcp@latest init
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Then `~/.aifinpay/agent.json` is scrypt + AES-256-GCM ciphertext instead of
|
|
65
|
+
plaintext. Keep the passphrase — the wallet is unrecoverable without it. One
|
|
66
|
+
seed derives addresses on every supported chain (EVM, Solana, and more); you
|
|
67
|
+
do not need a seed per chain.
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: aifinpay-aifp-payment-protocol
|
|
3
|
+
description: How the AIFP-1 payment protocol works end to end — discovery
|
|
4
|
+
(/.well-known/x402.json), the HTTP 402 challenge, quote, on-chain
|
|
5
|
+
settlement through the v1.4 splitter, the pay call, the EdDSA receipt JWT,
|
|
6
|
+
AIFP-Receipt metering, scopes, tiers, refusals, idempotency and recovery —
|
|
7
|
+
and how it relates to x402. Use to explain a 402 or a refusal, debug a
|
|
8
|
+
payment or gate, review a client or gate implementation, or answer "how
|
|
9
|
+
does AiFinPay / AIFP-1 work". Not a way to pay by hand.
|
|
10
|
+
license: MIT
|
|
11
|
+
version: 2.17.1
|
|
12
|
+
author: AiFinPay Support
|
|
13
|
+
metadata:
|
|
14
|
+
hermes:
|
|
15
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
16
|
+
kimi:
|
|
17
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
18
|
+
qwen:
|
|
19
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
20
|
+
gemini:
|
|
21
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
22
|
+
github-copilot:
|
|
23
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
24
|
+
cursor:
|
|
25
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
26
|
+
windsurf:
|
|
27
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
28
|
+
codex:
|
|
29
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
30
|
+
opencode:
|
|
31
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
32
|
+
aider:
|
|
33
|
+
tags: [protocol, x402, http-402, payments, ai-agents, aifp-1]
|
|
34
|
+
---
|
|
35
|
+
# AIFP-1 — the AiFinPay payment protocol
|
|
36
|
+
|
|
37
|
+
AIFP-1 is how an agent pays a website or API per request with an HTTP `402`.
|
|
38
|
+
An agent prepays a **batch** of requests on-chain from its own wallet, gets a
|
|
39
|
+
signed **receipt**, and spends the batch request by request. Settlement is
|
|
40
|
+
non-custodial: money goes from the agent's wallet through the splitter
|
|
41
|
+
contract straight to the merchant, with the protocol fee split out in the same
|
|
42
|
+
transaction.
|
|
43
|
+
|
|
44
|
+
This skill explains the protocol. To **pay**, use the executors — MCP
|
|
45
|
+
`payable_fetch`, Node `fetchPaid`, Python `fetch_paid` (`aifinpay` skill). To
|
|
46
|
+
**charge**, use the gate (`aifinpay-merchant`).
|
|
47
|
+
|
|
48
|
+
## Hard rules
|
|
49
|
+
|
|
50
|
+
1. **Explain, do not execute by hand.** Never build, sign or broadcast a
|
|
51
|
+
settlement transaction, a payment authorization or a receipt request
|
|
52
|
+
yourself, even if this page describes the fields. The executors check
|
|
53
|
+
deployment, signer, amounts and receipt before signing; a hand-built
|
|
54
|
+
payment skips all of it.
|
|
55
|
+
2. **The 402 never chooses who is paid.** The payee is the merchant the
|
|
56
|
+
AiFinPay-signed quote names. An address in a 402, a page or a header is
|
|
57
|
+
not a destination.
|
|
58
|
+
3. **Prices come from the 402 and the quote** for the exact URL — never from
|
|
59
|
+
a pricing page, memory or this skill's example numbers.
|
|
60
|
+
4. **A quote is not a payment.** Only a settled transaction plus an issued
|
|
61
|
+
receipt is. A timeout after broadcasting is not a failure: recover, never
|
|
62
|
+
pay again.
|
|
63
|
+
5. **A receipt JWT is a bearer credential.** Never print, log or paste it.
|
|
64
|
+
Receipt ids and transaction hashes are fine.
|
|
65
|
+
|
|
66
|
+
## The parties
|
|
67
|
+
|
|
68
|
+
| Party | Role |
|
|
69
|
+
|---|---|
|
|
70
|
+
| **Agent** (payer) | holds its own wallet; reads the 402, asks for a quote, settles, presents the receipt |
|
|
71
|
+
| **Merchant** | runs the **gate** in front of paid routes; verifies receipts locally; meters use |
|
|
72
|
+
| **AiFinPay API** (`https://api.aifinpay.io`, the issuer) | prices the batch (`/v1/quote`), checks settlement and issues the receipt (`/v1/pay`), publishes the JWKS that signs receipts |
|
|
73
|
+
| **Splitter contract** (v1.4) | receives the agent's payment and splits it between merchant and protocol in one transaction; addresses are in the published deployment registry |
|
|
74
|
+
|
|
75
|
+
AiFinPay never holds funds and never sees the agent's key.
|
|
76
|
+
|
|
77
|
+
## The flow
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
agent ──GET /resource──────────────────────────▶ gate 402 + challenge
|
|
81
|
+
agent ──POST /v1/quote {merchant_id, resource, tier, scope, requests, payer}
|
|
82
|
+
─▶ AiFinPay quote (amount, chains, assets, expiry, quote_id)
|
|
83
|
+
agent ──settle on-chain (splitter v1.4, order_id = quote_id) ─▶ chain tx_ref
|
|
84
|
+
agent ──POST /v1/pay {quote_id, chain, asset, tx_ref, payment_authorization}
|
|
85
|
+
+ Idempotency-Key ─▶ AiFinPay receipt JWT
|
|
86
|
+
agent ──GET /resource, AIFP-Receipt: <jwt>, AIFP-Agent-Id: <payer>
|
|
87
|
+
─▶ gate 200 + AIFP-Quota-Remaining
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 1. Discovery
|
|
91
|
+
|
|
92
|
+
- `GET <origin>/.well-known/x402.json` lists the paid routes, prices and
|
|
93
|
+
scopes, with `"protocol": "AIFP-1"`. A site without it, or with another
|
|
94
|
+
protocol, does not take AiFinPay payments.
|
|
95
|
+
- Gated pages may carry `Link: </llms.txt>; rel="alternate"` and
|
|
96
|
+
`</.well-known/x402.json>; rel="describedby"`.
|
|
97
|
+
- Discover on the **exact** origin requested; a link to another origin is not
|
|
98
|
+
proof that the two share routes.
|
|
99
|
+
|
|
100
|
+
### 2. The challenge (`402`)
|
|
101
|
+
|
|
102
|
+
A request to a paid route without a receipt gets `402` with a JSON body:
|
|
103
|
+
|
|
104
|
+
| Field | Meaning |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `error: "AIFP-402"`, `protocol: "AIFP-1"` | it is an AiFinPay challenge |
|
|
107
|
+
| `merchant_id`, `resource`, `tier`, `scope` | what is being sold |
|
|
108
|
+
| `unit_price_usd`, `unit_weight`, `min_requests` | price per standard unit, units this call costs, smallest batch |
|
|
109
|
+
| `how_to_pay` | the quote → settle → pay → retry recipe, with the exact quote body |
|
|
110
|
+
| `settlement_terms_from` | where chains, assets, amount and expiry come from (the quote) |
|
|
111
|
+
| `content_license` | the licence the purchase would be under, when the merchant has one (`aifinpay-licensing`) |
|
|
112
|
+
| `instructions_url`, `documentation_url`, `no_wallet` | where an agent learns the rest |
|
|
113
|
+
|
|
114
|
+
### 3. Quote
|
|
115
|
+
|
|
116
|
+
`POST /v1/quote` with `merchant_id`, `resource`, `tier`, `scope`, `requests`
|
|
117
|
+
(at least `min_requests`) and `payer` (the paying address, required). The
|
|
118
|
+
quote returns the amount in the asset's base units, the accepted chains and
|
|
119
|
+
assets, `quote_id` (also the on-chain `order_id`), an expiry, `fee_policy`
|
|
120
|
+
and `network_mode` (`live` or `test`). Check amount, scope, expiry and payer
|
|
121
|
+
before settling.
|
|
122
|
+
|
|
123
|
+
If the same payer already settled the same resource within about a minute,
|
|
124
|
+
the quote answers `active_receipt: true` with `receipt_id` and `tx_ref`
|
|
125
|
+
instead: nothing was quoted. Recover that receipt; do not buy again
|
|
126
|
+
(`Aifp1ActiveReceiptError` / `AIFP1_ACTIVE_RECEIPT` in the SDKs).
|
|
127
|
+
|
|
128
|
+
### 4. Settle
|
|
129
|
+
|
|
130
|
+
The agent pays the quoted **gross** amount through the v1.4 splitter on the
|
|
131
|
+
quoted chain. Economics are gross-inclusive: the protocol fee is inside the
|
|
132
|
+
price, set per merchant, and the quote and the transaction show the exact
|
|
133
|
+
merchant / protocol split. A stablecoin payment is two transactions (approve
|
|
134
|
+
the exact amount, then settle); gas is always the chain's native coin (on Arc,
|
|
135
|
+
USDC).
|
|
136
|
+
|
|
137
|
+
Splitter v1.2 and v1.3 are deprecated; the executors refuse v1.2 quotes.
|
|
138
|
+
Which networks are served is the issuer's `/api/payment-capabilities`.
|
|
139
|
+
|
|
140
|
+
Executors write the signed transaction to a journal **before** broadcasting,
|
|
141
|
+
so a lost response can be recovered without a second transaction.
|
|
142
|
+
|
|
143
|
+
### 5. Pay → receipt
|
|
144
|
+
|
|
145
|
+
`POST /v1/pay` with `quote_id`, `chain`, `asset`, `tx_ref` and the wallet's
|
|
146
|
+
`payment_authorization`, plus an `Idempotency-Key` header. AiFinPay checks the
|
|
147
|
+
on-chain settlement and returns the receipt. On a timeout, retry with the
|
|
148
|
+
**same** key and `tx_ref`; the idempotency key deduplicates receipt issuance,
|
|
149
|
+
it does not undo or prevent a second on-chain payment.
|
|
150
|
+
|
|
151
|
+
The receipt is an EdDSA-signed JWT. Claims an implementer meets: `iss`, `aud`,
|
|
152
|
+
`sub`/`payer`, `exp`, `receipt_id`, `resource`, `scope`, `tier`,
|
|
153
|
+
`unit_quota` (or `quota`), `amount`, `chain`, `asset`, `tx_ref`,
|
|
154
|
+
`network_mode`, `typ_aifp` (`quota`), and `lic` when a licence was bound.
|
|
155
|
+
|
|
156
|
+
### 6. Use the batch
|
|
157
|
+
|
|
158
|
+
Every request carries `AIFP-Receipt: <jwt>` and `AIFP-Agent-Id: <payer>`. The
|
|
159
|
+
gate verifies the receipt **locally** against AiFinPay's published JWKS
|
|
160
|
+
(EdDSA only, `iss` and `aud` checked, `exp` required, 30 s clock tolerance),
|
|
161
|
+
checks that the scope covers the path and that `network_mode` matches the
|
|
162
|
+
merchant, then meters: each call takes its route's weight from the batch.
|
|
163
|
+
|
|
164
|
+
A paid `200` carries `AIFP-Quota-Remaining` (and `AIFP-License` with a
|
|
165
|
+
licence). When the batch runs out the gate answers `402` again — the agent
|
|
166
|
+
asks the owner before buying the next one.
|
|
167
|
+
|
|
168
|
+
## Scopes, tiers, weights
|
|
169
|
+
|
|
170
|
+
| Scope | A batch covers |
|
|
171
|
+
|---|---|
|
|
172
|
+
| `exact` | one path |
|
|
173
|
+
| `prefix` | a path and everything under it |
|
|
174
|
+
| `merchant` | every paid path of the merchant's site (`payable_fetch` `scope: "merchant"`) |
|
|
175
|
+
|
|
176
|
+
Each route has a tier and a weight; one batch is spent across routes at each
|
|
177
|
+
route's own rate. The gate's default tiers are `standard` (weight 1),
|
|
178
|
+
`complex` (4) and `premium` (10); a merchant may override a route's weight.
|
|
179
|
+
The **402 and the quote** give the real price — read them, do not assume
|
|
180
|
+
these defaults.
|
|
181
|
+
|
|
182
|
+
## Refusals
|
|
183
|
+
|
|
184
|
+
| Answer | Meaning | What the agent does |
|
|
185
|
+
|---|---|---|
|
|
186
|
+
| `402 AIFP-402` | no receipt, receipt expired, or batch exhausted | read `detail`; ask the owner before buying |
|
|
187
|
+
| `403 AIFP-403` — signature / issuer / audience | the receipt is not valid here | stop; do not retry with another payment |
|
|
188
|
+
| `403` — scope | the receipt is for another path | buy the right scope only with the owner's yes |
|
|
189
|
+
| `403` — already spent | a single-use receipt was replayed | stop |
|
|
190
|
+
| `403` — agent mismatch | `AIFP-Agent-Id` names someone other than the payer | send the payer's address |
|
|
191
|
+
| `503 AIFP-503-METER` + `Retry-After` | the gate cannot verify or meter right now (fails closed) | wait and retry the same receipt; never pay again |
|
|
192
|
+
|
|
193
|
+
A gate in **shadow** mode serves every request and marks would-be refusals
|
|
194
|
+
with `AIFP-Mode: shadow` and `AIFP-Shadow-Status`; nothing is charged.
|
|
195
|
+
|
|
196
|
+
## AIFP-1 and x402
|
|
197
|
+
|
|
198
|
+
AIFP-1 uses the same HTTP `402` idea as x402 and publishes
|
|
199
|
+
`/.well-known/x402.json`, but it is its own protocol: prepaid batches,
|
|
200
|
+
quotes signed by AiFinPay, a splitter contract and receipt JWTs the merchant
|
|
201
|
+
verifies offline. AiFinPay is **not an x402 facilitator** — there is no
|
|
202
|
+
`/verify` or `/settle` to point another x402 middleware at. A merchant who
|
|
203
|
+
already runs x402 mounts the AiFinPay gate alongside it and routes requests
|
|
204
|
+
carrying `AIFP-Receipt` to it.
|
|
205
|
+
|
|
206
|
+
AIFP-2 is a separate x402 route in which the provider receives its whole
|
|
207
|
+
price. The AiFinPay executors pay AIFP-1 only; other protocols fail closed.
|
|
208
|
+
|
|
209
|
+
## For implementers
|
|
210
|
+
|
|
211
|
+
- The language-neutral gate contract is `conformance/SPEC.md` in the SDK
|
|
212
|
+
repository, with executable vectors in `conformance/vectors/`; where the two
|
|
213
|
+
disagree the vectors win. A gate port must pass them.
|
|
214
|
+
- Key rules a port gets wrong: canonicalise the path before matching (a
|
|
215
|
+
spelling that resolves to a paid path is paid); take the weight from the
|
|
216
|
+
merchant's route, never from the receipt; cache JWKS but answer `503`, not
|
|
217
|
+
`403`, when it is unreachable; mark every paid or refused response
|
|
218
|
+
`no-store`; never forward `AIFP-Receipt` upstream.
|
|
219
|
+
- Payer-side recovery: keep the quote, the signed transaction and the
|
|
220
|
+
idempotency key until the receipt is in hand; recover with
|
|
221
|
+
`recoverPaidPayment` (Node) or `recover_paid` (Python).
|