@me2em/core 1.0.0-rc.4 → 1.0.0-rc.8
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 +144 -31
- package/dist/attestation.d.ts +4 -1
- package/dist/attestation.d.ts.map +1 -1
- package/dist/attestation.js +4 -1
- package/dist/attestation.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/payment-x402.d.ts +215 -0
- package/dist/payment-x402.d.ts.map +1 -0
- package/dist/payment-x402.js +209 -0
- package/dist/payment-x402.js.map +1 -0
- package/dist/payment.d.ts +31 -2
- package/dist/payment.d.ts.map +1 -1
- package/dist/payment.js +1 -1
- package/dist/payment.js.map +1 -1
- package/package.json +5 -4
- package/src/attestation.ts +4 -1
- package/src/index.ts +24 -0
- package/src/payment-x402.ts +349 -0
- package/src/payment.ts +35 -3
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// payment-x402.ts
|
|
2
|
+
//
|
|
3
|
+
// x402 v2 wire types and structural guards (ТЗ @me2em/x402 v1.1 §2.1).
|
|
4
|
+
//
|
|
5
|
+
// Dependency-leaf: imports only `parseChain` from `payment.js`.
|
|
6
|
+
// No runtime dependencies, no network code — pure types and guards.
|
|
7
|
+
//
|
|
8
|
+
// These are the WIRE data shapes from the x402 v2 specification plus
|
|
9
|
+
// the `PaymentSigner` contract (moved here in rc.8 from `@me2em/x402`).
|
|
10
|
+
// They are carried in @me2em/core so that @me2em/x402 (M1) and chain
|
|
11
|
+
// packages (M2) share one definition without a cross-dependency: the
|
|
12
|
+
// transport imports the shapes from here, chain packages implement the
|
|
13
|
+
// signer contract from here — neither sees the other. Core does not
|
|
14
|
+
// interpret them logically; guards are structural only.
|
|
15
|
+
|
|
16
|
+
import { parseChain } from './payment.js';
|
|
17
|
+
|
|
18
|
+
/** The x402 protocol version carried in every wire message. */
|
|
19
|
+
export const X402_VERSION = 2;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resource descriptor inside an x402 v2 `PaymentRequired` response:
|
|
23
|
+
* what is being sold and how it is presented (ТЗ x402 v1.1 §2.1).
|
|
24
|
+
*/
|
|
25
|
+
export interface X402ResourceInfo {
|
|
26
|
+
/** Absolute http(s) URL of the resource. */
|
|
27
|
+
readonly url: string;
|
|
28
|
+
/** Human-readable description of the resource. */
|
|
29
|
+
readonly description?: string;
|
|
30
|
+
/** MIME type of the resource (e.g. `application/json`). */
|
|
31
|
+
readonly mimeType?: string;
|
|
32
|
+
/** Printable-ASCII service name, at most 32 characters. */
|
|
33
|
+
readonly serviceName?: string;
|
|
34
|
+
/** Free-form tags, at most 5, each at most 32 characters. */
|
|
35
|
+
readonly tags?: readonly string[];
|
|
36
|
+
/** Absolute http(s) icon URL, at most 2048 characters. */
|
|
37
|
+
readonly iconUrl?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* One payment option inside `PaymentRequired.accepts` (ТЗ x402 v1.1 §2.1).
|
|
42
|
+
* `amount` is in atomic units (smallest denomination), a decimal string.
|
|
43
|
+
*/
|
|
44
|
+
export interface X402PaymentRequirements {
|
|
45
|
+
/** x402 execution scheme: `exact`, `eip3009`, `permit2-exact`, … */
|
|
46
|
+
readonly scheme: string;
|
|
47
|
+
/** Exact CAIP-2 chain id (validated with `parseChain`). */
|
|
48
|
+
readonly network: string;
|
|
49
|
+
/** Amount in atomic units — decimal string matching `/^[0-9]+$/`. */
|
|
50
|
+
readonly amount: string;
|
|
51
|
+
/** Asset identifier: contract address or ISO 4217 code. */
|
|
52
|
+
readonly asset: string;
|
|
53
|
+
/** Recipient address on `network`. */
|
|
54
|
+
readonly payTo: string;
|
|
55
|
+
/** Maximum settlement timeout in seconds — integer ≥ 1. */
|
|
56
|
+
readonly maxTimeoutSeconds: number;
|
|
57
|
+
/** Scheme-specific and extension metadata. */
|
|
58
|
+
readonly extra?: Readonly<Record<string, unknown>>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* One (scheme, network) pair a signer can pay for — the routing half
|
|
63
|
+
* of an `X402PaymentRequirements` entry.
|
|
64
|
+
*/
|
|
65
|
+
export interface SignerCapability {
|
|
66
|
+
/** x402 execution scheme the signer can pay for (e.g. `exact`). */
|
|
67
|
+
readonly scheme: string;
|
|
68
|
+
/** Exact CAIP-2 chain id the signer can pay on. */
|
|
69
|
+
readonly network: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The key-owner side of the x402 payment contract (ТЗ x402 v1.2 §3.3):
|
|
74
|
+
* implementations live with the wallet owners — `@me2em/solana` ships
|
|
75
|
+
* one (M2); EVM wallets are the application's side. Chain-specific
|
|
76
|
+
* parameters (e.g. a blockhash source) go through the implementation's
|
|
77
|
+
* constructor — the contract itself never changes.
|
|
78
|
+
*/
|
|
79
|
+
export interface PaymentSigner {
|
|
80
|
+
/** What this signer can pay for; matched against `accepts` entries. */
|
|
81
|
+
readonly capabilities: readonly SignerCapability[];
|
|
82
|
+
/** Signs the payment; the result becomes `PaymentPayload.payload`. */
|
|
83
|
+
signPayment(
|
|
84
|
+
requirements: X402PaymentRequirements,
|
|
85
|
+
resource: X402ResourceInfo
|
|
86
|
+
): Promise<Record<string, unknown>>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The x402 v2 `402 Payment Required` response body (ТЗ x402 v1.1 §2.1).
|
|
91
|
+
*/
|
|
92
|
+
export interface X402PaymentRequired {
|
|
93
|
+
/** Always `2` for the v2 wire format. */
|
|
94
|
+
readonly x402Version: 2;
|
|
95
|
+
/** Optional machine-readable error context. */
|
|
96
|
+
readonly error?: string;
|
|
97
|
+
/** The resource being sold. */
|
|
98
|
+
readonly resource: X402ResourceInfo;
|
|
99
|
+
/** Non-empty list of acceptable payment options. */
|
|
100
|
+
readonly accepts: readonly X402PaymentRequirements[];
|
|
101
|
+
/** Protocol extensions keyed by name. */
|
|
102
|
+
readonly extensions?: Readonly<Record<string, { info: object; schema: object }>>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The buyer-signed `PAYMENT-SIGNATURE` header payload (ТЗ x402 v1.1 §2.1):
|
|
107
|
+
* the echoed accepted requirements plus the scheme-specific payload.
|
|
108
|
+
*/
|
|
109
|
+
export interface X402PaymentPayload {
|
|
110
|
+
/** Always `2` for the v2 wire format. */
|
|
111
|
+
readonly x402Version: 2;
|
|
112
|
+
/** Optional resource echo. */
|
|
113
|
+
readonly resource?: X402ResourceInfo;
|
|
114
|
+
/** The accepted payment option (echoed from `accepts`). */
|
|
115
|
+
readonly accepted: X402PaymentRequirements;
|
|
116
|
+
/** Scheme-specific payload (e.g. signed transfer fields). */
|
|
117
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
118
|
+
/** Protocol extensions keyed by name. */
|
|
119
|
+
readonly extensions?: Readonly<Record<string, { info: object; schema: object }>>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The `PAYMENT-RESPONSE` header: the result of a `settle` call
|
|
124
|
+
* (ТЗ x402 v1.1 §2.1).
|
|
125
|
+
*/
|
|
126
|
+
export interface X402SettleResponse {
|
|
127
|
+
/** Whether the payment settled successfully. */
|
|
128
|
+
readonly success: boolean;
|
|
129
|
+
/** Machine-readable failure reason (present on failure). */
|
|
130
|
+
readonly errorReason?: string;
|
|
131
|
+
/** Human-readable failure message (present on failure). */
|
|
132
|
+
readonly errorMessage?: string;
|
|
133
|
+
/** Payer address, when known. */
|
|
134
|
+
readonly payer?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Settlement transaction reference. Empty string is legal when no
|
|
137
|
+
* transaction was broadcast (upstream §5.3.2) — except for
|
|
138
|
+
* `errorReason: 'settlement_pending'`, where it MUST be non-empty.
|
|
139
|
+
*/
|
|
140
|
+
readonly transaction: string;
|
|
141
|
+
/** Blockchain network identifier in CAIP-2 format. */
|
|
142
|
+
readonly network: string;
|
|
143
|
+
/** Settled amount in atomic units. */
|
|
144
|
+
readonly amount?: string;
|
|
145
|
+
/** Scheme-specific extras. */
|
|
146
|
+
readonly extra?: Readonly<Record<string, unknown>>;
|
|
147
|
+
/** Protocol extensions keyed by name. */
|
|
148
|
+
readonly extensions?: Readonly<Record<string, unknown>>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The result of a `verify` call (ТЗ x402 v1.1 §2.1).
|
|
153
|
+
*/
|
|
154
|
+
export interface X402VerifyResponse {
|
|
155
|
+
/** Whether the payment payload is valid. */
|
|
156
|
+
readonly isValid: boolean;
|
|
157
|
+
/** Machine-readable invalidity reason (present when invalid). */
|
|
158
|
+
readonly invalidReason?: string;
|
|
159
|
+
/** Human-readable invalidity message (present when invalid). */
|
|
160
|
+
readonly invalidMessage?: string;
|
|
161
|
+
/** Payer address, when known. */
|
|
162
|
+
readonly payer?: string;
|
|
163
|
+
/** Protocol extensions keyed by name. */
|
|
164
|
+
readonly extensions?: Readonly<Record<string, unknown>>;
|
|
165
|
+
/** Scheme-specific extras. */
|
|
166
|
+
readonly extra?: Readonly<Record<string, unknown>>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The result of a `supported` call: which (version, scheme, network)
|
|
171
|
+
* triples the facilitator can handle (ТЗ x402 v1.1 §2.1).
|
|
172
|
+
*/
|
|
173
|
+
export interface X402Supported {
|
|
174
|
+
/** Supported (version, scheme, network) combinations. */
|
|
175
|
+
readonly kinds: ReadonlyArray<{
|
|
176
|
+
readonly x402Version: number;
|
|
177
|
+
readonly scheme: string;
|
|
178
|
+
readonly network: string;
|
|
179
|
+
}>;
|
|
180
|
+
/** Supported extension names. */
|
|
181
|
+
readonly extensions?: readonly string[];
|
|
182
|
+
/** Supported signers keyed by scheme. */
|
|
183
|
+
readonly signers?: Readonly<Record<string, readonly string[]>>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Me2eM-specific payment failure codes — a subset of
|
|
188
|
+
* `PaymentFailureReason` (ТЗ x402 v1.1 §2.2).
|
|
189
|
+
*/
|
|
190
|
+
export type Me2emErrorCode =
|
|
191
|
+
| 'REFERENCE_MISMATCH'
|
|
192
|
+
| 'PACT_INVALID'
|
|
193
|
+
| 'BUYER_NOT_ATTESTED'
|
|
194
|
+
| 'SELLER_NOT_ATTESTED';
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Application-declared buyer attestation policy (ТЗ x402 v1.1 §2.3).
|
|
198
|
+
* x402 does not enforce it — a contradictory configuration fails fast
|
|
199
|
+
* in `@me2em/x402` instead.
|
|
200
|
+
*/
|
|
201
|
+
export const BUYER_ATTESTATION_POLICY = {
|
|
202
|
+
NONE: 'none',
|
|
203
|
+
OPTIONAL: 'optional',
|
|
204
|
+
REQUIRED: 'required',
|
|
205
|
+
} as const;
|
|
206
|
+
export type BuyerAttestationPolicy =
|
|
207
|
+
typeof BUYER_ATTESTATION_POLICY[keyof typeof BUYER_ATTESTATION_POLICY];
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Application-declared compliance regime (ТЗ x402 v1.1 §2.3).
|
|
211
|
+
* x402 does not enforce it — declaration only.
|
|
212
|
+
*/
|
|
213
|
+
export const REGULATORY_PROFILES = {
|
|
214
|
+
NONE: 'none',
|
|
215
|
+
KYC: 'kyc',
|
|
216
|
+
AML: 'aml',
|
|
217
|
+
AGE_GATED: 'age-gated',
|
|
218
|
+
SANCTIONS: 'sanctions',
|
|
219
|
+
} as const;
|
|
220
|
+
export type RegulatoryProfile =
|
|
221
|
+
typeof REGULATORY_PROFILES[keyof typeof REGULATORY_PROFILES];
|
|
222
|
+
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
// Structural guards — never throw, always return a boolean.
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
|
|
227
|
+
const AMOUNT_RE = /^[0-9]+$/;
|
|
228
|
+
|
|
229
|
+
function isPlainObject(v: unknown): v is Record<string, unknown> {
|
|
230
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function isNonEmptyString(v: unknown): v is string {
|
|
234
|
+
return typeof v === 'string' && v.length > 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function isPositiveInteger(v: unknown): v is number {
|
|
238
|
+
return typeof v === 'number' && Number.isInteger(v) && v >= 1;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Structural guard for {@link X402PaymentRequirements}. Additionally
|
|
243
|
+
* validates that `network` is a well-formed CAIP-2 chain id.
|
|
244
|
+
*/
|
|
245
|
+
export function isX402PaymentRequirements(value: unknown): value is X402PaymentRequirements {
|
|
246
|
+
if (!isPlainObject(value)) return false;
|
|
247
|
+
if (!isNonEmptyString(value.scheme)) return false;
|
|
248
|
+
if (typeof value.network !== 'string' || parseChain(value.network) === null) return false;
|
|
249
|
+
if (typeof value.amount !== 'string' || !AMOUNT_RE.test(value.amount)) return false;
|
|
250
|
+
if (!isNonEmptyString(value.asset)) return false;
|
|
251
|
+
if (!isNonEmptyString(value.payTo)) return false;
|
|
252
|
+
if (!isPositiveInteger(value.maxTimeoutSeconds)) return false;
|
|
253
|
+
if (value.extra !== undefined && !isPlainObject(value.extra)) return false;
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Structural guard for {@link X402ResourceInfo}.
|
|
259
|
+
*/
|
|
260
|
+
function isX402ResourceInfo(value: unknown): value is X402ResourceInfo {
|
|
261
|
+
if (!isPlainObject(value)) return false;
|
|
262
|
+
if (!isNonEmptyString(value.url)) return false;
|
|
263
|
+
if (value.description !== undefined && typeof value.description !== 'string') return false;
|
|
264
|
+
if (value.mimeType !== undefined && typeof value.mimeType !== 'string') return false;
|
|
265
|
+
if (value.serviceName !== undefined && typeof value.serviceName !== 'string') return false;
|
|
266
|
+
if (value.tags !== undefined && (!Array.isArray(value.tags) || !value.tags.every((t) => typeof t === 'string'))) return false;
|
|
267
|
+
if (value.iconUrl !== undefined && typeof value.iconUrl !== 'string') return false;
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Structural guard for {@link X402PaymentRequired}.
|
|
273
|
+
*/
|
|
274
|
+
export function isX402PaymentRequired(value: unknown): value is X402PaymentRequired {
|
|
275
|
+
if (!isPlainObject(value)) return false;
|
|
276
|
+
if (value.x402Version !== 2) return false;
|
|
277
|
+
if (value.error !== undefined && typeof value.error !== 'string') return false;
|
|
278
|
+
if (!isX402ResourceInfo(value.resource)) return false;
|
|
279
|
+
if (!Array.isArray(value.accepts) || value.accepts.length === 0) return false;
|
|
280
|
+
for (const req of value.accepts) {
|
|
281
|
+
if (!isX402PaymentRequirements(req)) return false;
|
|
282
|
+
}
|
|
283
|
+
if (value.extensions !== undefined && !isPlainObject(value.extensions)) return false;
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Structural guard for {@link X402PaymentPayload}.
|
|
289
|
+
*/
|
|
290
|
+
export function isX402PaymentPayload(value: unknown): value is X402PaymentPayload {
|
|
291
|
+
if (!isPlainObject(value)) return false;
|
|
292
|
+
if (value.x402Version !== 2) return false;
|
|
293
|
+
if (value.resource !== undefined && !isX402ResourceInfo(value.resource)) return false;
|
|
294
|
+
if (!isX402PaymentRequirements(value.accepted)) return false;
|
|
295
|
+
if (!isPlainObject(value.payload)) return false;
|
|
296
|
+
if (value.extensions !== undefined && !isPlainObject(value.extensions)) return false;
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Structural guard for {@link X402SettleResponse}.
|
|
302
|
+
*/
|
|
303
|
+
export function isX402SettleResponse(value: unknown): value is X402SettleResponse {
|
|
304
|
+
if (!isPlainObject(value)) return false;
|
|
305
|
+
if (typeof value.success !== 'boolean') return false;
|
|
306
|
+
if (value.errorReason !== undefined && typeof value.errorReason !== 'string') return false;
|
|
307
|
+
if (value.errorMessage !== undefined && typeof value.errorMessage !== 'string') return false;
|
|
308
|
+
if (value.payer !== undefined && typeof value.payer !== 'string') return false;
|
|
309
|
+
// Upstream §5.3.2: an empty transaction is legal when nothing was
|
|
310
|
+
// broadcast; it MUST be non-empty for `errorReason: settlement_pending`.
|
|
311
|
+
if (typeof value.transaction !== 'string') return false;
|
|
312
|
+
if (value.transaction === '' && value.errorReason === 'settlement_pending') return false;
|
|
313
|
+
if (typeof value.network !== 'string' || parseChain(value.network) === null) return false;
|
|
314
|
+
if (value.amount !== undefined && (typeof value.amount !== 'string' || !AMOUNT_RE.test(value.amount))) return false;
|
|
315
|
+
if (value.extra !== undefined && !isPlainObject(value.extra)) return false;
|
|
316
|
+
if (value.extensions !== undefined && !isPlainObject(value.extensions)) return false;
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Structural guard for {@link X402VerifyResponse}.
|
|
322
|
+
*/
|
|
323
|
+
export function isX402VerifyResponse(value: unknown): value is X402VerifyResponse {
|
|
324
|
+
if (!isPlainObject(value)) return false;
|
|
325
|
+
if (typeof value.isValid !== 'boolean') return false;
|
|
326
|
+
if (value.invalidReason !== undefined && typeof value.invalidReason !== 'string') return false;
|
|
327
|
+
if (value.invalidMessage !== undefined && typeof value.invalidMessage !== 'string') return false;
|
|
328
|
+
if (value.payer !== undefined && typeof value.payer !== 'string') return false;
|
|
329
|
+
if (value.extensions !== undefined && !isPlainObject(value.extensions)) return false;
|
|
330
|
+
if (value.extra !== undefined && !isPlainObject(value.extra)) return false;
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Structural guard for {@link X402Supported}.
|
|
336
|
+
*/
|
|
337
|
+
export function isX402Supported(value: unknown): value is X402Supported {
|
|
338
|
+
if (!isPlainObject(value)) return false;
|
|
339
|
+
if (!Array.isArray(value.kinds)) return false;
|
|
340
|
+
for (const kind of value.kinds) {
|
|
341
|
+
if (!isPlainObject(kind)) return false;
|
|
342
|
+
if (typeof kind.x402Version !== 'number') return false;
|
|
343
|
+
if (!isNonEmptyString(kind.scheme)) return false;
|
|
344
|
+
if (!isNonEmptyString(kind.network)) return false;
|
|
345
|
+
}
|
|
346
|
+
if (value.extensions !== undefined && (!Array.isArray(value.extensions) || !value.extensions.every((e) => typeof e === 'string'))) return false;
|
|
347
|
+
if (value.signers !== undefined && !isPlainObject(value.signers)) return false;
|
|
348
|
+
return true;
|
|
349
|
+
}
|
package/src/payment.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// adapter interfaces, CAIP-2 grammar helpers, the process-wide adapter
|
|
5
5
|
// registry and the in-memory wallet-binding storage. Pure interfaces and
|
|
6
6
|
// stateless helpers — no network, no chain code. Chain-specific values
|
|
7
|
-
// (e.g. `solana:mainnet-beta`) live in the chain packages (
|
|
7
|
+
// (e.g. `solana:mainnet-beta`) live in the chain packages (solana,
|
|
8
8
|
// monero); core pins only the grammar.
|
|
9
9
|
//
|
|
10
10
|
// Module-graph note: this module imports NOTHING from the rest of src/
|
|
@@ -97,8 +97,17 @@ export interface PaymentAdapter extends WalletAdapter {
|
|
|
97
97
|
* (browser extensions) do not go through `pay` — they follow the
|
|
98
98
|
* chain-specific request-URL flow. On success `txRef` is non-empty;
|
|
99
99
|
* on failure `pay` throws (v1.2 §5.1).
|
|
100
|
+
*
|
|
101
|
+
* `opts` are chain-specific call options (rc.6 — additive, optional).
|
|
102
|
+
* Deterministic adapters require `opts.seed` (the same seed contract
|
|
103
|
+
* as `resolveWallet`) — without it they throw `TypeError`; the
|
|
104
|
+
* adapter never retains seed or derived key material.
|
|
100
105
|
*/
|
|
101
|
-
pay(
|
|
106
|
+
pay(
|
|
107
|
+
from: WalletDescriptor,
|
|
108
|
+
request: PaymentRequest,
|
|
109
|
+
opts?: { seed?: Uint8Array; memo?: string }
|
|
110
|
+
): Promise<string>;
|
|
102
111
|
/**
|
|
103
112
|
* Idempotent pure read of the chain state for a confirmed transaction
|
|
104
113
|
* (v1.2 §5.3): repeating the call with the same `txRef` yields the
|
|
@@ -133,7 +142,28 @@ export interface PaymentAdapter extends WalletAdapter {
|
|
|
133
142
|
export type PaymentFailureReason =
|
|
134
143
|
| 'NOT_FOUND' | 'UNDERPAID' | 'WRONG_RECIPIENT' | 'WRONG_ASSET'
|
|
135
144
|
| 'EXPIRED' | 'REPLAYED' | 'CHAIN_UNAVAILABLE' | 'REJECTED'
|
|
136
|
-
| 'REFERENCE_MISMATCH'
|
|
145
|
+
| 'REFERENCE_MISMATCH'
|
|
146
|
+
| 'PACT_INVALID' | 'BUYER_NOT_ATTESTED' | 'SELLER_NOT_ATTESTED';
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Me2eM metadata for the direct payment flow (ТЗ x402 v1.1 §2.4).
|
|
150
|
+
* In the x402 wire format these fields travel as `extra.me2em`
|
|
151
|
+
* (`X402Me2emExtra`, base64 — lives in `@me2em/x402`, M1).
|
|
152
|
+
*/
|
|
153
|
+
export interface Me2emExtra {
|
|
154
|
+
/** Seller entity id (base64url public key). */
|
|
155
|
+
readonly sellerId?: string;
|
|
156
|
+
/** Buyer entity id (base64url public key). */
|
|
157
|
+
readonly buyerId?: string;
|
|
158
|
+
/** Free-form memo. */
|
|
159
|
+
readonly memo?: string;
|
|
160
|
+
/** Correlation reference echoed into the transaction. */
|
|
161
|
+
readonly reference?: string;
|
|
162
|
+
/** Agreement proof bytes (base64 on the x402 wire). */
|
|
163
|
+
readonly agreementProof?: Uint8Array;
|
|
164
|
+
/** Application-defined extras. */
|
|
165
|
+
readonly [key: string]: unknown;
|
|
166
|
+
}
|
|
137
167
|
|
|
138
168
|
/**
|
|
139
169
|
* A signed-off payment demand (v1.2 §0.1): every parameter a verifier
|
|
@@ -158,6 +188,8 @@ export interface PaymentRequest {
|
|
|
158
188
|
readonly reference: string;
|
|
159
189
|
/** Unix seconds — payments observed after this are `EXPIRED` (block time first, observed time as fallback). */
|
|
160
190
|
readonly expiresAt: number;
|
|
191
|
+
/** Me2eM metadata of the direct flow. On the x402 wire — nested `extra.me2em` (ТЗ x402 v1.1 §3.6). */
|
|
192
|
+
readonly extra?: Me2emExtra;
|
|
161
193
|
}
|
|
162
194
|
|
|
163
195
|
/**
|