@integraledger/profile-facilitator 0.3.1 → 0.5.0
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/README.md +642 -456
- package/dist/answers.d.ts +11 -4
- package/dist/answers.js +24 -0
- package/dist/core.d.ts +51 -0
- package/dist/core.js +758 -0
- package/dist/http.d.ts +20 -3
- package/dist/http.js +32 -7
- package/dist/index.d.ts +12 -36
- package/dist/index.js +9 -162
- package/dist/module.d.ts +372 -0
- package/dist/module.js +13 -0
- package/dist/modules/algorand/index.d.ts +22 -0
- package/dist/modules/algorand/index.js +247 -0
- package/dist/modules/algorand/own.d.ts +26 -0
- package/dist/modules/algorand/own.js +231 -0
- package/dist/modules/aptos/index.d.ts +23 -0
- package/dist/modules/aptos/index.js +232 -0
- package/dist/modules/cardano/index.d.ts +18 -0
- package/dist/modules/cardano/index.js +124 -0
- package/dist/modules/casper/index.d.ts +120 -0
- package/dist/modules/casper/index.js +442 -0
- package/dist/modules/concordium/index.d.ts +16 -0
- package/dist/modules/concordium/index.js +77 -0
- package/dist/modules/erc7710/index.d.ts +26 -0
- package/dist/modules/erc7710/index.js +220 -0
- package/dist/modules/evm/forms.d.ts +74 -0
- package/dist/modules/evm/forms.js +182 -0
- package/dist/modules/evm/index.d.ts +40 -0
- package/dist/modules/evm/index.js +148 -0
- package/dist/modules/evm/node.d.ts +29 -0
- package/dist/modules/evm/node.js +222 -0
- package/dist/modules/hedera/executor.d.ts +63 -0
- package/dist/modules/hedera/executor.js +343 -0
- package/dist/modules/hedera/index.d.ts +23 -0
- package/dist/modules/hedera/index.js +136 -0
- package/dist/modules/hedera/mirror.d.ts +32 -0
- package/dist/modules/hedera/mirror.js +111 -0
- package/dist/modules/index.d.ts +23 -0
- package/dist/modules/index.js +24 -0
- package/dist/modules/lnbtc/index.d.ts +10 -0
- package/dist/modules/lnbtc/index.js +111 -0
- package/dist/modules/near/index.d.ts +18 -0
- package/dist/modules/near/index.js +246 -0
- package/dist/modules/polkadot/index.d.ts +12 -0
- package/dist/modules/polkadot/index.js +149 -0
- package/dist/modules/polkadot/rail.d.ts +40 -0
- package/dist/{polkadot.js → modules/polkadot/rail.js} +214 -288
- package/dist/modules/solana/index.d.ts +60 -0
- package/dist/modules/solana/index.js +304 -0
- package/dist/modules/solana/reader.d.ts +25 -0
- package/dist/modules/solana/reader.js +194 -0
- package/dist/modules/solana/state.d.ts +6 -0
- package/dist/modules/solana/state.js +103 -0
- package/dist/modules/starknet/index.d.ts +35 -0
- package/dist/modules/starknet/index.js +541 -0
- package/dist/modules/starknet/node.d.ts +78 -0
- package/dist/modules/starknet/node.js +339 -0
- package/dist/modules/stellar/index.d.ts +44 -0
- package/dist/modules/stellar/index.js +481 -0
- package/dist/modules/stellar/node.d.ts +57 -0
- package/dist/modules/stellar/node.js +151 -0
- package/dist/modules/sui/index.d.ts +16 -0
- package/dist/modules/sui/index.js +309 -0
- package/dist/modules/sui/node.d.ts +49 -0
- package/dist/modules/sui/node.js +197 -0
- package/dist/modules/ton/index.d.ts +16 -0
- package/dist/modules/ton/index.js +73 -0
- package/dist/modules/tron/index.d.ts +12 -0
- package/dist/modules/tron/index.js +120 -0
- package/dist/modules/tron/rail.d.ts +32 -0
- package/dist/{tron.js → modules/tron/rail.js} +206 -195
- package/dist/modules/xrpl/index.d.ts +28 -0
- package/dist/modules/xrpl/index.js +299 -0
- package/dist/modules/xrpl/node.d.ts +52 -0
- package/dist/modules/xrpl/node.js +231 -0
- package/dist/modules/xrpl/upto.d.ts +5 -0
- package/dist/modules/xrpl/upto.js +269 -0
- package/dist/record.d.ts +131 -0
- package/dist/record.js +330 -0
- package/dist/unexpected.d.ts +3 -2
- package/dist/unexpected.js +2 -1
- package/dist/wrapper.d.ts +68 -0
- package/dist/wrapper.js +126 -0
- package/package.json +47 -12
- package/dist/polkadot.d.ts +0 -21
- package/dist/store.d.ts +0 -59
- package/dist/store.js +0 -103
- package/dist/tron.d.ts +0 -12
- /package/dist/{base58check.d.ts → modules/tron/base58check.d.ts} +0 -0
- /package/dist/{base58check.js → modules/tron/base58check.js} +0 -0
package/README.md
CHANGED
|
@@ -1,579 +1,765 @@
|
|
|
1
1
|
# @integraledger/profile-facilitator
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
`
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
The settler: an x402 facilitator for the x402 pairings that
|
|
4
|
+
[`@integraledger/lcp`](https://www.npmjs.com/package/@integraledger/lcp) ships. A resource server calls it over x402's
|
|
5
|
+
facilitator API, one HTTP surface: `GET /supported`, `POST /verify` and `POST /settle`. It checks each payment against
|
|
6
|
+
its pairing's profile and the requirements it answers, submits what the payer signed, records each payment once in
|
|
7
|
+
Postgres, and answers what the chain shows.
|
|
8
8
|
|
|
9
9
|
## What it is
|
|
10
10
|
|
|
11
|
-
In x402, a **facilitator** is the role that verifies a payment and settles it on its network,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Approving that transaction is then the buyer's acceptance of that exact record, and the proof is on chain.
|
|
16
|
-
|
|
17
|
-
| Profile | `network` | `extra.assetTransferMethod` | Where H rides |
|
|
18
|
-
|---|---|---|---|
|
|
19
|
-
| `x402/exact/tron/lcp-trc20-memo` | `tron:<chain id in decimal>` | `lcp-trc20-memo` | The transaction's `raw_data.data`: the 77 ASCII bytes `lcp:sha256:` followed by H, beside one TRC-20 `transfer(payTo, amount)`. |
|
|
20
|
-
| `x402/exact/polkadot/lcp-assets-remark` | `polkadot:68d56f15f85d3136970ec16946040bc1` (Polkadot Asset Hub) or `polkadot:67f9723393ef76214df0118c34bbbd3d` (Westend Asset Hub) | `lcp-assets-remark` | `system.remark_with_event(R)`, where R is exactly `lcp:sha256:` followed by H in lowercase hex, batched with `assets.transfer_keep_alive` in one `utility.batch_all`. |
|
|
21
|
-
|
|
22
|
-
This package implements each profile's rule 5, the facilitator's duties. The profiles themselves are published with
|
|
23
|
-
`@integraledger/lcp`, in [its repository at 0.4.0](https://github.com/IntegraLedger/integra-protocol/tree/v0.4.0/lcp/profiles), the release this package pins.
|
|
11
|
+
In x402, a **facilitator** is the role that verifies a payment and settles it on its network. The resource server, the
|
|
12
|
+
seller's x402 server, sends it the buyer's payment and the requirements that payment answers. `POST /verify` says
|
|
13
|
+
whether the payment is valid, `POST /settle` submits it and answers with the transaction, and `GET /supported` lists the
|
|
14
|
+
kinds of payment it serves. The seller chooses its facilitator.
|
|
24
15
|
|
|
25
|
-
The
|
|
26
|
-
|
|
16
|
+
The Legal Context Protocol (LCP) binds a payment to the agreement's record: the payer's signed act carries the **ATR
|
|
17
|
+
hash (H)**, SHA-256 over the exact bytes of the Agentic Transaction Record (ATR). A **pairing** is one protocol, scheme
|
|
18
|
+
and rail, and its profile, published with `@integraledger/lcp`, fixes where H rides
|
|
19
|
+
([the pairing registry](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/reference/pairings.md)).
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
The settler runs x402's own facilitator class, `x402Facilitator` of `@x402/core` 2.31.0, with one registration for each
|
|
22
|
+
scheme on each configured network. Behind each registration is a **module**: x402's published facilitator class for
|
|
23
|
+
that chain, registered unchanged, or the settler's own facilitator where x402 publishes no class. Around the class the
|
|
24
|
+
settler adds three things:
|
|
29
25
|
|
|
30
|
-
- **
|
|
31
|
-
|
|
32
|
-
- **
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
- **
|
|
36
|
-
`x402/exact/tron/lcp-trc20-memo` and `x402/exact/polkadot/lcp-assets-remark`.
|
|
37
|
-
- **Binding:** how H rides in a pairing's payment: here, the Tron memo and the Polkadot remark.
|
|
38
|
-
- **Seller:** the party serving the resource. It calls this facilitator from its x402 resource server.
|
|
39
|
-
- **Facilitator:** the x402 role that verifies and settles.
|
|
40
|
-
- **Deduplication:** each payment is settled at most once, keyed by its network and transaction id, in Postgres.
|
|
26
|
+
- **lcp's checks of the pairing**, made from the payment and its requirements alone before the class is asked: the
|
|
27
|
+
payment carries H in its profile's form, and its form is one the kind declares.
|
|
28
|
+
- **The record**: one row per payment in Postgres, keyed as its profile names the payment (the single-use value its
|
|
29
|
+
signer signed, or its transaction id), so that one payment is submitted once and answered success once, across
|
|
30
|
+
every process that shares the database.
|
|
31
|
+
- **lcp's read of the chain**, which decides whether a payment the class did not answer success for is final.
|
|
41
32
|
|
|
42
33
|
```mermaid
|
|
43
34
|
sequenceDiagram
|
|
44
|
-
participant R as Resource server
|
|
45
|
-
participant
|
|
35
|
+
participant R as Resource server
|
|
36
|
+
participant S as Settler
|
|
46
37
|
participant P as Postgres
|
|
47
|
-
participant N as
|
|
48
|
-
R->>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
R->>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
F->>P: store the answer
|
|
58
|
-
F-->>R: success, transaction, payer
|
|
38
|
+
participant N as Node
|
|
39
|
+
R->>S: POST /verify
|
|
40
|
+
Note over S: lcp's checks, the record, the class's verify, lcp's read
|
|
41
|
+
S-->>R: isValid, payer
|
|
42
|
+
R->>S: POST /settle
|
|
43
|
+
S->>P: claim the payment
|
|
44
|
+
S->>N: the class submits what the payer signed
|
|
45
|
+
S->>N: lcp's read, where the class did not answer success
|
|
46
|
+
S->>P: store the answer
|
|
47
|
+
S-->>R: success, transaction, payer
|
|
59
48
|
```
|
|
60
49
|
|
|
50
|
+
**What it checks, and what it does not.** It checks that the payment carries H in its profile's form. It does not check
|
|
51
|
+
that this H is the one the resource server issued for the request, or that the resource server has not accepted it
|
|
52
|
+
before: those are the resource server's own records
|
|
53
|
+
([the seller guide](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/guides/seller.md)). It checks the
|
|
54
|
+
amount, asset and payee against the requirements because x402 requires that of a facilitator, and carries no business
|
|
55
|
+
or legal logic beyond that.
|
|
56
|
+
|
|
61
57
|
## Install
|
|
62
58
|
|
|
63
59
|
```sh
|
|
64
|
-
npm install @integraledger/profile-facilitator @integraledger/lcp
|
|
60
|
+
npm install @integraledger/profile-facilitator @integraledger/lcp
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
It needs Node.js `>=24.22.1`, Postgres (the tests run on Postgres 18), and, for each network it serves, the node its module
|
|
64
|
+
reads. It is ESM only. `@integraledger/lcp` is its peer dependency: install it with the settler. A module that holds a
|
|
65
|
+
key takes it as the signer object of x402's class for that chain; make it with that chain's x402 package at 2.31.0, the
|
|
66
|
+
release the settler's classes are pinned to (`@x402/evm`, `@x402/svm`, `@x402/avm`, and so on).
|
|
67
|
+
|
|
68
|
+
Two packages in its dependency tree have install scripts that it runs without: `protobufjs` (through `@hiero-ledger/sdk`
|
|
69
|
+
and `@concordium/web-sdk`) and `secp256k1` (through `@x402/near`). This repository installs with both denied, and runs
|
|
70
|
+
the settler's tests so. pnpm 12 stops an install at a build script it has no decision for (`ERR_PNPM_IGNORED_BUILDS`);
|
|
71
|
+
deny both in your `pnpm-workspace.yaml`:
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
permissions:
|
|
75
|
+
protobufjs: {build: false}
|
|
76
|
+
secp256k1: {build: false}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
With npm, `npm install --ignore-scripts` runs neither.
|
|
80
|
+
|
|
81
|
+
A project that installs under pnpm's `trustPolicy: no-downgrade`, as this repository does, excludes exactly two
|
|
82
|
+
versions from it, and nothing wider:
|
|
83
|
+
|
|
84
|
+
```yaml
|
|
85
|
+
trustPolicy: no-downgrade
|
|
86
|
+
trustPolicyExclude:
|
|
87
|
+
- '@noble/ed25519@1.7.5'
|
|
88
|
+
- '@noble/secp256k1@1.7.2'
|
|
65
89
|
```
|
|
66
90
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
The Casper module registers `@x402/casper` 2.31.0, which pins `casper-js-sdk` 5.1.1; every `casper-js-sdk` from 5.1.1
|
|
92
|
+
to 5.3.1 requires `@noble/ed25519` `^1.7.5` and `@noble/secp256k1` `^1.7.2`, with which it verifies a payer's ed25519
|
|
93
|
+
and secp256k1 signatures and signs with the settler's key, and no version of either package avoids them. Both were
|
|
94
|
+
published in April 2025 as maintenance releases of the packages' 1.x lines without provenance, after each package's
|
|
95
|
+
2.1.0 had been published with it in March 2024, so `no-downgrade` refuses them. Every other version of the two
|
|
96
|
+
packages, and every other package, stays under the policy.
|
|
97
|
+
|
|
98
|
+
A pnpm project that turns hoisting off (`hoist: false`) also declares, for the Concordium module, the one dependency
|
|
99
|
+
`@concordium/web-sdk` 12.0.2 imports without declaring it, `@protobuf-ts/runtime`; without it the module does not load
|
|
100
|
+
("Cannot find package '@protobuf-ts/runtime'"). With hoisting on, pnpm's default, and with npm, nothing is needed.
|
|
101
|
+
|
|
102
|
+
```yaml
|
|
103
|
+
packageExtensions:
|
|
104
|
+
"@concordium/web-sdk@12.0.2":
|
|
105
|
+
dependencies:
|
|
106
|
+
"@protobuf-ts/runtime": "2.11.1"
|
|
107
|
+
```
|
|
73
108
|
|
|
74
109
|
## Quickstart
|
|
75
110
|
|
|
76
|
-
Start the
|
|
77
|
-
|
|
78
|
-
connection string.
|
|
111
|
+
Start the settler for Tron mainnet and Polkadot Asset Hub, and read what it supports. Neither module holds a key, so
|
|
112
|
+
this deployment needs no credential. The node URLs are your own nodes; the settler calls them only when a payment
|
|
113
|
+
arrives. `DATABASE_URL` is your Postgres connection string.
|
|
79
114
|
|
|
80
|
-
```ts title="supported.ts"
|
|
115
|
+
```ts no-check title="supported.ts"
|
|
81
116
|
import { serveProfileFacilitator } from "@integraledger/profile-facilitator";
|
|
82
117
|
|
|
83
|
-
const
|
|
118
|
+
const settler = await serveProfileFacilitator({
|
|
84
119
|
listen: "127.0.0.1:4020",
|
|
85
|
-
tron: [{ network: "tron:728126428", fullNode: "http://127.0.0.1:8090", solidityNode: "http://127.0.0.1:8091" }],
|
|
86
|
-
polkadot: [{ network: "polkadot:68d56f15f85d3136970ec16946040bc1", rpc: "http://127.0.0.1:9944" }],
|
|
87
120
|
store: { url: process.env.DATABASE_URL ?? "postgres://postgres@127.0.0.1:5432/postgres" },
|
|
88
121
|
settleWaitMs: 30_000,
|
|
122
|
+
tron: [{ network: "tron:728126428", fullNode: "http://127.0.0.1:8090", solidityNode: "http://127.0.0.1:8091" }],
|
|
123
|
+
polkadot: [{ network: "polkadot:68d56f15f85d3136970ec16946040bc1", rpc: "http://127.0.0.1:9944" }],
|
|
89
124
|
});
|
|
90
125
|
|
|
91
126
|
const supported = await (await fetch("http://127.0.0.1:4020/supported")).json();
|
|
92
127
|
console.log(JSON.stringify(supported, null, 2));
|
|
93
|
-
await
|
|
128
|
+
await settler.close();
|
|
94
129
|
```
|
|
95
130
|
|
|
96
|
-
```text
|
|
131
|
+
```text
|
|
97
132
|
{
|
|
98
133
|
"kinds": [
|
|
99
134
|
{
|
|
100
135
|
"x402Version": 2,
|
|
101
136
|
"scheme": "exact",
|
|
102
|
-
"network": "
|
|
137
|
+
"network": "polkadot:68d56f15f85d3136970ec16946040bc1",
|
|
103
138
|
"extra": {
|
|
104
|
-
"assetTransferMethod": "lcp-
|
|
139
|
+
"assetTransferMethod": "lcp-assets-remark",
|
|
140
|
+
"key": "none",
|
|
141
|
+
"acceptsZero": false,
|
|
142
|
+
"pairings": [
|
|
143
|
+
"x402/exact/polkadot/lcp-assets-remark"
|
|
144
|
+
]
|
|
105
145
|
}
|
|
106
146
|
},
|
|
107
147
|
{
|
|
108
148
|
"x402Version": 2,
|
|
109
149
|
"scheme": "exact",
|
|
110
|
-
"network": "
|
|
150
|
+
"network": "tron:728126428",
|
|
111
151
|
"extra": {
|
|
112
|
-
"assetTransferMethod": "lcp-
|
|
152
|
+
"assetTransferMethod": "lcp-trc20-memo",
|
|
153
|
+
"key": "none",
|
|
154
|
+
"acceptsZero": false,
|
|
155
|
+
"pairings": [
|
|
156
|
+
"x402/exact/tron/lcp-trc20-memo"
|
|
157
|
+
]
|
|
113
158
|
}
|
|
114
159
|
}
|
|
115
160
|
],
|
|
116
161
|
"extensions": [],
|
|
117
|
-
"signers": {
|
|
162
|
+
"signers": {
|
|
163
|
+
"polkadot:*": [],
|
|
164
|
+
"tron:*": []
|
|
165
|
+
}
|
|
118
166
|
}
|
|
119
167
|
```
|
|
120
168
|
|
|
121
|
-
## Run it
|
|
169
|
+
## Run it as a service
|
|
122
170
|
|
|
123
171
|
The package exports one function that starts the server; it has no command-line entry. A service is a short module
|
|
124
|
-
that reads its configuration and stops cleanly on a signal
|
|
172
|
+
that reads its configuration, makes the signer objects its keyed modules take, and stops cleanly on a signal. This one
|
|
173
|
+
serves x402's `exact` scheme on Base Sepolia through the `evm` module, whose key, the seller's gas key, sends each
|
|
174
|
+
transaction and pays its gas:
|
|
125
175
|
|
|
126
|
-
```ts title="
|
|
176
|
+
```ts no-check title="settler.ts"
|
|
127
177
|
import { serveProfileFacilitator } from "@integraledger/profile-facilitator";
|
|
178
|
+
import { toFacilitatorEvmSigner } from "@x402/evm";
|
|
179
|
+
import { createWalletClient, http, publicActions, type Hex } from "viem";
|
|
180
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
181
|
+
import { baseSepolia } from "viem/chains";
|
|
182
|
+
|
|
183
|
+
const rpc = process.env.BASE_SEPOLIA_RPC ?? "http://127.0.0.1:8545";
|
|
184
|
+
const credential = process.env.SETTLER_CREDENTIAL;
|
|
185
|
+
const gasKey = process.env.SELLER_GAS_KEY as Hex | undefined;
|
|
186
|
+
if (credential === undefined || gasKey === undefined) throw new Error("set SETTLER_CREDENTIAL and SELLER_GAS_KEY");
|
|
187
|
+
|
|
188
|
+
// The seller's gas key, as x402's EVM classes take it.
|
|
189
|
+
const account = privateKeyToAccount(gasKey);
|
|
190
|
+
const client = createWalletClient({ account, chain: baseSepolia, transport: http(rpc) }).extend(publicActions);
|
|
191
|
+
const signer = toFacilitatorEvmSigner({
|
|
192
|
+
address: account.address,
|
|
193
|
+
getCode: (a) => client.getCode(a),
|
|
194
|
+
readContract: (a) => client.readContract({ ...a, args: a.args ?? [] } as never),
|
|
195
|
+
verifyTypedData: (a) => client.verifyTypedData(a as never),
|
|
196
|
+
writeContract: (a) => client.writeContract({ ...a, args: a.args ?? [] } as never),
|
|
197
|
+
sendTransaction: (a) => client.sendTransaction(a as never),
|
|
198
|
+
waitForTransactionReceipt: (a) => client.waitForTransactionReceipt(a) as never,
|
|
199
|
+
simulateCalls: (a) => client.simulateCalls(a as never) as never,
|
|
200
|
+
});
|
|
128
201
|
|
|
129
202
|
const listen = process.env.LISTEN ?? "127.0.0.1:4021";
|
|
130
|
-
const
|
|
203
|
+
const settler = await serveProfileFacilitator({
|
|
131
204
|
listen,
|
|
132
|
-
tron: [
|
|
133
|
-
{
|
|
134
|
-
network: "tron:728126428",
|
|
135
|
-
fullNode: process.env.TRON_FULL_NODE ?? "http://127.0.0.1:8090",
|
|
136
|
-
solidityNode: process.env.TRON_SOLIDITY_NODE ?? "http://127.0.0.1:8091",
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
205
|
store: { url: process.env.DATABASE_URL ?? "postgres://postgres@127.0.0.1:5432/postgres" },
|
|
140
|
-
settleWaitMs:
|
|
206
|
+
settleWaitMs: 30_000,
|
|
207
|
+
credential,
|
|
208
|
+
evm: [{ network: "eip155:84532", rpc, signer, schemes: ["exact"] }],
|
|
209
|
+
// At most 0.01 ETH of gas in any 24 hours; past it, payments whose gas the key pays are refused.
|
|
210
|
+
feeBudgets: [{ network: "eip155:84532", amount: "10000000000000000", periodSeconds: 86_400 }],
|
|
141
211
|
});
|
|
142
212
|
for (const signal of ["SIGINT", "SIGTERM"] as const) {
|
|
143
213
|
process.once(signal, () => {
|
|
144
|
-
void
|
|
214
|
+
void settler.close().then(() => process.exit(0));
|
|
145
215
|
});
|
|
146
216
|
}
|
|
147
|
-
console.log(`
|
|
217
|
+
console.log(`settler listening on ${listen}`);
|
|
148
218
|
```
|
|
149
219
|
|
|
150
|
-
```text
|
|
151
|
-
|
|
220
|
+
```text
|
|
221
|
+
settler listening on 127.0.0.1:4021
|
|
152
222
|
```
|
|
153
223
|
|
|
154
|
-
Run it with `node
|
|
155
|
-
|
|
224
|
+
Run it with `node settler.ts`: Node.js 26 runs TypeScript directly. Every call must then carry
|
|
225
|
+
`Authorization: Bearer <credential>`. Its `/supported` states:
|
|
156
226
|
|
|
157
|
-
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"kinds": [
|
|
230
|
+
{
|
|
231
|
+
"x402Version": 2,
|
|
232
|
+
"scheme": "exact",
|
|
233
|
+
"network": "eip155:84532",
|
|
234
|
+
"extra": {
|
|
235
|
+
"key": "relayer",
|
|
236
|
+
"acceptsZero": false,
|
|
237
|
+
"pairings": ["x402/exact/eip155/eip3009", "x402/exact/eip155/permit2"],
|
|
238
|
+
"feeBudget": true
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
],
|
|
242
|
+
"extensions": [],
|
|
243
|
+
"signers": { "eip155:*": ["<the gas key's address>"] }
|
|
244
|
+
}
|
|
245
|
+
```
|
|
158
246
|
|
|
159
|
-
`
|
|
247
|
+
`close()` stops accepting requests, closes open connections, closes what each module opened (the Polkadot nodes'
|
|
248
|
+
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.
|
|
160
250
|
|
|
161
|
-
|
|
251
|
+
## Configuration
|
|
252
|
+
|
|
253
|
+
`serveProfileFacilitator(config)` takes a `ProfileFacilitatorConfig`: the core's members, and one member for each module
|
|
254
|
+
the deployment starts, named for the module. A module whose member is absent is neither loaded nor started.
|
|
255
|
+
|
|
256
|
+
### The core's members
|
|
257
|
+
|
|
258
|
+
| Member | Type | Meaning |
|
|
162
259
|
|---|---|---|
|
|
163
260
|
| `listen` | `string` | `"host:port"`; an IPv6 host may be written in brackets. |
|
|
164
|
-
| `
|
|
165
|
-
| `
|
|
166
|
-
| `
|
|
167
|
-
| `
|
|
168
|
-
| `operatorLog` | `(entry, cause?) => void`, optional | Receives every entry for the operator (
|
|
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. |
|
|
262
|
+
| `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
|
+
| `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
|
+
| `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
|
+
| `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
|
+
|
|
267
|
+
### The modules
|
|
268
|
+
|
|
269
|
+
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. The network is the CAIP-2 id lcp's type for the chain
|
|
271
|
+
names (`eip155:<chain id>`, `solana:<genesis hash prefix>`, and so on).
|
|
272
|
+
|
|
273
|
+
| Member | Chain | Scheme: pairings | `extra.key` | `extra.acceptsZero` | Facilitator |
|
|
274
|
+
|---|---|---|---|---|---|
|
|
275
|
+
| `algorand` | Algorand | `exact`: `x402/exact/algorand` | `fee-payer` | `true` | `@x402/avm`'s class; the settler's own path for a rekeyed payer signing with one key and a Falcon-key payer |
|
|
276
|
+
| `aptos` | Aptos | `exact`: `x402/exact/aptos` | `fee-payer`, or `none` with `sponsor: false` | `false` | `@x402/aptos`'s class |
|
|
277
|
+
| `cardano` | Cardano | `exact`: `x402/exact/cardano`, `x402/exact/cardano/lock` | `none` | `false` | `@x402/cardano`'s class |
|
|
278
|
+
| `casper` | Casper | `exact`: `x402/exact/casper` | `relayer` | `false` | `@x402/casper`'s class |
|
|
279
|
+
| `concordium` | Concordium | `exact`: `x402/exact/ccd` | `fee-payer` | `true` | `@x402/concordium`'s class |
|
|
280
|
+
| `evm` | EVM | `exact`: `x402/exact/eip155/eip3009`, `x402/exact/eip155/permit2`; `upto`: `x402/upto/eip155/permit2`; `auth-capture`: `x402/auth-capture/eip155/eip3009`, `x402/auth-capture/eip155/permit2`; `batch-settlement`: `x402/batch-settlement/eip155` | `relayer` | `false` | `@x402/evm`'s classes |
|
|
281
|
+
| `erc7710` | EVM | `exact` with `erc7710`: `x402/exact/eip155/erc7710`, `x402/exact/eip155/erc7710-salt` | `relayer` | `false` | the settler's own, behind the `evm` module's `exact` |
|
|
282
|
+
| `hedera` | Hedera | `exact`: `x402/exact/hedera` | `fee-payer` | `false` | `@x402/hedera`'s class |
|
|
283
|
+
| `lnbtc` | Lightning | `exact`: `x402/exact/lnbtc/payment-hash` | `none` | `false` | the settler's own |
|
|
284
|
+
| `near` | NEAR | `exact`: `x402/exact/near` | `relayer` | `false` | `@x402/near`'s class |
|
|
285
|
+
| `polkadot` | Polkadot Asset Hub | `exact`: `x402/exact/polkadot/lcp-assets-remark` | `none` | `false` | the settler's own |
|
|
286
|
+
| `solana` | Solana | `exact`: `x402/exact/solana`; `upto`: `x402/upto/solana`; `batch-settlement`: `x402/batch-settlement/solana` | `fee-payer` | `true` on `exact`, `false` on the others | `@x402/svm`'s classes |
|
|
287
|
+
| `starknet` | Starknet | `exact`: `x402/exact/starknet` | `relayer` | `false` | the settler's own |
|
|
288
|
+
| `stellar` | Stellar | `exact` with `lcp-precondition`: `x402/exact/stellar/precondition` | `relayer` | `true` | the settler's own |
|
|
289
|
+
| `sui` | Sui | `exact`: `x402/exact/sui` | `none` | `false` | the settler's own |
|
|
290
|
+
| `ton` | TON | `exact`: `x402/exact/tvm` | `relayer` | `true` | `@x402/tvm`'s class |
|
|
291
|
+
| `tron` | Tron | `exact`: `x402/exact/tron/lcp-trc20-memo` | `none` | `false` | the settler's own |
|
|
292
|
+
| `xrpl` | XRP Ledger | `exact`: `x402/exact/xrpl`; `upto`: `x402/upto/xrpl` | `none` | `false` | `@x402/xrpl`'s class for a payer signing with one key; the settler's own for a multisigned payer and for `upto` |
|
|
293
|
+
|
|
294
|
+
Each member, one entry per network unless it says otherwise:
|
|
295
|
+
|
|
296
|
+
- **`algorand`**: `network`; `signer`, the seller's fee payer as `@x402/avm`'s class takes it (`FacilitatorAvmSigner`),
|
|
297
|
+
with its algod node; `indexer`, the seller's Indexer, which lcp's read uses; `archival`, optional, true where that
|
|
298
|
+
Indexer holds every round. The fee payer pools the group's fee by its own zero-amount payment in the same atomic
|
|
299
|
+
group. The class signs every entry of the group that one of the key's addresses sends, so a group may hold one such
|
|
300
|
+
entry, and only where the option's `extra.feePayer` names its sender: a group with two, or with one the option's
|
|
301
|
+
`extra.feePayer` does not name, is refused `invalid_exact_avm_invalid_fee_payer`; with no `extra.feePayer` the buyer
|
|
302
|
+
pays its own fee. An entry a logic signature authorises, and one that names `asnd`, are refused before anything
|
|
303
|
+
moves.
|
|
304
|
+
- **`aptos`**: `network`; `signer`, the seller's account (`FacilitatorAptosSigner`); `sponsor`, optional, whether the
|
|
305
|
+
key pays the payer's gas as its fee payer (default true, the class's own default); `node`, the seller's REST endpoint,
|
|
306
|
+
its base without `/v1`. With `sponsor: false` the payer pays its own gas and the key signs nothing: the kind states
|
|
307
|
+
`extra.key` `none` and `/supported` names no signer for it, and an option that names an `extra.feePayer` is refused
|
|
308
|
+
`invalid_payment_requirements` before the class is asked, since the class pays the gas of any payment whose option
|
|
309
|
+
names one of the key's addresses.
|
|
310
|
+
- **`cardano`**: `network`; `signer`, the chain-query object `@x402/cardano`'s class takes over the seller's provider (a
|
|
311
|
+
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. The class reads a transaction's confirmations from Blockfrost
|
|
313
|
+
alone: over Koios alone it sees none, so an option it settles there states `extra.confirmationPolicy` as
|
|
314
|
+
`{ "l1Confirmations": 0 }`, and an option that states none, whose default asks one confirmation, is refused at `/verify`
|
|
315
|
+
(`@x402/cardano` 2.31.0, `dist/esm/index.mjs:483-492`, `dist/esm/chunk-C7JT2R6E.mjs:38`, `:116-117`). A provider with a
|
|
316
|
+
Blockfrost project serves an option that asks confirmations. `/settle` answers success where the class does, and
|
|
317
|
+
otherwise once lcp's read through `reader` shows the transaction final, at the ledger's security parameter of
|
|
318
|
+
confirmations (2160 on mainnet and Preprod, some 12 hours); until then it answers `settlement_pending` naming the
|
|
319
|
+
transaction. Over Koios alone the class's settle gives no success, so a payment is answered at that mark. Its guard
|
|
320
|
+
against broadcasting one transaction twice is kept in the settler's database, so a repeat after a restart resumes
|
|
321
|
+
observing what was broadcast.
|
|
322
|
+
- **`casper`**: `network`, `casper:casper-test` (the settler does not start on `casper:casper`: see *What it does not
|
|
323
|
+
serve*); `signer`, the seller's key as `@x402/casper`'s class takes it (`FacilitatorCasperSigner`, made with its
|
|
324
|
+
`toFacilitatorCasperSigner` and an `rpcUrlConfig` that names `rpc` for the network), which sends the transaction that
|
|
325
|
+
calls the token package's `transfer_with_authorization` with the payer's CEP-3009 authorization, and pays its gas;
|
|
326
|
+
`rpc`, the seller's node, through which the class reads the token before it settles, lcp's read finds the payment and
|
|
327
|
+
the fee count reads its cost. The settler does not start where the signer names another node, as `@x402/casper`'s
|
|
328
|
+
signer does for a network its `rpcUrlConfig` leaves out, falling back to a public node, nor where its
|
|
329
|
+
`speculativeRpcUrlConfig` names a node other than `rpc`: with one, the class's check has the key sign a deploy of the
|
|
330
|
+
payer's authorization at every `/verify` and `/settle` and sends it there for speculative execution. `paymentMotes`,
|
|
331
|
+
optional, is the most the transaction can pay, in motes (`@x402/casper`'s default, 2.5 CSPR, where absent), which the
|
|
332
|
+
fee budget counts from the transaction's submission until the node shows the cost. The class refuses a zero amount.
|
|
333
|
+
`signers` lists the key's account hash, 64 hex digits without the `00` tag a payload's address carries. The class's
|
|
334
|
+
node calls and lcp's read carry no header of the seller's, so a node credential reaches the node only within `rpc`'s
|
|
335
|
+
URL; and the class waits up to a minute for its transaction, its node calls without a timeout of their own, so its
|
|
336
|
+
settle can run past `settleWaitMs`. lcp's read takes the token's used nonces from its dictionary
|
|
337
|
+
`used_nonces`, as lcp's profile names it, where the class's check before it settles reads `authorization_state`.
|
|
338
|
+
- **`concordium`**: `network`, the one the signer is connected to; `signer`, the seller's sponsor account and its key
|
|
339
|
+
with its node (`FacilitatorConcordiumSigner`), which co-signs the payer's sponsored transaction and pays its energy;
|
|
340
|
+
`reader`, lcp's `CcdReader` over the seller's node. The record names each payment by the digest of what its sender
|
|
341
|
+
signed, so a payment is never sent twice.
|
|
342
|
+
- **`evm`**: `network`; `rpc`, the seller's JSON-RPC endpoint, which lcp's reads and the fee's read go through; `signer`,
|
|
343
|
+
the seller's gas key (`FacilitatorEvmSigner`, made with `toFacilitatorEvmSigner` over the same node); `schemes`,
|
|
344
|
+
optional, the schemes registered (`exact`, `upto`, `auth-capture`, `batch-settlement`; all four where absent);
|
|
345
|
+
`eip6492AllowedFactories`, optional, the ERC-6492 factories `exact` and `batch-settlement` may call to deploy a payer's
|
|
346
|
+
wallet (none where absent); `authCapture`, optional, `auth-capture`'s own configuration, passed to its class
|
|
347
|
+
unchanged. Before the class is asked, `exact` refuses an option that pays several payees (a non-empty
|
|
348
|
+
`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.
|
|
350
|
+
- **`erc7710`**: `network`; `rpc`; `signer`, the seller's gas key, whose node must answer `eth_simulateV1`. The key
|
|
351
|
+
sends from its first address, so that address is the delegate the leaf delegation must name (or the reference
|
|
352
|
+
implementation's wildcard delegate), and the account the simulation runs from. It registers nothing of its own: on
|
|
353
|
+
each of its networks it is offered to the `evm` module's `exact` registration, which hands it every payment whose
|
|
354
|
+
option names `erc7710`. The settler does not start where the `evm` module does not register `exact` on such a
|
|
355
|
+
network. It simulates the redemption the payment names, then calls `redeemDelegations` on the delegation manager the
|
|
356
|
+
payload names, with one execution that transfers the option's amount to `payTo`.
|
|
357
|
+
- **`hedera`**: `network`; `signer`, the seller's fee-payer account and its key (`FacilitatorHederaSigner`): the class
|
|
358
|
+
takes only a payment whose transaction id names an account it manages as `extra.feePayer`; `mirror`, the seller's
|
|
359
|
+
Mirror Node REST base URL, which lcp's read and the fee count use; `archival`, optional, true where it holds every
|
|
360
|
+
record since the network began. `@x402/hedera` 2.31.0 makes the signer from its parts rather than from a key alone:
|
|
361
|
+
`toFacilitatorHederaSigner` over `signAndSubmitTransaction` from `createHederaSignAndSubmitTransaction` (a client per
|
|
362
|
+
network, such as `createHederaClient`'s, and the fee payer's `PrivateKey`), `verifyPayerSignature` from
|
|
363
|
+
`createHederaVerifyPayerSignature`, and `preflightTransfer` from `createHederaPreflightTransfer`.
|
|
364
|
+
- **`lnbtc`**: `network`, x402's `lnbtc` id of Bitcoin mainnet (`lnbtc:000000000019d6689c085ae165831e93`) or testnet3
|
|
365
|
+
(`lnbtc:000000000933ea01ad0ee984209779ba`). The buyer's node paid the invoice before the preimage reached the buyer,
|
|
366
|
+
so settling moves nothing: the module makes the scheme's validation through lcp's `validateExactLnbtc`, answers the
|
|
367
|
+
invoice's payment hash as the transaction, names no payer, and reads nothing. x402's scheme forbids `/verify` for
|
|
368
|
+
this flow, so `/verify` answers `unsupported_scheme`; `/settle` makes the validation before the record's claim.
|
|
369
|
+
- **`near`**: `network`; `signer`, the seller's relayer account and key with its RPC node (`FacilitatorNearSigner`),
|
|
370
|
+
which wraps the payer's NEP-366 delegate action in a transaction of its own and pays its gas and one-yoctoNEAR
|
|
371
|
+
deposit; `rpc`, the seller's RPC node.
|
|
372
|
+
- **`polkadot`**: `network`, `polkadot:68d56f15f85d3136970ec16946040bc1` (Polkadot Asset Hub) or
|
|
373
|
+
`polkadot:67f9723393ef76214df0118c34bbbd3d` (Westend Asset Hub); `rpc`, an HTTP JSON-RPC endpoint. The payer signs
|
|
374
|
+
and pays every fee. A node that keeps the state of every block (an archive node) gives the events of any block; a
|
|
375
|
+
pruning node discards the state of older blocks, and a block that holds the extrinsic and whose state is discarded
|
|
376
|
+
keeps the answer `settlement_pending`. The runtime metadata is loaded on the first payment for the network, and again
|
|
377
|
+
whenever the node's runtime version changes. A success names `<block hash>-<extrinsic index>`; a pending answer
|
|
378
|
+
names the extrinsic's hash.
|
|
379
|
+
- **`solana`**: `network`; `node`, the seller's JSON-RPC endpoint, one whose `getFirstAvailableBlock` is at or below the
|
|
380
|
+
slot at which each payment was issued; `signer`, the seller's fee payer (`FacilitatorSvmSigner`), which co-signs every
|
|
381
|
+
transaction the payer signed and, on the channel forms, pays the channel's rent; `transactionVersions`, optional, the
|
|
382
|
+
message versions the classes accept (their default `[0, 1]`). `upto` and `batch-settlement` need the payment-channels
|
|
383
|
+
program, which is deployed on devnet and testnet and not on mainnet: on Solana mainnet
|
|
384
|
+
(`solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`) only `exact` is registered. Their channels are kept in the settler's
|
|
385
|
+
database.
|
|
386
|
+
- **`starknet`**: an object `{ networks }`, one entry per network: `network`; `rpc`, a JSON-RPC node (specification 0.9
|
|
387
|
+
or later) that serves `starknet_traceTransaction` and `starknet_simulateTransactions`; `executor`, an `address` and
|
|
388
|
+
its `signer`, the account the payer's outside execution names as its caller, stated as `extra.feePayer`, which
|
|
389
|
+
sends and pays for the transaction that executes it; `maxFee`, optional, the most one settlement's resource bounds
|
|
390
|
+
may pay, in fri; `skewMarginSeconds` (default 60) and `minSettleMarginSeconds` (default 30), optional, the scheme's
|
|
391
|
+
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.
|
|
393
|
+
- **`stellar`**: an object `{ networks }`: `network`; `rpc`, a Stellar RPC endpoint that holds the history the read
|
|
394
|
+
searches; `source`, the seller's funded account as a signer (`address` and `signTransaction`, such as x402's
|
|
395
|
+
`createEd25519Signer` of `@x402/stellar` or a SEP-43 wallet), the transaction's source, which pays its fee;
|
|
396
|
+
`maxTransactionFeeStroops`, optional (default 50,000), and `inclusionFeeStroops`, optional (at least 100, default
|
|
397
|
+
100). It serves the agreement form, the option whose `extra.assetTransferMethod` is `lcp-precondition`: the module
|
|
398
|
+
builds the transaction around the buyer's operation and preconditions, unchanged, signs it as its source, and carries
|
|
399
|
+
the buyer's payload signature with its own.
|
|
400
|
+
- **`sui`**: an object `{ networks }`: `network` (`sui:mainnet`, `sui:testnet` or `sui:devnet`); `graphql`, the seller's
|
|
401
|
+
GraphQL endpoint. It serves the path where the buyer pays gas and the gasless path (`extra.gasless`), and holds no
|
|
402
|
+
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.
|
|
404
|
+
- **`ton`**: `network`; `signer`, the seller's highload-v3 wallet and its node (`FacilitatorTvmSigner`), which relays
|
|
405
|
+
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
|
+
Center v3 index.
|
|
407
|
+
- **`tron`**: `network`, `tron:<chain id in decimal>`; `fullNode` and `solidityNode`, the base URLs of a FullNode that
|
|
408
|
+
keeps the block history (not a lite FullNode) and of a Solidity node, with java-tron's HTTP API. The payer signs and
|
|
409
|
+
pays every fee.
|
|
410
|
+
- **`xrpl`**: `network`; `node`, the seller's rippled or Clio JSON-RPC endpoint, holding the ledgers from each payment's
|
|
411
|
+
issue to the validated ledger; `waitMs`, optional, how long a settle waits for its transaction in a validated ledger
|
|
412
|
+
(default 30 000); `maxFeeDrops`, optional, the most fee a payment may sign (the class's default, 10 000). Both paths
|
|
413
|
+
refuse a payment that names a `Delegate` or carries `Memos`, as x402's scheme requires. For `upto`, the payer opens a
|
|
414
|
+
payment channel to `payTo` and signs one claim off the ledger; at `/settle` the resource server adds
|
|
415
|
+
`settlementTransaction`, a `PaymentChannelClaim` its `payTo` key signed for the actual charge with `tfClose`, which the
|
|
416
|
+
module checks and submits unchanged; `/verify` refuses a payload that already carries one, as the scheme requires.
|
|
417
|
+
|
|
418
|
+
## Keys
|
|
419
|
+
|
|
420
|
+
`extra.key` states what the module's key signs, by one of three values:
|
|
421
|
+
|
|
422
|
+
| `extra.key` | The key | Modules |
|
|
423
|
+
|---|---|---|
|
|
424
|
+
| `none` | The module holds no key and signs nothing: it submits what the payer signed, and the payer pays the fee. | `cardano`, `lnbtc`, `polkadot`, `sui`, `tron`, `xrpl`, and `aptos` with `sponsor: false` |
|
|
425
|
+
| `relayer` | The key sends the transaction and pays its network fee. | `casper`, `erc7710`, `evm`, `near`, `starknet`, `stellar`, `ton` |
|
|
426
|
+
| `fee-payer` | The key co-signs the payer's transaction as the account that pays its fee. | `algorand`, `aptos`, `concordium`, `hedera`, `solana` |
|
|
427
|
+
|
|
428
|
+
Each chain's own name for the role (a gas key, a sponsor, a source account, an executor) stays in its module's notes
|
|
429
|
+
above. The key is always the seller's: the operator's code makes the signer object the module's class takes and passes
|
|
430
|
+
it in the configuration, and its address is in `/supported`'s `signers`. One kind states one purpose: two modules
|
|
431
|
+
behind one registration whose keys sign for different purposes are refused at start.
|
|
432
|
+
|
|
433
|
+
## The credential
|
|
434
|
+
|
|
435
|
+
The resource server names the payee and the amount, and a keyed module pays a fee for whatever it submits, so an open
|
|
436
|
+
settler would spend the seller's money on payments between other parties. A deployment with a module whose key is not
|
|
437
|
+
`none` therefore does not start without `credential`. Every call, `GET /supported` included, must then present it as
|
|
438
|
+
`Authorization: Bearer <credential>`; the settler compares the SHA-256 of what is presented with that of the credential
|
|
439
|
+
in constant time, and answers a call without it `401` `{"error":"unauthorized"}` with `WWW-Authenticate: Bearer`,
|
|
440
|
+
before it reads the body, closing the connection. A keyless deployment may set one too, with the same effect.
|
|
169
441
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
442
|
+
## What `/supported` states
|
|
443
|
+
|
|
444
|
+
`GET /supported` answers `{kinds, extensions, signers}` as x402's facilitator class gives it. Each kind is
|
|
445
|
+
`{x402Version: 2, scheme, network, extra}`, one per scheme on each configured network, and its `extra` holds:
|
|
446
|
+
|
|
447
|
+
| Member | Value |
|
|
448
|
+
|---|---|
|
|
449
|
+
| `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
|
+
| `extra.key` | `none`, `relayer` or `fee-payer` ([Keys](#keys)). |
|
|
451
|
+
| `extra.acceptsZero` | Whether the kind settles a payment of amount zero: true only where every pairing behind it does. A kind that states false refuses an option of amount zero `invalid_payment_requirements`. |
|
|
452
|
+
| `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
|
+
| 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
|
+
|
|
455
|
+
`signers` is keyed as x402's class keys it, by CAIP family (`eip155:*`, `solana:*`, ...), and holds the address of every
|
|
456
|
+
key that signs on that family. A seller reads `extra.key` to know what a deployment must hold, `extra.pairings` to know
|
|
457
|
+
which forms it can offer with this settler, and `extra.acceptsZero` before choosing a zero agreement amount.
|
|
173
458
|
|
|
174
459
|
## Verify and settle
|
|
175
460
|
|
|
176
|
-
Both `POST /verify` and `POST /settle` take
|
|
177
|
-
`{x402Version: 2, paymentPayload, paymentRequirements}`, with `paymentPayload.x402Version` 2
|
|
178
|
-
|
|
461
|
+
Both `POST /verify` and `POST /settle` take x402's facilitator request,
|
|
462
|
+
`{x402Version: 2, paymentPayload, paymentRequirements}`, with `paymentPayload.x402Version` 2. A refusal answers `200`
|
|
463
|
+
with the refusal in its body.
|
|
179
464
|
|
|
180
|
-
```ts title="verify.ts"
|
|
465
|
+
```ts no-check title="verify.ts"
|
|
181
466
|
import { serveProfileFacilitator } from "@integraledger/profile-facilitator";
|
|
182
467
|
|
|
183
|
-
const
|
|
468
|
+
const settler = await serveProfileFacilitator({
|
|
184
469
|
listen: "127.0.0.1:4022",
|
|
185
|
-
tron: [{ network: "tron:728126428", fullNode: "http://127.0.0.1:8090", solidityNode: "http://127.0.0.1:8091" }],
|
|
186
470
|
store: { url: process.env.DATABASE_URL ?? "postgres://postgres@127.0.0.1:5432/postgres" },
|
|
187
471
|
settleWaitMs: 30_000,
|
|
472
|
+
tron: [{ network: "tron:728126428", fullNode: "http://127.0.0.1:8090", solidityNode: "http://127.0.0.1:8091" }],
|
|
188
473
|
});
|
|
189
474
|
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
asset: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
198
|
-
payTo: "TCwX1UeSkVfu43HD5xNMmFqDR2Xgjdxihx",
|
|
199
|
-
maxTimeoutSeconds: 60,
|
|
200
|
-
extra: { assetTransferMethod: "lcp-trc20-memo" },
|
|
201
|
-
},
|
|
475
|
+
const requirements = {
|
|
476
|
+
scheme: "exact",
|
|
477
|
+
amount: "10000",
|
|
478
|
+
asset: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
479
|
+
payTo: "TCwX1UeSkVfu43HD5xNMmFqDR2Xgjdxihx",
|
|
480
|
+
maxTimeoutSeconds: 60,
|
|
481
|
+
extra: { assetTransferMethod: "lcp-trc20-memo" },
|
|
202
482
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
483
|
+
// The first network is configured, and its payload is not a Tron transaction; the second is not configured.
|
|
484
|
+
for (const network of ["tron:728126428", "tron:3448148188"]) {
|
|
485
|
+
const body = {
|
|
486
|
+
x402Version: 2,
|
|
487
|
+
paymentPayload: { x402Version: 2, payload: { transaction: "0a02" } },
|
|
488
|
+
paymentRequirements: { ...requirements, network },
|
|
489
|
+
};
|
|
490
|
+
for (const path of ["/verify", "/settle"]) {
|
|
491
|
+
const res = await fetch(`http://127.0.0.1:4022${path}`, {
|
|
492
|
+
method: "POST",
|
|
493
|
+
headers: { "content-type": "application/json" },
|
|
494
|
+
body: JSON.stringify(body),
|
|
495
|
+
});
|
|
496
|
+
console.log(path, res.status, JSON.stringify(await res.json()));
|
|
497
|
+
}
|
|
210
498
|
}
|
|
211
|
-
await
|
|
499
|
+
await settler.close();
|
|
212
500
|
```
|
|
213
501
|
|
|
214
|
-
```text
|
|
502
|
+
```text
|
|
503
|
+
/verify 200 {"isValid":false,"invalidReason":"invalid_payload"}
|
|
504
|
+
/settle 200 {"success":false,"errorReason":"invalid_payload","transaction":"","network":"tron:728126428"}
|
|
215
505
|
/verify 200 {"isValid":false,"invalidReason":"invalid_network"}
|
|
216
506
|
/settle 200 {"success":false,"errorReason":"invalid_network","transaction":"","network":"tron:3448148188"}
|
|
217
507
|
```
|
|
218
508
|
|
|
219
|
-
###
|
|
220
|
-
|
|
221
|
-
In order; the first
|
|
222
|
-
|
|
223
|
-
1. The
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
3.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
The
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
7. Once every block to the last is finalized without the extrinsic, and no block is unread, it can never be included:
|
|
349
|
-
`invalid_transaction_state`.
|
|
350
|
-
8. Stores the answer and returns it. A success is given only by the `/settle` that stores it, and an answer with an
|
|
351
|
-
empty `transaction` only once it is the stored answer. When either cannot be stored, the answer is
|
|
352
|
-
`settlement_pending` with the extrinsic's hash, and a later `/settle` reads the chain again.
|
|
353
|
-
|
|
354
|
-
Success is `{success: true, transaction, network, payer}`, where `transaction` is `<block hash>-<extrinsic index>`.
|
|
355
|
-
While the extrinsic is broadcast but not yet in a block, the answer is `settlement_pending` with `transaction` set to
|
|
356
|
-
the extrinsic's hash.
|
|
357
|
-
|
|
358
|
-
### Pending and repeated settles
|
|
359
|
-
|
|
360
|
-
When the wait ends first, `/settle` answers `{success: false, errorReason: "settlement_pending", transaction}` with the
|
|
361
|
-
transaction id or extrinsic hash; x402 requires that `transaction` not be empty. Call `/settle` again with the same
|
|
362
|
-
request: it reads the chain from where it stopped, never submits twice, and returns the final answer once there is one.
|
|
363
|
-
The facilitator keeps the payment's row until that final answer is written, however long that takes, so a repeat made
|
|
364
|
-
after the validity window has ended still reads the chain. On Tron a payment is answered success once: every later
|
|
365
|
-
`/settle` of it answers `invalid_transaction_state` with the transaction id, because x402's `exact` family requires that
|
|
366
|
-
a consumed payment produce a settlement failure, never a success. Once the payment's row is gone, the FullNode's blocks
|
|
367
|
-
give that answer. A broadcast or submission the node refused, or never received, is stored too, and every repeat gets
|
|
368
|
-
its answer. When the store cannot be read, the facilitator cannot know whether the payment was submitted, so it answers
|
|
369
|
-
`settlement_pending` with the id.
|
|
370
|
-
|
|
371
|
-
An answer with an empty `transaction` means nothing was submitted: on Tron always, and on Polkadot while the
|
|
372
|
-
facilitator keeps the payment's row (until 24 hours after its validity window). After that, a repeated `/settle` of a
|
|
373
|
-
Polkadot extrinsic that landed finds no row, the node's validation refuses it, and the answer is `invalid_transaction`
|
|
374
|
-
with an empty `transaction`.
|
|
375
|
-
|
|
376
|
-
A payment whose success has been answered is consumed. On Polkadot, while the facilitator keeps the payment's row, a
|
|
377
|
-
repeated `/settle` for it answers `invalid_transaction_state` with the success's `transaction`, never a second
|
|
378
|
-
success, as x402's `exact` family requires: *"A consumed primitive MUST produce a settlement failure, never a
|
|
379
|
-
success."* Of two concurrent settles of one payment, one answers success and the other that failure.
|
|
380
|
-
|
|
381
|
-
## API reference
|
|
382
|
-
|
|
383
|
-
The package's entry point exports:
|
|
384
|
-
|
|
385
|
-
| Export | Kind | What it is |
|
|
386
|
-
|---|---|---|
|
|
387
|
-
| `serveProfileFacilitator(config)` | `(c: ProfileFacilitatorConfig) => Promise<{ close(): Promise<void> }>` | Opens the store, starts the HTTP server and resolves once it listens. If it cannot start, it closes the store and rejects with the error that stopped it, such as the listen's `EADDRINUSE`. |
|
|
388
|
-
| `ProfileFacilitatorConfig` | interface | The configuration above. |
|
|
389
|
-
|
|
390
|
-
### HTTP API
|
|
509
|
+
### `/verify`
|
|
510
|
+
|
|
511
|
+
`/verify` moves nothing. In order; the first refusal is the answer:
|
|
512
|
+
|
|
513
|
+
1. The request's shape: `invalid_x402_version`, `invalid_payload`.
|
|
514
|
+
2. The network is one a module serves, else `invalid_network`, and the scheme one a module registers on it, else
|
|
515
|
+
`unsupported_scheme`. Where an own module claims the payment (by a member of the option, or by what the payment
|
|
516
|
+
holds), it goes to that module, else to the registration's class. On `lnbtc` the answer is `unsupported_scheme`.
|
|
517
|
+
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 `invalidMessage`
|
|
519
|
+
(on `starknet` and `sui`, the module's own code where its own check refused).
|
|
520
|
+
4. The record: a payment it holds, claimed or final, is refused `invalid_transaction_state`, since `isValid: true`
|
|
521
|
+
tells the caller that a settle may follow.
|
|
522
|
+
5. What the kind declares: an amount of zero where it does not take zero, and a form outside the pairings of the module
|
|
523
|
+
the payment goes to, are refused `invalid_payment_requirements`.
|
|
524
|
+
6. The fee budget, where the module's key pays the fee: a spent budget is refused `fee_budget_spent`.
|
|
525
|
+
7. The class's verify, unchanged, with its own reasons.
|
|
526
|
+
8. lcp's read of the chain: a payment the chain shows final (landed, or consumed by another act) is refused
|
|
527
|
+
`invalid_transaction_state`. A read that fails goes to the operator log and leaves the class's answer.
|
|
528
|
+
|
|
529
|
+
On `sui`, whose `/verify` judges a transaction the buyer already executed by its effects, steps 4 and 8 are not made.
|
|
530
|
+
The answer is `{isValid: true, payer}` or `{isValid: false, invalidReason, invalidMessage?, payer?}`.
|
|
531
|
+
|
|
532
|
+
### `/settle`
|
|
533
|
+
|
|
534
|
+
1. Steps 1 to 3 of `/verify`, with `errorMessage` for `invalidMessage`; `lnbtc` is served here.
|
|
535
|
+
2. The record. A final row is answered `invalid_transaction_state` naming the transaction it holds, never a second
|
|
536
|
+
success. A claim another settle holds, or one whose hold has ended, is answered as
|
|
537
|
+
[the record](#the-record-and-what-a-repeat-answers) says.
|
|
538
|
+
3. What the kind declares, as `/verify` checks it.
|
|
539
|
+
4. The class's verify. Where it refuses, lcp's read of the chain: a payment the chain shows landed, or whose value
|
|
540
|
+
another act consumed, is stored final and answered `invalid_transaction_state` naming its transaction; otherwise the
|
|
541
|
+
class's refusal is the answer, nothing is stored, and a repeat is checked again.
|
|
542
|
+
5. Where the module's read searches from a position no x402 call carries (a ledger, a slot, a block), the chain's
|
|
543
|
+
position, read just before the claim, which the row keeps for every later read.
|
|
544
|
+
6. The claim: one conditional insert of the payment's row, held by this settle for `settleWaitMs`, so that of two
|
|
545
|
+
settles of one payment only one submits.
|
|
546
|
+
7. The fee budget, where the module's key pays the fee: a spent budget answers `fee_budget_spent`, sends nothing, and
|
|
547
|
+
leaves the claim, not final.
|
|
548
|
+
8. The class's settle, which submits what the payer signed. A success that names a transaction is stored final, then
|
|
549
|
+
answered `{success: true, transaction, network, payer}`. Anything else is classified by lcp's read: a payment the
|
|
550
|
+
chain shows final is stored final and answered (success only where the read shows a transaction this settler sent,
|
|
551
|
+
or the payment it presented, settled); one still live is answered `settlement_pending` naming the transaction sent,
|
|
552
|
+
or the class's own failure where it named no transaction or its failure consumed nothing.
|
|
553
|
+
|
|
554
|
+
A success is answered once, only by the settle whose write stored it: of two settles of one payment, only one answers
|
|
555
|
+
success, and the other answers `invalid_transaction_state` naming the transaction, or `settlement_pending` where its
|
|
556
|
+
wait ends first. A success that cannot be stored is answered `settlement_pending` naming its transaction, and a later
|
|
557
|
+
`/settle` reads the chain again.
|
|
558
|
+
|
|
559
|
+
## The record, and what a repeat answers
|
|
560
|
+
|
|
561
|
+
The record is one row per payment, its **instrument**, within its network: the single-use value its signer signed (an
|
|
562
|
+
authorization nonce, a sequence number, an account nonce, with the token or nonce key it counts in), or the transaction
|
|
563
|
+
id where the chain derives it from the signed content alone, or the digest of the signed payment where the pairing's
|
|
564
|
+
single-use value is not shown. It is never the single-use value alone, which two payers can share, and never a hash
|
|
565
|
+
that a copy signed again would change. An agreement and a payment of one payer under one H are two instruments.
|
|
566
|
+
|
|
567
|
+
A row is **final** once its answer can never change: a success; a failed result that consumed the single-use value; a
|
|
568
|
+
value another act consumed; a validity that passed with the value unconsumed; or a payment that landed by another
|
|
569
|
+
route. A refused submission, one that cannot have reached the node, and a failed result that consumed nothing leave the
|
|
570
|
+
row a claim, which a repeat reads again. A claim is never removed.
|
|
571
|
+
|
|
572
|
+
| A repeated `/settle` finds | It answers |
|
|
573
|
+
|---|---|
|
|
574
|
+
| A final row | `invalid_transaction_state` naming the transaction the row holds. Never a second success, as x402's `exact` family requires: a consumed payment produces a settlement failure. |
|
|
575
|
+
| A claim another settle holds | It reads the row every second and sends nothing, until that settle answers or its hold ends; then the row's answer, or lcp's read. It answers `settlement_pending` naming the transaction where one is known, and `unexpected_settle_error` where none is known when its wait ends. |
|
|
576
|
+
| A claim whose hold has ended | It takes the claim and reads the chain. A payment the chain shows final is stored and answered. The identical signed payment is submitted again only where the pairing's `nonce` is `single-use` in lcp's registry, the row is not named by the digest of the signed payment, the read shows the value unconsumed and its validity open, the body is the one that claimed the row, and the class's verify passes again. Another body under the same instrument is answered `invalid_transaction_state`. Otherwise `settlement_pending` naming the transaction sent, or `unexpected_settle_error` where none is known. |
|
|
577
|
+
| No row, and the store cannot be read | `settlement_pending` where the payment's transaction id is known before it is sent, else `unexpected_settle_error`: the settler cannot know whether it was sent. |
|
|
578
|
+
|
|
579
|
+
When the wait ends first, `/settle` answers `{success: false, errorReason: "settlement_pending", transaction}`; x402
|
|
580
|
+
requires that `transaction` not be empty. Call `/settle` again with the same request: it reads the chain from where the
|
|
581
|
+
last read stopped, never sends what it sent before unless the rule above admits it, and returns the final answer once
|
|
582
|
+
there is one. A final row is kept at least 24 hours past the time its payment can last land (its signed validity, or
|
|
583
|
+
the longest the rail keeps a signed payment payable), and for the settler's life where neither is known or the
|
|
584
|
+
pairing's `nonce` is not `single-use`; a claim that is not final is kept until a repeat makes it final.
|
|
585
|
+
|
|
586
|
+
## The fee budget
|
|
587
|
+
|
|
588
|
+
A keyed module pays fees for what it submits. `feeBudgets` caps them per network: an amount of the network's fee asset,
|
|
589
|
+
in its smallest unit, over a period of seconds. The count holds every transaction a module whose key pays the fee
|
|
590
|
+
submitted on the network over the last period: its bound until the chain shows it included, then the fee it paid.
|
|
591
|
+
Where the count has reached the amount:
|
|
592
|
+
|
|
593
|
+
- `/verify` and `/settle` refuse a payment whose fee the module's key would pay, `fee_budget_spent`, before anything is
|
|
594
|
+
sent. A payment whose payer pays the fee is never refused for it.
|
|
595
|
+
- Each kind of the network states `extra.feeBudget: true`, so that a resource server learns that the settler may refuse
|
|
596
|
+
every payment on that network for a period.
|
|
597
|
+
|
|
598
|
+
The fee counted is what the chain shows. On an EVM network it is the gas used times its price and, on an OP Stack
|
|
599
|
+
network, the L1 data fee the receipt shows (`l1Fee`); before inclusion, the gas limit times the fee cap, with the L1
|
|
600
|
+
data fee the network's GasPriceOracle (`getL1Fee`) gives. On Hedera it is the fee the Mirror Node shows, asked for up
|
|
601
|
+
to five seconds after the settle answers; where the mirror shows none by then, the `maxFee` the payer signed. The
|
|
602
|
+
`evm`, `solana`, `aptos` and `casper` modules count each transaction their key sends as it is sent, one their class
|
|
603
|
+
does not name in its answer included: a payer's ERC-6492 wallet deployment on EVM, or a Solana or Casper transaction
|
|
604
|
+
whose send failed.
|
|
605
|
+
|
|
606
|
+
At start the settler refuses a budget on a network no configured module serves, and one on a network where a module
|
|
607
|
+
whose key pays fees can neither show the fee of what it sent nor count it as it sends: the `ton` and `concordium`
|
|
608
|
+
modules, whose classes and lcp's reads give no fee.
|
|
609
|
+
|
|
610
|
+
Its stated costs:
|
|
611
|
+
|
|
612
|
+
- A transaction is counted once it is sent (`evm`, `solana`, `aptos`, `casper`) or once its settle answers (`algorand`,
|
|
613
|
+
`erc7710`, `hedera`, `near`), so settles that run at once on a nearly spent budget can each pass the check before the
|
|
614
|
+
first is counted. The `starknet` and `stellar` modules count each send before it is made, one at a time per network.
|
|
615
|
+
The `evm` module's count at the send is what its node shows then: a transaction the node does not show yet (the
|
|
616
|
+
operator log's `fee-not-counted`, reason `not-shown`) is not counted until a later read shows it, when the class's
|
|
617
|
+
wait for its receipt ends or when the settle answers, and one the node never shows, never mined, is not counted.
|
|
618
|
+
- A transaction whose id is not known before it is sent is counted at its bound for the whole period, as well as at
|
|
619
|
+
the fee it paid once included. The count can exceed what was paid; it never falls short of it.
|
|
620
|
+
|
|
621
|
+
## What it does not serve
|
|
622
|
+
|
|
623
|
+
- **MPP.** The settler answers x402's facilitator calls only, and serves none of MPP's calls.
|
|
624
|
+
- **Sui's sponsored path.** x402's Sui scheme needs a gas station, whose wire its scheme does not state and whose caller
|
|
625
|
+
is the buyer's client, which does not hold the resource server's credential. An option that names one is refused
|
|
626
|
+
`invalid_payment_requirements`; the `sui` module holds no key.
|
|
627
|
+
- **Hedera's transfer executor** (`x402/exact/hedera/transfer-executor`). No member of the configuration names an
|
|
628
|
+
executor, and x402's specification of the method admits none by default.
|
|
629
|
+
- **Solana's channel forms on mainnet.** `x402/upto/solana` and `x402/batch-settlement/solana` need the payment-channels
|
|
630
|
+
program, which is not deployed on Solana mainnet; there only `exact` is registered.
|
|
631
|
+
- **Casper mainnet.** x402's Casper scheme names `casper:casper`, but no token there has yet been shown to execute
|
|
632
|
+
`transfer_with_authorization`, so the `casper` module does not start on it; it serves `casper:casper-test`.
|
|
633
|
+
- **lcp's x402 pairings that another party settles.** `x402/exact/eip155/gateway-batched`, Circle's batched option,
|
|
634
|
+
which the `evm` module refuses, and `x402/batch-settlement/cloudflare`, on Cloudflare's `cloudflare:402` network,
|
|
635
|
+
which no module serves.
|
|
636
|
+
|
|
637
|
+
## HTTP API
|
|
391
638
|
|
|
392
639
|
| Request | Answer |
|
|
393
640
|
|---|---|
|
|
394
|
-
| `GET /supported` | `200` `{kinds, extensions
|
|
395
|
-
| `POST /verify` | `200` `{isValid: true, payer}` or `{isValid: false, invalidReason, payer?}`; `400` `{isValid: false, invalidReason: "invalid_payload"}` when the body is not JSON. |
|
|
396
|
-
| `POST /settle` | `200` `{success: true, transaction, network, payer}` or `{success: false, errorReason, transaction, network}`; `400` with `errorReason` `invalid_payload` when the body is not JSON. |
|
|
397
|
-
| A
|
|
641
|
+
| `GET /supported` | `200` `{kinds, extensions, signers}`. |
|
|
642
|
+
| `POST /verify` | `200` `{isValid: true, payer}` or `{isValid: false, invalidReason, invalidMessage?, payer?}`; `400` `{isValid: false, invalidReason: "invalid_payload"}` when the body is not JSON. |
|
|
643
|
+
| `POST /settle` | `200` `{success: true, transaction, network, payer}` or `{success: false, errorReason, errorMessage?, transaction, network}`; `400` with `errorReason` `invalid_payload` when the body is not JSON. |
|
|
644
|
+
| A call without the credential, where one is configured | `401` `{error: "unauthorized"}` with `WWW-Authenticate: Bearer`, before the body is read; the connection is closed. |
|
|
645
|
+
| A body over 132,096 bytes | `413`, and the connection is closed. |
|
|
398
646
|
| Another method on a served path | `405` `{error}`. |
|
|
399
647
|
| Any other path | `404` `{error}`. |
|
|
648
|
+
| An error outside every answer | `500` `{error: "internal error"}`, once its entry is in the operator log. |
|
|
400
649
|
|
|
401
|
-
The
|
|
402
|
-
|
|
650
|
+
The body bound is twice lcp's `MAX_HEADER_BYTES` (65,536), the largest payment payload and the largest option lcp's
|
|
651
|
+
x402 codec reads, and 1,024 bytes for the envelope.
|
|
403
652
|
|
|
404
653
|
### Reasons
|
|
405
654
|
|
|
406
655
|
| Reason | `/verify` | `/settle` | Meaning |
|
|
407
656
|
|---|---|---|---|
|
|
408
657
|
| `invalid_x402_version` | yes | yes | `x402Version` is not 2 in the request or the payload. |
|
|
409
|
-
| `
|
|
410
|
-
| `
|
|
411
|
-
| `invalid_payment_requirements` | yes | yes | The requirements are not ones the profile admits. |
|
|
412
|
-
| `invalid_payload` | yes | yes | The payload does not match the profile or the requirements
|
|
413
|
-
| `unsupported_permission` | yes | yes | Tron: the
|
|
414
|
-
| `invalid_transaction` | yes | yes | The node refuses the transaction in simulation or validation
|
|
415
|
-
| `
|
|
416
|
-
| `
|
|
417
|
-
| `settlement_pending` | no | yes | Submitted, or possibly submitted
|
|
418
|
-
| `
|
|
658
|
+
| `invalid_network` | yes | yes | No configured module serves the network. |
|
|
659
|
+
| `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 where the kind does not take zero; a form outside the kind's pairings; an option the module refuses (each module's notes). |
|
|
661
|
+
| `invalid_payload` | yes | yes | The payload does not match the profile or the requirements. |
|
|
662
|
+
| `unsupported_permission` | yes | yes | Tron: the owner's permission does not accept the transaction's signatures. |
|
|
663
|
+
| `invalid_transaction` | yes | yes | The node refuses the transaction in simulation or validation, in a module of the settler's own. |
|
|
664
|
+
| `invalid_transaction_state` | yes | yes | `/verify`: the record or the chain already holds the payment. `/settle`: a repeat of a final row, or a payment the chain shows failed, consumed by another act, lapsed or landed by another route; each names the transaction where one is known. |
|
|
665
|
+
| `fee_budget_spent` | yes | yes | The network's fee budget is spent, and the module's key would pay the fee. |
|
|
666
|
+
| `settlement_pending` | no | yes | Submitted, or possibly submitted, and not yet final or not yet stored when the wait ended; `transaction` names it. |
|
|
667
|
+
| `unexpected_verify_error` | yes | no | A node or the store could not be read. |
|
|
668
|
+
| `unexpected_settle_error` | no | yes | A node or the store could not be read before submission, the settle's wait ended before it, or the submission failed with nothing sent. |
|
|
419
669
|
|
|
420
|
-
`unsupported_permission` and `
|
|
421
|
-
|
|
422
|
-
others are the x402 specification's.
|
|
670
|
+
`unsupported_permission`, `invalid_transaction` and `fee_budget_spent` are the settler's own; the others are x402's. A
|
|
671
|
+
published class's own reasons, such as `invalid_exact_evm_payload_signature`, pass unchanged.
|
|
423
672
|
|
|
424
|
-
|
|
673
|
+
## Storage
|
|
425
674
|
|
|
426
|
-
Postgres holds
|
|
675
|
+
Postgres holds three tables, created at start where they do not exist:
|
|
427
676
|
|
|
428
677
|
```sql
|
|
429
|
-
CREATE TABLE IF NOT EXISTS
|
|
678
|
+
CREATE TABLE IF NOT EXISTS instrument (
|
|
430
679
|
network text NOT NULL,
|
|
431
|
-
|
|
680
|
+
key text NOT NULL,
|
|
681
|
+
pairing text NOT NULL,
|
|
682
|
+
claimed bigint NOT NULL,
|
|
683
|
+
held_until bigint NOT NULL,
|
|
684
|
+
final boolean NOT NULL DEFAULT false,
|
|
685
|
+
outcome text,
|
|
432
686
|
answer jsonb,
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
687
|
+
transaction text,
|
|
688
|
+
sent text[] NOT NULL DEFAULT '{}',
|
|
689
|
+
body text,
|
|
690
|
+
payer text,
|
|
691
|
+
search jsonb,
|
|
692
|
+
since jsonb,
|
|
693
|
+
keep_until bigint,
|
|
694
|
+
PRIMARY KEY (network, key)
|
|
695
|
+
);
|
|
696
|
+
CREATE INDEX IF NOT EXISTS instrument_final_keep ON instrument (keep_until) WHERE final AND keep_until IS NOT NULL;
|
|
697
|
+
CREATE TABLE IF NOT EXISTS fee (
|
|
698
|
+
network text NOT NULL,
|
|
699
|
+
transaction text NOT NULL,
|
|
700
|
+
at bigint NOT NULL,
|
|
701
|
+
fee numeric(78, 0) NOT NULL,
|
|
702
|
+
included boolean NOT NULL,
|
|
703
|
+
PRIMARY KEY (network, transaction)
|
|
437
704
|
);
|
|
438
|
-
CREATE INDEX IF NOT EXISTS
|
|
439
|
-
|
|
705
|
+
CREATE INDEX IF NOT EXISTS fee_at ON fee (network, at);
|
|
706
|
+
CREATE TABLE IF NOT EXISTS module_state (
|
|
707
|
+
module text NOT NULL,
|
|
708
|
+
key text NOT NULL,
|
|
709
|
+
value jsonb NOT NULL,
|
|
710
|
+
PRIMARY KEY (module, key)
|
|
711
|
+
)
|
|
440
712
|
```
|
|
441
713
|
|
|
442
|
-
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
- `
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
network, so no request's deadline bounds it: the load has 30 seconds as a whole, and each of its calls has the node
|
|
486
|
-
call bound within the time the load has left. Once the 30 seconds have passed, the load is given up: it has no call
|
|
487
|
-
in flight and sends no further call, and a later request starts a fresh load.
|
|
488
|
-
- A request body is at most 64 KiB. The server's request timeout is `settleWaitMs` plus 60 seconds.
|
|
489
|
-
- The table holds a row with a final answer until 24 hours after its validity window ends. A row with no final answer
|
|
490
|
-
stays until a repeated `/settle` for it gives one. Each such row is a payment that passed every check and was
|
|
491
|
-
claimed for submission; it is one row of fixed columns, the sweep's index does not hold it, and each repeat reads the
|
|
492
|
-
chain within `settleWaitMs`. On Tron, one repeat made once the latest solidified block is two slots past the
|
|
493
|
-
expiration gives a final answer whenever the nodes answer its reads, each naming a latest block at or past that one.
|
|
494
|
-
- The facilitator gives its operator log (`operatorLog`; by default one JSON line on standard error) what the operator
|
|
495
|
-
should see and the answer does not carry, each entry with `network`, `payer` and `transaction` where they are known:
|
|
496
|
-
`settlement-failed` (with the events, or the receipt result and why the transfer does not count, that the chain
|
|
497
|
-
shows), `settlement-expired`, `answer-not-stored`, `block-unreadable` (a Polkadot block the node does not give, with
|
|
498
|
-
the node's reason; `final` when it was read at finality and is recorded as unread), `block-read-stopped` (a block read
|
|
499
|
-
the settle's deadline ended) and `settlement-consumed` (a repeated `/settle` of a Polkadot payment whose success has
|
|
500
|
-
been answered). Each error the facilitator turns into an answer or a retry is an entry with the error as its cause:
|
|
501
|
-
`verify-error`, `settle-error` and `request-error` (an error the request's handling threw), `node-call-failed` and
|
|
502
|
-
`store-call-failed` (with the `call`), and `store-connection-error`. Every `unexpected_verify_error` and
|
|
503
|
-
`unexpected_settle_error` answer has an entry that names why, written when it is first given (a repeated `/settle`
|
|
504
|
-
gets the stored answer), with the call or the bound: an error's entry above;
|
|
505
|
-
`node-call-failed` for a node answer the facilitator cannot read, its cause a `malformed` error naming the part, and
|
|
506
|
-
for a Tron broadcast the node does not accept, its cause the node's `code` and `message`; and
|
|
507
|
-
`settle-deadline-passed` for a settle whose deadline passed before its node reads or one of their node calls, or
|
|
508
|
-
whose wait for the chain ended before its claim or its submission, with `before`, the step it did not start
|
|
509
|
-
(`node reads` or `claim`, and on Polkadot, once the extrinsic is decoded, `finalized head` or `validation`) or the
|
|
510
|
-
call it did not send, named as `node-call-failed` names it, and `settleWaitMs`. A read made while following the
|
|
511
|
-
chain (a Tron status read, a Polkadot head or block read) that the wait for the chain leaves no time for is not
|
|
512
|
-
sent and writes no entry: the answer is the one the wait's end gives.
|
|
513
|
-
A request refused for its own bytes (a body that is not JSON, a signature
|
|
514
|
-
that recovers no key, an extrinsic that does not decode) is answered to its client and not logged, and a client that
|
|
515
|
-
leaves before its request body is complete writes no entry: the connection is destroyed.
|
|
516
|
-
`@polkadot/api`, which loads each Polkadot network's metadata, also writes its own lines (not JSON) on standard error
|
|
517
|
-
when that load fails; the facilitator's entry for it is `node-call-failed` with `call: metadata`.
|
|
518
|
-
|
|
519
|
-
## Security model and guarantees
|
|
520
|
-
|
|
521
|
-
- **No key, no fee.** The facilitator signs nothing. It submits exactly the bytes the payer signed, and the payer pays
|
|
522
|
-
every fee, as both profiles require.
|
|
523
|
-
- **Settled once.** Settlements are deduplicated by transaction id or extrinsic hash, atomically, for as long as the
|
|
524
|
-
answer is not final, and for at least 24 hours after the validity window ends. A payment is answered success once,
|
|
525
|
-
across every process that shares the store, to the `/settle` whose write stores it, on Tron and on Polkadot. On
|
|
526
|
-
Tron, a transaction id the node already holds is refused.
|
|
527
|
-
- **Success only from the chain.** `success: true` is given only when a node shows the transaction in a block with
|
|
528
|
-
the facilitator's success conditions: on Tron, receipt result `SUCCESS`, which the profile requires, and a `Transfer`
|
|
529
|
-
log from the token. A success read at the head, above the solidified or finalized block, can be reorganised out of
|
|
530
|
-
the chain.
|
|
531
|
-
- **What it does not check.** It checks that the payment carries H in the profile's form, not which H the seller issued.
|
|
532
|
-
Its store claims a payment's id once, so the payment is submitted once. On Tron and on Polkadot, a success is answered
|
|
533
|
-
only by the settle whose write stored it, and a repeated `/settle` of that payment answers `invalid_transaction_state`
|
|
534
|
-
with the transaction: on Tron from the stored answer or, once the row is gone, from the FullNode's blocks; on Polkadot
|
|
535
|
-
while the facilitator keeps the payment's row (until 24 hours after its validity window). Each profile's rule 6 puts
|
|
536
|
-
the remaining checks on the resource server: it accepts a payment only when the payment's H is one it issued for that
|
|
537
|
-
request and has not seen claimed. The seller door's `claim` makes both checks. It answers `404 claim/unknown` for an H
|
|
538
|
-
it holds no record of, `409 claim/not-this-request` for a payment of another request, and `409 claim/in-progress` or
|
|
539
|
-
`409 claim/paid` once the ATR's payment has been claimed. The facilitator checks the amount, asset and payee against
|
|
540
|
-
the requirements it is given because x402 requires that of a facilitator, and carries no business or legal logic
|
|
541
|
-
beyond that.
|
|
542
|
-
|
|
543
|
-
## Test vectors and conformance
|
|
544
|
-
|
|
545
|
-
The tests check each profile's rule 5 against local node stubs, with the transactions of `@integraledger/lcp`'s
|
|
546
|
-
shared vectors. The Tron stubs answer with Tron mainnet's recorded answers (`test/fixtures/tron-mainnet-answers.json`),
|
|
547
|
-
and the Polkadot stub with Polkadot Asset Hub's recorded runtime metadata
|
|
548
|
-
(`test/fixtures/polkadot-asset-hub-2005000.json.gz`); the Tron account, block and transaction reads follow
|
|
549
|
-
java-tron's HTTP answers and its signature and TaPoS checks. They cover two concurrent settles of one payment (one
|
|
550
|
-
submission), repeated settles while the node is down, a settle that finds its id claimed and unanswered, the end of
|
|
551
|
-
each validity window (Tron's expiration and Polkadot's mortal era, capped by `System.BlockHashCount`), and a
|
|
552
|
-
Polkadot remark that spells H with upper-case digits, refused before the node is asked. On Tron they also cover the
|
|
553
|
-
owner's permission, TaPoS, a transaction id the node (in a block or its pending pool) or the store already holds,
|
|
554
|
-
before and after the expiration and after the sweep has dropped the payment's row, a consumed payment, and a `SUCCESS`
|
|
555
|
-
receipt with and without the token's `Transfer` log, including the live USDT-TRC20 receipt whose `transfer` returned
|
|
556
|
-
false. On Polkadot they also cover a repeat of a consumed payment, a block answer over 4 MiB and one over the
|
|
557
|
-
`System.BlockLength` bound, and a block the node cannot give, before and after the era's end. They need
|
|
558
|
-
`INTEGRA_DATABASE_URL` set to a Postgres database.
|
|
559
|
-
|
|
560
|
-
## Requirements
|
|
561
|
-
|
|
562
|
-
- Node.js `>=26.11.1`.
|
|
563
|
-
- Postgres; the tests run on Postgres 18.
|
|
564
|
-
- For Tron, a FullNode and a Solidity node with java-tron's HTTP API: the FullNode serves `/wallet/getaccount`,
|
|
565
|
-
`/wallet/getnowblock`, `/wallet/getblock`, `/wallet/gettransactionbyid`, `/wallet/gettransactionfrompending`,
|
|
566
|
-
`/wallet/triggerconstantcontract`, `/wallet/broadcasthex` and `/wallet/gettransactioninfobyid`. The FullNode keeps
|
|
567
|
-
the block history, not a lite FullNode: `/wallet/gettransactionbyid` finds a transaction only in the blocks the node
|
|
568
|
-
holds, and it answers a repeated `/settle` of a payment whose row is gone.
|
|
569
|
-
- For Polkadot, an Asset Hub RPC node that serves JSON-RPC over HTTP. A node that keeps the state of every block (an
|
|
570
|
-
archive node) gives the events of any block; a pruning node discards the state of older blocks, and a block that
|
|
571
|
-
holds the extrinsic and whose state is discarded keeps the answer `settlement_pending`.
|
|
714
|
+
- `instrument` is the record: `key` is the instrument, its kind and parts as a JSON array. `held_until` is when the
|
|
715
|
+
settle holding the claim may no longer send (0 once it answered); `answer` is the answer as first given, once
|
|
716
|
+
`final`; `transaction` the transaction the row names; `sent` every transaction the settler's submissions for the
|
|
717
|
+
claim named, any of which can be the one that lands; `body` the SHA-256 of the body that claimed the row, the only
|
|
718
|
+
body sent again; `search` where the next read resumes; `since` the chain's position read just before the claim; times
|
|
719
|
+
are Unix milliseconds.
|
|
720
|
+
- `fee` is the fee count: one row per transaction a keyed module submitted on a network with a budget.
|
|
721
|
+
- `module_state` is the modules' durable state, under each module's name: a class's pending settlements, Cardano's
|
|
722
|
+
broadcast guard, Solana's channels.
|
|
723
|
+
- A sweep every minute drops the final rows kept 24 hours past their keep, and the fees older than the longest budget
|
|
724
|
+
period. The pool holds at most 10 connections; acquiring one, each query and each statement are bounded by 5 seconds.
|
|
725
|
+
|
|
726
|
+
## Bounds and logs
|
|
727
|
+
|
|
728
|
+
- 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
|
+
Polkadot's block reads, bounded by the runtime's `System.BlockLength` (at most 4 of them at once in a process). A
|
|
730
|
+
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.
|
|
732
|
+
- `/settle`'s reads and submission end a second before `settleWaitMs` (a quarter of a shorter wait), the time kept for
|
|
733
|
+
storing the answer. The server's request timeout is `settleWaitMs` plus 60 seconds.
|
|
734
|
+
- An error names a node by its origin alone, since a URL's path or query can hold an API key.
|
|
735
|
+
- The operator log (`operatorLog`; by default one JSON line on standard error) receives what the operator should see
|
|
736
|
+
and the answer does not carry, each entry with `network`, `payer` and `transaction` where they are known, and the
|
|
737
|
+
error that caused it as `cause`. The answer to the client is the same either way and carries nothing from the cause.
|
|
738
|
+
A log that throws, or returns a promise that rejects, changes no answer: the entry is written by the default, with an
|
|
739
|
+
`operator-log-failed` entry. The core's entries are `verify-error`, `settle-error` and `request-error` (an error the
|
|
740
|
+
handling threw); `read-failed` and `position-unread` (lcp's read, or the position before a claim, could not be made);
|
|
741
|
+
`store-call-failed` (with the `call`), `store-connection-error` and `answer-not-stored`; `settle-deadline-passed`
|
|
742
|
+
(with `before`, the step not started); `claim-unread` (a held claim whose read told nothing); `success-not-stored`;
|
|
743
|
+
and `fee-not-counted`. Each module adds its own, such as `node-call-failed` and `settlement-failed`. Every
|
|
744
|
+
`unexpected_verify_error` and `unexpected_settle_error` has an entry that names why, written when it is first given.
|
|
745
|
+
|
|
746
|
+
## Tests and the test database
|
|
747
|
+
|
|
748
|
+
The tests feed lcp's vectors for each module's pairings through the settler's `/verify` and `/settle`, against local
|
|
749
|
+
node stubs that replay recorded node answers (`test/fixtures/tron-mainnet-answers.json`, Polkadot Asset Hub's runtime
|
|
750
|
+
metadata in `test/fixtures/polkadot-asset-hub-2005000.json.gz`) or answers derived from the pairing's profile. They
|
|
751
|
+
need Postgres: set `INTEGRA_DATABASE_URL` to a connection string whose user may create databases. Each test file makes
|
|
752
|
+
and drops its own database, so test runs share one server. CI runs them against a Postgres 18 service.
|
|
753
|
+
|
|
754
|
+
```sh
|
|
755
|
+
INTEGRA_DATABASE_URL=postgres://postgres@127.0.0.1:5432/postgres pnpm --filter @integraledger/profile-facilitator test
|
|
756
|
+
```
|
|
572
757
|
|
|
573
758
|
## Contributing
|
|
574
759
|
|
|
575
|
-
See the [repository's README](https://github.com/IntegraLedger/integra-
|
|
576
|
-
[CONTRIBUTING.md](https://github.com/IntegraLedger/integra-
|
|
760
|
+
See the [repository's README](https://github.com/IntegraLedger/integra-protocol#readme) and
|
|
761
|
+
[CONTRIBUTING.md](https://github.com/IntegraLedger/integra-protocol/blob/main/CONTRIBUTING.md). The settler's
|
|
762
|
+
documentation is also at [lcp.integraledger.com](https://lcp.integraledger.com/guides/settler).
|
|
577
763
|
|
|
578
764
|
## License
|
|
579
765
|
|