@integraledger/profile-facilitator 0.5.1 → 0.6.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/CHANGELOG.md +449 -0
- package/README.md +551 -47
- package/dist/core.d.ts +1 -1
- package/dist/core.js +683 -66
- package/dist/http.d.ts +19 -4
- package/dist/http.js +16 -6
- package/dist/module.d.ts +108 -21
- package/dist/module.js +39 -0
- package/dist/modules/casper/index.js +14 -2
- package/dist/modules/erc7710/index.d.ts +8 -5
- package/dist/modules/erc7710/index.js +1110 -33
- package/dist/modules/evm/escrow.d.ts +125 -0
- package/dist/modules/evm/escrow.js +619 -0
- package/dist/modules/evm/forms.d.ts +37 -9
- package/dist/modules/evm/forms.js +165 -21
- package/dist/modules/evm/index.d.ts +41 -6
- package/dist/modules/evm/index.js +1127 -18
- package/dist/modules/evm/node.d.ts +16 -1
- package/dist/modules/evm/node.js +181 -26
- package/dist/modules/evm/nonce-proof.d.ts +186 -0
- package/dist/modules/evm/nonce-proof.js +779 -0
- package/dist/modules/solana/index.d.ts +3 -0
- package/dist/modules/solana/index.js +94 -7
- package/dist/modules/solana/reader.d.ts +2 -1
- package/dist/modules/solana/reader.js +42 -4
- package/dist/modules/solana/upto-claim.d.ts +58 -0
- package/dist/modules/solana/upto-claim.js +269 -0
- package/dist/modules/stellar/index.d.ts +5 -0
- package/dist/modules/stellar/index.js +17 -7
- package/dist/modules/stellar/node.d.ts +7 -1
- package/dist/modules/stellar/node.js +51 -7
- package/dist/modules/sui/index.js +63 -18
- package/dist/modules/sui/node.d.ts +13 -0
- package/dist/modules/sui/node.js +60 -0
- package/dist/modules/ton/index.js +5 -1
- package/dist/modules/xrpl/index.js +60 -11
- package/dist/modules/xrpl/node.d.ts +31 -2
- package/dist/modules/xrpl/node.js +88 -17
- package/dist/modules/xrpl/upto.js +105 -19
- package/dist/record.d.ts +52 -8
- package/dist/record.js +39 -5
- package/dist/wrapper.d.ts +3 -1
- package/dist/wrapper.js +4 -2
- package/package.json +3 -3
|
@@ -21,11 +21,17 @@ export declare const ERC7710_PAIRINGS: readonly ["x402/exact/eip155/erc7710", "x
|
|
|
21
21
|
type EvmPairing = (typeof PAIRINGS)[EvmScheme][number] | (typeof ERC7710_PAIRINGS)[number];
|
|
22
22
|
/** A presented payment's read keys, as the pairing's `reference` gives them: an object lcp checks again at `status`. */
|
|
23
23
|
type Ref = Record<string, unknown>;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* What the pure checks found: the payment's pairing and the read keys lcp gives it, where its form has them; `later`
|
|
26
|
+
* where it is a later message of its scheme (`laterMessage`).
|
|
27
|
+
*/
|
|
25
28
|
export interface Admitted {
|
|
26
29
|
readonly pairing: EvmPairing;
|
|
27
30
|
readonly ref?: Ref;
|
|
31
|
+
readonly later?: true;
|
|
28
32
|
}
|
|
33
|
+
/** Whether a payment under `scheme` is a later message of the scheme, by its payload's type alone. */
|
|
34
|
+
export declare function laterMessage(scheme: EvmScheme | "erc7710", payload: unknown): boolean;
|
|
29
35
|
/**
|
|
30
36
|
* The options of `exact` on EVM that no published EVM class may settle: one that pays several payees (a non-empty
|
|
31
37
|
* `extra.splits`, which `exact` does not carry), and Circle's batched option, which signs under the Gateway Wallet's
|
|
@@ -41,10 +47,19 @@ export declare function exactOptionRefused(requirements: {
|
|
|
41
47
|
* names, as lcp's option filter reads it alone (`invalid_payment_requirements` otherwise), and the payment is that
|
|
42
48
|
* pairing's as lcp's `reference` reads it against the option (`invalid_payload` otherwise), an `upto` option being
|
|
43
49
|
* the one `uptoOption` holds it to. A batch settlement's payment that is no opening has no reference: lcp's channel
|
|
44
|
-
* read holds
|
|
45
|
-
*
|
|
50
|
+
* read holds a voucher's or top-up's configuration to its voucher's channel. A later message of the scheme
|
|
51
|
+
* (`laterMessage`: an escrow's capture, void or refund; a channel's claim, settle or refund) has no reference either,
|
|
52
|
+
* since lcp does not decode it: it is x402's class's to check, and the escrow or the channel contract bounds what it
|
|
53
|
+
* moves by what the opening funded. A batch settlement's is admitted before its requirements are read, since the
|
|
54
|
+
* channel manager's name no pairing; an auth-capture one's requirements are the option the hold answered.
|
|
46
55
|
*/
|
|
47
56
|
export declare function admit(scheme: EvmScheme | "erc7710", p: X402Payment, pairings: readonly PairingId[]): Promise<Admitted | Refused>;
|
|
57
|
+
/**
|
|
58
|
+
* The delegation an admitted ERC-7710 payment redeems, as signed, whatever its spelling: the manager and the delegator
|
|
59
|
+
* in lowercase, and the leaf delegation's EIP-712 hash where the context decodes as the reference manager's encoding,
|
|
60
|
+
* else the context's bytes in lowercase hex. A redemption's record key is its digest with the sale's H.
|
|
61
|
+
*/
|
|
62
|
+
export declare function delegationOf(p: X402Payment, a: Admitted): Record<string, string>;
|
|
48
63
|
/**
|
|
49
64
|
* The record's key and keep for an admitted payment. EIP-3009: the network, the token, the authorization's `from` and
|
|
50
65
|
* its nonce, kept to `validBefore`; the auth-capture escrow's ERC-3009 collector signs its nonce in the token's one
|
|
@@ -52,20 +67,33 @@ export declare function admit(scheme: EvmScheme | "erc7710", p: X402Payment, pai
|
|
|
52
67
|
* owner, kept to the deadline. Neither is the nonce alone, and for an agreement the nonce signed is the agreement's own
|
|
53
68
|
* value, so one payer's agreement and payment under one H are two rows. A batch settlement's call and an ERC-7710
|
|
54
69
|
* redemption hold no single-use value: each is keyed by a digest, for the settler's life. A batch call's is the digest
|
|
55
|
-
* of its signed payload. A redemption's is the digest of the delegation it redeems as signed, whatever its spelling
|
|
56
|
-
* manager and the delegator in lowercase,
|
|
57
|
-
* reference manager's encoding (the hash commits to its caveats, its salt and, through its authority, the chain
|
|
58
|
-
* it; not to the signatures or the encoding's padding), else the context's bytes in lowercase hex
|
|
59
|
-
* one row, presented in any letter case or re-encoded
|
|
70
|
+
* of its signed payload. A redemption's is the digest of the delegation it redeems as signed, whatever its spelling, and
|
|
71
|
+
* of the sale: the manager and the delegator in lowercase, the leaf delegation's EIP-712 hash where the context decodes
|
|
72
|
+
* as the reference manager's encoding (the hash commits to its caveats, its salt and, through its authority, the chain
|
|
73
|
+
* above it; not to the signatures or the encoding's padding), else the context's bytes in lowercase hex, and the H the
|
|
74
|
+
* payment echoes. So one sale through one delegation is one row, presented in any letter case or re-encoded, and each
|
|
75
|
+
* other sale through a delegation that may be redeemed again (x402's ERC-7710 is one-time or multi-use, its caveats
|
|
76
|
+
* the limit) is its own row, which the redemption's simulation refuses once the caveats are spent.
|
|
77
|
+
* An escrow's capture, void or refund (`Admitted.later`) is its own row, never the row of the hold whose signed
|
|
78
|
+
* authorization a payload the resource server stamps with a type still carries: the digest of the message its receiver
|
|
79
|
+
* authorizer signs (`signedMessage`), every member it signs and nothing else, its signature excluded; the core also
|
|
80
|
+
* takes that message as the row's body (`Instrumented.body`). The escrow's amounts only fall as a payment's lifecycle
|
|
81
|
+
* goes on, so each such message occurs once in it, and one message spelt two ways, or signed again, is one row: never
|
|
82
|
+
* sent twice at once. A batch settlement's later message is keyed by the digest of its signed payload; its claim and settle are not
|
|
83
|
+
* recorded (`Instrumented.unrecorded`).
|
|
60
84
|
*/
|
|
61
85
|
export declare function instrumentOf(network: Network, p: X402Payment, a: Admitted): Promise<Instrumented | Refused>;
|
|
86
|
+
/** Whether an admitted payment is an auth-capture escrow's later message: its capture, void or refund. */
|
|
87
|
+
export declare function escrowMessage(a: Admitted): boolean;
|
|
62
88
|
/**
|
|
63
89
|
* lcp's read of an admitted payment, by the pairing's search, at the final mark `finalized`, as the act `payment`: the
|
|
64
90
|
* value an agreement signs stands in H's place in its reference, so the search for it is the search for that value.
|
|
65
91
|
* `at.search` resumes an earlier search. `at.transaction` is the transaction the settler's record holds for the
|
|
66
92
|
* payment, which the reference names as the transaction a settler names: read beside the search, and on a level that
|
|
67
93
|
* signs no H (`x402/exact/eip155/erc7710`) the only way the read finds the payment. A batch settlement's payment that
|
|
68
|
-
* is no opening has no reference and no read of its own: `pending`, `search-incomplete`, live
|
|
94
|
+
* is no opening has no reference and no read of its own: `pending`, `search-incomplete`, live (the module reads a
|
|
95
|
+
* channel refund's own receipt before it, `revertedAtFinalized` and `refundedAtFinalized`). An `exact` EIP-3009
|
|
96
|
+
* payment is read by the authorization it presents (`byAuthorization`).
|
|
69
97
|
*/
|
|
70
98
|
export declare function readOf(reader: EvmReader, a: Admitted, at: {
|
|
71
99
|
readonly search?: unknown;
|
|
@@ -7,6 +7,7 @@ import { canonicalJson, digestJson, isRefusal, pairingOf } from "@integraledger/
|
|
|
7
7
|
import { PERMIT2 } from "@integraledger/lcp/evm";
|
|
8
8
|
import { authCaptureEip3009, authCapturePermit2, exactEip3009, exactErc7710, exactErc7710Salt, exactPermit2, pairingOfPayment, uptoPermit2, } from "@integraledger/lcp/x402";
|
|
9
9
|
import { batchEvm } from "@integraledger/lcp/x402-batch-settlement";
|
|
10
|
+
import { resolveAuthCaptureDeployment } from "@x402/evm";
|
|
10
11
|
import { outcomeOf } from "../../module.js";
|
|
11
12
|
/** The pairings each scheme's class submits on an `eip155` network. */
|
|
12
13
|
export const PAIRINGS = {
|
|
@@ -34,6 +35,30 @@ function codec(b) {
|
|
|
34
35
|
function isObject(v) {
|
|
35
36
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The payload types x402's classes (`@x402/evm` 2.31.0) take as a later message on an instrument an earlier payment
|
|
40
|
+
* opened, which a resource server sends and the payer did not sign as a payment: `AuthCaptureEvmScheme` takes every
|
|
41
|
+
* payload of type `capture`, `void` or `refund` as the escrow's lifecycle call of that name (`isLifecyclePayload`),
|
|
42
|
+
* the hold's own payload the resource server stamps with a type (its capture after the handler, its void on cancel)
|
|
43
|
+
* among them; `BatchSettlementEvmScheme` takes `claim`, `settle` and `refund` as the channel contract's call of that
|
|
44
|
+
* name, `claim` and `settle` as x402's channel manager builds them, under requirements of its own (amount `"0"`, no
|
|
45
|
+
* `extra`) that name no lcp pairing.
|
|
46
|
+
*/
|
|
47
|
+
const LATER = {
|
|
48
|
+
"auth-capture": ["capture", "void", "refund"],
|
|
49
|
+
"batch-settlement": ["claim", "settle", "refund"],
|
|
50
|
+
};
|
|
51
|
+
/** A payment's payload's `type`, where it states one. */
|
|
52
|
+
function laterType(payload) {
|
|
53
|
+
const body = isObject(payload) ? payload["payload"] : undefined;
|
|
54
|
+
const kind = isObject(body) ? body["type"] : undefined;
|
|
55
|
+
return typeof kind === "string" ? kind : undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Whether a payment under `scheme` is a later message of the scheme, by its payload's type alone. */
|
|
58
|
+
export function laterMessage(scheme, payload) {
|
|
59
|
+
const kind = laterType(payload);
|
|
60
|
+
return scheme !== "erc7710" && kind !== undefined && (LATER[scheme] ?? []).includes(kind);
|
|
61
|
+
}
|
|
37
62
|
/**
|
|
38
63
|
* The options of `exact` on EVM that no published EVM class may settle: one that pays several payees (a non-empty
|
|
39
64
|
* `extra.splits`, which `exact` does not carry), and Circle's batched option, which signs under the Gateway Wallet's
|
|
@@ -79,8 +104,11 @@ function uptoOption(p) {
|
|
|
79
104
|
* names, as lcp's option filter reads it alone (`invalid_payment_requirements` otherwise), and the payment is that
|
|
80
105
|
* pairing's as lcp's `reference` reads it against the option (`invalid_payload` otherwise), an `upto` option being
|
|
81
106
|
* the one `uptoOption` holds it to. A batch settlement's payment that is no opening has no reference: lcp's channel
|
|
82
|
-
* read holds
|
|
83
|
-
*
|
|
107
|
+
* read holds a voucher's or top-up's configuration to its voucher's channel. A later message of the scheme
|
|
108
|
+
* (`laterMessage`: an escrow's capture, void or refund; a channel's claim, settle or refund) has no reference either,
|
|
109
|
+
* since lcp does not decode it: it is x402's class's to check, and the escrow or the channel contract bounds what it
|
|
110
|
+
* moves by what the opening funded. A batch settlement's is admitted before its requirements are read, since the
|
|
111
|
+
* channel manager's name no pairing; an auth-capture one's requirements are the option the hold answered.
|
|
84
112
|
*/
|
|
85
113
|
export async function admit(scheme, p, pairings) {
|
|
86
114
|
const { payload, requirements } = p;
|
|
@@ -88,6 +116,9 @@ export async function admit(scheme, p, pairings) {
|
|
|
88
116
|
return { refused: "invalid_payment_requirements" };
|
|
89
117
|
if (requirements.scheme === "exact" && exactOptionRefused(requirements))
|
|
90
118
|
return { refused: "invalid_payment_requirements" };
|
|
119
|
+
const later = laterMessage(scheme, payload);
|
|
120
|
+
if (later && scheme === "batch-settlement")
|
|
121
|
+
return { pairing: batchEvm.id, later: true };
|
|
91
122
|
const option = pairingOf(requirements);
|
|
92
123
|
if (option === undefined)
|
|
93
124
|
return { refused: "invalid_payment_requirements" };
|
|
@@ -96,10 +127,9 @@ export async function admit(scheme, p, pairings) {
|
|
|
96
127
|
return { refused: "invalid_payment_requirements" };
|
|
97
128
|
}
|
|
98
129
|
const pairing = level;
|
|
130
|
+
if (later)
|
|
131
|
+
return { pairing, later: true };
|
|
99
132
|
if (pairing === batchEvm.id) {
|
|
100
|
-
const kind = isObject(payload.payload) ? payload.payload["type"] : undefined;
|
|
101
|
-
if (kind === "claim" || kind === "settle")
|
|
102
|
-
return { pairing };
|
|
103
133
|
const k = batchEvm.channel.kind(payload);
|
|
104
134
|
if (isRefusal(k))
|
|
105
135
|
return { refused: "invalid_payload" };
|
|
@@ -125,6 +155,20 @@ function permit2Nonce(v) {
|
|
|
125
155
|
function lapse(seconds) {
|
|
126
156
|
return { until: "lapse", at: Number(BigInt(String(seconds))) * 1000 };
|
|
127
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* The delegation an admitted ERC-7710 payment redeems, as signed, whatever its spelling: the manager and the delegator
|
|
160
|
+
* in lowercase, and the leaf delegation's EIP-712 hash where the context decodes as the reference manager's encoding,
|
|
161
|
+
* else the context's bytes in lowercase hex. A redemption's record key is its digest with the sale's H.
|
|
162
|
+
*/
|
|
163
|
+
export function delegationOf(p, a) {
|
|
164
|
+
const r = isObject(p.payload.payload) ? p.payload.payload : {};
|
|
165
|
+
const leaf = isObject(a.ref?.["presented"]) ? a.ref["presented"]["delegation"] : undefined;
|
|
166
|
+
return {
|
|
167
|
+
delegationManager: lower(r["delegationManager"]),
|
|
168
|
+
delegator: lower(r["delegator"]),
|
|
169
|
+
...(typeof leaf === "string" ? { delegation: lower(leaf) } : { permissionContext: lower(r["permissionContext"]) }),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
128
172
|
/**
|
|
129
173
|
* The record's key and keep for an admitted payment. EIP-3009: the network, the token, the authorization's `from` and
|
|
130
174
|
* its nonce, kept to `validBefore`; the auth-capture escrow's ERC-3009 collector signs its nonce in the token's one
|
|
@@ -132,11 +176,20 @@ function lapse(seconds) {
|
|
|
132
176
|
* owner, kept to the deadline. Neither is the nonce alone, and for an agreement the nonce signed is the agreement's own
|
|
133
177
|
* value, so one payer's agreement and payment under one H are two rows. A batch settlement's call and an ERC-7710
|
|
134
178
|
* redemption hold no single-use value: each is keyed by a digest, for the settler's life. A batch call's is the digest
|
|
135
|
-
* of its signed payload. A redemption's is the digest of the delegation it redeems as signed, whatever its spelling
|
|
136
|
-
* manager and the delegator in lowercase,
|
|
137
|
-
* reference manager's encoding (the hash commits to its caveats, its salt and, through its authority, the chain
|
|
138
|
-
* it; not to the signatures or the encoding's padding), else the context's bytes in lowercase hex
|
|
139
|
-
* one row, presented in any letter case or re-encoded
|
|
179
|
+
* of its signed payload. A redemption's is the digest of the delegation it redeems as signed, whatever its spelling, and
|
|
180
|
+
* of the sale: the manager and the delegator in lowercase, the leaf delegation's EIP-712 hash where the context decodes
|
|
181
|
+
* as the reference manager's encoding (the hash commits to its caveats, its salt and, through its authority, the chain
|
|
182
|
+
* above it; not to the signatures or the encoding's padding), else the context's bytes in lowercase hex, and the H the
|
|
183
|
+
* payment echoes. So one sale through one delegation is one row, presented in any letter case or re-encoded, and each
|
|
184
|
+
* other sale through a delegation that may be redeemed again (x402's ERC-7710 is one-time or multi-use, its caveats
|
|
185
|
+
* the limit) is its own row, which the redemption's simulation refuses once the caveats are spent.
|
|
186
|
+
* An escrow's capture, void or refund (`Admitted.later`) is its own row, never the row of the hold whose signed
|
|
187
|
+
* authorization a payload the resource server stamps with a type still carries: the digest of the message its receiver
|
|
188
|
+
* authorizer signs (`signedMessage`), every member it signs and nothing else, its signature excluded; the core also
|
|
189
|
+
* takes that message as the row's body (`Instrumented.body`). The escrow's amounts only fall as a payment's lifecycle
|
|
190
|
+
* goes on, so each such message occurs once in it, and one message spelt two ways, or signed again, is one row: never
|
|
191
|
+
* sent twice at once. A batch settlement's later message is keyed by the digest of its signed payload; its claim and settle are not
|
|
192
|
+
* recorded (`Instrumented.unrecorded`).
|
|
140
193
|
*/
|
|
141
194
|
export async function instrumentOf(network, p, a) {
|
|
142
195
|
const nonce = CODEC[a.pairing].nonce;
|
|
@@ -145,18 +198,26 @@ export async function instrumentOf(network, p, a) {
|
|
|
145
198
|
const d = await digestJson(signed);
|
|
146
199
|
if (isRefusal(d))
|
|
147
200
|
return { refused: "invalid_payload" };
|
|
148
|
-
|
|
201
|
+
const unrecorded = a.later === true && a.pairing === batchEvm.id && laterType(p.payload) !== "refund";
|
|
202
|
+
return {
|
|
203
|
+
pairing: a.pairing,
|
|
204
|
+
instrument: { by: "digest", network, digest: d },
|
|
205
|
+
nonce,
|
|
206
|
+
keep: { until: "settler" },
|
|
207
|
+
...(a.later ? { later: true } : {}),
|
|
208
|
+
...(unrecorded ? { unrecorded: true } : {}),
|
|
209
|
+
};
|
|
149
210
|
};
|
|
150
211
|
const digest = () => digestOf(p.payload.payload);
|
|
151
|
-
if (a
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
...(typeof leaf === "string" ? { delegation: lower(leaf) } : { permissionContext: lower(r["permissionContext"]) }),
|
|
158
|
-
});
|
|
212
|
+
if (escrowMessage(a)) {
|
|
213
|
+
// The row's key and its body are the message the receiver authorizer signs, so that one message signed again (a
|
|
214
|
+
// signer that does not sign deterministically) is one row and one body, and its signature is the class's to judge.
|
|
215
|
+
const message = signedMessage(p);
|
|
216
|
+
const keyed = await digestOf(message);
|
|
217
|
+
return "refused" in keyed ? keyed : { ...keyed, resendable: true, body: message };
|
|
159
218
|
}
|
|
219
|
+
if (a.pairing === exactErc7710.id || a.pairing === exactErc7710Salt.id)
|
|
220
|
+
return digestOf({ ...delegationOf(p, a), h: lower(a.ref?.["h"]) });
|
|
160
221
|
if (ref === undefined)
|
|
161
222
|
return digest();
|
|
162
223
|
const presented = isObject(ref["presented"]) ? ref["presented"] : {};
|
|
@@ -185,18 +246,101 @@ export async function instrumentOf(network, p, a) {
|
|
|
185
246
|
}
|
|
186
247
|
return { pairing: a.pairing, instrument, nonce, keep };
|
|
187
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* A value as a signature binds it: text `BigInt` reads as an integer, as its decimal digits, since x402's class and
|
|
251
|
+
* viem's encoder read a message's numbers with `BigInt` (so `" 400000"`, `"+400000"` and `"0x61a80"` are one amount);
|
|
252
|
+
* other text in lowercase.
|
|
253
|
+
*/
|
|
254
|
+
function bound(v) {
|
|
255
|
+
if (typeof v !== "string")
|
|
256
|
+
return v;
|
|
257
|
+
try {
|
|
258
|
+
return BigInt(v).toString(10);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
return v.toLowerCase();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/** Whether an admitted payment is an auth-capture escrow's later message: its capture, void or refund. */
|
|
265
|
+
export function escrowMessage(a) {
|
|
266
|
+
return a.later === true && (a.pairing === authCaptureEip3009.id || a.pairing === authCapturePermit2.id);
|
|
267
|
+
}
|
|
268
|
+
/** The members of the commerce-payments escrow's `PaymentInfo`, in its order. */
|
|
269
|
+
const PAYMENT_INFO = [
|
|
270
|
+
"operator",
|
|
271
|
+
"payer",
|
|
272
|
+
"receiver",
|
|
273
|
+
"token",
|
|
274
|
+
"maxAmount",
|
|
275
|
+
"preApprovalExpiry",
|
|
276
|
+
"authorizationExpiry",
|
|
277
|
+
"refundExpiry",
|
|
278
|
+
"minFeeBps",
|
|
279
|
+
"maxFeeBps",
|
|
280
|
+
"feeReceiver",
|
|
281
|
+
"salt",
|
|
282
|
+
];
|
|
283
|
+
/**
|
|
284
|
+
* The EIP-712 domain's name and version under which x402's `AuthCaptureEvmScheme` of `@x402/evm` 2.31.0 has the receiver
|
|
285
|
+
* authorizer sign a capture, void or refund (its `getOperatorEip712Domain`, whose `verifyingContract` is the
|
|
286
|
+
* requirements' `captureAuthorizer` and whose `chainId` is the network's).
|
|
287
|
+
*/
|
|
288
|
+
const OPERATOR_DOMAIN = { name: "x402 Auth Capture Operator", version: "1" };
|
|
289
|
+
/**
|
|
290
|
+
* The message the receiver authorizer of an auth-capture lifecycle message signs, as x402's `AuthCaptureEvmScheme` of
|
|
291
|
+
* `@x402/evm` 2.31.0 has it signed and verifies it, every member it signs, as `instrumentOf` keys the row and states
|
|
292
|
+
* its body; the signatures are not in it. The typed-data domain: its name and version, the network's chain id, and the
|
|
293
|
+
* requirements' `captureAuthorizer` as its verifying contract. The payment's hash (`paymentInfoHash`) as the members it
|
|
294
|
+
* commits to: the chain id, the escrow of the requirements' deployment, and the twelve members of the escrow's
|
|
295
|
+
* `PaymentInfo`. Its type; for a capture, its amount, its fee receiver and fee (`feeBps` or `feeAmount`, as the
|
|
296
|
+
* deployment's version signs) and the capturable and refundable amounts it expects; for a refund, its amount, its token
|
|
297
|
+
* collector (the deployment's `operatorRefundCollector`, which the class has signed and verifies) and the amounts it
|
|
298
|
+
* expects. Each integer or address is the number it is, so one message spelt two ways is one. The void of the
|
|
299
|
+
* payment's remainder a capture may carry is another message the receiver authorizer signs (`Void`, over the payment's
|
|
300
|
+
* hash alone), which the escrow's event of the capture does not show: a capture with it and the same capture without
|
|
301
|
+
* it are one message, one row and one body, and the void goes with whichever carries it.
|
|
302
|
+
*/
|
|
303
|
+
function signedMessage(p) {
|
|
304
|
+
const payload = p.payload.payload;
|
|
305
|
+
const body = isObject(payload) ? payload : {};
|
|
306
|
+
const extra = isObject(p.requirements.extra) ? p.requirements.extra : {};
|
|
307
|
+
const info = isObject(body["paymentInfo"]) ? body["paymentInfo"] : {};
|
|
308
|
+
const deployment = resolveAuthCaptureDeployment(typeof extra["authCaptureEscrow"] === "string" ? extra["authCaptureEscrow"] : undefined);
|
|
309
|
+
const chainId = String(p.requirements.network).startsWith("eip155:") ? bound(String(p.requirements.network).slice("eip155:".length)) : null;
|
|
310
|
+
const domain = { ...OPERATOR_DOMAIN, chainId, verifyingContract: bound(extra["captureAuthorizer"]) ?? null };
|
|
311
|
+
// The members the escrow's `PaymentInfo` holds, and so its hash: a member the escrow does not take changes nothing.
|
|
312
|
+
const paymentInfo = Object.fromEntries(PAYMENT_INFO.map((k) => [k, bound(info[k]) ?? null]));
|
|
313
|
+
const payment = { chainId, escrow: deployment === undefined ? null : bound(deployment.escrow), paymentInfo };
|
|
314
|
+
const type = body["type"];
|
|
315
|
+
const member = (k) => bound(body[k]) ?? null;
|
|
316
|
+
const expected = [member("expectedCapturableAmount"), member("expectedRefundableAmount")];
|
|
317
|
+
if (type === "capture") {
|
|
318
|
+
const fee = body["feeAmount"] !== undefined ? { feeAmount: member("feeAmount") } : { feeBps: member("feeBps") };
|
|
319
|
+
return { domain, type, payment, amount: member("amount"), feeReceiver: member("feeReceiver"), ...fee, expected };
|
|
320
|
+
}
|
|
321
|
+
if (type === "refund") {
|
|
322
|
+
const tokenCollector = deployment === undefined ? null : bound(deployment.operatorRefundCollector);
|
|
323
|
+
return { domain, type, payment, amount: member("amount"), tokenCollector, expected };
|
|
324
|
+
}
|
|
325
|
+
return { domain, type, payment };
|
|
326
|
+
}
|
|
188
327
|
/**
|
|
189
328
|
* lcp's read of an admitted payment, by the pairing's search, at the final mark `finalized`, as the act `payment`: the
|
|
190
329
|
* value an agreement signs stands in H's place in its reference, so the search for it is the search for that value.
|
|
191
330
|
* `at.search` resumes an earlier search. `at.transaction` is the transaction the settler's record holds for the
|
|
192
331
|
* payment, which the reference names as the transaction a settler names: read beside the search, and on a level that
|
|
193
332
|
* signs no H (`x402/exact/eip155/erc7710`) the only way the read finds the payment. A batch settlement's payment that
|
|
194
|
-
* is no opening has no reference and no read of its own: `pending`, `search-incomplete`, live
|
|
333
|
+
* is no opening has no reference and no read of its own: `pending`, `search-incomplete`, live (the module reads a
|
|
334
|
+
* channel refund's own receipt before it, `revertedAtFinalized` and `refundedAtFinalized`). An `exact` EIP-3009
|
|
335
|
+
* payment is read by the authorization it presents (`byAuthorization`).
|
|
195
336
|
*/
|
|
196
337
|
export async function readOf(reader, a, at) {
|
|
197
338
|
if (a.ref === undefined)
|
|
198
339
|
return outcomeOf({ state: "pending", reason: "search-incomplete", foreign: [] });
|
|
199
|
-
|
|
340
|
+
// An EIP-3009 payment is read by the authorization it presents, its use on the asset (`byAuthorization`): the payer's
|
|
341
|
+
// use of the same H on another token is another payment, never this one's answer.
|
|
342
|
+
const own = a.pairing === exactEip3009.id ? { ...a.ref, byAuthorization: true } : a.ref;
|
|
343
|
+
const ref = at.transaction === undefined ? own : { ...own, transaction: at.transaction.toLowerCase() };
|
|
200
344
|
const query = at.search === undefined
|
|
201
345
|
? { act: "payment", finality: "finalized" }
|
|
202
346
|
: { act: "payment", finality: "finalized", search: at.search };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { Hex } from "@integraledger/lcp/evm";
|
|
1
2
|
import type { PendingSettlementStore } from "@x402/core/facilitator";
|
|
2
3
|
import { type AuthCaptureFacilitatorConfig } from "@x402/evm/auth-capture/facilitator";
|
|
3
|
-
import type
|
|
4
|
-
import { type FeeMeter, type FeeNeeds, type Module, type ModuleStarter } from "../../module.js";
|
|
4
|
+
import { type FacilitatorEvmSigner } from "@x402/evm";
|
|
5
|
+
import { type Core, type FeeMeter, type FeeNeeds, type Module, type ModuleStarter, type ModuleState } from "../../module.js";
|
|
5
6
|
import { type EvmScheme } from "./forms.js";
|
|
6
7
|
/** One `eip155` network the `evm` module serves. */
|
|
7
8
|
export interface EvmConfig {
|
|
@@ -11,9 +12,11 @@ export interface EvmConfig {
|
|
|
11
12
|
readonly rpc: string;
|
|
12
13
|
/**
|
|
13
14
|
* The seller's gas key, as x402's EVM classes take it (`toFacilitatorEvmSigner` of a client over the same node): it
|
|
14
|
-
* sends every transaction the module submits and pays its gas.
|
|
15
|
+
* sends every transaction the module submits and pays its gas. For `auth-capture` it must also sign a transaction
|
|
16
|
+
* without sending it, and send one signed (`EvmSender`): the escrow's calls are signed first, named in the record,
|
|
17
|
+
* then sent, and the module does not start where `auth-capture` is registered with a key without these members.
|
|
15
18
|
*/
|
|
16
|
-
readonly signer: FacilitatorEvmSigner
|
|
19
|
+
readonly signer: FacilitatorEvmSigner & Partial<EvmSender>;
|
|
17
20
|
/** The schemes registered on the network; every one of the four where absent. */
|
|
18
21
|
readonly schemes?: readonly EvmScheme[];
|
|
19
22
|
/** ERC-6492 factories `exact` and `batch-settlement` may call to deploy a payer's wallet; none where absent. */
|
|
@@ -21,17 +24,49 @@ export interface EvmConfig {
|
|
|
21
24
|
/** `auth-capture`'s own configuration (fee terms, operators, its authorizers), passed to its class unchanged. */
|
|
22
25
|
readonly authCapture?: AuthCaptureFacilitatorConfig;
|
|
23
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* A gas key that signs a transaction without sending it, and sends one signed: with viem's wallet client over a local
|
|
29
|
+
* account, `prepareTransactionRequest` then `signTransaction`, and `sendRawTransaction`.
|
|
30
|
+
*/
|
|
31
|
+
export interface EvmSender {
|
|
32
|
+
/**
|
|
33
|
+
* Signs, and does not send, a transaction from the key calling `to` with `data`: its gas and fees filled as viem's
|
|
34
|
+
* `prepareTransactionRequest` fills them, unless the request names them (`gas`, and `maxFeePerGas` with
|
|
35
|
+
* `maxPriorityFeePerGas`, which a replacement at the same nonce names), and its nonce, unless `nonce`
|
|
36
|
+
* names one, the key's `pending` count. The signed transaction, serialized.
|
|
37
|
+
*/
|
|
38
|
+
signTransaction(request: {
|
|
39
|
+
readonly to: Hex;
|
|
40
|
+
readonly data: Hex;
|
|
41
|
+
readonly gas?: bigint;
|
|
42
|
+
readonly nonce?: number;
|
|
43
|
+
readonly maxFeePerGas?: bigint;
|
|
44
|
+
readonly maxPriorityFeePerGas?: bigint;
|
|
45
|
+
}): Promise<Hex>;
|
|
46
|
+
/** Sends a signed, serialized transaction (`eth_sendRawTransaction`), once: its hash. */
|
|
47
|
+
sendRawTransaction(request: {
|
|
48
|
+
readonly serializedTransaction: Hex;
|
|
49
|
+
}): Promise<Hex>;
|
|
50
|
+
}
|
|
24
51
|
/** A module whose key pays the fee of what it sends, with the read of each transaction's fee. */
|
|
25
52
|
export type EvmModule = Module & {
|
|
26
53
|
readonly fees: Required<FeeNeeds>;
|
|
27
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* `receipt` where it is the receipt of `transaction`; otherwise it throws, so that the escrow's class or the `erc7710`
|
|
57
|
+
* module answers the transaction pending and the record's read decides (neither keeps a pending settlement of its own). viem's `waitForTransactionReceipt` answers, by default, the receipt of another
|
|
58
|
+
* transaction of the same key at the same nonce where it finds one: a replacement of the same call, which the read
|
|
59
|
+
* then shows, or another payment's transaction, which paid nothing of this one.
|
|
60
|
+
*/
|
|
61
|
+
export declare function ownReceipt<R>(transaction: Hex, receipt: R): R;
|
|
28
62
|
/**
|
|
29
63
|
* The `evm` module's schemes on one network, each x402's class with what the core needs beside it, the gas key counted
|
|
30
64
|
* by `meter`, the network's fee meter. `pending` is where `exact`, `upto` and `batch-settlement` keep a settlement they
|
|
31
65
|
* sent and the chain does not yet show, so that a retried settle reconciles against it; each class keeps its own in
|
|
32
|
-
* memory where absent.
|
|
66
|
+
* memory where absent. `core` names an escrow call's replacement in the row before it is sent (`Core.naming`) and
|
|
67
|
+
* gives the settle wait a tip-only replacement waits for; where absent, no replacement is made.
|
|
33
68
|
*/
|
|
34
|
-
export declare function evmModules(c: EvmConfig, meter: FeeMeter, pending?: PendingSettlementStore): EvmModule[];
|
|
69
|
+
export declare function evmModules(c: EvmConfig, meter: FeeMeter, state: ModuleState, pending?: PendingSettlementStore, core?: Pick<Core, "naming" | "settleWaitMs">): EvmModule[];
|
|
35
70
|
/**
|
|
36
71
|
* How the core starts the module: the configuration's `evm` member lists the networks, one entry each, and each
|
|
37
72
|
* configured scheme on a network is one registration of x402's class, whose pending settlements are kept in the
|