@metalntwx/metal-pay 0.2.0 → 0.3.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 +72 -33
- package/dist/clearing-abi.d.ts +1836 -0
- package/dist/clearing-abi.js +2361 -0
- package/dist/clearing-client.d.ts +49 -159
- package/dist/clearing-client.js +191 -564
- package/dist/clearing-codec.d.ts +57 -0
- package/dist/clearing-codec.js +173 -0
- package/dist/clearing-custody.d.ts +191 -0
- package/dist/clearing-custody.js +490 -0
- package/dist/clearing-server.d.ts +30 -49
- package/dist/clearing-server.js +87 -67
- package/dist/clearing-x402.d.ts +29 -0
- package/dist/clearing-x402.js +203 -0
- package/dist/client.d.ts +7 -13
- package/dist/client.js +16 -18
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/mandates/binding.d.ts +4 -27
- package/dist/mandates/binding.js +5 -9
- package/dist/mandates/checkout.js +5 -5
- package/dist/mandates/client.js +4 -3
- package/dist/mandates/l3a.d.ts +2 -2
- package/dist/mandates/l3a.js +5 -4
- package/dist/mandates/seller.d.ts +1 -1
- package/dist/mandates/seller.js +1 -1
- package/dist/mandates/verify.d.ts +4 -6
- package/dist/mandates/verify.js +42 -66
- package/dist/mandates/vi/credential.js +4 -4
- package/dist/node.d.ts +11 -0
- package/dist/node.js +97 -0
- package/package.json +18 -11
- package/src/clearing-abi.ts +2361 -0
- package/src/clearing-client.ts +303 -0
- package/src/clearing-codec.test.ts +57 -0
- package/src/clearing-codec.ts +251 -0
- package/src/clearing-custody.test.ts +534 -0
- package/src/clearing-custody.ts +665 -0
- package/src/clearing-fixture.json +37 -0
- package/src/clearing-server.test.ts +388 -0
- package/src/clearing-server.ts +123 -0
- package/src/clearing-x402.test.ts +181 -0
- package/src/clearing-x402.ts +279 -0
- package/src/client.test.ts +325 -0
- package/src/client.ts +156 -0
- package/src/index.ts +33 -0
- package/src/mandates/account.ts +91 -0
- package/src/mandates/binding.ts +280 -0
- package/src/mandates/chain.ts +68 -0
- package/src/mandates/checkout.ts +368 -0
- package/src/mandates/client.ts +159 -0
- package/src/mandates/extension.ts +48 -0
- package/src/mandates/index.ts +121 -0
- package/src/mandates/ingest.ts +42 -0
- package/src/mandates/jcs.ts +16 -0
- package/src/mandates/l3a.ts +216 -0
- package/src/mandates/seller.ts +91 -0
- package/src/mandates/verify.ts +532 -0
- package/src/mandates/vi/credential.ts +477 -0
- package/src/mandates/vi/issue.ts +118 -0
- package/src/mandates/vi/sd-jwt.ts +189 -0
- package/src/networks.test.ts +16 -0
- package/src/networks.ts +152 -0
- package/src/node.test.ts +24 -0
- package/src/node.ts +96 -0
- package/src/server.test.ts +223 -0
- package/src/server.ts +77 -0
- package/dist/clearing.d.ts +0 -204
- package/dist/clearing.js +0 -151
- package/dist/file-storage.d.ts +0 -39
- package/dist/file-storage.js +0 -195
package/README.md
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Agent payments on Metal for the official x402 packages: registers the Metal
|
|
4
4
|
devnet (`eip155:1337`) and testnet (`eip155:63825`) for the `exact` scheme,
|
|
5
|
-
priced in `*USDZ`, for both sides of
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Metal enforces.
|
|
5
|
+
priced in `*USDZ`, for both sides of an on-chain payment, and mandates,
|
|
6
|
+
which let an agent pay from its owner's account within limits Metal
|
|
7
|
+
enforces.
|
|
9
8
|
|
|
10
9
|
```bash
|
|
11
10
|
npm install @metalntwx/metal-pay @x402/core viem
|
|
@@ -17,10 +16,12 @@ registers the scheme on an `x402Client` you already have. Both refuse,
|
|
|
17
16
|
before signing, a Metal `exact` offer in any token but `*USDZ` or under any
|
|
18
17
|
EIP-712 domain but USDZ's. `createMetalPaymentClient` also refuses any offer
|
|
19
18
|
above `maxAmount`, a `bigint` in `*USDZ` base units. The default is
|
|
20
|
-
`DEFAULT_MAX_PAYMENT`, 1 `*USDZ`. It works with `@x402
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
`DEFAULT_MAX_PAYMENT`, 1 `*USDZ`. It works with `@x402/core`, `@x402/evm`
|
|
20
|
+
and `@x402/fetch` from 2.28 up to the next major, installed as its peers
|
|
21
|
+
(npm 7+ and pnpm do that themselves). The stock client pays only tokens in
|
|
22
|
+
its own table unless its spend controls list others;
|
|
23
|
+
`createMetalPaymentClient` turns them off on its client, so its own refusals
|
|
24
|
+
name the offer. On a client of your own, add
|
|
24
25
|
`{ network, asset: USDZ.address }` to `setSpendControls({ allowedAssets })`.
|
|
25
26
|
A paid request is never redirected to another origin, so no other site
|
|
26
27
|
receives the payment. `createMandatePaymentClient` does the same.
|
|
@@ -46,42 +47,78 @@ registers `ExactEvmScheme` for other networks, add
|
|
|
46
47
|
`facilitatorUrl` is Metal's x402 facilitator for it:
|
|
47
48
|
`https://x402-testnet.metalntwx.com/x402/facilitator` on testnet, and
|
|
48
49
|
`http://127.0.0.1:7090/x402/facilitator` on devnet, where
|
|
49
|
-
`just x402-facilitator` runs it. It settles
|
|
50
|
-
|
|
51
|
-
the `createAuthHeaders` option, and
|
|
50
|
+
`just x402-facilitator` runs it. It settles payments for any seller, in
|
|
51
|
+
either scheme; a seller Metal issued a token to sends it with
|
|
52
|
+
`sellerToken(token)`, the `createAuthHeaders` option, and `GET
|
|
53
|
+
/settlements` then lists its payments under that label. To also take
|
|
54
|
+
clearing, register `new ClearingServerScheme(network)` on that network
|
|
55
|
+
beside `exact` and list a `bajillion` offer whose `payTo` is the seller's
|
|
56
|
+
clearing key; the offer names the Clearing deployment the facilitator lists
|
|
57
|
+
in `/supported` and binds its invoices to the resource.
|
|
52
58
|
|
|
53
59
|
```typescript
|
|
54
60
|
import { HTTPFacilitatorClient, x402ResourceServer } from "@x402/core/server";
|
|
55
61
|
import { paymentMiddleware } from "@x402/hono";
|
|
56
62
|
import { METAL_NETWORKS, registerMetalScheme } from "@metalntwx/metal-pay";
|
|
57
63
|
|
|
58
|
-
const facilitator = new HTTPFacilitatorClient({
|
|
64
|
+
const facilitator = new HTTPFacilitatorClient({
|
|
65
|
+
url: METAL_NETWORKS.devnet.facilitatorUrl,
|
|
66
|
+
});
|
|
59
67
|
const server = registerMetalScheme(new x402ResourceServer(facilitator));
|
|
60
68
|
app.use(
|
|
61
69
|
paymentMiddleware(
|
|
62
|
-
{
|
|
70
|
+
{
|
|
71
|
+
"GET /quote": {
|
|
72
|
+
accepts: {
|
|
73
|
+
scheme: "exact",
|
|
74
|
+
network: "eip155:1337",
|
|
75
|
+
payTo: "0x…",
|
|
76
|
+
price: "0.01",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
63
80
|
server,
|
|
64
81
|
),
|
|
65
82
|
);
|
|
66
83
|
```
|
|
67
84
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
## Native Bajillion payments
|
|
86
|
+
|
|
87
|
+
`createClearingClient` signs cumulative P-256 payments and retains the exact
|
|
88
|
+
pending authorization across transport errors. Supply trusted `serviceUrl`,
|
|
89
|
+
`rpcUrl`, `network`, `settlement`, `asset`, a signer, an atomic store and a
|
|
90
|
+
`maxAmount` limit. In Node 22.13 or later (23.4 or later on Node 23),
|
|
91
|
+
`openClearingWallet(directory)` from `@metalntwx/metal-pay/node` supplies a
|
|
92
|
+
persistent signer and store with exclusive
|
|
93
|
+
process ownership. Preserve that directory across restarts; call `close()` on
|
|
94
|
+
shutdown. Retry an unknown outcome using the same invoice before another payment.
|
|
95
|
+
|
|
96
|
+
`clearingRequirements` and `clearingInvoice` bind an invoice to a resource,
|
|
97
|
+
recipient, amount and deployment. `registerClearingClient` adds the `bajillion`
|
|
98
|
+
scheme to an official x402 client, which then pays by clearing wherever its
|
|
99
|
+
wallet can pay the offer. Behind the stock middleware, Metal's facilitator
|
|
100
|
+
verifies and deduplicates clearing payments before the handler runs. A seller that
|
|
101
|
+
verifies them itself calls `verifyClearingPayment` with its own trusted
|
|
102
|
+
RPC/service configuration and deduplicates `clearingPaymentId` in durable
|
|
103
|
+
storage before delivering. The returned receipt is **preconfirmed**;
|
|
104
|
+
watch `Clearing.finalizedCount` before labeling its epoch finalized. It is not
|
|
105
|
+
an EVM transaction hash.
|
|
106
|
+
|
|
107
|
+
`depositToClearing` funds a clearing account from an EVM account, waiting
|
|
108
|
+
for the contract's deposit window; `clearingSpendable` reads the service's
|
|
109
|
+
estimate of what the account can spend, in token base units, and
|
|
110
|
+
`clearingBalance` the finalized balance and its proof, in clearing units
|
|
111
|
+
(`Clearing.unit()` base units each, a millionth of `*USDZ`);
|
|
112
|
+
`withdrawFromClearing` queues a withdrawal of the finalized balance and,
|
|
113
|
+
once its epoch has finalized, claims it, for payer and seller alike.
|
|
114
|
+
`clearingClose` and `clearingLogProof` are the pieces it is built from.
|
|
115
|
+
`recoverFromClearing` takes an account's funds out of a deployment whose
|
|
116
|
+
service has missed a deadline: it faults the deployment, starts recovery,
|
|
117
|
+
and takes the payout of the account's finalized withdrawal, its last
|
|
118
|
+
finalized balance and its uncounted deposits, with proofs from the service
|
|
119
|
+
or the first of several validators that retained the epoch. The
|
|
120
|
+
[service README](../../apps/clearing-service/README.md) describes
|
|
121
|
+
operator/validator setup, receipt retention and proof endpoints.
|
|
85
122
|
|
|
86
123
|
**Mandates.** `@metalntwx/metal-pay/mandates` lets an agent pay from its
|
|
87
124
|
owner's account with a P-256 key of its own, within limits Metal enforces on
|
|
@@ -98,9 +135,11 @@ ordinary account execution. Factory-created clones share an immutable VI
|
|
|
98
135
|
verifier; budgets and replay protection live in each account. `createMandatePaymentClient({ credential, signDigest, network })`
|
|
99
136
|
is the payer, and `MandateExactScheme` the same payer as a scheme for an
|
|
100
137
|
`x402Client` of your own: each payment is an ERC-3009 authorization from the
|
|
101
|
-
owner's account whose signature is the agent's per-payment mandate
|
|
102
|
-
|
|
103
|
-
|
|
138
|
+
owner's account whose signature is the agent's per-payment mandate; Metal's
|
|
139
|
+
facilitator submits it as `pull` on the owner's account, which checks it
|
|
140
|
+
against the mandate, spends the budget and hands the token the
|
|
141
|
+
authorization. Sellers see an ordinary `exact` payment. The client sets no
|
|
142
|
+
limit of its own.
|
|
104
143
|
`readCheck` names the limit behind a refusal, `readMandateState` reads the
|
|
105
144
|
spend, and `pullCall` builds a direct payment with no seller. A credential's amounts
|
|
106
145
|
are decimal, to the cent. `verifyMandate` and `verifyMandatePayment` trust the
|