@integraledger/profile-facilitator 0.5.0 → 0.5.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/CHANGELOG.md +107 -0
- package/README.md +219 -80
- package/dist/module.d.ts +3 -3
- package/dist/modules/algorand/index.js +1 -1
- package/dist/modules/aptos/index.js +1 -1
- package/dist/modules/cardano/index.js +1 -1
- package/dist/modules/casper/index.js +1 -1
- package/dist/modules/concordium/index.js +1 -1
- package/dist/modules/erc7710/index.js +1 -1
- package/dist/modules/evm/forms.d.ts +4 -4
- package/dist/modules/evm/forms.js +28 -6
- package/dist/modules/evm/index.d.ts +1 -1
- package/dist/modules/evm/index.js +11 -5
- package/dist/modules/hedera/executor.js +1 -1
- package/dist/modules/hedera/index.js +1 -1
- package/dist/modules/lnbtc/index.js +3 -2
- package/dist/modules/near/index.js +1 -1
- package/dist/modules/polkadot/index.js +1 -1
- package/dist/modules/solana/index.js +30 -8
- package/dist/modules/starknet/index.js +9 -2
- package/dist/modules/stellar/index.js +1 -1
- package/dist/modules/sui/index.js +3 -2
- package/dist/modules/ton/index.js +1 -1
- package/dist/modules/tron/index.js +1 -1
- package/dist/modules/xrpl/index.js +1 -1
- package/dist/modules/xrpl/upto.js +1 -1
- package/dist/wrapper.d.ts +4 -4
- package/dist/wrapper.js +4 -4
- package/package.json +4 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Every release of `@integraledger/profile-facilitator`, the settler, with what an operator must act on. The format
|
|
4
|
+
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). The package is 0.x: a minor release may change the
|
|
5
|
+
configuration, the answers or the storage.
|
|
6
|
+
|
|
7
|
+
## [0.5.1] - 2026-11-20
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- The peer dependency is `@integraledger/lcp` `~0.6.3` (0.5.0: `~0.6.0`). Install `@integraledger/lcp@~0.6.3` beside
|
|
12
|
+
it: the `starknet` kind takes an amount of zero on Starknet Sepolia's STRK and USDC, as lcp does from 0.6.3.
|
|
13
|
+
- The README's module table gives each pairing's `confirmed` as `@integraledger/lcp`'s registry now states it: `yes`
|
|
14
|
+
on `x402/exact/cardano/lock`, `x402/exact/eip155/permit2`, `x402/upto/eip155/permit2`,
|
|
15
|
+
`x402/auth-capture/eip155/eip3009`, `x402/auth-capture/eip155/permit2`, `x402/batch-settlement/eip155`,
|
|
16
|
+
`x402/exact/eip155/erc7710`, `x402/exact/eip155/erc7710-salt` and `x402/upto/xrpl`, each shown end to end by a
|
|
17
|
+
recorded run on a test network. No module's behaviour changes.
|
|
18
|
+
- `GET /supported`: each kind's `extra.acceptsZero` is the list of its pairings that take an amount of zero, `[]`
|
|
19
|
+
where none does, where 0.5.0 stated a boolean for the kind. An option of amount zero is refused
|
|
20
|
+
`invalid_payment_requirements` where its pairing is not in the list. `exact` on an `eip155` network names
|
|
21
|
+
`x402/exact/eip155/eip3009`, whose transfer of zero Base Sepolia's USDC takes, and not `x402/exact/eip155/permit2`,
|
|
22
|
+
whose proxy reverts at zero; `sui` names `x402/exact/sui`, a transfer of zero having executed on Sui testnet where the
|
|
23
|
+
buyer pays gas; `starknet` names `x402/exact/starknet` on `starknet:SN_SEPOLIA`, where lcp takes an amount of zero on
|
|
24
|
+
STRK and USDC, each of whose `transfer` of 0 emits a `Transfer` of 0, and states `[]` on `starknet:SN_MAIN`.
|
|
25
|
+
`polkadot` states `[]`. Each module's list and its evidence are in [The modules](./README.md#the-modules).
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- `x402/upto/eip155/permit2`: `/settle` of a charge below the maximum the payment accepted, the requirements x402's
|
|
30
|
+
`upto` resource server sends, was refused `invalid_payload`. Requirements that are the option the payment accepted in
|
|
31
|
+
every member but an `amount` at or below the accepted one are held as that option, and the check `/settle` makes
|
|
32
|
+
before it submits verifies the permit against the accepted maximum, as the class's own settle does
|
|
33
|
+
([The modules](./README.md#the-modules)).
|
|
34
|
+
- `x402/upto/solana`: `/settle` of the deposit and of the claim x402's `upto` resource server sends, each carrying the
|
|
35
|
+
`type` that server adds, was refused `invalid_upto_svm_payload_type` by the check `/settle` makes before it submits,
|
|
36
|
+
the class's `verify` of an opening. A deposit is checked as the buyer sent it, without the `type`, and a claim by the
|
|
37
|
+
class's own settle ([The modules](./README.md#the-modules)).
|
|
38
|
+
|
|
39
|
+
## [0.5.0] - 2026-11-18
|
|
40
|
+
|
|
41
|
+
The settler for the x402 pairings `@integraledger/lcp` 0.6.0 ships, on x402's own facilitator class (`@x402/core`
|
|
42
|
+
2.31.0) with one module per chain form. 0.4.0 served Tron and Polkadot alone.
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- The package moved into this repository, in [`settler/`](https://github.com/IntegraLedger/integra-protocol/tree/main/settler):
|
|
47
|
+
its `repository`, `homepage` and `bugs` name `IntegraLedger/integra-protocol`. 0.4.0 and earlier were published from
|
|
48
|
+
another repository, and this file starts at 0.5.0.
|
|
49
|
+
- The peer dependency is `@integraledger/lcp` `~0.6.0` (0.4.0: `~0.5.0`). Install `@integraledger/lcp@~0.6.0` beside it.
|
|
50
|
+
- `engines.node` is `>=24.22.1` (0.4.0: `>=24`).
|
|
51
|
+
- Storage. The record moves from the table `settlement` to the table `instrument`, beside two new tables, `fee` and
|
|
52
|
+
`module_state`, all three created at start where they do not exist ([Storage](./README.md#storage)). 0.5.0 never
|
|
53
|
+
reads or writes `settlement`, and does not fill `instrument` from it. The role in `store.url` needs `CREATE` on the
|
|
54
|
+
schema and owns the tables ([The database](./README.md#the-database)).
|
|
55
|
+
- The record keys a payment by its instrument: a Tron payment by its transaction id, as before, and a Polkadot payment
|
|
56
|
+
by its signer and the account nonce it signed, no longer by the extrinsic's hash, so a payment signed again at the
|
|
57
|
+
same nonce is the same payment.
|
|
58
|
+
- A repeated `/settle` of a payment the record holds final is answered `invalid_transaction_state` naming the
|
|
59
|
+
transaction the row holds, whatever the first answer was. 0.4.0 answered a stored success so, and returned any other
|
|
60
|
+
stored final answer as first given.
|
|
61
|
+
- `GET /supported`: each kind's `extra` also states `pairings`, `key` and `acceptsZero`, and `feeBudget: true` on a
|
|
62
|
+
network with a fee budget; `signers` is keyed by CAIP family (`"tron:*": []`, `"polkadot:*": []`), where 0.4.0
|
|
63
|
+
answered `{}`.
|
|
64
|
+
- A request body may hold up to 132,096 bytes (0.4.0: 65,536); a larger one is answered `413`.
|
|
65
|
+
|
|
66
|
+
### Added
|
|
67
|
+
|
|
68
|
+
- Sixteen modules, each started by its own member of the configuration: `algorand`, `aptos`, `cardano`, `casper`,
|
|
69
|
+
`concordium`, `erc7710`, `evm`, `hedera`, `lnbtc`, `near`, `solana`, `starknet`, `stellar`, `sui`, `ton` and `xrpl`,
|
|
70
|
+
beside `tron` and `polkadot`. Each module's networks, pairings, key and the registry's `confirmed` value for each
|
|
71
|
+
pairing are in [The modules](./README.md#the-modules). `casper` serves `casper:casper-test` alone and does not start
|
|
72
|
+
on `casper:casper`; `x402/exact/casper` and `x402/exact/ccd` are served with `confirmed` `no`. The `cardano`,
|
|
73
|
+
`concordium` and `ton` modules take an lcp reader the operator writes.
|
|
74
|
+
- `credential`: the bearer credential every call must then present. A deployment with a module whose key is not
|
|
75
|
+
`none` does not start without it; `tron` and `polkadot` hold no key, so a 0.4.0 configuration starts without one. A
|
|
76
|
+
call without it is answered `401` before its body is read.
|
|
77
|
+
- `feeBudgets`, at most one per network, which cap the fees a module's key pays; a spent budget is answered
|
|
78
|
+
`fee_budget_spent`.
|
|
79
|
+
- The export `FeeBudgetConfig`.
|
|
80
|
+
- `extra.acceptsZero`: a kind that states `false`, as Tron's and Polkadot's do, refuses an option of amount zero
|
|
81
|
+
`invalid_payment_requirements`.
|
|
82
|
+
- Start refusals for the new members (a credential's characters, fee budgets, the modules' own members, a keyed module
|
|
83
|
+
without `credential`), each listed with its message in [What stops the start](./README.md#what-stops-the-start).
|
|
84
|
+
|
|
85
|
+
### Unchanged
|
|
86
|
+
|
|
87
|
+
- The configuration members `listen`, `store`, `settleWaitMs`, `operatorLog`, `tron` and `polkadot`, with the same
|
|
88
|
+
shapes, and the server's request timeout of `settleWaitMs` plus 60 seconds.
|
|
89
|
+
|
|
90
|
+
### Upgrading from 0.4.0
|
|
91
|
+
|
|
92
|
+
0.5.0 does not know the payments 0.4.0 answered, and judges a repeated `/settle` of one afresh, by the module's checks
|
|
93
|
+
and lcp's read of the chain ([Upgrading from 0.4.0](./README.md#upgrading-from-040)):
|
|
94
|
+
|
|
95
|
+
- A payment 0.4.0 answered success is never answered success again: Tron's checks refuse a transaction id the node
|
|
96
|
+
holds in its blocks or pending pool, and an expiration passed; Polkadot's node no longer answers the extrinsic valid
|
|
97
|
+
once its nonce is used. The answer is `invalid_transaction_state` naming the transaction where lcp's read shows the
|
|
98
|
+
payment final, and otherwise the check's refusal.
|
|
99
|
+
- A payment 0.4.0 answered `settlement_pending` is answered the same way once its transaction is in a block, so 0.5.0
|
|
100
|
+
never answers it success, though it landed; a Polkadot extrinsic still in the node's pool when the repeat arrives is
|
|
101
|
+
claimed and answered success once final.
|
|
102
|
+
- Neither rail lets one signed payment land twice. Finish 0.4.0's pending payments on 0.4.0 before switching, or read
|
|
103
|
+
them with lcp's `status`, and do not run both versions at once for the same payments: each keeps its own record, and
|
|
104
|
+
each can answer one payment success.
|
|
105
|
+
|
|
106
|
+
[0.5.1]: https://github.com/IntegraLedger/integra-protocol/tree/settler-v0.5.1/settler
|
|
107
|
+
[0.5.0]: https://github.com/IntegraLedger/integra-protocol/tree/settler-v0.5.0/settler
|
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# @integraledger/profile-facilitator
|
|
2
2
|
|
|
3
|
-
The settler: an x402 facilitator
|
|
4
|
-
[`@integraledger/lcp`](https://www.npmjs.com/package/@integraledger/lcp) ships. A resource server
|
|
5
|
-
facilitator API, one HTTP surface: `GET /supported`, `POST /verify` and `POST /settle`. It checks
|
|
6
|
-
its pairing's profile and the requirements it answers, submits what the payer signed, records each
|
|
7
|
-
Postgres, and answers what the chain shows.
|
|
3
|
+
The settler: an x402 facilitator that holds each payment to its pairing's LCP profile (hence the package name), for
|
|
4
|
+
the x402 pairings that [`@integraledger/lcp`](https://www.npmjs.com/package/@integraledger/lcp) ships. A resource server
|
|
5
|
+
calls it over x402's facilitator API, one HTTP surface: `GET /supported`, `POST /verify` and `POST /settle`. It checks
|
|
6
|
+
each payment against its pairing's profile and the requirements it answers, submits what the payer signed, records each
|
|
7
|
+
payment once in Postgres, and answers what the chain shows.
|
|
8
|
+
|
|
9
|
+
This page is for the operator who runs it: at the end you can install it, configure each module with its keys, nodes
|
|
10
|
+
and database, put it behind TLS, and read every answer it gives.
|
|
8
11
|
|
|
9
12
|
## What it is
|
|
10
13
|
|
|
@@ -57,13 +60,14 @@ or legal logic beyond that.
|
|
|
57
60
|
## Install
|
|
58
61
|
|
|
59
62
|
```sh
|
|
60
|
-
npm install @integraledger/profile-facilitator @integraledger/lcp
|
|
63
|
+
npm install @integraledger/profile-facilitator @integraledger/lcp@~0.6.3
|
|
61
64
|
```
|
|
62
65
|
|
|
63
|
-
It needs Node.js `>=24.22.1`, Postgres
|
|
64
|
-
reads. It is ESM only. `@integraledger/lcp` is its peer dependency
|
|
65
|
-
key takes it as the signer object of x402's class for that
|
|
66
|
-
release the settler's classes are pinned to
|
|
66
|
+
It needs Node.js `>=24.22.1`, Postgres 11 or later ([The database](#the-database)), and, for each network it serves,
|
|
67
|
+
the node its module reads. It is ESM only. `@integraledger/lcp` is its peer dependency, at `~0.6.3`: install it with
|
|
68
|
+
the settler ([Versions](#versions)). A module that holds a key takes it as the signer object of x402's class for that
|
|
69
|
+
chain; make it with that chain's x402 package at 2.31.0, the release the settler's classes are pinned to
|
|
70
|
+
(`@x402/evm`, `@x402/svm`, `@x402/avm`, and so on).
|
|
67
71
|
|
|
68
72
|
Two packages in its dependency tree have install scripts that it runs without: `protobufjs` (through `@hiero-ledger/sdk`
|
|
69
73
|
and `@concordium/web-sdk`) and `secp256k1` (through `@x402/near`). This repository installs with both denied, and runs
|
|
@@ -138,7 +142,7 @@ await settler.close();
|
|
|
138
142
|
"extra": {
|
|
139
143
|
"assetTransferMethod": "lcp-assets-remark",
|
|
140
144
|
"key": "none",
|
|
141
|
-
"acceptsZero":
|
|
145
|
+
"acceptsZero": [],
|
|
142
146
|
"pairings": [
|
|
143
147
|
"x402/exact/polkadot/lcp-assets-remark"
|
|
144
148
|
]
|
|
@@ -151,7 +155,7 @@ await settler.close();
|
|
|
151
155
|
"extra": {
|
|
152
156
|
"assetTransferMethod": "lcp-trc20-memo",
|
|
153
157
|
"key": "none",
|
|
154
|
-
"acceptsZero":
|
|
158
|
+
"acceptsZero": [],
|
|
155
159
|
"pairings": [
|
|
156
160
|
"x402/exact/tron/lcp-trc20-memo"
|
|
157
161
|
]
|
|
@@ -168,10 +172,11 @@ await settler.close();
|
|
|
168
172
|
|
|
169
173
|
## Run it as a service
|
|
170
174
|
|
|
171
|
-
The package exports one function that starts the server; it has no command-line entry.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
The package exports one function that starts the server; it has no command-line entry. It reads no environment variable
|
|
176
|
+
and no file: every setting is a member of the configuration, and the variable names in these samples are the samples'
|
|
177
|
+
own. A service is a short module that reads its configuration, makes the signer objects its keyed modules take, and
|
|
178
|
+
stops cleanly on a signal. This one serves x402's `exact` scheme on Base Sepolia through the `evm` module, whose key,
|
|
179
|
+
the seller's gas key, sends each transaction and pays its gas:
|
|
175
180
|
|
|
176
181
|
```ts no-check title="settler.ts"
|
|
177
182
|
import { serveProfileFacilitator } from "@integraledger/profile-facilitator";
|
|
@@ -188,16 +193,20 @@ if (credential === undefined || gasKey === undefined) throw new Error("set SETTL
|
|
|
188
193
|
// The seller's gas key, as x402's EVM classes take it.
|
|
189
194
|
const account = privateKeyToAccount(gasKey);
|
|
190
195
|
const client = createWalletClient({ account, chain: baseSepolia, transport: http(rpc) }).extend(publicActions);
|
|
191
|
-
const signer = toFacilitatorEvmSigner(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
196
|
+
const signer = toFacilitatorEvmSigner(
|
|
197
|
+
{
|
|
198
|
+
address: account.address,
|
|
199
|
+
getCode: (a) => client.getCode(a),
|
|
200
|
+
readContract: (a) => client.readContract({ ...a, args: a.args ?? [] } as never),
|
|
201
|
+
verifyTypedData: (a) => client.verifyTypedData(a as never),
|
|
202
|
+
writeContract: (a) => client.writeContract({ ...a, args: a.args ?? [] } as never),
|
|
203
|
+
sendTransaction: (a) => client.sendTransaction(a as never),
|
|
204
|
+
waitForTransactionReceipt: (a) => client.waitForTransactionReceipt(a) as never,
|
|
205
|
+
simulateCalls: (a) => client.simulateCalls(a as never) as never,
|
|
206
|
+
},
|
|
207
|
+
// Below settleWaitMs, so /settle answers settlement_pending instead of waiting up to x402's default 180 s.
|
|
208
|
+
{ confirmationTimeoutMs: 25_000 },
|
|
209
|
+
);
|
|
201
210
|
|
|
202
211
|
const listen = process.env.LISTEN ?? "127.0.0.1:4021";
|
|
203
212
|
const settler = await serveProfileFacilitator({
|
|
@@ -233,7 +242,7 @@ Run it with `node settler.ts`: Node.js 26 runs TypeScript directly. Every call m
|
|
|
233
242
|
"network": "eip155:84532",
|
|
234
243
|
"extra": {
|
|
235
244
|
"key": "relayer",
|
|
236
|
-
"acceptsZero":
|
|
245
|
+
"acceptsZero": ["x402/exact/eip155/eip3009"],
|
|
237
246
|
"pairings": ["x402/exact/eip155/eip3009", "x402/exact/eip155/permit2"],
|
|
238
247
|
"feeBudget": true
|
|
239
248
|
}
|
|
@@ -246,7 +255,8 @@ Run it with `node settler.ts`: Node.js 26 runs TypeScript directly. Every call m
|
|
|
246
255
|
|
|
247
256
|
`close()` stops accepting requests, closes open connections, closes what each module opened (the Polkadot nodes'
|
|
248
257
|
connections among them), stops the sweep and closes the Postgres pool. If the settler cannot start, it closes what it
|
|
249
|
-
opened and rejects with the error that stopped it, such as the listen's `EADDRINUSE` or a configuration it refuses
|
|
258
|
+
opened and rejects with the error that stopped it, such as the listen's `EADDRINUSE` or a configuration it refuses
|
|
259
|
+
([What stops the start](#what-stops-the-start)).
|
|
250
260
|
|
|
251
261
|
## Configuration
|
|
252
262
|
|
|
@@ -258,38 +268,58 @@ the deployment starts, named for the module. A module whose member is absent is
|
|
|
258
268
|
| Member | Type | Meaning |
|
|
259
269
|
|---|---|---|
|
|
260
270
|
| `listen` | `string` | `"host:port"`; an IPv6 host may be written in brackets. |
|
|
261
|
-
| `store` | `{ url: string }` | The Postgres connection string. Postgres holds the record, the fee count and the modules' durable state; the settler creates its tables at start where they do not exist. |
|
|
271
|
+
| `store` | `{ url: string }` | The Postgres connection string. Postgres holds the record, the fee count and the modules' durable state; the settler creates its tables at start where they do not exist ([The database](#the-database)). |
|
|
262
272
|
| `settleWaitMs` | `number` | How long `/settle` waits for the chain before it answers `settlement_pending`. A value that is not a positive finite number means 30 000. |
|
|
263
273
|
| `credential` | `string`, optional | The credential every call must present as `Authorization: Bearer <credential>`; required where a configured module holds a key ([The credential](#the-credential)). Its characters are those RFC 6750 admits in a bearer token: letters, digits and `-._~+/`, then any `=`. |
|
|
264
274
|
| `feeBudgets` | `{ network, amount, periodSeconds }[]`, optional | At most one per network, each on a network a configured module serves ([The fee budget](#the-fee-budget)). `amount` is in the smallest unit of the network's fee asset, a `bigint` or its decimal digits, and positive; `periodSeconds` is a positive whole number. |
|
|
265
275
|
| `operatorLog` | `(entry, cause?) => void`, optional | Receives every entry for the operator ([Bounds and logs](#bounds-and-logs)). The default writes one JSON line per entry on standard error. |
|
|
266
276
|
|
|
277
|
+
### The database
|
|
278
|
+
|
|
279
|
+
The settler needs Postgres 11 or later: nothing it runs is newer than `hashtextextended`, which Postgres 11 added. Its
|
|
280
|
+
tests run on Postgres 18. At every start it runs `CREATE TABLE IF NOT EXISTS` and `CREATE INDEX IF NOT EXISTS` for its
|
|
281
|
+
three tables and two indexes ([Storage](#storage)), so the role in `store.url` needs `CREATE` on the schema they live
|
|
282
|
+
in and owns them. From Postgres 15, the schema `public` grants `CREATE` to no role but its owner by default: grant it,
|
|
283
|
+
or create a schema named for the role and owned by it, which Postgres's default `search_path` (`"$user", public`) puts
|
|
284
|
+
first. The role then reads and writes only those tables, and takes transaction-level advisory locks. Each process holds
|
|
285
|
+
at most 10 connections.
|
|
286
|
+
|
|
287
|
+
Every settler process that may settle the same payments uses the same database: the record is what keeps one payment
|
|
288
|
+
submitted once and answered success once. Do not truncate or replace its tables while payments they hold can still
|
|
289
|
+
land, and back them up as you back up payment records.
|
|
290
|
+
|
|
267
291
|
### The modules
|
|
268
292
|
|
|
269
293
|
Each module's member lists the networks it serves. Its keys reach it inside that member, as the signer objects its
|
|
270
|
-
classes take; the settler reads no key material of its own.
|
|
271
|
-
names
|
|
272
|
-
|
|
273
|
-
| Member | Chain | Scheme: pairings | `extra.key` | `extra.acceptsZero` | Facilitator |
|
|
274
|
-
|
|
275
|
-
| `algorand` | Algorand | `exact`: `x402/exact/algorand` | `fee-payer` | `
|
|
276
|
-
| `aptos` | Aptos | `exact`: `x402/exact/aptos` | `fee-payer`, or `none` with `sponsor: false` | `
|
|
277
|
-
| `cardano` | Cardano | `exact`: `x402/exact/cardano
|
|
278
|
-
| `casper` | Casper | `exact`: `x402/exact/casper` | `relayer` | `
|
|
279
|
-
| `concordium` | Concordium | `exact`: `x402/exact/ccd` | `fee-payer` | `
|
|
280
|
-
| `evm` | EVM | `exact`: `x402/exact/eip155/eip3009
|
|
281
|
-
| `erc7710` | EVM | `exact` with `erc7710`: `x402/exact/eip155/erc7710
|
|
282
|
-
| `hedera` | Hedera | `exact`: `x402/exact/hedera` | `fee-payer` | `
|
|
283
|
-
| `lnbtc` | Lightning | `exact`: `x402/exact/lnbtc/payment-hash` | `none` | `
|
|
284
|
-
| `near` | NEAR | `exact`: `x402/exact/near` | `relayer` | `
|
|
285
|
-
| `polkadot` | Polkadot Asset Hub | `exact`: `x402/exact/polkadot/lcp-assets-remark` | `none` | `
|
|
286
|
-
| `solana` | Solana | `exact`: `x402/exact/solana
|
|
287
|
-
| `starknet` | Starknet | `exact`: `x402/exact/starknet` | `relayer` | `
|
|
288
|
-
| `stellar` | Stellar | `exact` with `lcp-precondition`: `x402/exact/stellar/precondition` | `relayer` | `
|
|
289
|
-
| `sui` | Sui | `exact`: `x402/exact/sui` | `none` | `
|
|
290
|
-
| `ton` | TON | `exact`: `x402/exact/tvm` | `relayer` | `
|
|
291
|
-
| `tron` | Tron | `exact`: `x402/exact/tron/lcp-trc20-memo` | `none` | `
|
|
292
|
-
| `xrpl` | XRP Ledger | `exact`: `x402/exact/xrpl
|
|
294
|
+
classes take; the settler reads no key material of its own. A network is the CAIP-2 id lcp's type for the chain
|
|
295
|
+
names, and the table gives the ones each module takes.
|
|
296
|
+
|
|
297
|
+
| Member | Chain | Networks | Scheme: pairings (`confirmed`) | `extra.key` | `extra.acceptsZero` | Facilitator |
|
|
298
|
+
|---|---|---|---|---|---|---|
|
|
299
|
+
| `algorand` | Algorand | `algorand:<genesis hash prefix>` | `exact`: `x402/exact/algorand` (yes) | `fee-payer` | `x402/exact/algorand` | `@x402/avm`'s class; the settler's own path for a rekeyed payer signing with one key and a Falcon-key payer |
|
|
300
|
+
| `aptos` | Aptos | `aptos:<chain id>` | `exact`: `x402/exact/aptos` (yes) | `fee-payer`, or `none` with `sponsor: false` | `[]` | `@x402/aptos`'s class |
|
|
301
|
+
| `cardano` | Cardano | `cardano:mainnet`, `cardano:preprod`, `cardano:preview` | `exact`: `x402/exact/cardano` (yes), `x402/exact/cardano/lock` (yes) | `none` | `[]` | `@x402/cardano`'s class |
|
|
302
|
+
| `casper` | Casper | `casper:casper-test` | `exact`: `x402/exact/casper` (no) | `relayer` | `[]` | `@x402/casper`'s class |
|
|
303
|
+
| `concordium` | Concordium | `ccd:<genesis hash prefix>` | `exact`: `x402/exact/ccd` (no) | `fee-payer` | `x402/exact/ccd` | `@x402/concordium`'s class |
|
|
304
|
+
| `evm` | EVM | `eip155:<chain id>` | `exact`: `x402/exact/eip155/eip3009` (yes), `x402/exact/eip155/permit2` (yes); `upto`: `x402/upto/eip155/permit2` (yes); `auth-capture`: `x402/auth-capture/eip155/eip3009` (yes), `x402/auth-capture/eip155/permit2` (yes); `batch-settlement`: `x402/batch-settlement/eip155` (yes) | `relayer` | `x402/exact/eip155/eip3009` on `exact`; `[]` on the others | `@x402/evm`'s classes |
|
|
305
|
+
| `erc7710` | EVM | `eip155:<chain id>`, where `evm` registers `exact` | `exact` with `erc7710`: `x402/exact/eip155/erc7710` (yes), `x402/exact/eip155/erc7710-salt` (yes) | `relayer` | `[]` | the settler's own, behind the `evm` module's `exact` |
|
|
306
|
+
| `hedera` | Hedera | `hedera:mainnet`, `hedera:testnet`, `hedera:previewnet`, `hedera:devnet` | `exact`: `x402/exact/hedera` (yes) | `fee-payer` | `[]` | `@x402/hedera`'s class |
|
|
307
|
+
| `lnbtc` | Lightning | `lnbtc:000000000019d6689c085ae165831e93`, `lnbtc:000000000933ea01ad0ee984209779ba` | `exact`: `x402/exact/lnbtc/payment-hash` (yes) | `none` | `[]` | the settler's own |
|
|
308
|
+
| `near` | NEAR | `near:mainnet`, `near:testnet` | `exact`: `x402/exact/near` (yes) | `relayer` | `[]` | `@x402/near`'s class |
|
|
309
|
+
| `polkadot` | Polkadot Asset Hub | `polkadot:68d56f15f85d3136970ec16946040bc1`, `polkadot:67f9723393ef76214df0118c34bbbd3d` | `exact`: `x402/exact/polkadot/lcp-assets-remark` (yes) | `none` | `[]` | the settler's own |
|
|
310
|
+
| `solana` | Solana | `solana:<genesis hash prefix>`; `upto` and `batch-settlement` not on `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` | `exact`: `x402/exact/solana` (yes); `upto`: `x402/upto/solana` (no); `batch-settlement`: `x402/batch-settlement/solana` (no) | `fee-payer` | `x402/exact/solana` on `exact`; `[]` on the others | `@x402/svm`'s classes |
|
|
311
|
+
| `starknet` | Starknet | `starknet:SN_MAIN`, `starknet:SN_SEPOLIA` | `exact`: `x402/exact/starknet` (yes) | `relayer` | `x402/exact/starknet` on `starknet:SN_SEPOLIA`; `[]` on `starknet:SN_MAIN` | the settler's own |
|
|
312
|
+
| `stellar` | Stellar | `stellar:pubnet`, `stellar:testnet` | `exact` with `lcp-precondition`: `x402/exact/stellar/precondition` (yes) | `relayer` | `x402/exact/stellar/precondition` | the settler's own |
|
|
313
|
+
| `sui` | Sui | `sui:mainnet`, `sui:testnet`, `sui:devnet` | `exact`: `x402/exact/sui` (yes) | `none` | `x402/exact/sui` | the settler's own |
|
|
314
|
+
| `ton` | TON | `tvm:-239`, `tvm:-3` | `exact`: `x402/exact/tvm` (yes) | `relayer` | `x402/exact/tvm` | `@x402/tvm`'s class |
|
|
315
|
+
| `tron` | Tron | `tron:<chain id in decimal>` | `exact`: `x402/exact/tron/lcp-trc20-memo` (yes) | `none` | `[]` | the settler's own |
|
|
316
|
+
| `xrpl` | XRP Ledger | `xrpl:<NetworkID>` | `exact`: `x402/exact/xrpl` (yes); `upto`: `x402/upto/xrpl` (yes) | `none` | `[]` | `@x402/xrpl`'s class for a payer signing with one key; the settler's own for a multisigned payer and for `upto` |
|
|
317
|
+
|
|
318
|
+
`confirmed` is lcp's registry's: whether something outside lcp has shown the form as its profile defines it
|
|
319
|
+
([the pairing registry](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/reference/pairings.md)). The
|
|
320
|
+
settler serves the forms marked `no` as their profiles define them, but no recorded run outside lcp has yet shown one.
|
|
321
|
+
The `casper` and `concordium` modules serve only such forms: run them on a test network, and do not offer those forms
|
|
322
|
+
to buyers until the registry says `yes`.
|
|
293
323
|
|
|
294
324
|
Each member, one entry per network unless it says otherwise:
|
|
295
325
|
|
|
@@ -309,11 +339,11 @@ Each member, one entry per network unless it says otherwise:
|
|
|
309
339
|
names one of the key's addresses.
|
|
310
340
|
- **`cardano`**: `network`; `signer`, the chain-query object `@x402/cardano`'s class takes over the seller's provider (a
|
|
311
341
|
provider's project id is its configuration, not a key); `reader`, lcp's `CardanoReader` over the seller's indexer. The
|
|
312
|
-
class broadcasts the transaction the buyer signed, whose fee the buyer pays.
|
|
313
|
-
alone: over Koios alone it sees none, so an option it settles there
|
|
314
|
-
`{ "l1Confirmations": 0 }`, and an option that states none, whose default asks
|
|
315
|
-
|
|
316
|
-
|
|
342
|
+
class broadcasts the transaction the buyer signed, whose fee the buyer pays. `@x402/cardano` 2.31.0 reads a
|
|
343
|
+
transaction's confirmations from Blockfrost alone: over Koios alone it sees none, so an option it settles there
|
|
344
|
+
states `extra.confirmationPolicy` as `{ "l1Confirmations": 0 }`, and an option that states none, whose default asks
|
|
345
|
+
one confirmation, is refused at `/verify`. A provider with a Blockfrost project serves an option that asks
|
|
346
|
+
confirmations. `/settle` answers success where the class does, and
|
|
317
347
|
otherwise once lcp's read through `reader` shows the transaction final, at the ledger's security parameter of
|
|
318
348
|
confirmations (2160 on mainnet and Preprod, some 12 hours); until then it answers `settlement_pending` naming the
|
|
319
349
|
transaction. Over Koios alone the class's settle gives no success, so a payment is answered at that mark. Its guard
|
|
@@ -346,7 +376,15 @@ Each member, one entry per network unless it says otherwise:
|
|
|
346
376
|
wallet (none where absent); `authCapture`, optional, `auth-capture`'s own configuration, passed to its class
|
|
347
377
|
unchanged. Before the class is asked, `exact` refuses an option that pays several payees (a non-empty
|
|
348
378
|
`extra.splits`) and Circle's batched option (`extra.name` `GatewayWalletBatched`, or an `extra.verifyingContract`
|
|
349
|
-
other than the asset), which no published EVM class settles.
|
|
379
|
+
other than the asset), which no published EVM class settles. At `/settle`, `upto` settles the amount its requirements
|
|
380
|
+
state, the charge: requirements that are the option the payment accepted in every member but an `amount` at or below
|
|
381
|
+
the accepted one are held as that option, and the class checks the permit against the accepted maximum, as its own
|
|
382
|
+
settle does; any other requirements are refused `invalid_payload`. `exact`'s `extra.acceptsZero` names
|
|
383
|
+
`x402/exact/eip155/eip3009` alone, and every other kind's is `[]`. On Base Sepolia, USDC's EIP-3009
|
|
384
|
+
`transferWithAuthorization` of 0 succeeds, emitting `AuthorizationUsed` and a `Transfer` of 0 (`eth_simulateV1` at
|
|
385
|
+
block 61198157); at block 61194449, x402's `exact` and `upto` Permit2 proxies revert `InvalidAmount` and the
|
|
386
|
+
commerce-payments escrow's `authorize` reverts `ZeroAmount`; batch settlement's facilitator requires a deposit above
|
|
387
|
+
0.
|
|
350
388
|
- **`erc7710`**: `network`; `rpc`; `signer`, the seller's gas key, whose node must answer `eth_simulateV1`. The key
|
|
351
389
|
sends from its first address, so that address is the delegate the leaf delegation must name (or the reference
|
|
352
390
|
implementation's wildcard delegate), and the account the simulation runs from. It registers nothing of its own: on
|
|
@@ -375,21 +413,31 @@ Each member, one entry per network unless it says otherwise:
|
|
|
375
413
|
pruning node discards the state of older blocks, and a block that holds the extrinsic and whose state is discarded
|
|
376
414
|
keeps the answer `settlement_pending`. The runtime metadata is loaded on the first payment for the network, and again
|
|
377
415
|
whenever the node's runtime version changes. A success names `<block hash>-<extrinsic index>`; a pending answer
|
|
378
|
-
names the extrinsic's hash.
|
|
416
|
+
names the extrinsic's hash. The kind's `extra.acceptsZero` is `[]`: lcp's option filter takes a positive amount only
|
|
417
|
+
(its profile's rule 1), and a `transfer_keep_alive` of 0, dry-run on Westend Asset Hub at block 19635446, dispatches
|
|
418
|
+
and emits no event.
|
|
379
419
|
- **`solana`**: `network`; `node`, the seller's JSON-RPC endpoint, one whose `getFirstAvailableBlock` is at or below the
|
|
380
420
|
slot at which each payment was issued; `signer`, the seller's fee payer (`FacilitatorSvmSigner`), which co-signs every
|
|
381
421
|
transaction the payer signed and, on the channel forms, pays the channel's rent; `transactionVersions`, optional, the
|
|
382
422
|
message versions the classes accept (their default `[0, 1]`). `upto` and `batch-settlement` need the payment-channels
|
|
383
423
|
program, which is deployed on devnet and testnet and not on mainnet: on Solana mainnet
|
|
384
424
|
(`solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`) only `exact` is registered. Their channels are kept in the settler's
|
|
385
|
-
database.
|
|
425
|
+
database. `upto` is settled in the order x402's `upto` resource server sends it: `/verify` of the opening as the buyer
|
|
426
|
+
sent it, then `/settle` of its deposit before the resource server's handler runs and of its claim after, each
|
|
427
|
+
carrying the `type` (`deposit`, `claim`) that server adds. A claim needs the voucher of the option's
|
|
428
|
+
`extra.receiverAuthorizer`, which the module does not sign: the resource server signs it with its own key.
|
|
386
429
|
- **`starknet`**: an object `{ networks }`, one entry per network: `network`; `rpc`, a JSON-RPC node (specification 0.9
|
|
387
430
|
or later) that serves `starknet_traceTransaction` and `starknet_simulateTransactions`; `executor`, an `address` and
|
|
388
431
|
its `signer`, the account the payer's outside execution names as its caller, stated as `extra.feePayer`, which
|
|
389
432
|
sends and pays for the transaction that executes it; `maxFee`, optional, the most one settlement's resource bounds
|
|
390
433
|
may pay, in fri; `skewMarginSeconds` (default 60) and `minSettleMarginSeconds` (default 30), optional, the scheme's
|
|
391
434
|
margins. x402 specifies Starknet and publishes no code for it, so the module is written to x402's scheme text and
|
|
392
|
-
lcp's profile.
|
|
435
|
+
lcp's profile. On `starknet:SN_SEPOLIA` the kind's `extra.acceptsZero` names `x402/exact/starknet`, and an option of
|
|
436
|
+
amount `"0"` is taken on STRK (`0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d`) and USDC
|
|
437
|
+
(`0x53b40a647cedfca6ca84f542a0fe36736031905a9639a7f19a3c1e66bfd5080`), the tokens on which lcp's `starknetFloor`
|
|
438
|
+
answers 0 (its profile's rule 24): a `transfer` of 0 of each, simulated on Starknet Sepolia at block 18422698, emits a
|
|
439
|
+
`Transfer` of 0. lcp refuses `"0"` on any other token, `starknet/option-malformed`, which the module answers
|
|
440
|
+
`invalid_payment_requirements`. On `starknet:SN_MAIN` the list is `[]`.
|
|
393
441
|
- **`stellar`**: an object `{ networks }`: `network`; `rpc`, a Stellar RPC endpoint that holds the history the read
|
|
394
442
|
searches; `source`, the seller's funded account as a signer (`address` and `signTransaction`, such as x402's
|
|
395
443
|
`createEd25519Signer` of `@x402/stellar` or a SEP-43 wallet), the transaction's source, which pays its fee;
|
|
@@ -400,7 +448,10 @@ Each member, one entry per network unless it says otherwise:
|
|
|
400
448
|
- **`sui`**: an object `{ networks }`: `network` (`sui:mainnet`, `sui:testnet` or `sui:devnet`); `graphql`, the seller's
|
|
401
449
|
GraphQL endpoint. It serves the path where the buyer pays gas and the gasless path (`extra.gasless`), and holds no
|
|
402
450
|
key. A transaction the buyer already executed is judged at `/verify` by its effects, and not refused for having
|
|
403
|
-
executed; its `/settle` answers a failure naming it.
|
|
451
|
+
executed; its `/settle` answers a failure naming it. The kind's `extra.acceptsZero` names `x402/exact/sui`: a
|
|
452
|
+
transfer of 0 executes where the buyer pays gas (Sui testnet transaction
|
|
453
|
+
`7EjfN1kqGng3phZjqgCzy8RRRXCP2Ybt7mikGgjBUwKA`, status `SUCCESS`, its only balance change the sender's gas), and at
|
|
454
|
+
0 the signed transfer must name the option's payee. lcp's option filter refuses 0 on the gasless path.
|
|
404
455
|
- **`ton`**: `network`; `signer`, the seller's highload-v3 wallet and its node (`FacilitatorTvmSigner`), which relays
|
|
405
456
|
the payer's W5 request in a message of its own and pays its gas; `reader`, lcp's `TvmReader` over the seller's TON
|
|
406
457
|
Center v3 index.
|
|
@@ -415,6 +466,45 @@ Each member, one entry per network unless it says otherwise:
|
|
|
415
466
|
`settlementTransaction`, a `PaymentChannelClaim` its `payTo` key signed for the actual charge with `tfClose`, which the
|
|
416
467
|
module checks and submits unchanged; `/verify` refuses a payload that already carries one, as the scheme requires.
|
|
417
468
|
|
|
469
|
+
The `cardano`, `concordium` and `ton` modules take an lcp reader in `reader` rather than a node's URL, and lcp ships the
|
|
470
|
+
interface but no implementation: `CardanoReader` of `@integraledger/lcp/cardano`, `CcdReader` of
|
|
471
|
+
`@integraledger/lcp/ccd` and `TvmReader` of `@integraledger/lcp/tvm`, each documented member by member on its API page
|
|
472
|
+
([`cardano`](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/reference/api/cardano.md),
|
|
473
|
+
[`ccd`](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/reference/api/ccd.md),
|
|
474
|
+
[`tvm`](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/reference/api/tvm.md)), with the calls each
|
|
475
|
+
makes in
|
|
476
|
+
[Rails: reading settlement](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/guides/rails.md#reading-settlement).
|
|
477
|
+
Write one over your own indexer or node. Its `network` is the module's `network`: the module refuses to start where they
|
|
478
|
+
differ. Each call is read-only and bounded by your own timeout and byte limit, and rejects on any failure, with lcp's
|
|
479
|
+
`ReaderError` (`@integraledger/lcp/evm`) where the kind is known: a rejection reads as `unreadable`, never as absence.
|
|
480
|
+
An item the endpoint does not hold is answered only in the form the interface names for it (`null`, or
|
|
481
|
+
`{ notFound: true, ... }` with the point the interface asks for), and only where the endpoint answered in the form it
|
|
482
|
+
documents for a missing item. lcp makes no other call, so the endpoint, its credentials, its timeouts and its retries
|
|
483
|
+
are yours.
|
|
484
|
+
|
|
485
|
+
### What stops the start
|
|
486
|
+
|
|
487
|
+
`serveProfileFacilitator` rejects with the first of these it meets, in this order, having closed what it opened; each
|
|
488
|
+
message starts as shown:
|
|
489
|
+
|
|
490
|
+
| The configuration | The message |
|
|
491
|
+
|---|---|
|
|
492
|
+
| `listen` is not `host:port` | `listen must be "host:port"` |
|
|
493
|
+
| `credential` holds a character RFC 6750 does not admit | `credential must be a bearer token` |
|
|
494
|
+
| A fee budget whose amount is not a positive integer, or whose period is not a positive whole number of seconds | `the fee budget of <network>: its amount is not a positive integer`, `the fee budget of <network>: its period is not a positive number of seconds` |
|
|
495
|
+
| Two fee budgets on one network | `<network> has two fee budgets` |
|
|
496
|
+
| Postgres cannot be reached, or the tables cannot be created ([The database](#the-database)) | the driver's own error |
|
|
497
|
+
| A module's member it refuses, the modules taken in the order of their names | `casper on <network>: not served` (`casper:casper`), `casper on <network>: the signer reads`, `casper on <network>: the signer's speculative execution goes to`, `casper on <network>: the signer names the chain`; `the Cardano reader serves`; `the Concordium signer and reader must serve`; `lnbtc: <network> is not an lnbtc network`; `not a Starknet network`, `the executor's address is not an account address`; `not a Stellar network`, `the source account's address is not an account strkey`, `the fee ceiling must be positive, and the inclusion fee at least 100 stroops`; `not a Sui network`; `the TON reader serves` |
|
|
498
|
+
| An `erc7710` network where the `evm` module does not register `exact` | `an own module is offered to exact on <network>, which no module registers` |
|
|
499
|
+
| A module's class that states `pairings`, `key`, `acceptsZero` or `feeBudget` in its `extra` | `<network>: a module's facilitator states` |
|
|
500
|
+
| Two registrations of one scheme on one network | `two registrations of <scheme> <network>` |
|
|
501
|
+
| Two modules behind one registration whose keys sign for different purposes | `<scheme> on <network>: its modules' keys sign for` |
|
|
502
|
+
| A fee budget on a network no module serves | `the fee budget of <network>: no module serves it` |
|
|
503
|
+
| A fee budget on a network where a keyed module neither counts nor shows its fees (`ton`, `concordium`) | `the fee budget of <network>: the <module> module's key pays fees it neither meters nor shows` |
|
|
504
|
+
| A keyed module, and no `credential` | `a module holds a key (<scheme> on <network>, ...): credential is required` |
|
|
505
|
+
|
|
506
|
+
Any other rejection is the error of a call the start makes, such as the listen's `EADDRINUSE`.
|
|
507
|
+
|
|
418
508
|
## Keys
|
|
419
509
|
|
|
420
510
|
`extra.key` states what the module's key signs, by one of three values:
|
|
@@ -439,6 +529,18 @@ settler would spend the seller's money on payments between other parties. A depl
|
|
|
439
529
|
in constant time, and answers a call without it `401` `{"error":"unauthorized"}` with `WWW-Authenticate: Bearer`,
|
|
440
530
|
before it reads the body, closing the connection. A keyless deployment may set one too, with the same effect.
|
|
441
531
|
|
|
532
|
+
## Security
|
|
533
|
+
|
|
534
|
+
The settler serves plain HTTP (`node:http`, no TLS option): the credential and every payment cross the network in clear
|
|
535
|
+
unless TLS is in front of it. Bind `listen` to loopback or a private interface and terminate TLS in a proxy before it,
|
|
536
|
+
or run the settler on the resource server's own host. The credential is its only gate: anyone who holds it can have a
|
|
537
|
+
keyed module pay fees for payments between other parties, without limit unless a fee budget caps them ([The fee
|
|
538
|
+
budget](#the-fee-budget)), so keep it as you keep the keys, and set a budget on each network whose fees a key pays (the
|
|
539
|
+
`ton` and `concordium` modules take none). The keys live in the operator's process, as the signer objects passed in; the
|
|
540
|
+
settler reads no key material itself, and names a node in an error by its origin alone. It does not check that H is the
|
|
541
|
+
one the resource server issued, nor that the resource server has not accepted it before ([What it is](#what-it-is)):
|
|
542
|
+
those checks are the resource server's.
|
|
543
|
+
|
|
442
544
|
## What `/supported` states
|
|
443
545
|
|
|
444
546
|
`GET /supported` answers `{kinds, extensions, signers}` as x402's facilitator class gives it. Each kind is
|
|
@@ -448,7 +550,7 @@ before it reads the body, closing the connection. A keyless deployment may set o
|
|
|
448
550
|
|---|---|
|
|
449
551
|
| `extra.pairings` | The lcp pairing ids the kind submits. A scheme on one network can hold several forms, so the scheme alone does not name them. |
|
|
450
552
|
| `extra.key` | `none`, `relayer` or `fee-payer` ([Keys](#keys)). |
|
|
451
|
-
| `extra.acceptsZero` |
|
|
553
|
+
| `extra.acceptsZero` | The pairings of `extra.pairings` the kind settles at an amount of zero; `[]` where none does. An option of amount zero whose pairing it does not name is refused `invalid_payment_requirements`. |
|
|
452
554
|
| `extra.feeBudget` | `true` on each kind of a network whose fee budget the operator set; absent otherwise. Neither the amount nor what remains is stated. |
|
|
453
555
|
| The class's own members | Kept unchanged, such as `assetTransferMethod` on Tron and Polkadot, `feePayer` where a fee payer co-signs, and `areFeesSponsored` on the XRP Ledger and Stellar. No module's class may state one of the four members above: the settler refuses one that does at start. |
|
|
454
556
|
|
|
@@ -515,12 +617,12 @@ await settler.close();
|
|
|
515
617
|
`unsupported_scheme`. Where an own module claims the payment (by a member of the option, or by what the payment
|
|
516
618
|
holds), it goes to that module, else to the registration's class. On `lnbtc` the answer is `unsupported_scheme`.
|
|
517
619
|
3. lcp's checks of the pairing, from the payment and its requirements alone. A refusal carries x402's reason and, on
|
|
518
|
-
the `algorand`, `aptos`, `hedera`, `solana`, `starknet` and `sui` modules, lcp's refusal code as
|
|
519
|
-
(on `starknet` and `sui`, the module's own code where its own check refused).
|
|
620
|
+
the `algorand`, `aptos`, `casper`, `hedera`, `solana`, `starknet` and `sui` modules, lcp's refusal code as
|
|
621
|
+
`invalidMessage` (on `starknet` and `sui`, the module's own code where its own check refused).
|
|
520
622
|
4. The record: a payment it holds, claimed or final, is refused `invalid_transaction_state`, since `isValid: true`
|
|
521
623
|
tells the caller that a settle may follow.
|
|
522
|
-
5. What the kind declares: an amount of zero
|
|
523
|
-
the payment goes to, are refused `invalid_payment_requirements`.
|
|
624
|
+
5. What the kind declares: an amount of zero whose pairing `extra.acceptsZero` does not name, and a form outside the
|
|
625
|
+
pairings of the module the payment goes to, are refused `invalid_payment_requirements`.
|
|
524
626
|
6. The fee budget, where the module's key pays the fee: a spent budget is refused `fee_budget_spent`.
|
|
525
627
|
7. The class's verify, unchanged, with its own reasons.
|
|
526
628
|
8. lcp's read of the chain: a payment the chain shows final (landed, or consumed by another act) is refused
|
|
@@ -532,20 +634,21 @@ The answer is `{isValid: true, payer}` or `{isValid: false, invalidReason, inval
|
|
|
532
634
|
### `/settle`
|
|
533
635
|
|
|
534
636
|
1. Steps 1 to 3 of `/verify`, with `errorMessage` for `invalidMessage`; `lnbtc` is served here.
|
|
535
|
-
2. The record
|
|
536
|
-
success.
|
|
537
|
-
[the record](#the-record-and-what-a-repeat-answers) says.
|
|
637
|
+
2. The record: a final row is answered `invalid_transaction_state` naming the transaction it holds, never a second
|
|
638
|
+
success.
|
|
538
639
|
3. What the kind declares, as `/verify` checks it.
|
|
539
|
-
4.
|
|
640
|
+
4. A claim the record holds that is not final, which another settle holds or whose hold has ended: it is answered as
|
|
641
|
+
[the record](#the-record-and-what-a-repeat-answers) says, and no step below is made.
|
|
642
|
+
5. The class's verify. Where it refuses, lcp's read of the chain: a payment the chain shows landed, or whose value
|
|
540
643
|
another act consumed, is stored final and answered `invalid_transaction_state` naming its transaction; otherwise the
|
|
541
644
|
class's refusal is the answer, nothing is stored, and a repeat is checked again.
|
|
542
|
-
|
|
645
|
+
6. Where the module's read searches from a position no x402 call carries (a ledger, a slot, a block), the chain's
|
|
543
646
|
position, read just before the claim, which the row keeps for every later read.
|
|
544
|
-
|
|
647
|
+
7. The claim: one conditional insert of the payment's row, held by this settle for `settleWaitMs`, so that of two
|
|
545
648
|
settles of one payment only one submits.
|
|
546
|
-
|
|
649
|
+
8. The fee budget, where the module's key pays the fee: a spent budget answers `fee_budget_spent`, sends nothing, and
|
|
547
650
|
leaves the claim, not final.
|
|
548
|
-
|
|
651
|
+
9. The class's settle, which submits what the payer signed. A success that names a transaction is stored final, then
|
|
549
652
|
answered `{success: true, transaction, network, payer}`. Anything else is classified by lcp's read: a payment the
|
|
550
653
|
chain shows final is stored final and answered (success only where the read shows a transaction this settler sent,
|
|
551
654
|
or the payment it presented, settled); one still live is answered `settlement_pending` naming the transaction sent,
|
|
@@ -657,7 +760,7 @@ x402 codec reads, and 1,024 bytes for the envelope.
|
|
|
657
760
|
| `invalid_x402_version` | yes | yes | `x402Version` is not 2 in the request or the payload. |
|
|
658
761
|
| `invalid_network` | yes | yes | No configured module serves the network. |
|
|
659
762
|
| `unsupported_scheme` | yes | yes | No module registers the scheme on the network. On `lnbtc`, every `/verify`. |
|
|
660
|
-
| `invalid_payment_requirements` | yes | yes | The requirements are not ones the pairing's profile admits; an amount of zero
|
|
763
|
+
| `invalid_payment_requirements` | yes | yes | The requirements are not ones the pairing's profile admits; an amount of zero whose pairing the kind's `extra.acceptsZero` does not name; a form outside the kind's pairings; an option the module refuses (each module's notes). |
|
|
661
764
|
| `invalid_payload` | yes | yes | The payload does not match the profile or the requirements. |
|
|
662
765
|
| `unsupported_permission` | yes | yes | Tron: the owner's permission does not accept the transaction's signatures. |
|
|
663
766
|
| `invalid_transaction` | yes | yes | The node refuses the transaction in simulation or validation, in a module of the settler's own. |
|
|
@@ -728,7 +831,9 @@ CREATE TABLE IF NOT EXISTS module_state (
|
|
|
728
831
|
- Each node call the settler makes itself has a timeout of at most 5 seconds and an answer of at most 4 MiB, except
|
|
729
832
|
Polkadot's block reads, bounded by the runtime's `System.BlockLength` (at most 4 of them at once in a process). A
|
|
730
833
|
published class's calls are bounded by the class, and its settle takes no deadline: `settleWaitMs` bounds the
|
|
731
|
-
settler's own reads and store calls, and a class's settle runs on its own bounds.
|
|
834
|
+
settler's own reads and store calls, and a class's settle runs on its own bounds. x402's EVM signer waits up to
|
|
835
|
+
180 s for a receipt unless `toFacilitatorEvmSigner`'s `confirmationTimeoutMs` is set: set it below `settleWaitMs`,
|
|
836
|
+
as the service above does, or a `/settle` can outlast its wait.
|
|
732
837
|
- `/settle`'s reads and submission end a second before `settleWaitMs` (a quarter of a shorter wait), the time kept for
|
|
733
838
|
storing the answer. The server's request timeout is `settleWaitMs` plus 60 seconds.
|
|
734
839
|
- An error names a node by its origin alone, since a URL's path or query can hold an API key.
|
|
@@ -743,10 +848,44 @@ CREATE TABLE IF NOT EXISTS module_state (
|
|
|
743
848
|
and `fee-not-counted`. Each module adds its own, such as `node-call-failed` and `settlement-failed`. Every
|
|
744
849
|
`unexpected_verify_error` and `unexpected_settle_error` has an entry that names why, written when it is first given.
|
|
745
850
|
|
|
746
|
-
##
|
|
851
|
+
## Versions
|
|
852
|
+
|
|
853
|
+
0.5.1 takes `@integraledger/lcp` `~0.6.3` as its peer dependency: install `@integraledger/lcp@~0.6.3` beside it. A
|
|
854
|
+
later lcp minor release needs a settler release that names it. While both packages are 0.x, a minor release may change
|
|
855
|
+
the configuration, the answers or the storage; [the CHANGELOG](./CHANGELOG.md) lists what each release changes. It
|
|
856
|
+
needs Node.js 24.22.1 or later.
|
|
857
|
+
|
|
858
|
+
### Upgrading from 0.4.0
|
|
859
|
+
|
|
860
|
+
0.4.0 served the `tron` and `polkadot` modules alone. 0.5.0 takes `listen`, `store`, `settleWaitMs`, `operatorLog`,
|
|
861
|
+
`tron` and `polkadot` unchanged, and needs `@integraledger/lcp` `~0.6.0` (0.4.0 took `~0.5.0`) and Node.js 24.22.1.
|
|
862
|
+
|
|
863
|
+
0.4.0 kept its record in the table `settlement`. 0.5.0 creates `instrument`, `fee` and `module_state` beside it, never
|
|
864
|
+
reads or writes `settlement`, and does not fill `instrument` from it, so it does not know the payments 0.4.0 answered.
|
|
865
|
+
A repeated `/settle` of one of them is judged afresh, by the module's checks and lcp's read of the chain:
|
|
866
|
+
|
|
867
|
+
- **A payment 0.4.0 answered success is never answered success again.** On Tron, the module's checks refuse a
|
|
868
|
+
transaction id the node holds in its blocks or pending pool, and an expiration already passed; on Polkadot, the node
|
|
869
|
+
no longer answers the extrinsic valid once its nonce is used. The answer is `invalid_transaction_state` naming the
|
|
870
|
+
transaction, stored, where lcp's read shows the payment final, and otherwise the check's refusal, with nothing stored.
|
|
871
|
+
- **A payment 0.4.0 answered `settlement_pending` is answered the same way once its transaction is in a block, and so
|
|
872
|
+
is never answered success by 0.5.0, though it landed.** The one exception is a Polkadot extrinsic still in the
|
|
873
|
+
node's pool, not yet in a block, when the repeat arrives: it passes the checks, 0.5.0 claims it, the node refuses
|
|
874
|
+
its submission as already seen, and 0.5.0 answers success once lcp's read shows it final.
|
|
875
|
+
- **A payment 0.4.0 claimed and never sent** is new to 0.5.0, which settles it.
|
|
876
|
+
|
|
877
|
+
Neither rail lets one signed payment land twice: a Tron transaction id and a Polkadot account nonce are each used once.
|
|
878
|
+
Before you switch, call `/settle` on 0.4.0 again for each payment it left pending, until each has a final answer (its
|
|
879
|
+
rows in `settlement` whose `answer` is null or whose `answer->>'errorReason'` is `settlement_pending`), or read those
|
|
880
|
+
payments with lcp's `status` after the switch. Do not run 0.4.0 and 0.5.0 at once for the same payments: each keeps its
|
|
881
|
+
own record, so each can submit a payment and answer it success. `settlement` can be dropped once no payment it holds
|
|
882
|
+
can still land.
|
|
883
|
+
|
|
884
|
+
## Tests (in a clone of this repository)
|
|
747
885
|
|
|
748
|
-
The
|
|
749
|
-
|
|
886
|
+
The package ships no tests: they run in a clone of [the repository](https://github.com/IntegraLedger/integra-protocol).
|
|
887
|
+
They feed lcp's vectors for each module's pairings through the settler's `/verify` and `/settle`, against local node
|
|
888
|
+
stubs that replay recorded node answers (`test/fixtures/tron-mainnet-answers.json`, Polkadot Asset Hub's runtime
|
|
750
889
|
metadata in `test/fixtures/polkadot-asset-hub-2005000.json.gz`) or answers derived from the pairing's profile. They
|
|
751
890
|
need Postgres: set `INTEGRA_DATABASE_URL` to a connection string whose user may create databases. Each test file makes
|
|
752
891
|
and drops its own database, so test runs share one server. CI runs them against a Postgres 18 service.
|
package/dist/module.d.ts
CHANGED
|
@@ -38,10 +38,10 @@ export interface Descriptor {
|
|
|
38
38
|
*/
|
|
39
39
|
readonly pairings: readonly PairingId[];
|
|
40
40
|
/**
|
|
41
|
-
* `extra.acceptsZero`:
|
|
42
|
-
* needs to know
|
|
41
|
+
* `extra.acceptsZero`: the pairings of `pairings` the module settles at an amount of zero, as a seller choosing a zero
|
|
42
|
+
* agreement needs to know; empty where none does.
|
|
43
43
|
*/
|
|
44
|
-
readonly acceptsZero:
|
|
44
|
+
readonly acceptsZero: readonly PairingId[];
|
|
45
45
|
/**
|
|
46
46
|
* Set where the module's `/verify` judges a payment that has already landed, by what the chain shows of it, and does
|
|
47
47
|
* not refuse it for having landed: the core then asks neither its record nor the chain whether the instrument is
|
|
@@ -213,7 +213,7 @@ function feesOf(c) {
|
|
|
213
213
|
/** The descriptor of `x402/exact/algorand`, one kind for both paths. */
|
|
214
214
|
function descriptor() {
|
|
215
215
|
// lcp's floor is 0: the scheme sets none, the class compares amounts by equality, and a zero transfer needs no opt-in.
|
|
216
|
-
return { name: "algorand", key: "fee-payer", pairings: [exactAvm.id], acceptsZero:
|
|
216
|
+
return { name: "algorand", key: "fee-payer", pairings: [exactAvm.id], acceptsZero: [exactAvm.id] };
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
219
|
* The registration of `x402/exact/algorand` on the configured network: the published class, and behind its
|
|
@@ -176,7 +176,7 @@ export function aptosModule(c, meter) {
|
|
|
176
176
|
const cls = new ExactAptosScheme(meter === undefined ? c.signer : counted(c, meter), sponsor);
|
|
177
177
|
return {
|
|
178
178
|
// A zero amount is not established on Aptos, so the kind does not take zero.
|
|
179
|
-
descriptor: { name: "aptos", key: sponsor ? "fee-payer" : "none", pairings: [exactAptos.id], acceptsZero:
|
|
179
|
+
descriptor: { name: "aptos", key: sponsor ? "fee-payer" : "none", pairings: [exactAptos.id], acceptsZero: [] },
|
|
180
180
|
network,
|
|
181
181
|
facilitator: sponsor ? cls : unsponsored(cls),
|
|
182
182
|
record: {
|
|
@@ -70,7 +70,7 @@ export function cardanoModule(c, state) {
|
|
|
70
70
|
throw new TypeError(`the Cardano reader serves ${c.reader.network}, not ${c.network}`);
|
|
71
71
|
return {
|
|
72
72
|
// Every output carries at least the ledger's smallest, so neither pairing takes zero.
|
|
73
|
-
descriptor: { name: "cardano", key: "none", pairings: [exactCardano.id, exactCardanoLock.id], acceptsZero:
|
|
73
|
+
descriptor: { name: "cardano", key: "none", pairings: [exactCardano.id, exactCardanoLock.id], acceptsZero: [] },
|
|
74
74
|
network,
|
|
75
75
|
facilitator: new ExactCardanoScheme(c.signer, { settlementStore: settlementStore(state, c.network) }),
|
|
76
76
|
record: {
|
|
@@ -363,7 +363,7 @@ export function casperModule(c, p, meter) {
|
|
|
363
363
|
const signer = meter === undefined ? c.signer : counted(c.signer, meter, (hash) => chargedOf(c.rpc, hash, bound, performance.now() + NODE_TIMEOUT_MS));
|
|
364
364
|
return {
|
|
365
365
|
// x402's Casper settler refuses a zero amount, so the kind does not take zero (the profile, rule 24).
|
|
366
|
-
descriptor: { name: "casper", key: "relayer", pairings: [exactCasper.id], acceptsZero:
|
|
366
|
+
descriptor: { name: "casper", key: "relayer", pairings: [exactCasper.id], acceptsZero: [] },
|
|
367
367
|
network,
|
|
368
368
|
facilitator: new p.Scheme(signer, c.paymentMotes === undefined ? {} : { limitedPaymentMotes: c.paymentMotes }),
|
|
369
369
|
record: {
|
|
@@ -32,7 +32,7 @@ export function concordiumModule(c) {
|
|
|
32
32
|
throw new TypeError(`the Concordium signer and reader must serve ${c.network}`);
|
|
33
33
|
}
|
|
34
34
|
return {
|
|
35
|
-
descriptor: { name: "concordium", key: "fee-payer", pairings: [exactCcd.id], acceptsZero:
|
|
35
|
+
descriptor: { name: "concordium", key: "fee-payer", pairings: [exactCcd.id], acceptsZero: [exactCcd.id] },
|
|
36
36
|
network,
|
|
37
37
|
facilitator: new ExactConcordiumScheme({ signer: c.signer }),
|
|
38
38
|
record: {
|
|
@@ -187,7 +187,7 @@ export function erc7710Handoff(c) {
|
|
|
187
187
|
},
|
|
188
188
|
};
|
|
189
189
|
const module = {
|
|
190
|
-
descriptor: { name: "erc7710", key: "relayer", pairings: ERC7710_PAIRINGS, acceptsZero:
|
|
190
|
+
descriptor: { name: "erc7710", key: "relayer", pairings: ERC7710_PAIRINGS, acceptsZero: [] },
|
|
191
191
|
network,
|
|
192
192
|
facilitator: facilitatorOf(c),
|
|
193
193
|
record,
|
|
@@ -39,10 +39,10 @@ export declare function exactOptionRefused(requirements: {
|
|
|
39
39
|
/**
|
|
40
40
|
* The profile's pure checks of a payment answering an option of `scheme`: the option is one of the pairings `pairings`
|
|
41
41
|
* names, as lcp's option filter reads it alone (`invalid_payment_requirements` otherwise), and the payment is that
|
|
42
|
-
* pairing's as lcp's `reference` reads it against the option (`invalid_payload` otherwise)
|
|
43
|
-
* payment that is no opening has no reference: lcp's channel
|
|
44
|
-
* and the claim, settle and refund calls a resource server
|
|
45
|
-
* class's to check.
|
|
42
|
+
* pairing's as lcp's `reference` reads it against the option (`invalid_payload` otherwise), an `upto` option being
|
|
43
|
+
* the one `uptoOption` holds it to. A batch settlement's payment that is no opening has no reference: lcp's channel
|
|
44
|
+
* read holds its configuration to its voucher's channel, and the claim, settle and refund calls a resource server
|
|
45
|
+
* makes of the channel, which lcp does not decode, are x402's class's to check.
|
|
46
46
|
*/
|
|
47
47
|
export declare function admit(scheme: EvmScheme | "erc7710", p: X402Payment, pairings: readonly PairingId[]): Promise<Admitted | Refused>;
|
|
48
48
|
/**
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* of its profile, the instrument the record keys it by, how long a final row is kept, and lcp's read of it. Nothing here
|
|
4
4
|
* reads the chain or the clock but the read itself.
|
|
5
5
|
*/
|
|
6
|
-
import { digestJson, isRefusal, pairingOf } from "@integraledger/lcp";
|
|
6
|
+
import { canonicalJson, digestJson, isRefusal, pairingOf } from "@integraledger/lcp";
|
|
7
7
|
import { PERMIT2 } from "@integraledger/lcp/evm";
|
|
8
8
|
import { authCaptureEip3009, authCapturePermit2, exactEip3009, exactErc7710, exactErc7710Salt, exactPermit2, pairingOfPayment, uptoPermit2, } from "@integraledger/lcp/x402";
|
|
9
9
|
import { batchEvm } from "@integraledger/lcp/x402-batch-settlement";
|
|
@@ -53,13 +53,34 @@ export function exactOptionRefused(requirements) {
|
|
|
53
53
|
return (verifying !== undefined &&
|
|
54
54
|
!(typeof verifying === "string" && typeof requirements.asset === "string" && verifying.toLowerCase() === requirements.asset.toLowerCase()));
|
|
55
55
|
}
|
|
56
|
+
const DECIMAL = /^[0-9]+$/;
|
|
57
|
+
/**
|
|
58
|
+
* The option an `upto` payment is held to. x402's `upto` settles the amount its requirements state, at most the maximum
|
|
59
|
+
* the payment accepted: requirements that are the option the payment accepted in every member but an `amount` at or
|
|
60
|
+
* below the accepted one, as RFC 8785 forms compare them, are held as that option. Any other requirements are the
|
|
61
|
+
* option as given.
|
|
62
|
+
*/
|
|
63
|
+
function uptoOption(p) {
|
|
64
|
+
const { requirements } = p;
|
|
65
|
+
const accepted = p.payload.accepted;
|
|
66
|
+
if (!isObject(accepted))
|
|
67
|
+
return requirements;
|
|
68
|
+
const charge = requirements.amount;
|
|
69
|
+
const max = accepted.amount;
|
|
70
|
+
if (typeof charge !== "string" || typeof max !== "string" || !DECIMAL.test(charge) || !DECIMAL.test(max))
|
|
71
|
+
return requirements;
|
|
72
|
+
if (BigInt(charge) > BigInt(max))
|
|
73
|
+
return requirements;
|
|
74
|
+
const asAccepted = canonicalJson({ ...requirements, amount: max });
|
|
75
|
+
return typeof asAccepted === "string" && asAccepted === canonicalJson(accepted) ? accepted : requirements;
|
|
76
|
+
}
|
|
56
77
|
/**
|
|
57
78
|
* The profile's pure checks of a payment answering an option of `scheme`: the option is one of the pairings `pairings`
|
|
58
79
|
* names, as lcp's option filter reads it alone (`invalid_payment_requirements` otherwise), and the payment is that
|
|
59
|
-
* pairing's as lcp's `reference` reads it against the option (`invalid_payload` otherwise)
|
|
60
|
-
* payment that is no opening has no reference: lcp's channel
|
|
61
|
-
* and the claim, settle and refund calls a resource server
|
|
62
|
-
* class's to check.
|
|
80
|
+
* pairing's as lcp's `reference` reads it against the option (`invalid_payload` otherwise), an `upto` option being
|
|
81
|
+
* the one `uptoOption` holds it to. A batch settlement's payment that is no opening has no reference: lcp's channel
|
|
82
|
+
* read holds its configuration to its voucher's channel, and the claim, settle and refund calls a resource server
|
|
83
|
+
* makes of the channel, which lcp does not decode, are x402's class's to check.
|
|
63
84
|
*/
|
|
64
85
|
export async function admit(scheme, p, pairings) {
|
|
65
86
|
const { payload, requirements } = p;
|
|
@@ -87,7 +108,8 @@ export async function admit(scheme, p, pairings) {
|
|
|
87
108
|
return isRefusal(channel) ? { refused: "invalid_payload" } : { pairing };
|
|
88
109
|
}
|
|
89
110
|
}
|
|
90
|
-
const
|
|
111
|
+
const held = requirements.scheme === "upto" ? uptoOption(p) : requirements;
|
|
112
|
+
const ref = await CODEC[pairing].reference(payload, held);
|
|
91
113
|
if (isRefusal(ref))
|
|
92
114
|
return { refused: "invalid_payload" };
|
|
93
115
|
return { pairing, ref: ref };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PendingSettlementStore } from "@x402/core/facilitator";
|
|
2
2
|
import { type AuthCaptureFacilitatorConfig } from "@x402/evm/auth-capture/facilitator";
|
|
3
3
|
import type { FacilitatorEvmSigner } from "@x402/evm";
|
|
4
|
-
import type
|
|
4
|
+
import { type FeeMeter, type FeeNeeds, type Module, type ModuleStarter } from "../../module.js";
|
|
5
5
|
import { type EvmScheme } from "./forms.js";
|
|
6
6
|
/** One `eip155` network the `evm` module serves. */
|
|
7
7
|
export interface EvmConfig {
|
|
@@ -3,6 +3,8 @@ import { BatchSettlementEvmScheme } from "@x402/evm/batch-settlement/facilitator
|
|
|
3
3
|
import { ExactEvmScheme } from "@x402/evm/exact/facilitator";
|
|
4
4
|
import { UptoEvmScheme } from "@x402/evm/upto/facilitator";
|
|
5
5
|
import { NODE_TIMEOUT_MS } from "../../http.js";
|
|
6
|
+
import { phaseOf } from "../../module.js";
|
|
7
|
+
import { exactEip3009 } from "@integraledger/lcp/x402";
|
|
6
8
|
import { admit, instrumentOf, PAIRINGS, readOf } from "./forms.js";
|
|
7
9
|
import { chargedFrom, evmReader, feeShown } from "./node.js";
|
|
8
10
|
const SCHEMES = ["exact", "upto", "auth-capture", "batch-settlement"];
|
|
@@ -65,7 +67,9 @@ function payerOf(payload) {
|
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* The class behind the profile's pure checks: a payment they refuse is answered with their reason and never reaches
|
|
68
|
-
* the class; every other call is the class's own, its `getExtra` and `getSigners` included.
|
|
70
|
+
* the class; every other call is the class's own, its `getExtra` and `getSigners` included. At `/settle` of `upto`,
|
|
71
|
+
* whose requirements carry the charge, the class's `verify` is given them at the maximum the payment accepted, as its
|
|
72
|
+
* own `settle` verifies the permit before it submits.
|
|
69
73
|
*/
|
|
70
74
|
function checked(scheme, inner, pairings) {
|
|
71
75
|
return {
|
|
@@ -79,7 +83,8 @@ function checked(scheme, inner, pairings) {
|
|
|
79
83
|
const payer = payerOf(payload);
|
|
80
84
|
return payer === undefined ? { isValid: false, invalidReason: a.refused } : { isValid: false, invalidReason: a.refused, payer };
|
|
81
85
|
}
|
|
82
|
-
|
|
86
|
+
const held = scheme === "upto" && phaseOf(context) === "settle" ? { ...requirements, amount: payload.accepted.amount } : requirements;
|
|
87
|
+
return inner.verify(payload, held, context);
|
|
83
88
|
},
|
|
84
89
|
async settle(payload, requirements, context) {
|
|
85
90
|
const a = await admit(scheme, { payload, requirements }, pairings);
|
|
@@ -117,9 +122,10 @@ export function evmModules(c, meter, pending) {
|
|
|
117
122
|
name: "evm",
|
|
118
123
|
key: "relayer",
|
|
119
124
|
pairings,
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
|
|
125
|
+
// At 0 on Base Sepolia: EIP-3009's transfer lands (test/fixtures/base-sepolia-eip3009-zero.json), x402's Permit2
|
|
126
|
+
// proxies revert `InvalidAmount`, the escrow's `authorize` reverts `ZeroAmount`; batch settlement's facilitator
|
|
127
|
+
// requires a deposit above 0.
|
|
128
|
+
acceptsZero: scheme === "exact" ? [exactEip3009.id] : [],
|
|
123
129
|
},
|
|
124
130
|
network,
|
|
125
131
|
facilitator: checked(scheme, classOf(scheme, c, signer, pending), pairings),
|
|
@@ -285,7 +285,7 @@ export function transferExecutorModule(c, offering) {
|
|
|
285
285
|
},
|
|
286
286
|
};
|
|
287
287
|
return {
|
|
288
|
-
descriptor: { name: "hedera", key: "relayer", pairings: [exactHederaExecutor.id], acceptsZero:
|
|
288
|
+
descriptor: { name: "hedera", key: "relayer", pairings: [exactHederaExecutor.id], acceptsZero: [] },
|
|
289
289
|
network,
|
|
290
290
|
facilitator,
|
|
291
291
|
record: {
|
|
@@ -69,7 +69,7 @@ export function hederaModule(c) {
|
|
|
69
69
|
const mirror = mirrorOf(c);
|
|
70
70
|
return {
|
|
71
71
|
// A zero transfer is not established on Hedera, so the kind does not take zero.
|
|
72
|
-
descriptor: { name: "hedera", key: "fee-payer", pairings: [exactHedera.id], acceptsZero:
|
|
72
|
+
descriptor: { name: "hedera", key: "fee-payer", pairings: [exactHedera.id], acceptsZero: [] },
|
|
73
73
|
network,
|
|
74
74
|
facilitator: naming(new ExactHederaScheme(c.signer)),
|
|
75
75
|
record: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Lightning module: x402's `exact` scheme on the `lnbtc` networks, for lcp's pairing `x402/exact/lnbtc/payment-hash`,
|
|
3
|
-
* written to x402's scheme text (`specs/schemes/exact/scheme_exact_lnbtc.md`) and lcp's profile
|
|
3
|
+
* written to x402's scheme text (`specs/schemes/exact/scheme_exact_lnbtc.md`) and lcp's profile
|
|
4
|
+
* `x402-exact-lnbtc-payment-hash.md`.
|
|
4
5
|
* The buyer's node paid the invoice before the preimage reached the buyer, so settling moves nothing. The module makes
|
|
5
6
|
* the scheme's whole validation through lcp's `validateExactLnbtc`, the export a resource server also runs before it
|
|
6
7
|
* settles: the invoice's signature, its signer against `payTo`, its `h` against the request hash, its `p` against
|
|
@@ -90,7 +91,7 @@ const record = {
|
|
|
90
91
|
};
|
|
91
92
|
function moduleOn(network) {
|
|
92
93
|
return {
|
|
93
|
-
descriptor: { name: "lnbtc", key: "none", pairings: [exactLnbtcPaymentHash.id], acceptsZero:
|
|
94
|
+
descriptor: { name: "lnbtc", key: "none", pairings: [exactLnbtcPaymentHash.id], acceptsZero: [], verifyForbidden: true },
|
|
94
95
|
network,
|
|
95
96
|
facilitator,
|
|
96
97
|
record,
|
|
@@ -177,7 +177,7 @@ export function nearModule(c) {
|
|
|
177
177
|
const network = c.network;
|
|
178
178
|
return {
|
|
179
179
|
// The standard token refuses a zero ft_transfer, so the kind does not take zero.
|
|
180
|
-
descriptor: { name: "near", key: "relayer", pairings: [exactNear.id], acceptsZero:
|
|
180
|
+
descriptor: { name: "near", key: "relayer", pairings: [exactNear.id], acceptsZero: [] },
|
|
181
181
|
network,
|
|
182
182
|
facilitator: new ExactNearScheme(c.signer),
|
|
183
183
|
record: {
|
|
@@ -92,7 +92,7 @@ export function polkadotModules(rail, log) {
|
|
|
92
92
|
pairings: [exactPolkadotRemark.id],
|
|
93
93
|
// The assets pallet returns early on a transfer of zero and emits no `Transferred` event, so the smallest
|
|
94
94
|
// amount is one base unit (polkadot-sdk `substrate/frame/assets/src/functions.rs`, `do_transfer`).
|
|
95
|
-
acceptsZero:
|
|
95
|
+
acceptsZero: [],
|
|
96
96
|
},
|
|
97
97
|
network,
|
|
98
98
|
facilitator,
|
|
@@ -20,7 +20,7 @@ import { getBase58Decoder, getTransactionDecoder } from "@solana/kit";
|
|
|
20
20
|
import { createHash } from "node:crypto";
|
|
21
21
|
import { isObject } from "../../answers.js";
|
|
22
22
|
import { NODE_TIMEOUT_MS } from "../../http.js";
|
|
23
|
-
import { outcomeOf, } from "../../module.js";
|
|
23
|
+
import { outcomeOf, phaseOf, } from "../../module.js";
|
|
24
24
|
import { chargedOn, svmReader } from "./reader.js";
|
|
25
25
|
import { batchPendingStore, channelStorage } from "./state.js";
|
|
26
26
|
/** Solana mainnet, where the payment-channels program the `upto` and batch-settlement forms call is not deployed. */
|
|
@@ -39,9 +39,10 @@ function presented(payload) {
|
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* The published class, unchanged, with the module's checks before it on both calls: a payment they refuse is answered
|
|
42
|
-
* by x402's failure shape with lcp's code as its message, and the class never sees it.
|
|
42
|
+
* by x402's failure shape with lcp's code as its message, and the class never sees it. At `/settle`, the class's check
|
|
43
|
+
* is `atSettle` where given, else its `verify`.
|
|
43
44
|
*/
|
|
44
|
-
function behind(cls, check) {
|
|
45
|
+
function behind(cls, check, atSettle) {
|
|
45
46
|
return {
|
|
46
47
|
scheme: cls.scheme,
|
|
47
48
|
caipFamily: cls.caipFamily,
|
|
@@ -52,6 +53,8 @@ function behind(cls, check) {
|
|
|
52
53
|
if (refused !== null) {
|
|
53
54
|
return { isValid: false, invalidReason: refused.reason, ...(refused.code ? { invalidMessage: refused.code } : {}) };
|
|
54
55
|
}
|
|
56
|
+
if (atSettle !== undefined && phaseOf(context) === "settle")
|
|
57
|
+
return atSettle(cls, payload, requirements, context);
|
|
55
58
|
return cls.verify(payload, requirements, context);
|
|
56
59
|
},
|
|
57
60
|
async settle(payload, requirements, context) {
|
|
@@ -187,7 +190,7 @@ function instrumentOf(pairing, nonce, ref) {
|
|
|
187
190
|
* whose later settles are collection (`isOpening` false: an `upto` claim, a batch's voucher, top-up or refund), which
|
|
188
191
|
* lcp does not read: those go to the class with the network checked, and each is its own row.
|
|
189
192
|
*/
|
|
190
|
-
function moduleOf(c, pairing, cls, acceptsZero, isOpening) {
|
|
193
|
+
function moduleOf(c, pairing, cls, acceptsZero, isOpening, atSettle) {
|
|
191
194
|
const network = c.network;
|
|
192
195
|
const check = async (payload, requirements) => {
|
|
193
196
|
if (!isOpening({ payload, requirements })) {
|
|
@@ -199,7 +202,7 @@ function moduleOf(c, pairing, cls, acceptsZero, isOpening) {
|
|
|
199
202
|
return {
|
|
200
203
|
descriptor: { name: "solana", key: "fee-payer", pairings: [pairing.id], acceptsZero },
|
|
201
204
|
network,
|
|
202
|
-
facilitator: behind(cls, check),
|
|
205
|
+
facilitator: behind(cls, check, atSettle),
|
|
203
206
|
record: {
|
|
204
207
|
async instrument(p) {
|
|
205
208
|
if (!isOpening(p)) {
|
|
@@ -250,6 +253,25 @@ function uptoOpening(p) {
|
|
|
250
253
|
return false;
|
|
251
254
|
return !(type === undefined && typeof body["voucherSignature"] === "string");
|
|
252
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* The `upto` class's check at `/settle`. The resource server stamps `type` on each settle it sends (x402's `upto`
|
|
258
|
+
* server: `deposit` before its handler runs, `claim` after it), and the class's `verify`, the check of the buyer's
|
|
259
|
+
* opening, refuses a payload that carries one. A deposit is checked by that `verify` as the buyer sent it, without
|
|
260
|
+
* the stamp. A claim, which that `verify` never takes, is checked by the class's `settle` before it sends anything (the
|
|
261
|
+
* channel it opened, the receiver authorizer, the validity window, the voucher): here it is valid, naming the
|
|
262
|
+
* payload's payer.
|
|
263
|
+
*/
|
|
264
|
+
const uptoAtSettle = async (cls, payload, requirements, context) => {
|
|
265
|
+
const body = payload.payload;
|
|
266
|
+
if (!uptoOpening({ payload, requirements })) {
|
|
267
|
+
const from = body["from"];
|
|
268
|
+
return { isValid: true, ...(typeof from === "string" ? { payer: from } : {}) };
|
|
269
|
+
}
|
|
270
|
+
if (body["type"] !== "deposit")
|
|
271
|
+
return cls.verify(payload, requirements, context);
|
|
272
|
+
const { type: _stamp, ...signed } = body;
|
|
273
|
+
return cls.verify({ ...payload, payload: signed }, requirements, context);
|
|
274
|
+
};
|
|
253
275
|
/**
|
|
254
276
|
* Whether a batch-settlement payload goes through lcp's checks as an opening: a deposit that lcp's channel read does not
|
|
255
277
|
* place within an open channel (a top-up), that is its `open`, and a deposit lcp cannot read, which its checks refuse.
|
|
@@ -270,7 +292,7 @@ export function solanaModules(config, state, meter) {
|
|
|
270
292
|
const pending = state === undefined ? {} : { pendingSettlementStore: state.pending };
|
|
271
293
|
const exact = new ExactSvmScheme(c.signer, undefined, { ...versions, ...pending });
|
|
272
294
|
// lcp's floor on x402/exact/solana is 0: a zero TransferChecked lands, and the class compares amounts by equality.
|
|
273
|
-
const modules = [moduleOf(c, exactSvm, exact,
|
|
295
|
+
const modules = [moduleOf(c, exactSvm, exact, [exactSvm.id], () => true)];
|
|
274
296
|
if (c.network === SOLANA_MAINNET || state === undefined)
|
|
275
297
|
return modules;
|
|
276
298
|
const upto = new UptoSvmScheme(c.signer, { ...versions, channelStorage: state.channels, pendingSettlementStore: state.pending });
|
|
@@ -280,8 +302,8 @@ export function solanaModules(config, state, meter) {
|
|
|
280
302
|
pendingSettlementStore: state.batchPending,
|
|
281
303
|
});
|
|
282
304
|
// upto: lcp's filter admits a positive amount only. Batch settlement: zero through it has not been read.
|
|
283
|
-
modules.push(moduleOf(c, uptoSvm, upto,
|
|
284
|
-
modules.push(moduleOf(c, batchSvm, batch,
|
|
305
|
+
modules.push(moduleOf(c, uptoSvm, upto, [], uptoOpening, uptoAtSettle));
|
|
306
|
+
modules.push(moduleOf(c, batchSvm, batch, [], batchOpening));
|
|
285
307
|
return modules;
|
|
286
308
|
}
|
|
287
309
|
/**
|
|
@@ -19,6 +19,12 @@ const ID = exactStarknet.id;
|
|
|
19
19
|
const U128 = 1n << 128n;
|
|
20
20
|
const POLL_MS = 1_000;
|
|
21
21
|
const NETWORKS = ["starknet:SN_MAIN", "starknet:SN_SEPOLIA"];
|
|
22
|
+
/**
|
|
23
|
+
* The networks whose kind names the pairing in `extra.acceptsZero`: each holds a token on which lcp's `starknetFloor`
|
|
24
|
+
* answers 0 (the profile's rule 24), on Starknet Sepolia STRK and USDC. lcp's check of the option refuses an amount of
|
|
25
|
+
* "0" on any other token, `starknet/option-malformed`, which the module answers `invalid_payment_requirements`.
|
|
26
|
+
*/
|
|
27
|
+
const ZERO_NETWORKS = ["starknet:SN_SEPOLIA"];
|
|
22
28
|
/** The `l2_gas` a simulation may spend, which charges no fee: Starknet's per-transaction execution bound. */
|
|
23
29
|
const SIMULATION_L2_GAS = 1000000000n;
|
|
24
30
|
const no = (reason, message) => (message === undefined ? { reason } : { reason, message });
|
|
@@ -486,8 +492,9 @@ export function starknetModule(c, core) {
|
|
|
486
492
|
name: "starknet",
|
|
487
493
|
key: "relayer",
|
|
488
494
|
pairings: [ID],
|
|
489
|
-
//
|
|
490
|
-
|
|
495
|
+
// A `transfer` of 0 of STRK and of USDC on Starknet Sepolia emits a `Transfer` of 0 (`starknet_simulateTransactions`
|
|
496
|
+
// at block 18422698, lcp's test/fixtures/starknet-zero-transfer-sepolia.json).
|
|
497
|
+
acceptsZero: ZERO_NETWORKS.includes(network) ? [ID] : [],
|
|
491
498
|
},
|
|
492
499
|
network: network,
|
|
493
500
|
facilitator,
|
|
@@ -410,7 +410,7 @@ export function stellarModule(c, core) {
|
|
|
410
410
|
key: "relayer",
|
|
411
411
|
pairings: [ID],
|
|
412
412
|
// The Stellar Asset Contract refuses only a negative amount and emits its event at zero (the profile, rule 13).
|
|
413
|
-
acceptsZero:
|
|
413
|
+
acceptsZero: [ID],
|
|
414
414
|
},
|
|
415
415
|
network: network,
|
|
416
416
|
facilitator,
|
|
@@ -248,8 +248,9 @@ export function suiModule(c, core) {
|
|
|
248
248
|
name: "sui",
|
|
249
249
|
key: "none",
|
|
250
250
|
pairings: [ID],
|
|
251
|
-
//
|
|
252
|
-
|
|
251
|
+
// A transfer of 0 executes where the buyer pays gas: Sui testnet transaction 7EjfN1kqGng3phZjqgCzy8RRRXCP2Ybt7mikGgjBUwKA,
|
|
252
|
+
// status SUCCESS, its only balance change the sender's gas. lcp's option filter refuses 0 on the gasless path.
|
|
253
|
+
acceptsZero: [ID],
|
|
253
254
|
verifiesLanded: true,
|
|
254
255
|
},
|
|
255
256
|
network: network,
|
|
@@ -30,7 +30,7 @@ export function tonModule(c) {
|
|
|
30
30
|
if (c.reader.network !== c.network)
|
|
31
31
|
throw new TypeError(`the TON reader serves ${c.reader.network}, not ${c.network}`);
|
|
32
32
|
return {
|
|
33
|
-
descriptor: { name: "ton", key: "relayer", pairings: [exactTvm.id], acceptsZero:
|
|
33
|
+
descriptor: { name: "ton", key: "relayer", pairings: [exactTvm.id], acceptsZero: [exactTvm.id] },
|
|
34
34
|
network,
|
|
35
35
|
facilitator: new ExactTvmScheme(c.signer),
|
|
36
36
|
record: {
|
|
@@ -67,7 +67,7 @@ export function tronModules(rail, log) {
|
|
|
67
67
|
pairings: [exactTronMemo.id],
|
|
68
68
|
// The profile's floor is 1 base unit until a run shows a contract's transfer(to, 0) succeeding with a Transfer
|
|
69
69
|
// log (rule 1); no contract is so shown, so no payment of zero is settled.
|
|
70
|
-
acceptsZero:
|
|
70
|
+
acceptsZero: [],
|
|
71
71
|
},
|
|
72
72
|
network,
|
|
73
73
|
facilitator,
|
|
@@ -240,7 +240,7 @@ function multisignedModule(c, node) {
|
|
|
240
240
|
}
|
|
241
241
|
/** One kind for both paths: x402/exact/xrpl, no key; zero is no Payment (a Payment of zero is malformed). */
|
|
242
242
|
function descriptor() {
|
|
243
|
-
return { name: "xrpl", key: "none", pairings: [exactXrpl.id], acceptsZero:
|
|
243
|
+
return { name: "xrpl", key: "none", pairings: [exactXrpl.id], acceptsZero: [] };
|
|
244
244
|
}
|
|
245
245
|
/** The published class with the module's pure checks before it on both calls. */
|
|
246
246
|
function behind(cls, network) {
|
|
@@ -234,7 +234,7 @@ export function uptoModule(network, node) {
|
|
|
234
234
|
const n = network;
|
|
235
235
|
return {
|
|
236
236
|
// The maximum a payment authorises is a positive number of drops (lcp's option filter); zero is not established.
|
|
237
|
-
descriptor: { name: "xrpl", key: "none", pairings: [uptoXrpl.id], acceptsZero:
|
|
237
|
+
descriptor: { name: "xrpl", key: "none", pairings: [uptoXrpl.id], acceptsZero: [] },
|
|
238
238
|
network: n,
|
|
239
239
|
facilitator: uptoFacilitator(network, node),
|
|
240
240
|
record: {
|
package/dist/wrapper.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export interface Kind {
|
|
|
15
15
|
readonly scheme: string;
|
|
16
16
|
readonly network: Network;
|
|
17
17
|
readonly key: KeyPurpose;
|
|
18
|
-
/**
|
|
19
|
-
readonly acceptsZero:
|
|
18
|
+
/** The kind's pairings that take an amount of zero: each one every module submitting it names so. */
|
|
19
|
+
readonly acceptsZero: readonly PairingId[];
|
|
20
20
|
/** Every pairing a module behind the kind submits, each once. */
|
|
21
21
|
readonly pairings: readonly PairingId[];
|
|
22
22
|
/** Whether the network has a fee budget. */
|
|
@@ -35,8 +35,8 @@ export declare function kindOf(r: Registration, feeBudget: boolean): Kind;
|
|
|
35
35
|
*/
|
|
36
36
|
export declare function route(r: Registration, payload: PaymentPayload, requirements: PaymentRequirements): Module;
|
|
37
37
|
/**
|
|
38
|
-
* The kind's declaration, held to a payment before the class is asked: an option of amount zero
|
|
39
|
-
* not
|
|
38
|
+
* The kind's declaration, held to a payment before the class is asked: an option of amount zero whose pairing the kind
|
|
39
|
+
* does not name as taking zero, and a form outside the pairings the module the payment goes to submits, are refused
|
|
40
40
|
* `invalid_payment_requirements`.
|
|
41
41
|
*/
|
|
42
42
|
export declare function declared(kind: Kind, module: Module, p: X402Payment, i: Instrumented, phase: Phase): string | undefined;
|
package/dist/wrapper.js
CHANGED
|
@@ -21,7 +21,7 @@ export function kindOf(r, feeBudget) {
|
|
|
21
21
|
scheme: r.module.facilitator.scheme,
|
|
22
22
|
network: r.network,
|
|
23
23
|
key: keys[0] ?? "none",
|
|
24
|
-
acceptsZero: modules.every((m) => m.descriptor.acceptsZero),
|
|
24
|
+
acceptsZero: pairings.filter((id) => modules.every((m) => !m.descriptor.pairings.includes(id) || m.descriptor.acceptsZero.includes(id))),
|
|
25
25
|
pairings,
|
|
26
26
|
feeBudget,
|
|
27
27
|
};
|
|
@@ -47,12 +47,12 @@ function optionAmount(kind, p, phase) {
|
|
|
47
47
|
return String(phase === "settle" && kind.scheme === "upto" ? p.payload.accepted?.amount : p.requirements.amount);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* The kind's declaration, held to a payment before the class is asked: an option of amount zero
|
|
51
|
-
* not
|
|
50
|
+
* The kind's declaration, held to a payment before the class is asked: an option of amount zero whose pairing the kind
|
|
51
|
+
* does not name as taking zero, and a form outside the pairings the module the payment goes to submits, are refused
|
|
52
52
|
* `invalid_payment_requirements`.
|
|
53
53
|
*/
|
|
54
54
|
export function declared(kind, module, p, i, phase) {
|
|
55
|
-
if (
|
|
55
|
+
if (/^0+$/.test(optionAmount(kind, p, phase)) && !kind.acceptsZero.includes(i.pairing))
|
|
56
56
|
return "invalid_payment_requirements";
|
|
57
57
|
if (!module.descriptor.pairings.includes(i.pairing))
|
|
58
58
|
return "invalid_payment_requirements";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@integraledger/profile-facilitator",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "An x402 facilitator for the pairings @integraledger/lcp ships: it checks, submits what the payer signed, records each payment once in Postgres, and answers what the chain shows, with one module per chain form on x402's published facilitator classes where x402 publishes them.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"engines": {
|
|
@@ -49,10 +49,11 @@
|
|
|
49
49
|
"files": [
|
|
50
50
|
"dist",
|
|
51
51
|
"README.md",
|
|
52
|
+
"CHANGELOG.md",
|
|
52
53
|
"LICENSE"
|
|
53
54
|
],
|
|
54
55
|
"peerDependencies": {
|
|
55
|
-
"@integraledger/lcp": "~0.6.
|
|
56
|
+
"@integraledger/lcp": "~0.6.3"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
59
|
"@algorandfoundation/algokit-utils": "10.0.0-alpha.46",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
"xrpl": "4.7.0"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
|
-
"@integraledger/lcp": "0.6.
|
|
87
|
+
"@integraledger/lcp": "0.6.3",
|
|
87
88
|
"vitest": "5.0.4"
|
|
88
89
|
},
|
|
89
90
|
"scripts": {
|