@relai-fi/x402 0.5.8 → 0.5.9
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 +104 -0
- package/dist/client.cjs +535 -9
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +64 -3
- package/dist/client.d.ts +64 -3
- package/dist/client.js +535 -9
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +812 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +810 -34
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +540 -10
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +7 -2
- package/dist/react/index.d.ts +7 -2
- package/dist/react/index.js +540 -10
- package/dist/react/index.js.map +1 -1
- package/dist/server.cjs +273 -25
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +17 -2
- package/dist/server.d.ts +17 -2
- package/dist/server.js +273 -25
- package/dist/server.js.map +1 -1
- package/dist/{types-C-2GNyMh.d.cts → types-CWtUxi3l.d.cts} +12 -1
- package/dist/{types-C-2GNyMh.d.ts → types-CWtUxi3l.d.ts} +12 -1
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -41,6 +41,117 @@ var NETWORK_CAIP2 = {
|
|
|
41
41
|
var CAIP2_TO_NETWORK = Object.fromEntries(
|
|
42
42
|
Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k])
|
|
43
43
|
);
|
|
44
|
+
var NETWORK_TOKENS = {
|
|
45
|
+
"solana": [
|
|
46
|
+
{
|
|
47
|
+
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
48
|
+
symbol: "USDC",
|
|
49
|
+
name: "USD Coin",
|
|
50
|
+
decimals: 6
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"base": [
|
|
54
|
+
{
|
|
55
|
+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
56
|
+
symbol: "USDC",
|
|
57
|
+
name: "USD Coin",
|
|
58
|
+
decimals: 6,
|
|
59
|
+
domainVersion: "2",
|
|
60
|
+
isStableUsd: true
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"avalanche": [
|
|
64
|
+
{
|
|
65
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
66
|
+
symbol: "USDC",
|
|
67
|
+
name: "USD Coin",
|
|
68
|
+
decimals: 6,
|
|
69
|
+
domainVersion: "2",
|
|
70
|
+
isStableUsd: true
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"skale-base": [
|
|
74
|
+
{
|
|
75
|
+
address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
|
|
76
|
+
symbol: "USDC",
|
|
77
|
+
name: "Bridged USDC (SKALE Bridge)",
|
|
78
|
+
decimals: 6,
|
|
79
|
+
domainVersion: "2",
|
|
80
|
+
isStableUsd: true
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
address: "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA",
|
|
84
|
+
symbol: "USDT",
|
|
85
|
+
name: "Bridged USDT (SKALE Bridge)",
|
|
86
|
+
decimals: 6,
|
|
87
|
+
domainVersion: "2",
|
|
88
|
+
isStableUsd: true
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
address: "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e",
|
|
92
|
+
symbol: "WBTC",
|
|
93
|
+
name: "Wrapped Bitcoin",
|
|
94
|
+
decimals: 8,
|
|
95
|
+
domainVersion: "2",
|
|
96
|
+
isStableUsd: false
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
address: "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486",
|
|
100
|
+
symbol: "WETH",
|
|
101
|
+
name: "Wrapped Ether",
|
|
102
|
+
decimals: 18,
|
|
103
|
+
domainVersion: "2",
|
|
104
|
+
isStableUsd: false
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"skale-base-sepolia": [
|
|
108
|
+
{
|
|
109
|
+
address: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
|
|
110
|
+
symbol: "USDC",
|
|
111
|
+
name: "Bridged USDC (SKALE Bridge)",
|
|
112
|
+
decimals: 6,
|
|
113
|
+
domainVersion: "2",
|
|
114
|
+
isStableUsd: true
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"skale-bite": [
|
|
118
|
+
{
|
|
119
|
+
address: "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
|
|
120
|
+
symbol: "USDC",
|
|
121
|
+
name: "USDC",
|
|
122
|
+
decimals: 6,
|
|
123
|
+
domainVersion: "1",
|
|
124
|
+
isStableUsd: true
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"polygon": [
|
|
128
|
+
{
|
|
129
|
+
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
130
|
+
symbol: "USDC",
|
|
131
|
+
name: "USD Coin",
|
|
132
|
+
decimals: 6,
|
|
133
|
+
domainVersion: "2",
|
|
134
|
+
isStableUsd: true
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"ethereum": [
|
|
138
|
+
{
|
|
139
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
140
|
+
symbol: "USDC",
|
|
141
|
+
name: "USD Coin",
|
|
142
|
+
decimals: 6,
|
|
143
|
+
domainVersion: "2",
|
|
144
|
+
isStableUsd: true
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
};
|
|
148
|
+
function resolveToken(network, asset) {
|
|
149
|
+
const tokens = NETWORK_TOKENS[network];
|
|
150
|
+
if (!tokens || tokens.length === 0) return null;
|
|
151
|
+
if (!asset) return tokens[0];
|
|
152
|
+
const normalized = String(asset).toLowerCase();
|
|
153
|
+
return tokens.find((token) => token.address.toLowerCase() === normalized) || null;
|
|
154
|
+
}
|
|
44
155
|
var USDC_ADDRESSES = {
|
|
45
156
|
"solana": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
46
157
|
"base": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
@@ -67,9 +178,103 @@ function stripePayTo(stripeSecretKey, options) {
|
|
|
67
178
|
stripeNetwork: options?.network || "base"
|
|
68
179
|
};
|
|
69
180
|
}
|
|
181
|
+
var USD_PRICE_CACHE_TTL_MS = 60 * 1e3;
|
|
182
|
+
var usdPriceCache = /* @__PURE__ */ new Map();
|
|
183
|
+
var COINGECKO_ID_BY_SYMBOL = {
|
|
184
|
+
WETH: "ethereum",
|
|
185
|
+
WBTC: "bitcoin"
|
|
186
|
+
};
|
|
187
|
+
function isStableUsdToken(token) {
|
|
188
|
+
if (token.isStableUsd === true) return true;
|
|
189
|
+
const symbol = String(token.symbol || "").toUpperCase();
|
|
190
|
+
return symbol === "USDC" || symbol === "USDT";
|
|
191
|
+
}
|
|
192
|
+
async function fetchUsdPriceFromCoinGecko(coinId) {
|
|
193
|
+
const now = Date.now();
|
|
194
|
+
const cached = usdPriceCache.get(coinId);
|
|
195
|
+
if (cached && cached.expiresAt > now) {
|
|
196
|
+
return cached.usd;
|
|
197
|
+
}
|
|
198
|
+
const url = `https://api.coingecko.com/api/v3/simple/price?ids=${encodeURIComponent(coinId)}&vs_currencies=usd`;
|
|
199
|
+
const res = await fetch(url, {
|
|
200
|
+
method: "GET",
|
|
201
|
+
headers: {
|
|
202
|
+
Accept: "application/json"
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
if (!res.ok) {
|
|
206
|
+
throw new Error(`CoinGecko price request failed: HTTP ${res.status}`);
|
|
207
|
+
}
|
|
208
|
+
const payload = await res.json();
|
|
209
|
+
const usd = Number(payload?.[coinId]?.usd);
|
|
210
|
+
if (!Number.isFinite(usd) || usd <= 0) {
|
|
211
|
+
throw new Error(`CoinGecko returned invalid usd price for ${coinId}`);
|
|
212
|
+
}
|
|
213
|
+
usdPriceCache.set(coinId, {
|
|
214
|
+
usd,
|
|
215
|
+
expiresAt: now + USD_PRICE_CACHE_TTL_MS
|
|
216
|
+
});
|
|
217
|
+
return usd;
|
|
218
|
+
}
|
|
219
|
+
async function resolveAmountAtomicFromUsd({
|
|
220
|
+
priceUsd,
|
|
221
|
+
token,
|
|
222
|
+
network
|
|
223
|
+
}) {
|
|
224
|
+
const decimals = Number(token.decimals);
|
|
225
|
+
if (!Number.isFinite(decimals) || decimals < 0) {
|
|
226
|
+
throw new Error(`Invalid token decimals for ${token.symbol || token.address}`);
|
|
227
|
+
}
|
|
228
|
+
if (isStableUsdToken(token)) {
|
|
229
|
+
const units = Math.floor(priceUsd * Math.pow(10, decimals));
|
|
230
|
+
return String(Math.max(1, units));
|
|
231
|
+
}
|
|
232
|
+
const symbol = String(token.symbol || "").toUpperCase();
|
|
233
|
+
const coinGeckoId = COINGECKO_ID_BY_SYMBOL[symbol];
|
|
234
|
+
if (!coinGeckoId) {
|
|
235
|
+
throw new Error(`No USD quote source configured for token ${symbol || token.address} on ${network}`);
|
|
236
|
+
}
|
|
237
|
+
const overrideEnv = process.env[`EVM_TOKEN_PRICE_${symbol}_USD`];
|
|
238
|
+
const usdPerToken = overrideEnv && Number(overrideEnv) > 0 ? Number(overrideEnv) : await fetchUsdPriceFromCoinGecko(coinGeckoId);
|
|
239
|
+
const tokenAmount = priceUsd / usdPerToken;
|
|
240
|
+
const rawUnits = tokenAmount * Math.pow(10, decimals);
|
|
241
|
+
if (!Number.isFinite(rawUnits) || rawUnits <= 0) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
`Invalid conversion result for token ${symbol || token.address}: priceUsd=${priceUsd}, usdPerToken=${usdPerToken}`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
return String(Math.max(1, Math.floor(rawUnits)));
|
|
247
|
+
}
|
|
70
248
|
function isStripePayTo(payTo) {
|
|
71
249
|
return typeof payTo === "object" && payTo !== null && payTo.__brand === "stripePayTo";
|
|
72
250
|
}
|
|
251
|
+
function parseBooleanHeader(value) {
|
|
252
|
+
if (value == null) return null;
|
|
253
|
+
const normalized = String(value).trim().toLowerCase();
|
|
254
|
+
if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
function normalizeIntegritasFlow(value) {
|
|
263
|
+
const normalized = String(value || "").trim().toLowerCase();
|
|
264
|
+
if (normalized === "single") return "single";
|
|
265
|
+
if (normalized === "dual") return "dual";
|
|
266
|
+
return void 0;
|
|
267
|
+
}
|
|
268
|
+
function normalizeIntegritasOptions(value) {
|
|
269
|
+
if (value === true) return { enabled: true };
|
|
270
|
+
if (value === false || value == null) return { enabled: false };
|
|
271
|
+
const flow = normalizeIntegritasFlow(value.flow);
|
|
272
|
+
const enabled = typeof value.enabled === "boolean" ? value.enabled : true;
|
|
273
|
+
return {
|
|
274
|
+
enabled,
|
|
275
|
+
...flow ? { flow } : {}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
73
278
|
async function createStripeDepositAddress(secretKey, amountUsdCents, network = "base") {
|
|
74
279
|
const params = new URLSearchParams();
|
|
75
280
|
params.append("amount", String(amountUsdCents));
|
|
@@ -164,8 +369,45 @@ var Relai = class {
|
|
|
164
369
|
const stripeConfig = isStripePayTo(options.payTo) ? options.payTo : null;
|
|
165
370
|
const network = stripeConfig ? stripeConfig.stripeNetwork || "base" : options.network || self.network;
|
|
166
371
|
const caip2 = NETWORK_CAIP2[network];
|
|
167
|
-
const
|
|
168
|
-
const
|
|
372
|
+
const requestedAsset = typeof options.asset === "string" && options.asset.trim() !== "" ? options.asset.trim() : void 0;
|
|
373
|
+
const explicitToken = requestedAsset ? resolveToken(network, requestedAsset) : null;
|
|
374
|
+
if (requestedAsset && !explicitToken) {
|
|
375
|
+
return res.status(400).json({
|
|
376
|
+
error: `Unsupported asset ${requestedAsset} for network ${network}`
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
const fallbackToken = {
|
|
380
|
+
address: USDC_ADDRESSES[network],
|
|
381
|
+
symbol: "USDC",
|
|
382
|
+
name: network === "skale-bite" ? "USDC" : "USD Coin",
|
|
383
|
+
decimals: 6,
|
|
384
|
+
domainVersion: network === "skale-bite" ? "1" : "2",
|
|
385
|
+
isStableUsd: true
|
|
386
|
+
};
|
|
387
|
+
const token = explicitToken || resolveToken(network) || fallbackToken;
|
|
388
|
+
const asset = token.address;
|
|
389
|
+
const tokenName = token.name || "USD Coin";
|
|
390
|
+
const tokenVersion = token.domainVersion || (network === "skale-bite" ? "1" : "2");
|
|
391
|
+
const tokenDecimals = Number.isFinite(Number(token.decimals)) ? Number(token.decimals) : 6;
|
|
392
|
+
let amount;
|
|
393
|
+
try {
|
|
394
|
+
amount = await resolveAmountAtomicFromUsd({
|
|
395
|
+
priceUsd: resolvedPrice,
|
|
396
|
+
token,
|
|
397
|
+
network
|
|
398
|
+
});
|
|
399
|
+
} catch (err) {
|
|
400
|
+
console.error("[Relai] Failed to convert USD amount to token units:", err);
|
|
401
|
+
return res.status(500).json({
|
|
402
|
+
error: "Failed to quote token amount for payment requirements"
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
const configuredIntegritas = normalizeIntegritasOptions(options.integritas);
|
|
406
|
+
const headerIntegritasEnabled = parseBooleanHeader(req.headers["x-integritas"]);
|
|
407
|
+
const headerIntegritasFlow = normalizeIntegritasFlow(req.headers["x-integritas-flow"]);
|
|
408
|
+
const integritasEnabled = headerIntegritasEnabled === null ? configuredIntegritas.enabled : headerIntegritasEnabled;
|
|
409
|
+
const integritasFlow = headerIntegritasFlow || configuredIntegritas.flow;
|
|
410
|
+
const integritasMode = integritasFlow === "single" ? "single_signature_fee_included" : integritasFlow === "dual" ? "dual_signature_split" : void 0;
|
|
169
411
|
const paymentHeader = req.headers["x-payment"] || req.headers["payment-signature"] || req.headers["x-payment-signature"];
|
|
170
412
|
if (!paymentHeader) {
|
|
171
413
|
options.onPaymentRequired?.(req, { price: resolvedPrice, network });
|
|
@@ -181,23 +423,6 @@ var Relai = class {
|
|
|
181
423
|
resolvedPayTo = options.payTo;
|
|
182
424
|
}
|
|
183
425
|
const feePayer = await self.getFeePayer(caip2);
|
|
184
|
-
const tokenMetadata = {
|
|
185
|
-
"eip155:103698795": { name: "USDC", version: "1" },
|
|
186
|
-
// SKALE BITE
|
|
187
|
-
"eip155:1187947933": { name: "Bridged USDC (SKALE Bridge)", version: "2" },
|
|
188
|
-
// SKALE Base
|
|
189
|
-
"eip155:324705682": { name: "Bridged USDC (SKALE Bridge)", version: "2" },
|
|
190
|
-
// SKALE Base Sepolia
|
|
191
|
-
"eip155:8453": { name: "USD Coin", version: "2" },
|
|
192
|
-
// Base
|
|
193
|
-
"eip155:43114": { name: "USD Coin", version: "2" },
|
|
194
|
-
// Avalanche
|
|
195
|
-
"eip155:137": { name: "USD Coin", version: "2" },
|
|
196
|
-
// Polygon
|
|
197
|
-
"eip155:1": { name: "USD Coin", version: "2" }
|
|
198
|
-
// Ethereum
|
|
199
|
-
};
|
|
200
|
-
const metadata = tokenMetadata[caip2] || { name: "USDC", version: "1" };
|
|
201
426
|
return res.status(402).json({
|
|
202
427
|
x402Version: 2,
|
|
203
428
|
error: "Payment required",
|
|
@@ -214,13 +439,28 @@ var Relai = class {
|
|
|
214
439
|
payTo: resolvedPayTo,
|
|
215
440
|
maxTimeoutSeconds: options.maxTimeoutSeconds || 60,
|
|
216
441
|
extra: {
|
|
217
|
-
name:
|
|
218
|
-
version:
|
|
219
|
-
decimals:
|
|
220
|
-
|
|
442
|
+
name: tokenName,
|
|
443
|
+
version: tokenVersion,
|
|
444
|
+
decimals: tokenDecimals,
|
|
445
|
+
symbol: token.symbol,
|
|
446
|
+
...feePayer && { feePayer },
|
|
221
447
|
// Add feePayer if available
|
|
448
|
+
...integritasEnabled ? { integritasEnabled: true } : {},
|
|
449
|
+
...integritasFlow ? { integritasFlow } : {},
|
|
450
|
+
...integritasMode ? { integritasMode } : {},
|
|
451
|
+
...integritasFlow === "single" ? { integritasSingleSignature: true } : {}
|
|
452
|
+
}
|
|
453
|
+
}],
|
|
454
|
+
...configuredIntegritas.enabled || integritasEnabled || !!integritasFlow ? {
|
|
455
|
+
extensions: {
|
|
456
|
+
integritas: {
|
|
457
|
+
available: true,
|
|
458
|
+
selectedFlow: integritasFlow || null,
|
|
459
|
+
availableFlows: ["single", "dual"],
|
|
460
|
+
enabled: integritasEnabled
|
|
461
|
+
}
|
|
222
462
|
}
|
|
223
|
-
}
|
|
463
|
+
} : {}
|
|
224
464
|
});
|
|
225
465
|
}
|
|
226
466
|
let paymentProof;
|
|
@@ -255,7 +495,15 @@ var Relai = class {
|
|
|
255
495
|
amount,
|
|
256
496
|
asset,
|
|
257
497
|
payTo: settlePayTo,
|
|
258
|
-
maxTimeoutSeconds: options.maxTimeoutSeconds || 60
|
|
498
|
+
maxTimeoutSeconds: options.maxTimeoutSeconds || 60,
|
|
499
|
+
...integritasEnabled ? {
|
|
500
|
+
extra: {
|
|
501
|
+
integritasEnabled: true,
|
|
502
|
+
...integritasFlow ? { integritasFlow } : {},
|
|
503
|
+
...integritasMode ? { integritasMode } : {},
|
|
504
|
+
...integritasFlow === "single" ? { integritasSingleSignature: true } : {}
|
|
505
|
+
}
|
|
506
|
+
} : {}
|
|
259
507
|
};
|
|
260
508
|
const settleUrl = `${self.facilitatorUrl}/settle`;
|
|
261
509
|
const settleRes = await fetch(settleUrl, {
|
package/dist/server.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts","../src/types.ts"],"sourcesContent":["// src/server.ts\nimport {\n NETWORK_CAIP2,\n USDC_ADDRESSES,\n RELAI_FACILITATOR_URL,\n type RelaiNetwork,\n} from './types';\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface RelaiServerConfig {\n /** Network to accept payments on */\n network: RelaiNetwork;\n /** RelAI facilitator URL (default: https://facilitator.x402.fi) */\n facilitatorUrl?: string;\n}\n\nexport type DynamicPrice = number | ((req: any) => number | Promise<number>);\n\nexport interface ProtectOptions {\n /** Price in USD (e.g., 0.01 for 1 cent) */\n price: DynamicPrice;\n /** Wallet address to receive payments, or stripePayTo() for Stripe settlement */\n payTo: string | StripePayTo;\n /** Description shown to payer */\n description?: string;\n /** MIME type of the response (default: application/json) */\n mimeType?: string;\n /** Maximum timeout in seconds (default: 60) */\n maxTimeoutSeconds?: number;\n /** Override network for this endpoint */\n network?: RelaiNetwork;\n /** Custom validation after payment is settled */\n customRules?: (req: any) => boolean | Promise<boolean>;\n /** Callback when 402 is returned (no payment provided) */\n onPaymentRequired?: (req: any, info: { price: number; network: RelaiNetwork }) => void;\n /** Callback when payment is settled successfully */\n onPaymentSettled?: (req: any, result: SettleResult) => void;\n /** Callback on error */\n onError?: (req: any, error: unknown) => void;\n}\n\nexport interface SettleResult {\n success: boolean;\n transaction?: string;\n payer?: string;\n network?: string;\n error?: string;\n errorReason?: string;\n}\n\nexport interface PaymentInfo {\n verified: boolean;\n transactionId?: string;\n payer?: string;\n network: RelaiNetwork;\n amount: number;\n}\n\n// ============================================================================\n// Stripe Pay-To Helper\n// ============================================================================\n\n/** Config returned by stripePayTo() - used by protect() to create Stripe deposit addresses */\nexport interface StripePayTo {\n readonly __brand: 'stripePayTo';\n readonly secretKey: string;\n /** Stripe crypto deposits network (default: 'base') */\n readonly stripeNetwork: string;\n}\n\n/**\n * Create a Stripe pay-to configuration for x402 payments.\n * Payments settle as USD in your Stripe Dashboard - no crypto knowledge required.\n *\n * Stripe creates a fresh PaymentIntent + deposit address per request.\n * Network is auto-set to Base (Stripe settles USDC on Base).\n *\n * @example\n * ```typescript\n * import Relai, { stripePayTo } from '@relai-fi/x402/server';\n *\n * const relai = new Relai({ network: 'base' });\n *\n * app.get('/api/data', relai.protect({\n * price: 0.01,\n * payTo: stripePayTo(process.env.STRIPE_SECRET_KEY!),\n * }), (req, res) => {\n * res.json({ data: 'paid content' });\n * });\n * ```\n */\nexport function stripePayTo(\n stripeSecretKey: string,\n options?: { network?: string },\n): StripePayTo {\n if (!stripeSecretKey) {\n throw new Error('stripePayTo requires a Stripe secret key');\n }\n return {\n __brand: 'stripePayTo' as const,\n secretKey: stripeSecretKey,\n stripeNetwork: options?.network || 'base',\n };\n}\n\n/** @internal Type guard for StripePayTo */\nfunction isStripePayTo(payTo: unknown): payTo is StripePayTo {\n return (\n typeof payTo === 'object' &&\n payTo !== null &&\n (payTo as any).__brand === 'stripePayTo'\n );\n}\n\n/**\n * @internal Create a Stripe PaymentIntent with crypto payment method\n * and extract the deposit address.\n */\nasync function createStripeDepositAddress(\n secretKey: string,\n amountUsdCents: number,\n network: string = 'base',\n): Promise<string> {\n const params = new URLSearchParams();\n params.append('amount', String(amountUsdCents));\n params.append('currency', 'usd');\n params.append('payment_method_types[]', 'crypto');\n params.append('payment_method_data[type]', 'crypto');\n params.append('confirm', 'true');\n\n const res = await fetch('https://api.stripe.com/v1/payment_intents', {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${secretKey}`,\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: params.toString(),\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as any;\n const msg = err?.error?.message || res.statusText;\n\n // Provide actionable guidance for common issues\n if (msg.includes('unknown parameter') || msg.includes('crypto')) {\n throw new Error(\n `Stripe crypto payins not enabled on this account. ` +\n `Enable at: https://support.stripe.com/questions/get-started-with-pay-with-crypto ` +\n `(Original: ${msg})`,\n );\n }\n throw new Error(`Stripe PaymentIntent creation failed: ${msg}`);\n }\n\n const pi = await res.json() as any;\n const depositDetails = pi.next_action?.crypto_collect_deposit_details;\n if (!depositDetails) {\n throw new Error(\n 'Stripe PaymentIntent missing crypto deposit details. ' +\n 'Ensure crypto payins are enabled: https://support.stripe.com/questions/get-started-with-pay-with-crypto',\n );\n }\n\n const address = depositDetails.deposit_addresses?.[network]?.address;\n if (!address) {\n throw new Error(`No Stripe deposit address for network: ${network}`);\n }\n\n return address;\n}\n\n// ============================================================================\n// Relai Server SDK\n// ============================================================================\n\n/**\n * Server-side SDK for protecting Express endpoints with x402 micropayments.\n * Settles payments through the RelAI facilitator (zero gas fees for users).\n *\n * Supports: Solana, Base, Avalanche, SKALE Base, SKALE Base Sepolia, SKALE BITE, Polygon, and Ethereum.\n *\n * @example\n * ```typescript\n * import Relai from '@relai-fi/x402/server';\n *\n * const relai = new Relai({ network: 'base' });\n *\n * app.get('/api/data', relai.protect({\n * payTo: '0xYourWallet',\n * price: 0.01, // $0.01 USDC\n * }), (req, res) => {\n * res.json({ data: 'Protected content', payment: req.payment });\n * });\n * ```\n */\nexport class Relai {\n private network: RelaiNetwork;\n private facilitatorUrl: string;\n private feePayerCache: Map<string, string> = new Map(); // Cache feePayer per network\n\n constructor(config: RelaiServerConfig) {\n this.network = config.network;\n this.facilitatorUrl = config.facilitatorUrl || RELAI_FACILITATOR_URL;\n }\n\n /**\n * Get feePayer address for a network (cached)\n */\n private async getFeePayer(caip2: string): Promise<string | undefined> {\n // Check cache first\n if (this.feePayerCache.has(caip2)) {\n return this.feePayerCache.get(caip2);\n }\n\n // If using RelAI facilitator, use hardcoded address (no fetch needed)\n const isRelAI = this.facilitatorUrl.includes('facilitator.x402.fi') || \n this.facilitatorUrl.includes('relai');\n \n if (isRelAI) {\n const relaiFeePayer = '0x1892f72fdB3A966b2AD8595aA5f7741Ef72d6085';\n this.feePayerCache.set(caip2, relaiFeePayer);\n return relaiFeePayer;\n }\n\n // For other facilitators, fetch from /supported\n try {\n const supportedUrl = `${this.facilitatorUrl}/supported`;\n const supportedRes = await fetch(supportedUrl);\n if (supportedRes.ok) {\n const supportedData = await supportedRes.json();\n // Cache all feePayers from supported kinds\n supportedData.kinds?.forEach((kind: any) => {\n if (kind.network && kind.extra?.feePayer) {\n this.feePayerCache.set(kind.network, kind.extra.feePayer);\n }\n });\n return this.feePayerCache.get(caip2);\n }\n } catch (err) {\n // feePayer MUST come from facilitator - cannot use env for security\n console.error(`[Relai] Failed to fetch feePayer from facilitator: ${err}`);\n }\n return undefined;\n }\n\n /**\n * Express middleware to protect an endpoint with x402 micropayments.\n *\n * Flow:\n * 1. No payment header → returns 402 with payment requirements\n * 2. Payment header present → calls RelAI facilitator `/settle`\n * 3. Settlement success → sets `PAYMENT-RESPONSE` header, attaches `req.payment`, calls `next()`\n */\n protect(options: ProtectOptions) {\n const self = this;\n\n return async (req: any, res: any, next: any) => {\n try {\n // Resolve dynamic price\n const resolvedPrice = typeof options.price === 'function'\n ? await options.price(req)\n : options.price;\n\n if (typeof resolvedPrice !== 'number' || !isFinite(resolvedPrice) || resolvedPrice <= 0) {\n return res.status(400).json({ error: 'Invalid price configuration' });\n }\n\n // Resolve network (Stripe auto-sets to base)\n const stripeConfig = isStripePayTo(options.payTo) ? options.payTo : null;\n const network = stripeConfig\n ? (stripeConfig.stripeNetwork as RelaiNetwork) || 'base'\n : (options.network || self.network);\n const caip2 = NETWORK_CAIP2[network];\n const asset = USDC_ADDRESSES[network];\n const amount = String(Math.floor(resolvedPrice * 1_000_000)); // USD → USDC atomic units (6 decimals)\n\n // Check for payment header (base64-encoded JSON)\n const paymentHeader =\n req.headers['x-payment'] ||\n req.headers['payment-signature'] ||\n req.headers['x-payment-signature'];\n\n // -----------------------------------------------------------\n // No payment → return 402 Payment Required\n // -----------------------------------------------------------\n if (!paymentHeader) {\n options.onPaymentRequired?.(req, { price: resolvedPrice, network });\n\n // Resolve payTo address (Stripe creates a fresh deposit address per request)\n let resolvedPayTo: string;\n if (stripeConfig) {\n const amountInCents = Math.max(1, Math.round(resolvedPrice * 100));\n resolvedPayTo = await createStripeDepositAddress(\n stripeConfig.secretKey,\n amountInCents,\n stripeConfig.stripeNetwork,\n );\n } else {\n resolvedPayTo = options.payTo as string;\n }\n\n // Get facilitator feePayer address (cached)\n const feePayer = await self.getFeePayer(caip2);\n\n // Token metadata per network\n // IMPORTANT: These must match the actual EIP-712 domain on each network\n const tokenMetadata: Record<string, { name: string; version: string }> = {\n 'eip155:103698795': { name: 'USDC', version: '1' }, // SKALE BITE\n 'eip155:1187947933': { name: 'Bridged USDC (SKALE Bridge)', version: '2' }, // SKALE Base\n 'eip155:324705682': { name: 'Bridged USDC (SKALE Bridge)', version: '2' }, // SKALE Base Sepolia\n 'eip155:8453': { name: 'USD Coin', version: '2' }, // Base\n 'eip155:43114': { name: 'USD Coin', version: '2' }, // Avalanche\n 'eip155:137': { name: 'USD Coin', version: '2' }, // Polygon\n 'eip155:1': { name: 'USD Coin', version: '2' }, // Ethereum\n };\n const metadata = tokenMetadata[caip2] || { name: 'USDC', version: '1' };\n\n return res.status(402).json({\n x402Version: 2,\n error: 'Payment required',\n resource: {\n url: `${req.protocol}://${req.get('host')}${req.originalUrl}`,\n description: options.description || 'API access',\n mimeType: options.mimeType || 'application/json',\n },\n accepts: [{\n scheme: 'exact',\n network: caip2,\n amount,\n asset,\n payTo: resolvedPayTo,\n maxTimeoutSeconds: options.maxTimeoutSeconds || 60,\n extra: {\n name: metadata.name,\n version: metadata.version,\n decimals: 6,\n ...(feePayer && { feePayer }), // Add feePayer if available\n },\n }],\n });\n }\n\n // -----------------------------------------------------------\n // Payment header present → parse and settle via facilitator\n // -----------------------------------------------------------\n let paymentProof: any;\n try {\n // Try base64 first (standard x402 format)\n const decoded = Buffer.from(paymentHeader, 'base64').toString('utf-8');\n paymentProof = JSON.parse(decoded);\n } catch {\n try {\n // Fallback: raw JSON string\n paymentProof = JSON.parse(paymentHeader);\n } catch {\n return res.status(400).json({\n x402Version: 2,\n error: 'Invalid payment header — expected base64-encoded JSON',\n });\n }\n }\n\n // Resolve payTo for settle (extract from signed proof when using Stripe)\n let settlePayTo: string;\n if (stripeConfig) {\n settlePayTo =\n paymentProof.payload?.authorization?.to ||\n paymentProof.accepted?.payTo ||\n '';\n if (!settlePayTo) {\n return res.status(400).json({\n x402Version: 2,\n error: 'Cannot extract destination address from payment proof',\n });\n }\n } else {\n settlePayTo = options.payTo as string;\n }\n\n // Build payment requirements for facilitator\n const paymentRequirements = {\n scheme: 'exact',\n network,\n amount,\n asset,\n payTo: settlePayTo,\n maxTimeoutSeconds: options.maxTimeoutSeconds || 60,\n };\n\n // Call facilitator /settle\n const settleUrl = `${self.facilitatorUrl}/settle`;\n const settleRes = await fetch(settleUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n paymentPayload: paymentProof,\n paymentRequirements,\n }),\n });\n\n const result: SettleResult = await settleRes.json() as SettleResult;\n\n if (!result.success) {\n return res.status(402).json({\n x402Version: 2,\n error: result.errorReason || result.error || 'Payment settlement failed',\n });\n }\n\n // Attach payment info to request\n const paymentInfo: PaymentInfo = {\n verified: true,\n transactionId: result.transaction,\n payer: result.payer,\n network,\n amount: resolvedPrice,\n };\n req.payment = paymentInfo;\n req.x402Payer = result.payer;\n req.x402Paid = true;\n req.x402Transaction = result.transaction;\n req.x402Network = network;\n\n // Set x402 v2 PAYMENT-RESPONSE header (base64 JSON)\n const paymentResponse = {\n x402Version: 2,\n scheme: 'exact',\n network: caip2,\n transaction: result.transaction,\n payer: result.payer,\n amount,\n asset,\n };\n res.setHeader(\n 'PAYMENT-RESPONSE',\n Buffer.from(JSON.stringify(paymentResponse)).toString('base64'),\n );\n\n options.onPaymentSettled?.(req, result);\n\n // Custom validation after payment\n if (options.customRules) {\n const valid = await options.customRules(req);\n if (!valid) {\n return res.status(403).json({ error: 'Custom validation failed' });\n }\n }\n\n next();\n } catch (error) {\n options.onError?.(req, error);\n console.error('[Relai] Protection error:', error);\n res.status(500).json({ error: 'Internal server error' });\n }\n };\n }\n}\n\nexport default Relai;\n","// src/types.ts\n\n// ============================================================================\n// Constants\n// ============================================================================\n\n/** RelAI Facilitator URL */\nexport const RELAI_FACILITATOR_URL = 'https://facilitator.x402.fi';\n\n// ============================================================================\n// Supported Networks\n// ============================================================================\n\n/** All networks supported by RelAI facilitator */\nexport type RelaiNetwork =\n | 'solana'\n | 'base'\n | 'avalanche'\n | 'skale-base'\n | 'skale-base-sepolia'\n | 'skale-bite'\n | 'polygon'\n | 'ethereum';\n\n/** CAIP-2 network identifiers */\nexport const NETWORK_CAIP2: Record<RelaiNetwork, string> = {\n 'solana': 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n 'base': 'eip155:8453',\n 'avalanche': 'eip155:43114',\n 'skale-base': 'eip155:1187947933',\n 'skale-base-sepolia': 'eip155:324705682',\n 'skale-bite': 'eip155:103698795',\n 'polygon': 'eip155:137',\n 'ethereum': 'eip155:1',\n};\n\n/** Reverse lookup: CAIP-2 → simple network name */\nexport const CAIP2_TO_NETWORK: Record<string, RelaiNetwork> = Object.fromEntries(\n Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k as RelaiNetwork])\n) as Record<string, RelaiNetwork>;\n\n/** Chain IDs for EVM networks */\nexport const CHAIN_IDS: Record<string, number> = {\n 'base': 8453,\n 'avalanche': 43114,\n 'skale-base': 1187947933,\n 'skale-base-sepolia': 324705682,\n 'skale-bite': 103698795,\n 'polygon': 137,\n 'ethereum': 1,\n};\n\n/** USDC contract addresses per network */\nexport const USDC_ADDRESSES: Record<RelaiNetwork, string> = {\n 'solana': 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',\n 'base': '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n 'avalanche': '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',\n 'skale-base': '0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20',\n 'skale-base-sepolia': '0x2e08028E3C4c2356572E096d8EF835cD5C6030bD',\n 'skale-bite': '0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8',\n 'polygon': '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n 'ethereum': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n};\n\n/** Explorer URLs per network */\nexport const EXPLORER_TX_URL: Record<RelaiNetwork, (tx: string) => string> = {\n 'solana': (tx) => `https://solscan.io/tx/${tx}`,\n 'base': (tx) => `https://basescan.org/tx/${tx}`,\n 'avalanche': (tx) => `https://snowtrace.io/tx/${tx}`,\n 'skale-base': (tx) => `https://skale-base-explorer.skalenodes.com/tx/${tx}`,\n 'skale-base-sepolia': (tx) => `https://base-sepolia-testnet-explorer.skalenodes.com/tx/${tx}`,\n 'skale-bite': (tx) => `https://base-sepolia-testnet.explorer.skalenodes.com/tx/${tx}`,\n 'polygon': (tx) => `https://polygonscan.com/tx/${tx}`,\n 'ethereum': (tx) => `https://etherscan.io/tx/${tx}`,\n};\n\n/** Human-readable network labels */\nexport const NETWORK_LABELS: Record<RelaiNetwork, string> = {\n 'solana': 'Solana',\n 'base': 'Base',\n 'avalanche': 'Avalanche',\n 'skale-base': 'SKALE Base',\n 'skale-base-sepolia': 'SKALE Base Sepolia',\n 'skale-bite': 'SKALE BITE V2',\n 'polygon': 'Polygon',\n 'ethereum': 'Ethereum',\n};\n\n/** Legacy CAIP-2 exports for backward compatibility */\nexport const SOLANA_MAINNET_NETWORK = NETWORK_CAIP2['solana'];\nexport const BASE_MAINNET_NETWORK = NETWORK_CAIP2['base'];\n\n/** Legacy USDC exports for backward compatibility */\nexport const USDC_SOLANA = USDC_ADDRESSES['solana'];\nexport const USDC_BASE = USDC_ADDRESSES['base'];\n\n/** All supported RelAI networks list */\nexport const RELAI_NETWORKS: RelaiNetwork[] = [\n 'solana',\n 'base',\n 'avalanche',\n 'skale-base',\n 'skale-base-sepolia',\n 'skale-bite',\n 'polygon',\n 'ethereum',\n];\n\n/** Check if a network is Solana-based */\nexport function isSolana(network: string): boolean {\n return network === 'solana' || network.startsWith('solana:');\n}\n\n/** Check if a network is EVM-based */\nexport function isEvm(network: string): boolean {\n return ['base', 'avalanche', 'skale-base', 'skale-base-sepolia', 'skale-bite', 'polygon', 'ethereum'].includes(network) || network.startsWith('eip155:');\n}\n\n/** Normalize CAIP-2 or simple name to RelaiNetwork */\nexport function normalizeNetwork(network: string): RelaiNetwork | null {\n if (RELAI_NETWORKS.includes(network as RelaiNetwork)) return network as RelaiNetwork;\n const fromCaip2 = CAIP2_TO_NETWORK[network];\n if (fromCaip2) return fromCaip2;\n // Partial match\n if (network.startsWith('solana:')) return 'solana';\n if (network.startsWith('eip155:')) {\n const chainId = parseInt(network.split(':')[1]);\n const entry = Object.entries(CHAIN_IDS).find(([, id]) => id === chainId);\n if (entry) return entry[0] as RelaiNetwork;\n }\n return null;\n}\n\n// ============================================================================\n// Wallet Types\n// ============================================================================\n\n/** Solana wallet interface */\nexport interface SolanaWallet {\n publicKey: { toString(): string } | null;\n signTransaction: ((tx: unknown) => Promise<unknown>) | null;\n signAllTransactions?: ((txs: unknown[]) => Promise<unknown[]>) | null;\n}\n\n/** EVM wallet interface (viem-compatible) */\nexport interface EvmWallet {\n address: string;\n signTypedData: (params: unknown) => Promise<string>;\n chain?: { id: number };\n}\n\n/** Wallet set for multi-chain support */\nexport interface WalletSet {\n solana?: SolanaWallet;\n evm?: EvmWallet;\n}\n\n// ============================================================================\n// Payment Types\n// ============================================================================\n\n/** Extra fields in payment requirements */\nexport interface AcceptsExtra {\n feePayer?: string;\n decimals?: number;\n name?: string;\n version?: string;\n [key: string]: unknown;\n}\n\n/** A single payment option */\nexport interface PaymentAccept {\n x402Version?: 1 | 2;\n scheme: string;\n network: string;\n maxAmountRequired?: string;\n amount?: string;\n asset: string;\n payTo: string;\n maxTimeoutSeconds?: number;\n extra?: AcceptsExtra;\n resource?: string;\n description?: string;\n mimeType?: string;\n outputSchema?: unknown;\n}\n\n/** Resource info for v2 */\nexport interface ResourceInfo {\n url: string;\n description?: string;\n mimeType?: string;\n}\n\n/** Payment requirements (402 response) */\nexport interface PaymentRequired {\n x402Version: 1 | 2;\n error?: string;\n accepts: PaymentAccept[];\n resource?: ResourceInfo;\n extensions?: Record<string, unknown>;\n}\n\n// ============================================================================\n// Config Types (server-specific types are in server.ts)\n// ============================================================================\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAM,wBAAwB;AAkB9B,IAAM,gBAA8C;AAAA,EACzD,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AACd;AAGO,IAAM,mBAAiD,OAAO;AAAA,EACnE,OAAO,QAAQ,aAAa,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAiB,CAAC;AACtE;AAcO,IAAM,iBAA+C;AAAA,EAC1D,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AACd;AA2BO,IAAM,yBAAyB,cAAc,QAAQ;AACrD,IAAM,uBAAuB,cAAc,MAAM;AAGjD,IAAM,cAAc,eAAe,QAAQ;AAC3C,IAAM,YAAY,eAAe,MAAM;;;ADAvC,SAAS,YACd,iBACA,SACa;AACb,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AACA,SAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW;AAAA,IACX,eAAe,SAAS,WAAW;AAAA,EACrC;AACF;AAGA,SAAS,cAAc,OAAsC;AAC3D,SACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAc,YAAY;AAE/B;AAMA,eAAe,2BACb,WACA,gBACA,UAAkB,QACD;AACjB,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,OAAO,UAAU,OAAO,cAAc,CAAC;AAC9C,SAAO,OAAO,YAAY,KAAK;AAC/B,SAAO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ADDRESSES,\n RELAI_FACILITATOR_URL,\n resolveToken,\n type NetworkToken,\n type RelaiNetwork,\n} from './types';\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface RelaiServerConfig {\n /** Network to accept payments on */\n network: RelaiNetwork;\n /** RelAI facilitator URL (default: https://facilitator.x402.fi) */\n facilitatorUrl?: string;\n}\n\nexport type DynamicPrice = number | ((req: any) => number | Promise<number>);\n\nexport type RelaiIntegritasFlow = 'single' | 'dual';\n\nexport interface RelaiIntegritasOptions {\n /** Enable Integritas by default for this endpoint */\n enabled?: boolean;\n /** Default flow when Integritas is enabled */\n flow?: RelaiIntegritasFlow;\n}\n\nexport interface ProtectOptions {\n /** Price in USD (e.g., 0.01 for 1 cent) */\n price: DynamicPrice;\n /** Optional token asset address for networks supporting multiple tokens */\n asset?: string;\n /** Wallet address to receive payments, or stripePayTo() for Stripe settlement */\n payTo: string | StripePayTo;\n /** Description shown to payer */\n description?: string;\n /** MIME type of the response (default: application/json) */\n mimeType?: string;\n /** Maximum timeout in seconds (default: 60) */\n maxTimeoutSeconds?: number;\n /** Integritas options (or simple boolean enable flag) */\n integritas?: boolean | RelaiIntegritasOptions;\n /** Override network for this endpoint */\n network?: RelaiNetwork;\n /** Custom validation after payment is settled */\n customRules?: (req: any) => boolean | Promise<boolean>;\n /** Callback when 402 is returned (no payment provided) */\n onPaymentRequired?: (req: any, info: { price: number; network: RelaiNetwork }) => void;\n /** Callback when payment is settled successfully */\n onPaymentSettled?: (req: any, result: SettleResult) => void;\n /** Callback on error */\n onError?: (req: any, error: unknown) => void;\n}\n\nexport interface SettleResult {\n success: boolean;\n transaction?: string;\n payer?: string;\n network?: string;\n splitTransfers?: Record<string, unknown>;\n integritasFeePaid?: boolean;\n provenance?: Record<string, unknown>;\n integritas?: Record<string, unknown>;\n error?: string;\n errorReason?: string;\n}\n\nexport interface PaymentInfo {\n verified: boolean;\n transactionId?: string;\n payer?: string;\n network: RelaiNetwork;\n amount: number;\n}\n\n// ============================================================================\n// Stripe Pay-To Helper\n// ============================================================================\n\n/** Config returned by stripePayTo() - used by protect() to create Stripe deposit addresses */\nexport interface StripePayTo {\n readonly __brand: 'stripePayTo';\n readonly secretKey: string;\n /** Stripe crypto deposits network (default: 'base') */\n readonly stripeNetwork: string;\n}\n\n/**\n * Create a Stripe pay-to configuration for x402 payments.\n * Payments settle as USD in your Stripe Dashboard - no crypto knowledge required.\n *\n * Stripe creates a fresh PaymentIntent + deposit address per request.\n * Network is auto-set to Base (Stripe settles USDC on Base).\n *\n * @example\n * ```typescript\n * import Relai, { stripePayTo } from '@relai-fi/x402/server';\n *\n * const relai = new Relai({ network: 'base' });\n *\n * app.get('/api/data', relai.protect({\n * price: 0.01,\n * payTo: stripePayTo(process.env.STRIPE_SECRET_KEY!),\n * }), (req, res) => {\n * res.json({ data: 'paid content' });\n * });\n * ```\n */\nexport function stripePayTo(\n stripeSecretKey: string,\n options?: { network?: string },\n): StripePayTo {\n if (!stripeSecretKey) {\n throw new Error('stripePayTo requires a Stripe secret key');\n }\n return {\n __brand: 'stripePayTo' as const,\n secretKey: stripeSecretKey,\n stripeNetwork: options?.network || 'base',\n };\n}\n\nconst USD_PRICE_CACHE_TTL_MS = 60 * 1000;\nconst usdPriceCache = new Map<string, { usd: number; expiresAt: number }>();\n\nconst COINGECKO_ID_BY_SYMBOL: Record<string, string> = {\n WETH: 'ethereum',\n WBTC: 'bitcoin',\n};\n\nfunction isStableUsdToken(token: NetworkToken): boolean {\n if (token.isStableUsd === true) return true;\n const symbol = String(token.symbol || '').toUpperCase();\n return symbol === 'USDC' || symbol === 'USDT';\n}\n\nasync function fetchUsdPriceFromCoinGecko(coinId: string): Promise<number> {\n const now = Date.now();\n const cached = usdPriceCache.get(coinId);\n if (cached && cached.expiresAt > now) {\n return cached.usd;\n }\n\n const url = `https://api.coingecko.com/api/v3/simple/price?ids=${encodeURIComponent(coinId)}&vs_currencies=usd`;\n const res = await fetch(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n });\n\n if (!res.ok) {\n throw new Error(`CoinGecko price request failed: HTTP ${res.status}`);\n }\n\n const payload = await res.json() as Record<string, { usd?: number }>;\n const usd = Number(payload?.[coinId]?.usd);\n if (!Number.isFinite(usd) || usd <= 0) {\n throw new Error(`CoinGecko returned invalid usd price for ${coinId}`);\n }\n\n usdPriceCache.set(coinId, {\n usd,\n expiresAt: now + USD_PRICE_CACHE_TTL_MS,\n });\n\n return usd;\n}\n\nasync function resolveAmountAtomicFromUsd({\n priceUsd,\n token,\n network,\n}: {\n priceUsd: number;\n token: NetworkToken;\n network: RelaiNetwork;\n}): Promise<string> {\n const decimals = Number(token.decimals);\n if (!Number.isFinite(decimals) || decimals < 0) {\n throw new Error(`Invalid token decimals for ${token.symbol || token.address}`);\n }\n\n if (isStableUsdToken(token)) {\n const units = Math.floor(priceUsd * Math.pow(10, decimals));\n return String(Math.max(1, units));\n }\n\n const symbol = String(token.symbol || '').toUpperCase();\n const coinGeckoId = COINGECKO_ID_BY_SYMBOL[symbol];\n if (!coinGeckoId) {\n throw new Error(`No USD quote source configured for token ${symbol || token.address} on ${network}`);\n }\n\n const overrideEnv = process.env[`EVM_TOKEN_PRICE_${symbol}_USD`];\n const usdPerToken =\n overrideEnv && Number(overrideEnv) > 0\n ? Number(overrideEnv)\n : await fetchUsdPriceFromCoinGecko(coinGeckoId);\n\n const tokenAmount = priceUsd / usdPerToken;\n const rawUnits = tokenAmount * Math.pow(10, decimals);\n\n if (!Number.isFinite(rawUnits) || rawUnits <= 0) {\n throw new Error(\n `Invalid conversion result for token ${symbol || token.address}: priceUsd=${priceUsd}, usdPerToken=${usdPerToken}`,\n );\n }\n\n return String(Math.max(1, Math.floor(rawUnits)));\n}\n\n/** @internal Type guard for StripePayTo */\nfunction isStripePayTo(payTo: unknown): payTo is StripePayTo {\n return (\n typeof payTo === 'object' &&\n payTo !== null &&\n (payTo as any).__brand === 'stripePayTo'\n );\n}\n\nfunction parseBooleanHeader(value: unknown): boolean | null {\n if (value == null) return null;\n const normalized = String(value).trim().toLowerCase();\n if (normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on') {\n return true;\n }\n if (normalized === 'false' || normalized === '0' || normalized === 'no' || normalized === 'off') {\n return false;\n }\n return null;\n}\n\nfunction normalizeIntegritasFlow(value: unknown): RelaiIntegritasFlow | undefined {\n const normalized = String(value || '').trim().toLowerCase();\n if (normalized === 'single') return 'single';\n if (normalized === 'dual') return 'dual';\n return undefined;\n}\n\nfunction normalizeIntegritasOptions(\n value: boolean | RelaiIntegritasOptions | undefined,\n): { enabled: boolean; flow?: RelaiIntegritasFlow } {\n if (value === true) return { enabled: true };\n if (value === false || value == null) return { enabled: false };\n\n const flow = normalizeIntegritasFlow(value.flow);\n const enabled =\n typeof value.enabled === 'boolean'\n ? value.enabled\n : true;\n\n return {\n enabled,\n ...(flow ? { flow } : {}),\n };\n}\n\n/**\n * @internal Create a Stripe PaymentIntent with crypto payment method\n * and extract the deposit address.\n */\nasync function createStripeDepositAddress(\n secretKey: string,\n amountUsdCents: number,\n network: string = 'base',\n): Promise<string> {\n const params = new URLSearchParams();\n params.append('amount', String(amountUsdCents));\n params.append('currency', 'usd');\n params.append('payment_method_types[]', 'crypto');\n params.append('payment_method_data[type]', 'crypto');\n params.append('confirm', 'true');\n\n const res = await fetch('https://api.stripe.com/v1/payment_intents', {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${secretKey}`,\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: params.toString(),\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as any;\n const msg = err?.error?.message || res.statusText;\n\n // Provide actionable guidance for common issues\n if (msg.includes('unknown parameter') || msg.includes('crypto')) {\n throw new Error(\n `Stripe crypto payins not enabled on this account. ` +\n `Enable at: https://support.stripe.com/questions/get-started-with-pay-with-crypto ` +\n `(Original: ${msg})`,\n );\n }\n throw new Error(`Stripe PaymentIntent creation failed: ${msg}`);\n }\n\n const pi = await res.json() as any;\n const depositDetails = pi.next_action?.crypto_collect_deposit_details;\n if (!depositDetails) {\n throw new Error(\n 'Stripe PaymentIntent missing crypto deposit details. ' +\n 'Ensure crypto payins are enabled: https://support.stripe.com/questions/get-started-with-pay-with-crypto',\n );\n }\n\n const address = depositDetails.deposit_addresses?.[network]?.address;\n if (!address) {\n throw new Error(`No Stripe deposit address for network: ${network}`);\n }\n\n return address;\n}\n\n// ============================================================================\n// Relai Server SDK\n// ============================================================================\n\n/**\n * Server-side SDK for protecting Express endpoints with x402 micropayments.\n * Settles payments through the RelAI facilitator (zero gas fees for users).\n *\n * Supports: Solana, Base, Avalanche, SKALE Base, SKALE Base Sepolia, SKALE BITE, Polygon, and Ethereum.\n *\n * @example\n * ```typescript\n * import Relai from '@relai-fi/x402/server';\n *\n * const relai = new Relai({ network: 'base' });\n *\n * app.get('/api/data', relai.protect({\n * payTo: '0xYourWallet',\n * price: 0.01, // $0.01 USDC\n * }), (req, res) => {\n * res.json({ data: 'Protected content', payment: req.payment });\n * });\n * ```\n */\nexport class Relai {\n private network: RelaiNetwork;\n private facilitatorUrl: string;\n private feePayerCache: Map<string, string> = new Map(); // Cache feePayer per network\n\n constructor(config: RelaiServerConfig) {\n this.network = config.network;\n this.facilitatorUrl = config.facilitatorUrl || RELAI_FACILITATOR_URL;\n }\n\n /**\n * Get feePayer address for a network (cached)\n */\n private async getFeePayer(caip2: string): Promise<string | undefined> {\n // Check cache first\n if (this.feePayerCache.has(caip2)) {\n return this.feePayerCache.get(caip2);\n }\n\n // If using RelAI facilitator, use hardcoded address (no fetch needed)\n const isRelAI = this.facilitatorUrl.includes('facilitator.x402.fi') || \n this.facilitatorUrl.includes('relai');\n \n if (isRelAI) {\n const relaiFeePayer = '0x1892f72fdB3A966b2AD8595aA5f7741Ef72d6085';\n this.feePayerCache.set(caip2, relaiFeePayer);\n return relaiFeePayer;\n }\n\n // For other facilitators, fetch from /supported\n try {\n const supportedUrl = `${this.facilitatorUrl}/supported`;\n const supportedRes = await fetch(supportedUrl);\n if (supportedRes.ok) {\n const supportedData = await supportedRes.json();\n // Cache all feePayers from supported kinds\n supportedData.kinds?.forEach((kind: any) => {\n if (kind.network && kind.extra?.feePayer) {\n this.feePayerCache.set(kind.network, kind.extra.feePayer);\n }\n });\n return this.feePayerCache.get(caip2);\n }\n } catch (err) {\n // feePayer MUST come from facilitator - cannot use env for security\n console.error(`[Relai] Failed to fetch feePayer from facilitator: ${err}`);\n }\n return undefined;\n }\n\n /**\n * Express middleware to protect an endpoint with x402 micropayments.\n *\n * Flow:\n * 1. No payment header → returns 402 with payment requirements\n * 2. Payment header present → calls RelAI facilitator `/settle`\n * 3. Settlement success → sets `PAYMENT-RESPONSE` header, attaches `req.payment`, calls `next()`\n */\n protect(options: ProtectOptions) {\n const self = this;\n\n return async (req: any, res: any, next: any) => {\n try {\n // Resolve dynamic price\n const resolvedPrice = typeof options.price === 'function'\n ? await options.price(req)\n : options.price;\n\n if (typeof resolvedPrice !== 'number' || !isFinite(resolvedPrice) || resolvedPrice <= 0) {\n return res.status(400).json({ error: 'Invalid price configuration' });\n }\n\n // Resolve network (Stripe auto-sets to base)\n const stripeConfig = isStripePayTo(options.payTo) ? options.payTo : null;\n const network = stripeConfig\n ? (stripeConfig.stripeNetwork as RelaiNetwork) || 'base'\n : (options.network || self.network);\n const caip2 = NETWORK_CAIP2[network];\n const requestedAsset =\n typeof options.asset === 'string' && options.asset.trim() !== ''\n ? options.asset.trim()\n : undefined;\n const explicitToken = requestedAsset ? resolveToken(network, requestedAsset) : null;\n if (requestedAsset && !explicitToken) {\n return res.status(400).json({\n error: `Unsupported asset ${requestedAsset} for network ${network}`,\n });\n }\n\n const fallbackToken: NetworkToken = {\n address: USDC_ADDRESSES[network],\n symbol: 'USDC',\n name: network === 'skale-bite' ? 'USDC' : 'USD Coin',\n decimals: 6,\n domainVersion: network === 'skale-bite' ? '1' : '2',\n isStableUsd: true,\n };\n const token = explicitToken || resolveToken(network) || fallbackToken;\n const asset = token.address;\n const tokenName = token.name || 'USD Coin';\n const tokenVersion = token.domainVersion || (network === 'skale-bite' ? '1' : '2');\n const tokenDecimals = Number.isFinite(Number(token.decimals)) ? Number(token.decimals) : 6;\n\n let amount: string;\n try {\n amount = await resolveAmountAtomicFromUsd({\n priceUsd: resolvedPrice,\n token,\n network,\n });\n } catch (err) {\n console.error('[Relai] Failed to convert USD amount to token units:', err);\n return res.status(500).json({\n error: 'Failed to quote token amount for payment requirements',\n });\n }\n\n const configuredIntegritas = normalizeIntegritasOptions(options.integritas);\n const headerIntegritasEnabled = parseBooleanHeader(req.headers['x-integritas']);\n const headerIntegritasFlow = normalizeIntegritasFlow(req.headers['x-integritas-flow']);\n const integritasEnabled =\n headerIntegritasEnabled === null\n ? configuredIntegritas.enabled\n : headerIntegritasEnabled;\n const integritasFlow = headerIntegritasFlow || configuredIntegritas.flow;\n const integritasMode =\n integritasFlow === 'single'\n ? 'single_signature_fee_included'\n : (integritasFlow === 'dual' ? 'dual_signature_split' : undefined);\n\n // Check for payment header (base64-encoded JSON)\n const paymentHeader =\n req.headers['x-payment'] ||\n req.headers['payment-signature'] ||\n req.headers['x-payment-signature'];\n\n // -----------------------------------------------------------\n // No payment → return 402 Payment Required\n // -----------------------------------------------------------\n if (!paymentHeader) {\n options.onPaymentRequired?.(req, { price: resolvedPrice, network });\n\n // Resolve payTo address (Stripe creates a fresh deposit address per request)\n let resolvedPayTo: string;\n if (stripeConfig) {\n const amountInCents = Math.max(1, Math.round(resolvedPrice * 100));\n resolvedPayTo = await createStripeDepositAddress(\n stripeConfig.secretKey,\n amountInCents,\n stripeConfig.stripeNetwork,\n );\n } else {\n resolvedPayTo = options.payTo as string;\n }\n\n // Get facilitator feePayer address (cached)\n const feePayer = await self.getFeePayer(caip2);\n\n return res.status(402).json({\n x402Version: 2,\n error: 'Payment required',\n resource: {\n url: `${req.protocol}://${req.get('host')}${req.originalUrl}`,\n description: options.description || 'API access',\n mimeType: options.mimeType || 'application/json',\n },\n accepts: [{\n scheme: 'exact',\n network: caip2,\n amount,\n asset,\n payTo: resolvedPayTo,\n maxTimeoutSeconds: options.maxTimeoutSeconds || 60,\n extra: {\n name: tokenName,\n version: tokenVersion,\n decimals: tokenDecimals,\n symbol: token.symbol,\n ...(feePayer && { feePayer }), // Add feePayer if available\n ...(integritasEnabled ? { integritasEnabled: true } : {}),\n ...(integritasFlow ? { integritasFlow } : {}),\n ...(integritasMode ? { integritasMode } : {}),\n ...(integritasFlow === 'single' ? { integritasSingleSignature: true } : {}),\n },\n }],\n ...((configuredIntegritas.enabled || integritasEnabled || !!integritasFlow)\n ? {\n extensions: {\n integritas: {\n available: true,\n selectedFlow: integritasFlow || null,\n availableFlows: ['single', 'dual'],\n enabled: integritasEnabled,\n },\n },\n }\n : {}),\n });\n }\n\n // -----------------------------------------------------------\n // Payment header present → parse and settle via facilitator\n // -----------------------------------------------------------\n let paymentProof: any;\n try {\n // Try base64 first (standard x402 format)\n const decoded = Buffer.from(paymentHeader, 'base64').toString('utf-8');\n paymentProof = JSON.parse(decoded);\n } catch {\n try {\n // Fallback: raw JSON string\n paymentProof = JSON.parse(paymentHeader);\n } catch {\n return res.status(400).json({\n x402Version: 2,\n error: 'Invalid payment header — expected base64-encoded JSON',\n });\n }\n }\n\n // Resolve payTo for settle (extract from signed proof when using Stripe)\n let settlePayTo: string;\n if (stripeConfig) {\n settlePayTo =\n paymentProof.payload?.authorization?.to ||\n paymentProof.accepted?.payTo ||\n '';\n if (!settlePayTo) {\n return res.status(400).json({\n x402Version: 2,\n error: 'Cannot extract destination address from payment proof',\n });\n }\n } else {\n settlePayTo = options.payTo as string;\n }\n\n // Build payment requirements for facilitator\n const paymentRequirements = {\n scheme: 'exact',\n network,\n amount,\n asset,\n payTo: settlePayTo,\n maxTimeoutSeconds: options.maxTimeoutSeconds || 60,\n ...(integritasEnabled\n ? {\n extra: {\n integritasEnabled: true,\n ...(integritasFlow ? { integritasFlow } : {}),\n ...(integritasMode ? { integritasMode } : {}),\n ...(integritasFlow === 'single' ? { integritasSingleSignature: true } : {}),\n },\n }\n : {}),\n };\n\n // Call facilitator /settle\n const settleUrl = `${self.facilitatorUrl}/settle`;\n const settleRes = await fetch(settleUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n paymentPayload: paymentProof,\n paymentRequirements,\n }),\n });\n\n const result: SettleResult = await settleRes.json() as SettleResult;\n\n if (!result.success) {\n return res.status(402).json({\n x402Version: 2,\n error: result.errorReason || result.error || 'Payment settlement failed',\n });\n }\n\n // Attach payment info to request\n const paymentInfo: PaymentInfo = {\n verified: true,\n transactionId: result.transaction,\n payer: result.payer,\n network,\n amount: resolvedPrice,\n };\n req.payment = paymentInfo;\n req.x402Payer = result.payer;\n req.x402Paid = true;\n req.x402Transaction = result.transaction;\n req.x402Network = network;\n\n // Set x402 v2 PAYMENT-RESPONSE header (base64 JSON)\n const paymentResponse = {\n x402Version: 2,\n scheme: 'exact',\n network: caip2,\n transaction: result.transaction,\n payer: result.payer,\n amount,\n asset,\n };\n res.setHeader(\n 'PAYMENT-RESPONSE',\n Buffer.from(JSON.stringify(paymentResponse)).toString('base64'),\n );\n\n options.onPaymentSettled?.(req, result);\n\n // Custom validation after payment\n if (options.customRules) {\n const valid = await options.customRules(req);\n if (!valid) {\n return res.status(403).json({ error: 'Custom validation failed' });\n }\n }\n\n next();\n } catch (error) {\n options.onError?.(req, error);\n console.error('[Relai] Protection error:', error);\n res.status(500).json({ error: 'Internal server error' });\n }\n };\n }\n}\n\nexport default Relai;\n","// src/types.ts\n\n// ============================================================================\n// Constants\n// ============================================================================\n\n/** RelAI Facilitator URL */\nexport const RELAI_FACILITATOR_URL = 'https://facilitator.x402.fi';\n\n// ============================================================================\n// Supported Networks\n// ============================================================================\n\n/** All networks supported by RelAI facilitator */\nexport type RelaiNetwork =\n | 'solana'\n | 'base'\n | 'avalanche'\n | 'skale-base'\n | 'skale-base-sepolia'\n | 'skale-bite'\n | 'polygon'\n | 'ethereum';\n\n/** CAIP-2 network identifiers */\nexport const NETWORK_CAIP2: Record<RelaiNetwork, string> = {\n 'solana': 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n 'base': 'eip155:8453',\n 'avalanche': 'eip155:43114',\n 'skale-base': 'eip155:1187947933',\n 'skale-base-sepolia': 'eip155:324705682',\n 'skale-bite': 'eip155:103698795',\n 'polygon': 'eip155:137',\n 'ethereum': 'eip155:1',\n};\n\n/** Reverse lookup: CAIP-2 → simple network name */\nexport const CAIP2_TO_NETWORK: Record<string, RelaiNetwork> = Object.fromEntries(\n Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k as RelaiNetwork])\n) as Record<string, RelaiNetwork>;\n\n/** Chain IDs for EVM networks */\nexport const CHAIN_IDS: Record<string, number> = {\n 'base': 8453,\n 'avalanche': 43114,\n 'skale-base': 1187947933,\n 'skale-base-sepolia': 324705682,\n 'skale-bite': 103698795,\n 'polygon': 137,\n 'ethereum': 1,\n};\n\nexport interface NetworkToken {\n address: string;\n symbol: string;\n name: string;\n decimals: number;\n domainVersion?: string;\n isStableUsd?: boolean;\n}\n\n/** Token metadata per network (default token is always the first entry) */\nexport const NETWORK_TOKENS: Partial<Record<RelaiNetwork, NetworkToken[]>> = {\n 'solana': [\n {\n address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',\n symbol: 'USDC',\n name: 'USD Coin',\n decimals: 6,\n },\n ],\n 'base': [\n {\n address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n symbol: 'USDC',\n name: 'USD Coin',\n decimals: 6,\n domainVersion: '2',\n isStableUsd: true,\n },\n ],\n 'avalanche': [\n {\n address: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',\n symbol: 'USDC',\n name: 'USD Coin',\n decimals: 6,\n domainVersion: '2',\n isStableUsd: true,\n },\n ],\n 'skale-base': [\n {\n address: '0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20',\n symbol: 'USDC',\n name: 'Bridged USDC (SKALE Bridge)',\n decimals: 6,\n domainVersion: '2',\n isStableUsd: true,\n },\n {\n address: '0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA',\n symbol: 'USDT',\n name: 'Bridged USDT (SKALE Bridge)',\n decimals: 6,\n domainVersion: '2',\n isStableUsd: true,\n },\n {\n address: '0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e',\n symbol: 'WBTC',\n name: 'Wrapped Bitcoin',\n decimals: 8,\n domainVersion: '2',\n isStableUsd: false,\n },\n {\n address: '0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486',\n symbol: 'WETH',\n name: 'Wrapped Ether',\n decimals: 18,\n domainVersion: '2',\n isStableUsd: false,\n },\n ],\n 'skale-base-sepolia': [\n {\n address: '0x2e08028E3C4c2356572E096d8EF835cD5C6030bD',\n symbol: 'USDC',\n name: 'Bridged USDC (SKALE Bridge)',\n decimals: 6,\n domainVersion: '2',\n isStableUsd: true,\n },\n ],\n 'skale-bite': [\n {\n address: '0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8',\n symbol: 'USDC',\n name: 'USDC',\n decimals: 6,\n domainVersion: '1',\n isStableUsd: true,\n },\n ],\n 'polygon': [\n {\n address: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n symbol: 'USDC',\n name: 'USD Coin',\n decimals: 6,\n domainVersion: '2',\n isStableUsd: true,\n },\n ],\n 'ethereum': [\n {\n address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n symbol: 'USDC',\n name: 'USD Coin',\n decimals: 6,\n domainVersion: '2',\n isStableUsd: true,\n },\n ],\n};\n\nexport function resolveToken(network: RelaiNetwork, asset?: string): NetworkToken | null {\n const tokens = NETWORK_TOKENS[network];\n if (!tokens || tokens.length === 0) return null;\n if (!asset) return tokens[0];\n\n const normalized = String(asset).toLowerCase();\n return tokens.find((token) => token.address.toLowerCase() === normalized) || null;\n}\n\n/** USDC contract addresses per network */\nexport const USDC_ADDRESSES: Record<RelaiNetwork, string> = {\n 'solana': 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',\n 'base': '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n 'avalanche': '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',\n 'skale-base': '0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20',\n 'skale-base-sepolia': '0x2e08028E3C4c2356572E096d8EF835cD5C6030bD',\n 'skale-bite': '0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8',\n 'polygon': '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n 'ethereum': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n};\n\n/** Explorer URLs per network */\nexport const EXPLORER_TX_URL: Record<RelaiNetwork, (tx: string) => string> = {\n 'solana': (tx) => `https://solscan.io/tx/${tx}`,\n 'base': (tx) => `https://basescan.org/tx/${tx}`,\n 'avalanche': (tx) => `https://snowtrace.io/tx/${tx}`,\n 'skale-base': (tx) => `https://skale-base-explorer.skalenodes.com/tx/${tx}`,\n 'skale-base-sepolia': (tx) => `https://base-sepolia-testnet-explorer.skalenodes.com/tx/${tx}`,\n 'skale-bite': (tx) => `https://base-sepolia-testnet.explorer.skalenodes.com/tx/${tx}`,\n 'polygon': (tx) => `https://polygonscan.com/tx/${tx}`,\n 'ethereum': (tx) => `https://etherscan.io/tx/${tx}`,\n};\n\n/** Human-readable network labels */\nexport const NETWORK_LABELS: Record<RelaiNetwork, string> = {\n 'solana': 'Solana',\n 'base': 'Base',\n 'avalanche': 'Avalanche',\n 'skale-base': 'SKALE Base',\n 'skale-base-sepolia': 'SKALE Base Sepolia',\n 'skale-bite': 'SKALE BITE V2',\n 'polygon': 'Polygon',\n 'ethereum': 'Ethereum',\n};\n\n/** Legacy CAIP-2 exports for backward compatibility */\nexport const SOLANA_MAINNET_NETWORK = NETWORK_CAIP2['solana'];\nexport const BASE_MAINNET_NETWORK = NETWORK_CAIP2['base'];\n\n/** Legacy USDC exports for backward compatibility */\nexport const USDC_SOLANA = USDC_ADDRESSES['solana'];\nexport const USDC_BASE = USDC_ADDRESSES['base'];\n\n/** All supported RelAI networks list */\nexport const RELAI_NETWORKS: RelaiNetwork[] = [\n 'solana',\n 'base',\n 'avalanche',\n 'skale-base',\n 'skale-base-sepolia',\n 'skale-bite',\n 'polygon',\n 'ethereum',\n];\n\n/** Check if a network is Solana-based */\nexport function isSolana(network: string): boolean {\n return network === 'solana' || network.startsWith('solana:');\n}\n\n/** Check if a network is EVM-based */\nexport function isEvm(network: string): boolean {\n return ['base', 'avalanche', 'skale-base', 'skale-base-sepolia', 'skale-bite', 'polygon', 'ethereum'].includes(network) || network.startsWith('eip155:');\n}\n\n/** Normalize CAIP-2 or simple name to RelaiNetwork */\nexport function normalizeNetwork(network: string): RelaiNetwork | null {\n if (RELAI_NETWORKS.includes(network as RelaiNetwork)) return network as RelaiNetwork;\n const fromCaip2 = CAIP2_TO_NETWORK[network];\n if (fromCaip2) return fromCaip2;\n // Partial match\n if (network.startsWith('solana:')) return 'solana';\n if (network.startsWith('eip155:')) {\n const chainId = parseInt(network.split(':')[1]);\n const entry = Object.entries(CHAIN_IDS).find(([, id]) => id === chainId);\n if (entry) return entry[0] as RelaiNetwork;\n }\n return null;\n}\n\n// ============================================================================\n// Wallet Types\n// ============================================================================\n\n/** Solana wallet interface */\nexport interface SolanaWallet {\n publicKey: { toString(): string } | null;\n signTransaction: ((tx: unknown) => Promise<unknown>) | null;\n signAllTransactions?: ((txs: unknown[]) => Promise<unknown[]>) | null;\n}\n\n/** EVM wallet interface (viem-compatible) */\nexport interface EvmWallet {\n address: string;\n signTypedData: (params: unknown) => Promise<string>;\n chain?: { id: number };\n}\n\n/** Wallet set for multi-chain support */\nexport interface WalletSet {\n solana?: SolanaWallet;\n evm?: EvmWallet;\n}\n\n// ============================================================================\n// Payment Types\n// ============================================================================\n\n/** Extra fields in payment requirements */\nexport interface AcceptsExtra {\n feePayer?: string;\n decimals?: number;\n name?: string;\n version?: string;\n [key: string]: unknown;\n}\n\n/** A single payment option */\nexport interface PaymentAccept {\n x402Version?: 1 | 2;\n scheme: string;\n network: string;\n maxAmountRequired?: string;\n amount?: string;\n asset: string;\n payTo: string;\n maxTimeoutSeconds?: number;\n extra?: AcceptsExtra;\n resource?: string;\n description?: string;\n mimeType?: string;\n outputSchema?: unknown;\n}\n\n/** Resource info for v2 */\nexport interface ResourceInfo {\n url: string;\n description?: string;\n mimeType?: string;\n}\n\n/** Payment requirements (402 response) */\nexport interface PaymentRequired {\n x402Version: 1 | 2;\n error?: string;\n accepts: PaymentAccept[];\n resource?: ResourceInfo;\n extensions?: Record<string, unknown>;\n}\n\n// ============================================================================\n// Config Types (server-specific types are in server.ts)\n// ============================================================================\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAM,wBAAwB;AAkB9B,IAAM,gBAA8C;AAAA,EACzD,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AACd;AAGO,IAAM,mBAAiD,OAAO;AAAA,EACnE,OAAO,QAAQ,aAAa,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAiB,CAAC;AACtE;AAuBO,IAAM,iBAAgE;AAAA,EAC3E,UAAU;AAAA,IACR;AAAA,MACE,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN;AAAA,MACE,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,MACV,eAAe;AAAA,MACf,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX;AAAA,MACE,SAAS;AAAA,MACT,QAAQ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AAC;AAAA,UACnE;AAAA,QACF;AAEA,aAAK;AAAA,MACP,SAAS,OAAO;AACd,gBAAQ,UAAU,KAAK,KAAK;AAC5B,gBAAQ,MAAM,6BAA6B,KAAK;AAChD,YAAI,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,wBAAwB,CAAC;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,iBAAQ;","names":[]}
|
package/dist/server.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as RelaiNetwork } from './types-
|
|
1
|
+
import { a as RelaiNetwork } from './types-CWtUxi3l.cjs';
|
|
2
2
|
|
|
3
3
|
interface RelaiServerConfig {
|
|
4
4
|
/** Network to accept payments on */
|
|
@@ -7,9 +7,18 @@ interface RelaiServerConfig {
|
|
|
7
7
|
facilitatorUrl?: string;
|
|
8
8
|
}
|
|
9
9
|
type DynamicPrice = number | ((req: any) => number | Promise<number>);
|
|
10
|
+
type RelaiIntegritasFlow = 'single' | 'dual';
|
|
11
|
+
interface RelaiIntegritasOptions {
|
|
12
|
+
/** Enable Integritas by default for this endpoint */
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
/** Default flow when Integritas is enabled */
|
|
15
|
+
flow?: RelaiIntegritasFlow;
|
|
16
|
+
}
|
|
10
17
|
interface ProtectOptions {
|
|
11
18
|
/** Price in USD (e.g., 0.01 for 1 cent) */
|
|
12
19
|
price: DynamicPrice;
|
|
20
|
+
/** Optional token asset address for networks supporting multiple tokens */
|
|
21
|
+
asset?: string;
|
|
13
22
|
/** Wallet address to receive payments, or stripePayTo() for Stripe settlement */
|
|
14
23
|
payTo: string | StripePayTo;
|
|
15
24
|
/** Description shown to payer */
|
|
@@ -18,6 +27,8 @@ interface ProtectOptions {
|
|
|
18
27
|
mimeType?: string;
|
|
19
28
|
/** Maximum timeout in seconds (default: 60) */
|
|
20
29
|
maxTimeoutSeconds?: number;
|
|
30
|
+
/** Integritas options (or simple boolean enable flag) */
|
|
31
|
+
integritas?: boolean | RelaiIntegritasOptions;
|
|
21
32
|
/** Override network for this endpoint */
|
|
22
33
|
network?: RelaiNetwork;
|
|
23
34
|
/** Custom validation after payment is settled */
|
|
@@ -37,6 +48,10 @@ interface SettleResult {
|
|
|
37
48
|
transaction?: string;
|
|
38
49
|
payer?: string;
|
|
39
50
|
network?: string;
|
|
51
|
+
splitTransfers?: Record<string, unknown>;
|
|
52
|
+
integritasFeePaid?: boolean;
|
|
53
|
+
provenance?: Record<string, unknown>;
|
|
54
|
+
integritas?: Record<string, unknown>;
|
|
40
55
|
error?: string;
|
|
41
56
|
errorReason?: string;
|
|
42
57
|
}
|
|
@@ -118,4 +133,4 @@ declare class Relai {
|
|
|
118
133
|
protect(options: ProtectOptions): (req: any, res: any, next: any) => Promise<any>;
|
|
119
134
|
}
|
|
120
135
|
|
|
121
|
-
export { type DynamicPrice, type PaymentInfo, type ProtectOptions, Relai, type RelaiServerConfig, type SettleResult, type StripePayTo, Relai as default, stripePayTo };
|
|
136
|
+
export { type DynamicPrice, type PaymentInfo, type ProtectOptions, Relai, type RelaiIntegritasFlow, type RelaiIntegritasOptions, type RelaiServerConfig, type SettleResult, type StripePayTo, Relai as default, stripePayTo };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as RelaiNetwork } from './types-
|
|
1
|
+
import { a as RelaiNetwork } from './types-CWtUxi3l.js';
|
|
2
2
|
|
|
3
3
|
interface RelaiServerConfig {
|
|
4
4
|
/** Network to accept payments on */
|
|
@@ -7,9 +7,18 @@ interface RelaiServerConfig {
|
|
|
7
7
|
facilitatorUrl?: string;
|
|
8
8
|
}
|
|
9
9
|
type DynamicPrice = number | ((req: any) => number | Promise<number>);
|
|
10
|
+
type RelaiIntegritasFlow = 'single' | 'dual';
|
|
11
|
+
interface RelaiIntegritasOptions {
|
|
12
|
+
/** Enable Integritas by default for this endpoint */
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
/** Default flow when Integritas is enabled */
|
|
15
|
+
flow?: RelaiIntegritasFlow;
|
|
16
|
+
}
|
|
10
17
|
interface ProtectOptions {
|
|
11
18
|
/** Price in USD (e.g., 0.01 for 1 cent) */
|
|
12
19
|
price: DynamicPrice;
|
|
20
|
+
/** Optional token asset address for networks supporting multiple tokens */
|
|
21
|
+
asset?: string;
|
|
13
22
|
/** Wallet address to receive payments, or stripePayTo() for Stripe settlement */
|
|
14
23
|
payTo: string | StripePayTo;
|
|
15
24
|
/** Description shown to payer */
|
|
@@ -18,6 +27,8 @@ interface ProtectOptions {
|
|
|
18
27
|
mimeType?: string;
|
|
19
28
|
/** Maximum timeout in seconds (default: 60) */
|
|
20
29
|
maxTimeoutSeconds?: number;
|
|
30
|
+
/** Integritas options (or simple boolean enable flag) */
|
|
31
|
+
integritas?: boolean | RelaiIntegritasOptions;
|
|
21
32
|
/** Override network for this endpoint */
|
|
22
33
|
network?: RelaiNetwork;
|
|
23
34
|
/** Custom validation after payment is settled */
|
|
@@ -37,6 +48,10 @@ interface SettleResult {
|
|
|
37
48
|
transaction?: string;
|
|
38
49
|
payer?: string;
|
|
39
50
|
network?: string;
|
|
51
|
+
splitTransfers?: Record<string, unknown>;
|
|
52
|
+
integritasFeePaid?: boolean;
|
|
53
|
+
provenance?: Record<string, unknown>;
|
|
54
|
+
integritas?: Record<string, unknown>;
|
|
40
55
|
error?: string;
|
|
41
56
|
errorReason?: string;
|
|
42
57
|
}
|
|
@@ -118,4 +133,4 @@ declare class Relai {
|
|
|
118
133
|
protect(options: ProtectOptions): (req: any, res: any, next: any) => Promise<any>;
|
|
119
134
|
}
|
|
120
135
|
|
|
121
|
-
export { type DynamicPrice, type PaymentInfo, type ProtectOptions, Relai, type RelaiServerConfig, type SettleResult, type StripePayTo, Relai as default, stripePayTo };
|
|
136
|
+
export { type DynamicPrice, type PaymentInfo, type ProtectOptions, Relai, type RelaiIntegritasFlow, type RelaiIntegritasOptions, type RelaiServerConfig, type SettleResult, type StripePayTo, Relai as default, stripePayTo };
|