@agent402-dev/pay-server 0.1.0 → 0.2.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 +24 -17
- package/dist/chain.d.ts +6 -6
- package/dist/chain.js +7 -7
- package/dist/core.d.ts +6 -6
- package/dist/core.js +11 -11
- package/dist/gate.d.ts +42 -25
- package/dist/gate.js +62 -33
- package/dist/index.d.ts +4 -3
- package/dist/index.js +6 -4
- package/dist/preq.d.ts +10 -0
- package/dist/preq.js +18 -0
- package/dist/pricing.d.ts +57 -27
- package/dist/pricing.js +91 -35
- package/dist/rates-file.js +2 -2
- package/dist/rates.d.ts +5 -8
- package/dist/rates.js +9 -10
- package/dist/x402.d.ts +34 -33
- package/dist/x402.js +32 -32
- package/package.json +2 -2
package/dist/x402.d.ts
CHANGED
|
@@ -6,19 +6,20 @@ type TxRecordWithInstructions = ChainTx;
|
|
|
6
6
|
export declare const SOLANA_MAINNET = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
7
7
|
export declare const SOLANA_DEVNET = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
8
8
|
export interface Asset {
|
|
9
|
-
|
|
9
|
+
/** A402 is deprecated (v1). Only when enabled explicitly (prints a warning) */
|
|
10
|
+
symbol: 'USDC' | 'PREQ' | 'A402';
|
|
10
11
|
mint: string;
|
|
11
12
|
decimals: number;
|
|
12
|
-
/** SPL Token
|
|
13
|
+
/** SPL Token or Token-2022 program address */
|
|
13
14
|
tokenProgram: string;
|
|
14
15
|
}
|
|
15
16
|
export interface Offer {
|
|
16
17
|
asset: Asset;
|
|
17
18
|
amount: bigint;
|
|
18
|
-
/**
|
|
19
|
+
/** For tokens (PREQ, etc.), the rate basis (published as extra.rate). tokenUsd = USD per token */
|
|
19
20
|
rate?: {
|
|
20
21
|
date: string;
|
|
21
|
-
|
|
22
|
+
tokenUsd: number;
|
|
22
23
|
method: string;
|
|
23
24
|
discountPercent: number;
|
|
24
25
|
};
|
|
@@ -29,9 +30,9 @@ export interface NamedFacilitator {
|
|
|
29
30
|
}
|
|
30
31
|
export interface X402Config {
|
|
31
32
|
network: string;
|
|
32
|
-
/**
|
|
33
|
+
/** Public address of the receiving wallet */
|
|
33
34
|
payTo: string;
|
|
34
|
-
/**
|
|
35
|
+
/** First is primary, the rest are fallbacks */
|
|
35
36
|
facilitators: NamedFacilitator[];
|
|
36
37
|
maxTimeoutSeconds: number;
|
|
37
38
|
}
|
|
@@ -41,24 +42,24 @@ interface Chosen {
|
|
|
41
42
|
transactionVersions?: unknown;
|
|
42
43
|
server: x402ResourceServer;
|
|
43
44
|
}
|
|
44
|
-
/**
|
|
45
|
+
/** First facilitator, primary then fallbacks, that supports exact on this network */
|
|
45
46
|
export declare function chooseFacilitator(cfg: X402Config, nowMs: number): Promise<Chosen | null>;
|
|
46
|
-
/**
|
|
47
|
+
/** Facilitator using the feePayer in the payment requirements (settlement must go to that facilitator) */
|
|
47
48
|
export declare function facilitatorForFeePayer(cfg: X402Config, feePayer: unknown, nowMs: number): Promise<Chosen | null>;
|
|
48
49
|
export declare function clearSupportedCache(): void;
|
|
49
|
-
/**
|
|
50
|
+
/** Builds payment requirements with the official x402ResourceServer.buildPaymentRequirementsFromOptions (the official SVM server fills feePayer and transactionVersions) */
|
|
50
51
|
export declare function buildRequirements(cfg: X402Config, offers: Offer[], chosen: Chosen): Promise<PaymentRequirements[]>;
|
|
51
52
|
export interface X402Ledger {
|
|
52
53
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
* Claims the payment (key).
|
|
55
|
+
* new: first time → proceed to settle / settled: settled but the report was not received → skip settlement
|
|
56
|
+
* in_progress, fulfilled: reject
|
|
56
57
|
*/
|
|
57
58
|
claim(key: string, nowMs: number): Promise<{
|
|
58
59
|
ok: true;
|
|
59
60
|
state: 'new';
|
|
60
61
|
}
|
|
61
|
-
/**
|
|
62
|
+
/** The result of the previous settle request is unknown; must be decided on-chain */
|
|
62
63
|
| {
|
|
63
64
|
ok: true;
|
|
64
65
|
state: 'settle_unknown';
|
|
@@ -67,15 +68,15 @@ export interface X402Ledger {
|
|
|
67
68
|
ok: false;
|
|
68
69
|
state: 'in_progress' | 'fulfilled';
|
|
69
70
|
}>;
|
|
70
|
-
/**
|
|
71
|
+
/** The settle request result is unknown (timeout, etc.) */
|
|
71
72
|
markSettleUnknown(key: string, nowMs: number): Promise<void>;
|
|
72
73
|
fulfill(key: string, nowMs: number): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
+
/** Failed before settlement → release */
|
|
74
75
|
release(key: string): Promise<void>;
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
* When the settlement result is unknown and the transaction is still not on-chain after this time, it can no longer be processed
|
|
79
|
+
* (blockhash is valid for 150 blocks ≈ 60 to 90 s, with margin)
|
|
79
80
|
*/
|
|
80
81
|
export declare const SETTLE_UNKNOWN_EXPIRY_MS = 150000;
|
|
81
82
|
type LedgerEntry = {
|
|
@@ -88,7 +89,7 @@ type LedgerEntry = {
|
|
|
88
89
|
state: 'fulfilled';
|
|
89
90
|
at: number;
|
|
90
91
|
};
|
|
91
|
-
/**
|
|
92
|
+
/** Ledger state transitions (shared by the Durable Object and memory implementations) */
|
|
92
93
|
export declare function ledgerClaim(e: LedgerEntry | undefined, nowMs: number): {
|
|
93
94
|
next: LedgerEntry;
|
|
94
95
|
result: {
|
|
@@ -130,25 +131,25 @@ export declare function sha256Hex(s: string): Promise<string>;
|
|
|
130
131
|
export interface ProcessDeps {
|
|
131
132
|
cfg: X402Config;
|
|
132
133
|
ledger: X402Ledger;
|
|
133
|
-
/**
|
|
134
|
+
/** Reads transactions on the payment network (on-chain recheck) */
|
|
134
135
|
loadTx: (signature: string) => Promise<TxRecordWithInstructions | null>;
|
|
135
|
-
/**
|
|
136
|
+
/** Recent signatures for an address on the payment network (to decide when the settlement result is unknown) */
|
|
136
137
|
recentSignatures: (address: string, limit: number) => Promise<string[]>;
|
|
137
|
-
/**
|
|
138
|
+
/** Payment asset mint → token program (to compute the receiving token account address) */
|
|
138
139
|
tokenProgramOf: (mint: string) => string;
|
|
139
140
|
nowMs: number;
|
|
140
|
-
/**
|
|
141
|
+
/** Retry intervals for the on-chain recheck */
|
|
141
142
|
confirmDelaysMs?: number[];
|
|
142
143
|
}
|
|
143
|
-
/**
|
|
144
|
+
/** A payment that passed verification (no money has moved yet) */
|
|
144
145
|
export interface VerifiedPayment {
|
|
145
146
|
key: string;
|
|
146
147
|
payload: PaymentPayload;
|
|
147
148
|
accepted: PaymentRequirements;
|
|
148
149
|
facilitator: NamedFacilitator;
|
|
149
|
-
/**
|
|
150
|
+
/** Official resource server wrapping that facilitator (calls verify and settle) */
|
|
150
151
|
server: x402ResourceServer;
|
|
151
|
-
/**
|
|
152
|
+
/** If reprocessing a payment whose previous settlement result is unknown, its time */
|
|
152
153
|
settleUnknownSince: number | null;
|
|
153
154
|
}
|
|
154
155
|
export type VerifyOutcome = {
|
|
@@ -173,27 +174,27 @@ export type SettleOutcome = {
|
|
|
173
174
|
kind: 'unavailable';
|
|
174
175
|
message: string;
|
|
175
176
|
}
|
|
176
|
-
/** confirmation: confirmed =
|
|
177
|
+
/** confirmation: confirmed = confirmed on-chain with our RPC / pending = facilitator reported success, not yet confirmed on-chain */
|
|
177
178
|
| {
|
|
178
179
|
kind: 'paid';
|
|
179
180
|
settlement: SettleResponse;
|
|
180
181
|
confirmation: 'confirmed' | 'pending';
|
|
181
182
|
};
|
|
182
|
-
/**
|
|
183
|
+
/** Signatures already filled in a partially signed transaction (base64) (the buyer's signatures). Empty slots (all zeros) are left out */
|
|
183
184
|
export declare function presentSignatures(txBase64: string): string[];
|
|
184
185
|
/**
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
* Decides on-chain when the settlement result is unknown: finds a transaction containing the buyer's signature among recent records of the receiving token account.
|
|
187
|
+
* Returns that transaction if found, otherwise null
|
|
187
188
|
*/
|
|
188
189
|
export declare function findSettledOnChain(v: VerifiedPayment, d: ProcessDeps): Promise<TxRecordWithInstructions | null>;
|
|
189
190
|
/**
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
* Step 1: check PAYMENT-SIGNATURE → claim in the ledger → facilitator /verify. No money moves yet.
|
|
192
|
+
* The caller then builds the report and calls settleVerified only on success
|
|
192
193
|
*/
|
|
193
194
|
export declare function verifyPaymentHeader(header: string, resourcePath: string, current: PaymentRequirements[], d: ProcessDeps): Promise<VerifyOutcome>;
|
|
194
195
|
/**
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
* Step 2 (only after the report is built): facilitator /settle → on-chain recheck with our RPC.
|
|
197
|
+
* If the settlement result is unknown (timeout, etc.), decide on-chain by the buyer's signature; if still unknown, leave it as "result unknown"
|
|
197
198
|
*/
|
|
198
199
|
export declare function settleVerified(v: VerifiedPayment, d: ProcessDeps): Promise<SettleOutcome>;
|
|
199
200
|
export declare function paymentResponseHeader(s: SettleResponse): string;
|
package/dist/x402.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Standard x402 v2 (exact, Solana): resource-server-side processing steps (internal to @agent402-dev/pay-server, used by gate.ts).
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// - verifyPaymentHeader:
|
|
5
|
-
// - settleVerified: facilitator settle →
|
|
6
|
-
//
|
|
3
|
+
// Flow: verify → (caller's work) → settle
|
|
4
|
+
// - verifyPaymentHeader: checks the payment's chosen requirement (accepted) equals the current one (official matching), the resource path, claims it in the ledger, facilitator verify
|
|
5
|
+
// - settleVerified: facilitator settle → on-chain recheck. If it fails or the result is unknown, decide on-chain by the buyer's signature;
|
|
6
|
+
// if not found, keep it as "result unknown" and mark "not paid" only when it is still missing after the validity window (150 s)
|
|
7
7
|
//
|
|
8
|
-
//
|
|
8
|
+
// The server holds only the receiving wallet's public address. The fee payer (feePayer) key belongs to the facilitator.
|
|
9
9
|
import { decodePaymentSignatureHeader, encodePaymentResponseHeader } from '@x402/core/http';
|
|
10
10
|
import { buildCoreRequirements, createCoreServer, definiteVerifyRejection, matchRequirement, settleFailureReason } from './core.js';
|
|
11
11
|
import { ataOf, base58Encode, receivedBy, SPL_TOKEN, TOKEN_2022 } from './chain.js';
|
|
@@ -14,7 +14,7 @@ export const SOLANA_MAINNET = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
|
|
|
14
14
|
export const SOLANA_DEVNET = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1';
|
|
15
15
|
const supportedCache = new Map();
|
|
16
16
|
const SUPPORTED_TTL_MS = 10 * 60_000;
|
|
17
|
-
/**
|
|
17
|
+
/** feePayer for exact (v2) on this network from one facilitator's /supported (cached) */
|
|
18
18
|
async function supportedFor(f, network, nowMs) {
|
|
19
19
|
const key = `${f.name}|${network}`;
|
|
20
20
|
const c = supportedCache.get(key);
|
|
@@ -28,11 +28,11 @@ async function supportedFor(f, network, nowMs) {
|
|
|
28
28
|
if (feePayer)
|
|
29
29
|
chosen = { facilitator: f, feePayer, transactionVersions: kind?.extra?.transactionVersions, server };
|
|
30
30
|
}
|
|
31
|
-
catch { /*
|
|
31
|
+
catch { /* outage → null (cached briefly, move on to the next facilitator) */ }
|
|
32
32
|
supportedCache.set(key, { at: chosen ? nowMs : nowMs - SUPPORTED_TTL_MS + 30_000, chosen });
|
|
33
33
|
return chosen;
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
35
|
+
/** First facilitator, primary then fallbacks, that supports exact on this network */
|
|
36
36
|
export async function chooseFacilitator(cfg, nowMs) {
|
|
37
37
|
for (const f of cfg.facilitators) {
|
|
38
38
|
const c = await supportedFor(f, cfg.network, nowMs);
|
|
@@ -41,7 +41,7 @@ export async function chooseFacilitator(cfg, nowMs) {
|
|
|
41
41
|
}
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
44
|
+
/** Facilitator using the feePayer in the payment requirements (settlement must go to that facilitator) */
|
|
45
45
|
export async function facilitatorForFeePayer(cfg, feePayer, nowMs) {
|
|
46
46
|
if (typeof feePayer !== 'string')
|
|
47
47
|
return null;
|
|
@@ -54,7 +54,7 @@ export async function facilitatorForFeePayer(cfg, feePayer, nowMs) {
|
|
|
54
54
|
}
|
|
55
55
|
export function clearSupportedCache() { supportedCache.clear(); }
|
|
56
56
|
// ---------- 402 ----------
|
|
57
|
-
/**
|
|
57
|
+
/** Builds payment requirements with the official x402ResourceServer.buildPaymentRequirementsFromOptions (the official SVM server fills feePayer and transactionVersions) */
|
|
58
58
|
export function buildRequirements(cfg, offers, chosen) {
|
|
59
59
|
return buildCoreRequirements(chosen.server, cfg.network, cfg.payTo, cfg.maxTimeoutSeconds, offers.map((o) => ({
|
|
60
60
|
asset: o.asset.mint,
|
|
@@ -64,11 +64,11 @@ export function buildRequirements(cfg, offers, chosen) {
|
|
|
64
64
|
}
|
|
65
65
|
const IN_PROGRESS_TTL_MS = 120_000;
|
|
66
66
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
* When the settlement result is unknown and the transaction is still not on-chain after this time, it can no longer be processed
|
|
68
|
+
* (blockhash is valid for 150 blocks ≈ 60 to 90 s, with margin)
|
|
69
69
|
*/
|
|
70
70
|
export const SETTLE_UNKNOWN_EXPIRY_MS = 150_000;
|
|
71
|
-
/**
|
|
71
|
+
/** Ledger state transitions (shared by the Durable Object and memory implementations) */
|
|
72
72
|
export function ledgerClaim(e, nowMs) {
|
|
73
73
|
if (!e)
|
|
74
74
|
return { next: { state: 'in_progress', at: nowMs }, result: { ok: true, state: 'new' } };
|
|
@@ -78,7 +78,7 @@ export function ledgerClaim(e, nowMs) {
|
|
|
78
78
|
return { next: e, result: { ok: false, state: 'in_progress' } };
|
|
79
79
|
if (e.state === 'in_progress')
|
|
80
80
|
return { next: { state: 'in_progress', at: nowMs }, result: { ok: true, state: 'new' } };
|
|
81
|
-
// settle_unknown:
|
|
81
|
+
// settle_unknown: claim as in progress, and also return the original time
|
|
82
82
|
return { next: { state: 'in_progress', at: nowMs }, result: { ok: true, state: 'settle_unknown', since: e.at } };
|
|
83
83
|
}
|
|
84
84
|
export function memoryX402Ledger() {
|
|
@@ -95,7 +95,7 @@ export async function sha256Hex(s) {
|
|
|
95
95
|
const d = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s));
|
|
96
96
|
return [...new Uint8Array(d)].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
98
|
+
/** Signatures already filled in a partially signed transaction (base64) (the buyer's signatures). Empty slots (all zeros) are left out */
|
|
99
99
|
export function presentSignatures(txBase64) {
|
|
100
100
|
const buf = Uint8Array.from(atob(txBase64), (c) => c.charCodeAt(0));
|
|
101
101
|
let n = 0, shift = 0, i = 0;
|
|
@@ -114,13 +114,13 @@ export function presentSignatures(txBase64) {
|
|
|
114
114
|
}
|
|
115
115
|
return out;
|
|
116
116
|
}
|
|
117
|
-
/**
|
|
117
|
+
/** Whether the on-chain record satisfies this payment requirement */
|
|
118
118
|
function satisfies(tx, accepted) {
|
|
119
119
|
return !tx.err && receivedBy(tx, accepted.payTo, accepted.asset) >= BigInt(accepted.amount);
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
* Decides on-chain when the settlement result is unknown: finds a transaction containing the buyer's signature among recent records of the receiving token account.
|
|
123
|
+
* Returns that transaction if found, otherwise null
|
|
124
124
|
*/
|
|
125
125
|
export async function findSettledOnChain(v, d) {
|
|
126
126
|
const mine = new Set(presentSignatures(v.payload.payload.transaction));
|
|
@@ -135,8 +135,8 @@ export async function findSettledOnChain(v, d) {
|
|
|
135
135
|
return null;
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
* Step 1: check PAYMENT-SIGNATURE → claim in the ledger → facilitator /verify. No money moves yet.
|
|
139
|
+
* The caller then builds the report and calls settleVerified only on success
|
|
140
140
|
*/
|
|
141
141
|
export async function verifyPaymentHeader(header, resourcePath, current, d) {
|
|
142
142
|
let payload;
|
|
@@ -156,7 +156,7 @@ export async function verifyPaymentHeader(header, resourcePath, current, d) {
|
|
|
156
156
|
catch {
|
|
157
157
|
return { kind: 'payment_required', reason: 'resource_mismatch', message: 'Could not parse resource.url. No payment was taken.' };
|
|
158
158
|
}
|
|
159
|
-
//
|
|
159
|
+
// Official matching rules (exact match of scheme, network, asset, amount, payTo, maxTimeoutSeconds + extra containment)
|
|
160
160
|
const accepted = matchRequirement(current, payload, d.cfg.network);
|
|
161
161
|
if (!accepted) {
|
|
162
162
|
return { kind: 'payment_required', reason: 'requirements_mismatch', message: 'The chosen payment requirements no longer match the current ones (amount, rate, recipient or facilitator may have changed). No payment was taken; pay again with the new requirements.' };
|
|
@@ -174,7 +174,7 @@ export async function verifyPaymentHeader(header, resourcePath, current, d) {
|
|
|
174
174
|
return { kind: 'unavailable', message: 'Could not reach the facilitator. No payment was taken.' };
|
|
175
175
|
}
|
|
176
176
|
const payment = { key, payload, accepted, facilitator: target.facilitator, server: target.server, settleUnknownSince: claim.state === 'settle_unknown' ? claim.since : null };
|
|
177
|
-
//
|
|
177
|
+
// Payment whose previous settlement result is unknown: do not verify again; decide on-chain in the settle step
|
|
178
178
|
if (payment.settleUnknownSince !== null)
|
|
179
179
|
return { kind: 'verified', payment };
|
|
180
180
|
try {
|
|
@@ -194,12 +194,12 @@ export async function verifyPaymentHeader(header, resourcePath, current, d) {
|
|
|
194
194
|
return { kind: 'verified', payment };
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
* Step 2 (only after the report is built): facilitator /settle → on-chain recheck with our RPC.
|
|
198
|
+
* If the settlement result is unknown (timeout, etc.), decide on-chain by the buyer's signature; if still unknown, leave it as "result unknown"
|
|
199
199
|
*/
|
|
200
200
|
export async function settleVerified(v, d) {
|
|
201
201
|
const { accepted, key } = v;
|
|
202
|
-
/**
|
|
202
|
+
/** Not found on-chain → within the validity window, "result unknown" (awaiting recheck); after it, released as "not paid" */
|
|
203
203
|
const unknown = async (facilitatorSaid) => {
|
|
204
204
|
const since = v.settleUnknownSince ?? d.nowMs;
|
|
205
205
|
if (d.nowMs - since > SETTLE_UNKNOWN_EXPIRY_MS) {
|
|
@@ -213,8 +213,8 @@ export async function settleVerified(v, d) {
|
|
|
213
213
|
};
|
|
214
214
|
};
|
|
215
215
|
/**
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
* When settlement failed or its result is unknown (no response, 4xx, 5xx, success:false): don't rely only on the facilitator; look on-chain first
|
|
217
|
+
* (the facilitator may have sent the tx and then returned a failure after timing out on confirmation, so money may have moved)
|
|
218
218
|
*/
|
|
219
219
|
const judgeOnChain = async (facilitatorSaid, reportedTx) => {
|
|
220
220
|
if (reportedTx) {
|
|
@@ -231,7 +231,7 @@ export async function settleVerified(v, d) {
|
|
|
231
231
|
kind: 'paid', confirmation: 'confirmed',
|
|
232
232
|
settlement: { success: true, transaction: tx.signature, network: accepted.network, payer: tx.accountKeys[0] },
|
|
233
233
|
});
|
|
234
|
-
//
|
|
234
|
+
// Payment with an unknown previous result → decide on-chain only (do not settle again)
|
|
235
235
|
if (v.settleUnknownSince !== null) {
|
|
236
236
|
const tx = await findSettledOnChain(v, d).catch(() => null);
|
|
237
237
|
if (tx && satisfies(tx, accepted))
|
|
@@ -243,13 +243,13 @@ export async function settleVerified(v, d) {
|
|
|
243
243
|
settlement = await v.server.settlePayment(v.payload, accepted);
|
|
244
244
|
}
|
|
245
245
|
catch (e) {
|
|
246
|
-
// 4xx
|
|
246
|
+
// Whether a 4xx failure response or no response (timeout, 5xx) → decide on-chain first
|
|
247
247
|
return judgeOnChain(settleFailureReason(e) ?? undefined);
|
|
248
248
|
}
|
|
249
249
|
if (!settlement.success) {
|
|
250
250
|
return judgeOnChain(settlement.errorReason ?? 'settle_failed', settlement.transaction || undefined);
|
|
251
251
|
}
|
|
252
|
-
//
|
|
252
|
+
// On-chain recheck (don't trust the facilitator response as is)
|
|
253
253
|
let confirmed = null;
|
|
254
254
|
for (const wait of [0, ...(d.confirmDelaysMs ?? [1000, 2000, 4000])]) {
|
|
255
255
|
if (wait)
|
|
@@ -262,7 +262,7 @@ export async function settleVerified(v, d) {
|
|
|
262
262
|
await d.ledger.release(key);
|
|
263
263
|
return { kind: 'payment_required', reason: 'onchain_mismatch', message: 'On-chain record shows the receiving address did not receive the required amount.' };
|
|
264
264
|
}
|
|
265
|
-
// facilitator
|
|
265
|
+
// The facilitator reported success but it is not on-chain yet → the buyer may have paid, so deliver the report and mark it "pending confirmation"
|
|
266
266
|
return { kind: 'paid', settlement, confirmation: confirmed ? 'confirmed' : 'pending' };
|
|
267
267
|
}
|
|
268
268
|
export function paymentResponseHeader(s) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent402-dev/pay-server",
|
|
3
|
-
"description": "Server helpers for x402 on Solana: accept USDC and optionally
|
|
3
|
+
"description": "Server helpers for x402 on Solana: accept USDC and optionally PREQ (Token-2022) through external facilitators. Verify, run your handler, then settle. Holds no funds and no private keys.",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"x402",
|
|
6
6
|
"solana",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@x402/core": "2.31.0",
|
|
26
26
|
"@x402/svm": "2.31.0"
|
|
27
27
|
},
|
|
28
|
-
"version": "0.
|
|
28
|
+
"version": "0.2.0",
|
|
29
29
|
"author": "Agent402",
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"type": "module",
|