@bankofai/x402-extensions 2.6.0-beta.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 +792 -0
- package/dist/cjs/bazaar/index.d.ts +3 -0
- package/dist/cjs/bazaar/index.js +629 -0
- package/dist/cjs/bazaar/index.js.map +1 -0
- package/dist/cjs/index-DPJQYYGe.d.ts +662 -0
- package/dist/cjs/index.d.ts +360 -0
- package/dist/cjs/index.js +1880 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/payment-identifier/index.d.ts +345 -0
- package/dist/cjs/payment-identifier/index.js +285 -0
- package/dist/cjs/payment-identifier/index.js.map +1 -0
- package/dist/cjs/sign-in-with-x/index.d.ts +1091 -0
- package/dist/cjs/sign-in-with-x/index.js +845 -0
- package/dist/cjs/sign-in-with-x/index.js.map +1 -0
- package/dist/esm/bazaar/index.d.mts +3 -0
- package/dist/esm/bazaar/index.mjs +33 -0
- package/dist/esm/bazaar/index.mjs.map +1 -0
- package/dist/esm/chunk-MTWK6ERV.mjs +777 -0
- package/dist/esm/chunk-MTWK6ERV.mjs.map +1 -0
- package/dist/esm/chunk-RERA4OZZ.mjs +233 -0
- package/dist/esm/chunk-RERA4OZZ.mjs.map +1 -0
- package/dist/esm/chunk-UHTNEDIJ.mjs +580 -0
- package/dist/esm/chunk-UHTNEDIJ.mjs.map +1 -0
- package/dist/esm/index-DPJQYYGe.d.mts +662 -0
- package/dist/esm/index.d.mts +360 -0
- package/dist/esm/index.mjs +323 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/payment-identifier/index.d.mts +345 -0
- package/dist/esm/payment-identifier/index.mjs +39 -0
- package/dist/esm/payment-identifier/index.mjs.map +1 -0
- package/dist/esm/sign-in-with-x/index.d.mts +1091 -0
- package/dist/esm/sign-in-with-x/index.mjs +71 -0
- package/dist/esm/sign-in-with-x/index.mjs.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,1880 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
BAZAAR: () => BAZAAR,
|
|
34
|
+
EIP2612_GAS_SPONSORING: () => EIP2612_GAS_SPONSORING,
|
|
35
|
+
ERC20_APPROVAL_GAS_SPONSORING: () => ERC20_APPROVAL_GAS_SPONSORING,
|
|
36
|
+
ERC20_APPROVAL_GAS_SPONSORING_VERSION: () => ERC20_APPROVAL_GAS_SPONSORING_VERSION,
|
|
37
|
+
InMemorySIWxStorage: () => InMemorySIWxStorage,
|
|
38
|
+
PAYMENT_IDENTIFIER: () => PAYMENT_IDENTIFIER,
|
|
39
|
+
PAYMENT_ID_MAX_LENGTH: () => PAYMENT_ID_MAX_LENGTH,
|
|
40
|
+
PAYMENT_ID_MIN_LENGTH: () => PAYMENT_ID_MIN_LENGTH,
|
|
41
|
+
PAYMENT_ID_PATTERN: () => PAYMENT_ID_PATTERN,
|
|
42
|
+
SIGN_IN_WITH_X: () => SIGN_IN_WITH_X,
|
|
43
|
+
SIWxPayloadSchema: () => SIWxPayloadSchema,
|
|
44
|
+
SOLANA_DEVNET: () => SOLANA_DEVNET,
|
|
45
|
+
SOLANA_MAINNET: () => SOLANA_MAINNET,
|
|
46
|
+
SOLANA_TESTNET: () => SOLANA_TESTNET,
|
|
47
|
+
appendPaymentIdentifierToExtensions: () => appendPaymentIdentifierToExtensions,
|
|
48
|
+
bazaarResourceServerExtension: () => bazaarResourceServerExtension,
|
|
49
|
+
buildSIWxSchema: () => buildSIWxSchema,
|
|
50
|
+
createErc20ApprovalGasSponsoringExtension: () => createErc20ApprovalGasSponsoringExtension,
|
|
51
|
+
createSIWxClientHook: () => createSIWxClientHook,
|
|
52
|
+
createSIWxMessage: () => createSIWxMessage,
|
|
53
|
+
createSIWxPayload: () => createSIWxPayload,
|
|
54
|
+
createSIWxRequestHook: () => createSIWxRequestHook,
|
|
55
|
+
createSIWxSettleHook: () => createSIWxSettleHook,
|
|
56
|
+
declareDiscoveryExtension: () => declareDiscoveryExtension,
|
|
57
|
+
declareEip2612GasSponsoringExtension: () => declareEip2612GasSponsoringExtension,
|
|
58
|
+
declareErc20ApprovalGasSponsoringExtension: () => declareErc20ApprovalGasSponsoringExtension,
|
|
59
|
+
declarePaymentIdentifierExtension: () => declarePaymentIdentifierExtension,
|
|
60
|
+
declareSIWxExtension: () => declareSIWxExtension,
|
|
61
|
+
decodeBase58: () => decodeBase58,
|
|
62
|
+
encodeBase58: () => encodeBase58,
|
|
63
|
+
encodeSIWxHeader: () => encodeSIWxHeader,
|
|
64
|
+
erc20ApprovalGasSponsoringSchema: () => erc20ApprovalGasSponsoringSchema,
|
|
65
|
+
extractAndValidatePaymentIdentifier: () => extractAndValidatePaymentIdentifier,
|
|
66
|
+
extractDiscoveryInfo: () => extractDiscoveryInfo,
|
|
67
|
+
extractDiscoveryInfoFromExtension: () => extractDiscoveryInfoFromExtension,
|
|
68
|
+
extractDiscoveryInfoV1: () => extractDiscoveryInfoV1,
|
|
69
|
+
extractEVMChainId: () => extractEVMChainId,
|
|
70
|
+
extractEip2612GasSponsoringInfo: () => extractEip2612GasSponsoringInfo,
|
|
71
|
+
extractErc20ApprovalGasSponsoringInfo: () => extractErc20ApprovalGasSponsoringInfo,
|
|
72
|
+
extractPaymentIdentifier: () => extractPaymentIdentifier,
|
|
73
|
+
extractResourceMetadataV1: () => extractResourceMetadataV1,
|
|
74
|
+
extractSolanaChainReference: () => extractSolanaChainReference,
|
|
75
|
+
formatSIWEMessage: () => formatSIWEMessage,
|
|
76
|
+
formatSIWSMessage: () => formatSIWSMessage,
|
|
77
|
+
generatePaymentId: () => generatePaymentId,
|
|
78
|
+
getEVMAddress: () => getEVMAddress,
|
|
79
|
+
getSolanaAddress: () => getSolanaAddress,
|
|
80
|
+
hasPaymentIdentifier: () => hasPaymentIdentifier,
|
|
81
|
+
isBodyExtensionConfig: () => isBodyExtensionConfig,
|
|
82
|
+
isDiscoverableV1: () => isDiscoverableV1,
|
|
83
|
+
isEVMSigner: () => isEVMSigner,
|
|
84
|
+
isMcpExtensionConfig: () => isMcpExtensionConfig,
|
|
85
|
+
isPaymentIdentifierExtension: () => isPaymentIdentifierExtension,
|
|
86
|
+
isPaymentIdentifierRequired: () => isPaymentIdentifierRequired,
|
|
87
|
+
isQueryExtensionConfig: () => isQueryExtensionConfig,
|
|
88
|
+
isSolanaSigner: () => isSolanaSigner,
|
|
89
|
+
isValidPaymentId: () => isValidPaymentId,
|
|
90
|
+
parseSIWxHeader: () => parseSIWxHeader,
|
|
91
|
+
paymentIdentifierResourceServerExtension: () => paymentIdentifierResourceServerExtension,
|
|
92
|
+
paymentIdentifierSchema: () => paymentIdentifierSchema,
|
|
93
|
+
signEVMMessage: () => signEVMMessage,
|
|
94
|
+
signSolanaMessage: () => signSolanaMessage,
|
|
95
|
+
siwxResourceServerExtension: () => siwxResourceServerExtension,
|
|
96
|
+
validateAndExtract: () => validateAndExtract,
|
|
97
|
+
validateDiscoveryExtension: () => validateDiscoveryExtension,
|
|
98
|
+
validateEip2612GasSponsoringInfo: () => validateEip2612GasSponsoringInfo,
|
|
99
|
+
validateErc20ApprovalGasSponsoringInfo: () => validateErc20ApprovalGasSponsoringInfo,
|
|
100
|
+
validatePaymentIdentifier: () => validatePaymentIdentifier,
|
|
101
|
+
validatePaymentIdentifierRequirement: () => validatePaymentIdentifierRequirement,
|
|
102
|
+
validateSIWxMessage: () => validateSIWxMessage,
|
|
103
|
+
verifyEVMSignature: () => verifyEVMSignature,
|
|
104
|
+
verifySIWxSignature: () => verifySIWxSignature,
|
|
105
|
+
verifySolanaSignature: () => verifySolanaSignature,
|
|
106
|
+
withBazaar: () => withBazaar,
|
|
107
|
+
wrapFetchWithSIWx: () => wrapFetchWithSIWx
|
|
108
|
+
});
|
|
109
|
+
module.exports = __toCommonJS(src_exports);
|
|
110
|
+
|
|
111
|
+
// src/bazaar/http/types.ts
|
|
112
|
+
var isQueryExtensionConfig = (config) => {
|
|
113
|
+
return !("bodyType" in config) && !("toolName" in config);
|
|
114
|
+
};
|
|
115
|
+
var isBodyExtensionConfig = (config) => {
|
|
116
|
+
return "bodyType" in config;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/bazaar/mcp/types.ts
|
|
120
|
+
var isMcpExtensionConfig = (config) => {
|
|
121
|
+
return "toolName" in config;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/bazaar/types.ts
|
|
125
|
+
var BAZAAR = { key: "bazaar" };
|
|
126
|
+
|
|
127
|
+
// src/bazaar/http/resourceService.ts
|
|
128
|
+
function createQueryDiscoveryExtension({
|
|
129
|
+
method,
|
|
130
|
+
input = {},
|
|
131
|
+
inputSchema = { properties: {} },
|
|
132
|
+
output
|
|
133
|
+
}) {
|
|
134
|
+
return {
|
|
135
|
+
info: {
|
|
136
|
+
input: {
|
|
137
|
+
type: "http",
|
|
138
|
+
...method ? { method } : {},
|
|
139
|
+
...input ? { queryParams: input } : {}
|
|
140
|
+
},
|
|
141
|
+
...output?.example ? {
|
|
142
|
+
output: {
|
|
143
|
+
type: "json",
|
|
144
|
+
example: output.example
|
|
145
|
+
}
|
|
146
|
+
} : {}
|
|
147
|
+
},
|
|
148
|
+
schema: {
|
|
149
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
150
|
+
type: "object",
|
|
151
|
+
properties: {
|
|
152
|
+
input: {
|
|
153
|
+
type: "object",
|
|
154
|
+
properties: {
|
|
155
|
+
type: {
|
|
156
|
+
type: "string",
|
|
157
|
+
const: "http"
|
|
158
|
+
},
|
|
159
|
+
method: {
|
|
160
|
+
type: "string",
|
|
161
|
+
enum: ["GET", "HEAD", "DELETE"]
|
|
162
|
+
},
|
|
163
|
+
...inputSchema ? {
|
|
164
|
+
queryParams: {
|
|
165
|
+
type: "object",
|
|
166
|
+
...typeof inputSchema === "object" ? inputSchema : {}
|
|
167
|
+
}
|
|
168
|
+
} : {}
|
|
169
|
+
},
|
|
170
|
+
required: ["type"],
|
|
171
|
+
additionalProperties: false
|
|
172
|
+
},
|
|
173
|
+
...output?.example ? {
|
|
174
|
+
output: {
|
|
175
|
+
type: "object",
|
|
176
|
+
properties: {
|
|
177
|
+
type: {
|
|
178
|
+
type: "string"
|
|
179
|
+
},
|
|
180
|
+
example: {
|
|
181
|
+
type: "object",
|
|
182
|
+
...output.schema && typeof output.schema === "object" ? output.schema : {}
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
required: ["type"]
|
|
186
|
+
}
|
|
187
|
+
} : {}
|
|
188
|
+
},
|
|
189
|
+
required: ["input"]
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function createBodyDiscoveryExtension({
|
|
194
|
+
method,
|
|
195
|
+
input = {},
|
|
196
|
+
inputSchema = { properties: {} },
|
|
197
|
+
bodyType,
|
|
198
|
+
output
|
|
199
|
+
}) {
|
|
200
|
+
return {
|
|
201
|
+
info: {
|
|
202
|
+
input: {
|
|
203
|
+
type: "http",
|
|
204
|
+
...method ? { method } : {},
|
|
205
|
+
bodyType,
|
|
206
|
+
body: input
|
|
207
|
+
},
|
|
208
|
+
...output?.example ? {
|
|
209
|
+
output: {
|
|
210
|
+
type: "json",
|
|
211
|
+
example: output.example
|
|
212
|
+
}
|
|
213
|
+
} : {}
|
|
214
|
+
},
|
|
215
|
+
schema: {
|
|
216
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
217
|
+
type: "object",
|
|
218
|
+
properties: {
|
|
219
|
+
input: {
|
|
220
|
+
type: "object",
|
|
221
|
+
properties: {
|
|
222
|
+
type: {
|
|
223
|
+
type: "string",
|
|
224
|
+
const: "http"
|
|
225
|
+
},
|
|
226
|
+
method: {
|
|
227
|
+
type: "string",
|
|
228
|
+
enum: ["POST", "PUT", "PATCH"]
|
|
229
|
+
},
|
|
230
|
+
bodyType: {
|
|
231
|
+
type: "string",
|
|
232
|
+
enum: ["json", "form-data", "text"]
|
|
233
|
+
},
|
|
234
|
+
body: inputSchema
|
|
235
|
+
},
|
|
236
|
+
required: ["type", "bodyType", "body"],
|
|
237
|
+
additionalProperties: false
|
|
238
|
+
},
|
|
239
|
+
...output?.example ? {
|
|
240
|
+
output: {
|
|
241
|
+
type: "object",
|
|
242
|
+
properties: {
|
|
243
|
+
type: {
|
|
244
|
+
type: "string"
|
|
245
|
+
},
|
|
246
|
+
example: {
|
|
247
|
+
type: "object",
|
|
248
|
+
...output.schema && typeof output.schema === "object" ? output.schema : {}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
required: ["type"]
|
|
252
|
+
}
|
|
253
|
+
} : {}
|
|
254
|
+
},
|
|
255
|
+
required: ["input"]
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// src/bazaar/mcp/resourceService.ts
|
|
261
|
+
function createMcpDiscoveryExtension({
|
|
262
|
+
toolName,
|
|
263
|
+
description,
|
|
264
|
+
transport,
|
|
265
|
+
inputSchema,
|
|
266
|
+
example,
|
|
267
|
+
output
|
|
268
|
+
}) {
|
|
269
|
+
return {
|
|
270
|
+
info: {
|
|
271
|
+
input: {
|
|
272
|
+
type: "mcp",
|
|
273
|
+
toolName,
|
|
274
|
+
...description !== void 0 ? { description } : {},
|
|
275
|
+
...transport !== void 0 ? { transport } : {},
|
|
276
|
+
inputSchema,
|
|
277
|
+
...example !== void 0 ? { example } : {}
|
|
278
|
+
},
|
|
279
|
+
...output?.example ? {
|
|
280
|
+
output: {
|
|
281
|
+
type: "json",
|
|
282
|
+
example: output.example
|
|
283
|
+
}
|
|
284
|
+
} : {}
|
|
285
|
+
},
|
|
286
|
+
schema: {
|
|
287
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
288
|
+
type: "object",
|
|
289
|
+
properties: {
|
|
290
|
+
input: {
|
|
291
|
+
type: "object",
|
|
292
|
+
properties: {
|
|
293
|
+
type: {
|
|
294
|
+
type: "string",
|
|
295
|
+
const: "mcp"
|
|
296
|
+
},
|
|
297
|
+
toolName: {
|
|
298
|
+
type: "string"
|
|
299
|
+
},
|
|
300
|
+
...description !== void 0 ? {
|
|
301
|
+
description: {
|
|
302
|
+
type: "string"
|
|
303
|
+
}
|
|
304
|
+
} : {},
|
|
305
|
+
...transport !== void 0 ? {
|
|
306
|
+
transport: {
|
|
307
|
+
type: "string",
|
|
308
|
+
enum: ["streamable-http", "sse"]
|
|
309
|
+
}
|
|
310
|
+
} : {},
|
|
311
|
+
inputSchema: {
|
|
312
|
+
type: "object"
|
|
313
|
+
},
|
|
314
|
+
...example !== void 0 ? {
|
|
315
|
+
example: {
|
|
316
|
+
type: "object"
|
|
317
|
+
}
|
|
318
|
+
} : {}
|
|
319
|
+
},
|
|
320
|
+
required: ["type", "toolName", "inputSchema"],
|
|
321
|
+
additionalProperties: false
|
|
322
|
+
},
|
|
323
|
+
...output?.example ? {
|
|
324
|
+
output: {
|
|
325
|
+
type: "object",
|
|
326
|
+
properties: {
|
|
327
|
+
type: {
|
|
328
|
+
type: "string"
|
|
329
|
+
},
|
|
330
|
+
example: {
|
|
331
|
+
type: "object",
|
|
332
|
+
...output.schema && typeof output.schema === "object" ? output.schema : {}
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
required: ["type"]
|
|
336
|
+
}
|
|
337
|
+
} : {}
|
|
338
|
+
},
|
|
339
|
+
required: ["input"]
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/bazaar/resourceService.ts
|
|
345
|
+
function declareDiscoveryExtension(config) {
|
|
346
|
+
if ("toolName" in config) {
|
|
347
|
+
const extension2 = createMcpDiscoveryExtension(config);
|
|
348
|
+
return { bazaar: extension2 };
|
|
349
|
+
}
|
|
350
|
+
const bodyType = config.bodyType;
|
|
351
|
+
const isBodyMethod2 = bodyType !== void 0;
|
|
352
|
+
const extension = isBodyMethod2 ? createBodyDiscoveryExtension(config) : createQueryDiscoveryExtension(config);
|
|
353
|
+
return { bazaar: extension };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/bazaar/server.ts
|
|
357
|
+
function isHTTPRequestContext(ctx) {
|
|
358
|
+
return ctx !== null && typeof ctx === "object" && "method" in ctx && "adapter" in ctx;
|
|
359
|
+
}
|
|
360
|
+
var bazaarResourceServerExtension = {
|
|
361
|
+
key: BAZAAR.key,
|
|
362
|
+
enrichDeclaration: (declaration, transportContext) => {
|
|
363
|
+
if (!isHTTPRequestContext(transportContext)) {
|
|
364
|
+
return declaration;
|
|
365
|
+
}
|
|
366
|
+
const extension = declaration;
|
|
367
|
+
if (extension.info?.input?.type === "mcp") {
|
|
368
|
+
return declaration;
|
|
369
|
+
}
|
|
370
|
+
const method = transportContext.method;
|
|
371
|
+
const existingInputProps = extension.schema?.properties?.input?.properties || {};
|
|
372
|
+
const updatedInputProps = {
|
|
373
|
+
...existingInputProps,
|
|
374
|
+
method: {
|
|
375
|
+
type: "string",
|
|
376
|
+
enum: [method]
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
return {
|
|
380
|
+
...extension,
|
|
381
|
+
info: {
|
|
382
|
+
...extension.info || {},
|
|
383
|
+
input: {
|
|
384
|
+
...extension.info?.input || {},
|
|
385
|
+
method
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
schema: {
|
|
389
|
+
...extension.schema || {},
|
|
390
|
+
properties: {
|
|
391
|
+
...extension.schema?.properties || {},
|
|
392
|
+
input: {
|
|
393
|
+
...extension.schema?.properties?.input || {},
|
|
394
|
+
properties: updatedInputProps,
|
|
395
|
+
required: [
|
|
396
|
+
...extension.schema?.properties?.input?.required || [],
|
|
397
|
+
...!(extension.schema?.properties?.input?.required || []).includes("method") ? ["method"] : []
|
|
398
|
+
]
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// src/bazaar/facilitator.ts
|
|
407
|
+
var import__ = __toESM(require("ajv/dist/2020.js"));
|
|
408
|
+
|
|
409
|
+
// src/bazaar/v1/facilitator.ts
|
|
410
|
+
function hasV1OutputSchema(obj) {
|
|
411
|
+
return obj !== null && typeof obj === "object" && "input" in obj && obj.input !== null && typeof obj.input === "object" && "type" in obj.input && obj.input.type === "http" && "method" in obj.input;
|
|
412
|
+
}
|
|
413
|
+
function isQueryMethod(method) {
|
|
414
|
+
const upperMethod = method.toUpperCase();
|
|
415
|
+
return upperMethod === "GET" || upperMethod === "HEAD" || upperMethod === "DELETE";
|
|
416
|
+
}
|
|
417
|
+
function isBodyMethod(method) {
|
|
418
|
+
const upperMethod = method.toUpperCase();
|
|
419
|
+
return upperMethod === "POST" || upperMethod === "PUT" || upperMethod === "PATCH";
|
|
420
|
+
}
|
|
421
|
+
function extractQueryParams(v1Input) {
|
|
422
|
+
if (v1Input.queryParams && typeof v1Input.queryParams === "object") {
|
|
423
|
+
return v1Input.queryParams;
|
|
424
|
+
}
|
|
425
|
+
if (v1Input.query_params && typeof v1Input.query_params === "object") {
|
|
426
|
+
return v1Input.query_params;
|
|
427
|
+
}
|
|
428
|
+
if (v1Input.query && typeof v1Input.query === "object") {
|
|
429
|
+
return v1Input.query;
|
|
430
|
+
}
|
|
431
|
+
if (v1Input.params && typeof v1Input.params === "object") {
|
|
432
|
+
return v1Input.params;
|
|
433
|
+
}
|
|
434
|
+
return void 0;
|
|
435
|
+
}
|
|
436
|
+
function extractBodyInfo(v1Input) {
|
|
437
|
+
let bodyType = "json";
|
|
438
|
+
const bodyTypeField = v1Input.bodyType || v1Input.body_type;
|
|
439
|
+
if (bodyTypeField && typeof bodyTypeField === "string") {
|
|
440
|
+
const type = bodyTypeField.toLowerCase();
|
|
441
|
+
if (type.includes("form") || type.includes("multipart")) {
|
|
442
|
+
bodyType = "form-data";
|
|
443
|
+
} else if (type.includes("text") || type.includes("plain")) {
|
|
444
|
+
bodyType = "text";
|
|
445
|
+
} else {
|
|
446
|
+
bodyType = "json";
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
let body = {};
|
|
450
|
+
if (v1Input.bodyFields && typeof v1Input.bodyFields === "object") {
|
|
451
|
+
body = v1Input.bodyFields;
|
|
452
|
+
} else if (v1Input.body_fields && v1Input.body_fields !== null && typeof v1Input.body_fields === "object") {
|
|
453
|
+
body = v1Input.body_fields;
|
|
454
|
+
} else if (v1Input.bodyParams && typeof v1Input.bodyParams === "object") {
|
|
455
|
+
body = v1Input.bodyParams;
|
|
456
|
+
} else if (v1Input.body && typeof v1Input.body === "object") {
|
|
457
|
+
body = v1Input.body;
|
|
458
|
+
} else if (v1Input.data && typeof v1Input.data === "object") {
|
|
459
|
+
body = v1Input.data;
|
|
460
|
+
} else if (v1Input.properties && typeof v1Input.properties === "object") {
|
|
461
|
+
body = v1Input.properties;
|
|
462
|
+
}
|
|
463
|
+
return { body, bodyType };
|
|
464
|
+
}
|
|
465
|
+
function extractDiscoveryInfoV1(paymentRequirements) {
|
|
466
|
+
const { outputSchema } = paymentRequirements;
|
|
467
|
+
if (!outputSchema || !hasV1OutputSchema(outputSchema)) {
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
const v1Input = outputSchema.input;
|
|
471
|
+
const isDiscoverable = v1Input.discoverable ?? true;
|
|
472
|
+
if (!isDiscoverable) {
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
const method = typeof v1Input.method === "string" ? v1Input.method.toUpperCase() : "";
|
|
476
|
+
const headersRaw = v1Input.headerFields || v1Input.header_fields || v1Input.headers;
|
|
477
|
+
const headers = headersRaw && typeof headersRaw === "object" ? headersRaw : void 0;
|
|
478
|
+
const output = outputSchema.output ? {
|
|
479
|
+
type: "json",
|
|
480
|
+
example: outputSchema.output
|
|
481
|
+
} : void 0;
|
|
482
|
+
if (isQueryMethod(method)) {
|
|
483
|
+
const queryParams = extractQueryParams(v1Input);
|
|
484
|
+
const discoveryInfo = {
|
|
485
|
+
input: {
|
|
486
|
+
type: "http",
|
|
487
|
+
method,
|
|
488
|
+
...queryParams ? { queryParams } : {},
|
|
489
|
+
...headers ? { headers } : {}
|
|
490
|
+
},
|
|
491
|
+
...output ? { output } : {}
|
|
492
|
+
};
|
|
493
|
+
return discoveryInfo;
|
|
494
|
+
} else if (isBodyMethod(method)) {
|
|
495
|
+
const { body, bodyType } = extractBodyInfo(v1Input);
|
|
496
|
+
const queryParams = extractQueryParams(v1Input);
|
|
497
|
+
const discoveryInfo = {
|
|
498
|
+
input: {
|
|
499
|
+
type: "http",
|
|
500
|
+
method,
|
|
501
|
+
bodyType,
|
|
502
|
+
body,
|
|
503
|
+
...queryParams ? { queryParams } : {},
|
|
504
|
+
...headers ? { headers } : {}
|
|
505
|
+
},
|
|
506
|
+
...output ? { output } : {}
|
|
507
|
+
};
|
|
508
|
+
return discoveryInfo;
|
|
509
|
+
}
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
function isDiscoverableV1(paymentRequirements) {
|
|
513
|
+
return extractDiscoveryInfoV1(paymentRequirements) !== null;
|
|
514
|
+
}
|
|
515
|
+
function extractResourceMetadataV1(paymentRequirements) {
|
|
516
|
+
return {
|
|
517
|
+
url: paymentRequirements.resource,
|
|
518
|
+
description: paymentRequirements.description,
|
|
519
|
+
mimeType: paymentRequirements.mimeType
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// src/bazaar/facilitator.ts
|
|
524
|
+
function validateDiscoveryExtension(extension) {
|
|
525
|
+
try {
|
|
526
|
+
const ajv = new import__.default({ strict: false, allErrors: true });
|
|
527
|
+
const validate = ajv.compile(extension.schema);
|
|
528
|
+
const valid = validate(extension.info);
|
|
529
|
+
if (valid) {
|
|
530
|
+
return { valid: true };
|
|
531
|
+
}
|
|
532
|
+
const errors = validate.errors?.map((err) => {
|
|
533
|
+
const path = err.instancePath || "(root)";
|
|
534
|
+
return `${path}: ${err.message}`;
|
|
535
|
+
}) || ["Unknown validation error"];
|
|
536
|
+
return { valid: false, errors };
|
|
537
|
+
} catch (error) {
|
|
538
|
+
return {
|
|
539
|
+
valid: false,
|
|
540
|
+
errors: [
|
|
541
|
+
`Schema validation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
542
|
+
]
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function extractDiscoveryInfo(paymentPayload, paymentRequirements, validate = true) {
|
|
547
|
+
let discoveryInfo = null;
|
|
548
|
+
let resourceUrl;
|
|
549
|
+
if (paymentPayload.x402Version === 2) {
|
|
550
|
+
resourceUrl = paymentPayload.resource?.url ?? "";
|
|
551
|
+
if (paymentPayload.extensions) {
|
|
552
|
+
const bazaarExtension = paymentPayload.extensions[BAZAAR.key];
|
|
553
|
+
if (bazaarExtension && typeof bazaarExtension === "object") {
|
|
554
|
+
try {
|
|
555
|
+
const extension = bazaarExtension;
|
|
556
|
+
if (validate) {
|
|
557
|
+
const result = validateDiscoveryExtension(extension);
|
|
558
|
+
if (!result.valid) {
|
|
559
|
+
console.warn(
|
|
560
|
+
`V2 discovery extension validation failed: ${result.errors?.join(", ")}`
|
|
561
|
+
);
|
|
562
|
+
} else {
|
|
563
|
+
discoveryInfo = extension.info;
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
discoveryInfo = extension.info;
|
|
567
|
+
}
|
|
568
|
+
} catch (error) {
|
|
569
|
+
console.warn(`V2 discovery extension extraction failed: ${error}`);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
} else if (paymentPayload.x402Version === 1) {
|
|
574
|
+
const requirementsV1 = paymentRequirements;
|
|
575
|
+
resourceUrl = requirementsV1.resource;
|
|
576
|
+
discoveryInfo = extractDiscoveryInfoV1(requirementsV1);
|
|
577
|
+
} else {
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
if (!discoveryInfo) {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
const url = new URL(resourceUrl);
|
|
584
|
+
const normalizedResourceUrl = `${url.origin}${url.pathname}`;
|
|
585
|
+
let description;
|
|
586
|
+
let mimeType;
|
|
587
|
+
if (paymentPayload.x402Version === 2) {
|
|
588
|
+
description = paymentPayload.resource?.description;
|
|
589
|
+
mimeType = paymentPayload.resource?.mimeType;
|
|
590
|
+
} else if (paymentPayload.x402Version === 1) {
|
|
591
|
+
const requirementsV1 = paymentRequirements;
|
|
592
|
+
description = requirementsV1.description;
|
|
593
|
+
mimeType = requirementsV1.mimeType;
|
|
594
|
+
}
|
|
595
|
+
const base = {
|
|
596
|
+
resourceUrl: normalizedResourceUrl,
|
|
597
|
+
description,
|
|
598
|
+
mimeType,
|
|
599
|
+
x402Version: paymentPayload.x402Version,
|
|
600
|
+
discoveryInfo
|
|
601
|
+
};
|
|
602
|
+
if (discoveryInfo.input.type === "mcp") {
|
|
603
|
+
return { ...base, toolName: discoveryInfo.input.toolName };
|
|
604
|
+
}
|
|
605
|
+
return { ...base, method: discoveryInfo.input.method };
|
|
606
|
+
}
|
|
607
|
+
function extractDiscoveryInfoFromExtension(extension, validate = true) {
|
|
608
|
+
if (validate) {
|
|
609
|
+
const result = validateDiscoveryExtension(extension);
|
|
610
|
+
if (!result.valid) {
|
|
611
|
+
throw new Error(
|
|
612
|
+
`Invalid discovery extension: ${result.errors?.join(", ") || "Unknown error"}`
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return extension.info;
|
|
617
|
+
}
|
|
618
|
+
function validateAndExtract(extension) {
|
|
619
|
+
const result = validateDiscoveryExtension(extension);
|
|
620
|
+
if (result.valid) {
|
|
621
|
+
return {
|
|
622
|
+
valid: true,
|
|
623
|
+
info: extension.info
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
valid: false,
|
|
628
|
+
errors: result.errors
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/bazaar/facilitatorClient.ts
|
|
633
|
+
function withBazaar(client) {
|
|
634
|
+
const existingExtensions = client.extensions ?? {};
|
|
635
|
+
const extended = client;
|
|
636
|
+
extended.extensions = {
|
|
637
|
+
...existingExtensions,
|
|
638
|
+
discovery: {
|
|
639
|
+
async listResources(params) {
|
|
640
|
+
let headers = {
|
|
641
|
+
"Content-Type": "application/json"
|
|
642
|
+
};
|
|
643
|
+
const authHeaders = await client.createAuthHeaders("discovery");
|
|
644
|
+
headers = { ...headers, ...authHeaders.headers };
|
|
645
|
+
const queryParams = new URLSearchParams();
|
|
646
|
+
if (params?.type !== void 0) {
|
|
647
|
+
queryParams.set("type", params.type);
|
|
648
|
+
}
|
|
649
|
+
if (params?.limit !== void 0) {
|
|
650
|
+
queryParams.set("limit", params.limit.toString());
|
|
651
|
+
}
|
|
652
|
+
if (params?.offset !== void 0) {
|
|
653
|
+
queryParams.set("offset", params.offset.toString());
|
|
654
|
+
}
|
|
655
|
+
const queryString = queryParams.toString();
|
|
656
|
+
const endpoint = `${client.url}/discovery/resources${queryString ? `?${queryString}` : ""}`;
|
|
657
|
+
const response = await fetch(endpoint, {
|
|
658
|
+
method: "GET",
|
|
659
|
+
headers
|
|
660
|
+
});
|
|
661
|
+
if (!response.ok) {
|
|
662
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
663
|
+
throw new Error(
|
|
664
|
+
`Facilitator listDiscoveryResources failed (${response.status}): ${errorText}`
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
return await response.json();
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
return extended;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// src/sign-in-with-x/types.ts
|
|
675
|
+
var import_zod = require("zod");
|
|
676
|
+
var SIGN_IN_WITH_X = "sign-in-with-x";
|
|
677
|
+
var SIWxPayloadSchema = import_zod.z.object({
|
|
678
|
+
domain: import_zod.z.string(),
|
|
679
|
+
address: import_zod.z.string(),
|
|
680
|
+
statement: import_zod.z.string().optional(),
|
|
681
|
+
uri: import_zod.z.string(),
|
|
682
|
+
version: import_zod.z.string(),
|
|
683
|
+
chainId: import_zod.z.string(),
|
|
684
|
+
type: import_zod.z.enum(["eip191", "ed25519"]),
|
|
685
|
+
nonce: import_zod.z.string(),
|
|
686
|
+
issuedAt: import_zod.z.string(),
|
|
687
|
+
expirationTime: import_zod.z.string().optional(),
|
|
688
|
+
notBefore: import_zod.z.string().optional(),
|
|
689
|
+
requestId: import_zod.z.string().optional(),
|
|
690
|
+
resources: import_zod.z.array(import_zod.z.string()).optional(),
|
|
691
|
+
signatureScheme: import_zod.z.enum(["eip191", "eip1271", "eip6492", "siws"]).optional(),
|
|
692
|
+
signature: import_zod.z.string()
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
// src/sign-in-with-x/solana.ts
|
|
696
|
+
var import_base = require("@scure/base");
|
|
697
|
+
var import_tweetnacl = __toESM(require("tweetnacl"));
|
|
698
|
+
var SOLANA_MAINNET = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
699
|
+
var SOLANA_DEVNET = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
700
|
+
var SOLANA_TESTNET = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
701
|
+
function extractSolanaChainReference(chainId) {
|
|
702
|
+
const [, reference] = chainId.split(":");
|
|
703
|
+
return reference;
|
|
704
|
+
}
|
|
705
|
+
function formatSIWSMessage(info, address) {
|
|
706
|
+
const lines = [
|
|
707
|
+
`${info.domain} wants you to sign in with your Solana account:`,
|
|
708
|
+
address,
|
|
709
|
+
""
|
|
710
|
+
];
|
|
711
|
+
if (info.statement) {
|
|
712
|
+
lines.push(info.statement, "");
|
|
713
|
+
}
|
|
714
|
+
lines.push(
|
|
715
|
+
`URI: ${info.uri}`,
|
|
716
|
+
`Version: ${info.version}`,
|
|
717
|
+
`Chain ID: ${extractSolanaChainReference(info.chainId)}`,
|
|
718
|
+
`Nonce: ${info.nonce}`,
|
|
719
|
+
`Issued At: ${info.issuedAt}`
|
|
720
|
+
);
|
|
721
|
+
if (info.expirationTime) {
|
|
722
|
+
lines.push(`Expiration Time: ${info.expirationTime}`);
|
|
723
|
+
}
|
|
724
|
+
if (info.notBefore) {
|
|
725
|
+
lines.push(`Not Before: ${info.notBefore}`);
|
|
726
|
+
}
|
|
727
|
+
if (info.requestId) {
|
|
728
|
+
lines.push(`Request ID: ${info.requestId}`);
|
|
729
|
+
}
|
|
730
|
+
if (info.resources && info.resources.length > 0) {
|
|
731
|
+
lines.push("Resources:");
|
|
732
|
+
for (const resource of info.resources) {
|
|
733
|
+
lines.push(`- ${resource}`);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return lines.join("\n");
|
|
737
|
+
}
|
|
738
|
+
function verifySolanaSignature(message, signature, publicKey) {
|
|
739
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
740
|
+
return import_tweetnacl.default.sign.detached.verify(messageBytes, signature, publicKey);
|
|
741
|
+
}
|
|
742
|
+
function decodeBase58(encoded) {
|
|
743
|
+
return import_base.base58.decode(encoded);
|
|
744
|
+
}
|
|
745
|
+
function encodeBase58(bytes) {
|
|
746
|
+
return import_base.base58.encode(bytes);
|
|
747
|
+
}
|
|
748
|
+
function isSolanaSigner(signer) {
|
|
749
|
+
if ("signMessages" in signer && typeof signer.signMessages === "function") {
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
if ("publicKey" in signer && signer.publicKey) {
|
|
753
|
+
const pk = signer.publicKey;
|
|
754
|
+
if (typeof pk === "object" && pk !== null && "toBase58" in pk) {
|
|
755
|
+
return true;
|
|
756
|
+
}
|
|
757
|
+
if (typeof pk === "string" && !pk.startsWith("0x")) {
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/sign-in-with-x/schema.ts
|
|
765
|
+
function buildSIWxSchema() {
|
|
766
|
+
return {
|
|
767
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
768
|
+
type: "object",
|
|
769
|
+
properties: {
|
|
770
|
+
domain: { type: "string" },
|
|
771
|
+
address: { type: "string" },
|
|
772
|
+
statement: { type: "string" },
|
|
773
|
+
uri: { type: "string", format: "uri" },
|
|
774
|
+
version: { type: "string" },
|
|
775
|
+
chainId: { type: "string" },
|
|
776
|
+
type: { type: "string" },
|
|
777
|
+
nonce: { type: "string" },
|
|
778
|
+
issuedAt: { type: "string", format: "date-time" },
|
|
779
|
+
expirationTime: { type: "string", format: "date-time" },
|
|
780
|
+
notBefore: { type: "string", format: "date-time" },
|
|
781
|
+
requestId: { type: "string" },
|
|
782
|
+
resources: { type: "array", items: { type: "string", format: "uri" } },
|
|
783
|
+
signature: { type: "string" }
|
|
784
|
+
},
|
|
785
|
+
required: [
|
|
786
|
+
"domain",
|
|
787
|
+
"address",
|
|
788
|
+
"uri",
|
|
789
|
+
"version",
|
|
790
|
+
"chainId",
|
|
791
|
+
"type",
|
|
792
|
+
"nonce",
|
|
793
|
+
"issuedAt",
|
|
794
|
+
"signature"
|
|
795
|
+
]
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// src/sign-in-with-x/declare.ts
|
|
800
|
+
function getSignatureType(network) {
|
|
801
|
+
return network.startsWith("solana:") ? "ed25519" : "eip191";
|
|
802
|
+
}
|
|
803
|
+
function declareSIWxExtension(options = {}) {
|
|
804
|
+
const info = {
|
|
805
|
+
version: options.version ?? "1"
|
|
806
|
+
};
|
|
807
|
+
if (options.domain) {
|
|
808
|
+
info.domain = options.domain;
|
|
809
|
+
}
|
|
810
|
+
if (options.resourceUri) {
|
|
811
|
+
info.uri = options.resourceUri;
|
|
812
|
+
info.resources = [options.resourceUri];
|
|
813
|
+
}
|
|
814
|
+
if (options.statement) {
|
|
815
|
+
info.statement = options.statement;
|
|
816
|
+
}
|
|
817
|
+
let supportedChains = [];
|
|
818
|
+
if (options.network) {
|
|
819
|
+
const networks = Array.isArray(options.network) ? options.network : [options.network];
|
|
820
|
+
supportedChains = networks.map((network) => ({
|
|
821
|
+
chainId: network,
|
|
822
|
+
type: getSignatureType(network)
|
|
823
|
+
}));
|
|
824
|
+
}
|
|
825
|
+
const declaration = {
|
|
826
|
+
info,
|
|
827
|
+
supportedChains,
|
|
828
|
+
schema: buildSIWxSchema(),
|
|
829
|
+
_options: options
|
|
830
|
+
};
|
|
831
|
+
return { [SIGN_IN_WITH_X]: declaration };
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// src/sign-in-with-x/server.ts
|
|
835
|
+
var import_crypto = require("crypto");
|
|
836
|
+
var siwxResourceServerExtension = {
|
|
837
|
+
key: SIGN_IN_WITH_X,
|
|
838
|
+
enrichPaymentRequiredResponse: async (declaration, context) => {
|
|
839
|
+
const decl = declaration;
|
|
840
|
+
const opts = decl._options ?? {};
|
|
841
|
+
const resourceUri = opts.resourceUri ?? context.resourceInfo.url;
|
|
842
|
+
let domain = opts.domain;
|
|
843
|
+
if (!domain && resourceUri) {
|
|
844
|
+
try {
|
|
845
|
+
domain = new URL(resourceUri).hostname;
|
|
846
|
+
} catch {
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
let networks;
|
|
850
|
+
if (opts.network) {
|
|
851
|
+
networks = Array.isArray(opts.network) ? opts.network : [opts.network];
|
|
852
|
+
} else {
|
|
853
|
+
networks = [...new Set(context.requirements.map((r) => r.network))];
|
|
854
|
+
}
|
|
855
|
+
const nonce = (0, import_crypto.randomBytes)(16).toString("hex");
|
|
856
|
+
const issuedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
857
|
+
const expirationSeconds = opts.expirationSeconds;
|
|
858
|
+
const expirationTime = expirationSeconds !== void 0 ? new Date(Date.now() + expirationSeconds * 1e3).toISOString() : void 0;
|
|
859
|
+
const info = {
|
|
860
|
+
domain: domain ?? "",
|
|
861
|
+
uri: resourceUri,
|
|
862
|
+
version: opts.version ?? "1",
|
|
863
|
+
nonce,
|
|
864
|
+
issuedAt,
|
|
865
|
+
resources: [resourceUri]
|
|
866
|
+
};
|
|
867
|
+
if (expirationTime) {
|
|
868
|
+
info.expirationTime = expirationTime;
|
|
869
|
+
}
|
|
870
|
+
if (opts.statement) {
|
|
871
|
+
info.statement = opts.statement;
|
|
872
|
+
}
|
|
873
|
+
const supportedChains = networks.map((network) => ({
|
|
874
|
+
chainId: network,
|
|
875
|
+
type: getSignatureType(network)
|
|
876
|
+
}));
|
|
877
|
+
return {
|
|
878
|
+
info,
|
|
879
|
+
supportedChains,
|
|
880
|
+
schema: buildSIWxSchema()
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
// src/sign-in-with-x/parse.ts
|
|
886
|
+
var import_utils = require("@bankofai/x402-core/utils");
|
|
887
|
+
function parseSIWxHeader(header) {
|
|
888
|
+
if (!import_utils.Base64EncodedRegex.test(header)) {
|
|
889
|
+
throw new Error("Invalid SIWX header: not valid base64");
|
|
890
|
+
}
|
|
891
|
+
const jsonStr = (0, import_utils.safeBase64Decode)(header);
|
|
892
|
+
let rawPayload;
|
|
893
|
+
try {
|
|
894
|
+
rawPayload = JSON.parse(jsonStr);
|
|
895
|
+
} catch (error) {
|
|
896
|
+
if (error instanceof SyntaxError) {
|
|
897
|
+
throw new Error("Invalid SIWX header: not valid JSON");
|
|
898
|
+
}
|
|
899
|
+
throw error;
|
|
900
|
+
}
|
|
901
|
+
const parsed = SIWxPayloadSchema.safeParse(rawPayload);
|
|
902
|
+
if (!parsed.success) {
|
|
903
|
+
const issues = parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join(", ");
|
|
904
|
+
throw new Error(`Invalid SIWX header: ${issues}`);
|
|
905
|
+
}
|
|
906
|
+
return parsed.data;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// src/sign-in-with-x/validate.ts
|
|
910
|
+
var DEFAULT_MAX_AGE_MS = 5 * 60 * 1e3;
|
|
911
|
+
async function validateSIWxMessage(message, expectedResourceUri, options = {}) {
|
|
912
|
+
const expectedUrl = new URL(expectedResourceUri);
|
|
913
|
+
const maxAge = options.maxAge ?? DEFAULT_MAX_AGE_MS;
|
|
914
|
+
if (message.domain !== expectedUrl.hostname) {
|
|
915
|
+
return {
|
|
916
|
+
valid: false,
|
|
917
|
+
error: `Domain mismatch: expected "${expectedUrl.hostname}", got "${message.domain}"`
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
if (!message.uri.startsWith(expectedUrl.origin)) {
|
|
921
|
+
return {
|
|
922
|
+
valid: false,
|
|
923
|
+
error: `URI mismatch: expected origin "${expectedUrl.origin}", got "${message.uri}"`
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
const issuedAt = new Date(message.issuedAt);
|
|
927
|
+
if (isNaN(issuedAt.getTime())) {
|
|
928
|
+
return {
|
|
929
|
+
valid: false,
|
|
930
|
+
error: "Invalid issuedAt timestamp"
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
const age = Date.now() - issuedAt.getTime();
|
|
934
|
+
if (age > maxAge) {
|
|
935
|
+
return {
|
|
936
|
+
valid: false,
|
|
937
|
+
error: `Message too old: ${Math.round(age / 1e3)}s exceeds ${maxAge / 1e3}s limit`
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
if (age < 0) {
|
|
941
|
+
return {
|
|
942
|
+
valid: false,
|
|
943
|
+
error: "issuedAt is in the future"
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
if (message.expirationTime) {
|
|
947
|
+
const expiration = new Date(message.expirationTime);
|
|
948
|
+
if (isNaN(expiration.getTime())) {
|
|
949
|
+
return {
|
|
950
|
+
valid: false,
|
|
951
|
+
error: "Invalid expirationTime timestamp"
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
if (expiration < /* @__PURE__ */ new Date()) {
|
|
955
|
+
return {
|
|
956
|
+
valid: false,
|
|
957
|
+
error: "Message expired"
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
if (message.notBefore) {
|
|
962
|
+
const notBefore = new Date(message.notBefore);
|
|
963
|
+
if (isNaN(notBefore.getTime())) {
|
|
964
|
+
return {
|
|
965
|
+
valid: false,
|
|
966
|
+
error: "Invalid notBefore timestamp"
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
if (/* @__PURE__ */ new Date() < notBefore) {
|
|
970
|
+
return {
|
|
971
|
+
valid: false,
|
|
972
|
+
error: "Message not yet valid (notBefore is in the future)"
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
if (options.checkNonce) {
|
|
977
|
+
const nonceValid = await options.checkNonce(message.nonce);
|
|
978
|
+
if (!nonceValid) {
|
|
979
|
+
return {
|
|
980
|
+
valid: false,
|
|
981
|
+
error: "Nonce validation failed (possible replay attack)"
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
return { valid: true };
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// src/sign-in-with-x/evm.ts
|
|
989
|
+
var import_viem = require("viem");
|
|
990
|
+
var import_siwe = require("siwe");
|
|
991
|
+
function extractEVMChainId(chainId) {
|
|
992
|
+
const match = /^eip155:(\d+)$/.exec(chainId);
|
|
993
|
+
if (!match) {
|
|
994
|
+
throw new Error(`Invalid EVM chainId format: ${chainId}. Expected eip155:<number>`);
|
|
995
|
+
}
|
|
996
|
+
return parseInt(match[1], 10);
|
|
997
|
+
}
|
|
998
|
+
function formatSIWEMessage(info, address) {
|
|
999
|
+
const numericChainId = extractEVMChainId(info.chainId);
|
|
1000
|
+
const siweMessage = new import_siwe.SiweMessage({
|
|
1001
|
+
domain: info.domain,
|
|
1002
|
+
address,
|
|
1003
|
+
statement: info.statement,
|
|
1004
|
+
uri: info.uri,
|
|
1005
|
+
version: info.version,
|
|
1006
|
+
chainId: numericChainId,
|
|
1007
|
+
nonce: info.nonce,
|
|
1008
|
+
issuedAt: info.issuedAt,
|
|
1009
|
+
expirationTime: info.expirationTime,
|
|
1010
|
+
notBefore: info.notBefore,
|
|
1011
|
+
requestId: info.requestId,
|
|
1012
|
+
resources: info.resources
|
|
1013
|
+
});
|
|
1014
|
+
return siweMessage.prepareMessage();
|
|
1015
|
+
}
|
|
1016
|
+
async function verifyEVMSignature(message, address, signature, verifier) {
|
|
1017
|
+
const args = {
|
|
1018
|
+
address,
|
|
1019
|
+
message,
|
|
1020
|
+
signature
|
|
1021
|
+
};
|
|
1022
|
+
if (verifier) {
|
|
1023
|
+
return verifier(args);
|
|
1024
|
+
}
|
|
1025
|
+
return (0, import_viem.verifyMessage)(args);
|
|
1026
|
+
}
|
|
1027
|
+
function isEVMSigner(signer) {
|
|
1028
|
+
if ("signMessages" in signer && typeof signer.signMessages === "function") {
|
|
1029
|
+
return false;
|
|
1030
|
+
}
|
|
1031
|
+
if ("publicKey" in signer && signer.publicKey) {
|
|
1032
|
+
const pk = signer.publicKey;
|
|
1033
|
+
if (typeof pk === "object" && pk !== null && "toBase58" in pk) {
|
|
1034
|
+
return false;
|
|
1035
|
+
}
|
|
1036
|
+
if (typeof pk === "string" && !pk.startsWith("0x")) {
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if ("account" in signer && signer.account && typeof signer.account === "object") {
|
|
1041
|
+
const account = signer.account;
|
|
1042
|
+
if (account.address && account.address.startsWith("0x")) {
|
|
1043
|
+
return true;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
if ("address" in signer && typeof signer.address === "string" && signer.address.startsWith("0x")) {
|
|
1047
|
+
return true;
|
|
1048
|
+
}
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// src/sign-in-with-x/verify.ts
|
|
1053
|
+
async function verifySIWxSignature(payload, options) {
|
|
1054
|
+
try {
|
|
1055
|
+
if (payload.chainId.startsWith("eip155:")) {
|
|
1056
|
+
return verifyEVMPayload(payload, options?.evmVerifier);
|
|
1057
|
+
}
|
|
1058
|
+
if (payload.chainId.startsWith("solana:")) {
|
|
1059
|
+
return verifySolanaPayload(payload);
|
|
1060
|
+
}
|
|
1061
|
+
return {
|
|
1062
|
+
valid: false,
|
|
1063
|
+
error: `Unsupported chain namespace: ${payload.chainId}. Supported: eip155:* (EVM), solana:* (Solana)`
|
|
1064
|
+
};
|
|
1065
|
+
} catch (error) {
|
|
1066
|
+
return {
|
|
1067
|
+
valid: false,
|
|
1068
|
+
error: error instanceof Error ? error.message : "Verification failed"
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
async function verifyEVMPayload(payload, verifier) {
|
|
1073
|
+
const message = formatSIWEMessage(
|
|
1074
|
+
{
|
|
1075
|
+
domain: payload.domain,
|
|
1076
|
+
uri: payload.uri,
|
|
1077
|
+
statement: payload.statement,
|
|
1078
|
+
version: payload.version,
|
|
1079
|
+
chainId: payload.chainId,
|
|
1080
|
+
type: payload.type,
|
|
1081
|
+
nonce: payload.nonce,
|
|
1082
|
+
issuedAt: payload.issuedAt,
|
|
1083
|
+
expirationTime: payload.expirationTime,
|
|
1084
|
+
notBefore: payload.notBefore,
|
|
1085
|
+
requestId: payload.requestId,
|
|
1086
|
+
resources: payload.resources
|
|
1087
|
+
},
|
|
1088
|
+
payload.address
|
|
1089
|
+
);
|
|
1090
|
+
try {
|
|
1091
|
+
const valid = await verifyEVMSignature(message, payload.address, payload.signature, verifier);
|
|
1092
|
+
if (!valid) {
|
|
1093
|
+
return {
|
|
1094
|
+
valid: false,
|
|
1095
|
+
error: "Signature verification failed"
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
return {
|
|
1099
|
+
valid: true,
|
|
1100
|
+
address: payload.address
|
|
1101
|
+
};
|
|
1102
|
+
} catch (error) {
|
|
1103
|
+
return {
|
|
1104
|
+
valid: false,
|
|
1105
|
+
error: error instanceof Error ? error.message : "Signature verification failed"
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function verifySolanaPayload(payload) {
|
|
1110
|
+
const message = formatSIWSMessage(
|
|
1111
|
+
{
|
|
1112
|
+
domain: payload.domain,
|
|
1113
|
+
uri: payload.uri,
|
|
1114
|
+
statement: payload.statement,
|
|
1115
|
+
version: payload.version,
|
|
1116
|
+
chainId: payload.chainId,
|
|
1117
|
+
type: payload.type,
|
|
1118
|
+
nonce: payload.nonce,
|
|
1119
|
+
issuedAt: payload.issuedAt,
|
|
1120
|
+
expirationTime: payload.expirationTime,
|
|
1121
|
+
notBefore: payload.notBefore,
|
|
1122
|
+
requestId: payload.requestId,
|
|
1123
|
+
resources: payload.resources
|
|
1124
|
+
},
|
|
1125
|
+
payload.address
|
|
1126
|
+
);
|
|
1127
|
+
let signature;
|
|
1128
|
+
let publicKey;
|
|
1129
|
+
try {
|
|
1130
|
+
signature = decodeBase58(payload.signature);
|
|
1131
|
+
publicKey = decodeBase58(payload.address);
|
|
1132
|
+
} catch (error) {
|
|
1133
|
+
return {
|
|
1134
|
+
valid: false,
|
|
1135
|
+
error: `Invalid Base58 encoding: ${error instanceof Error ? error.message : "decode failed"}`
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
if (signature.length !== 64) {
|
|
1139
|
+
return {
|
|
1140
|
+
valid: false,
|
|
1141
|
+
error: `Invalid signature length: expected 64 bytes, got ${signature.length}`
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
if (publicKey.length !== 32) {
|
|
1145
|
+
return {
|
|
1146
|
+
valid: false,
|
|
1147
|
+
error: `Invalid public key length: expected 32 bytes, got ${publicKey.length}`
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
const valid = verifySolanaSignature(message, signature, publicKey);
|
|
1151
|
+
if (!valid) {
|
|
1152
|
+
return {
|
|
1153
|
+
valid: false,
|
|
1154
|
+
error: "Solana signature verification failed"
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
return {
|
|
1158
|
+
valid: true,
|
|
1159
|
+
address: payload.address
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// src/sign-in-with-x/message.ts
|
|
1164
|
+
function createSIWxMessage(serverInfo, address) {
|
|
1165
|
+
if (serverInfo.chainId.startsWith("eip155:")) {
|
|
1166
|
+
return formatSIWEMessage(serverInfo, address);
|
|
1167
|
+
}
|
|
1168
|
+
if (serverInfo.chainId.startsWith("solana:")) {
|
|
1169
|
+
return formatSIWSMessage(serverInfo, address);
|
|
1170
|
+
}
|
|
1171
|
+
throw new Error(
|
|
1172
|
+
`Unsupported chain namespace: ${serverInfo.chainId}. Supported: eip155:* (EVM), solana:* (Solana)`
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// src/sign-in-with-x/sign.ts
|
|
1177
|
+
function getEVMAddress(signer) {
|
|
1178
|
+
if (signer.account?.address) {
|
|
1179
|
+
return signer.account.address;
|
|
1180
|
+
}
|
|
1181
|
+
if (signer.address) {
|
|
1182
|
+
return signer.address;
|
|
1183
|
+
}
|
|
1184
|
+
throw new Error("EVM signer missing address");
|
|
1185
|
+
}
|
|
1186
|
+
function getSolanaAddress(signer) {
|
|
1187
|
+
if ("address" in signer && signer.address) {
|
|
1188
|
+
return signer.address;
|
|
1189
|
+
}
|
|
1190
|
+
if ("publicKey" in signer) {
|
|
1191
|
+
const pk = signer.publicKey;
|
|
1192
|
+
return typeof pk === "string" ? pk : pk.toBase58();
|
|
1193
|
+
}
|
|
1194
|
+
throw new Error("Solana signer missing address or publicKey");
|
|
1195
|
+
}
|
|
1196
|
+
async function signEVMMessage(message, signer) {
|
|
1197
|
+
if (signer.account) {
|
|
1198
|
+
return signer.signMessage({ message, account: signer.account });
|
|
1199
|
+
}
|
|
1200
|
+
return signer.signMessage({ message });
|
|
1201
|
+
}
|
|
1202
|
+
async function signSolanaMessage(message, signer) {
|
|
1203
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
1204
|
+
if ("signMessages" in signer) {
|
|
1205
|
+
const results = await signer.signMessages([{ content: messageBytes, signatures: {} }]);
|
|
1206
|
+
const sigDict = results[0];
|
|
1207
|
+
const signatureBytes = Object.values(sigDict)[0];
|
|
1208
|
+
return encodeBase58(signatureBytes);
|
|
1209
|
+
}
|
|
1210
|
+
if ("signMessage" in signer) {
|
|
1211
|
+
const signatureBytes = await signer.signMessage(messageBytes);
|
|
1212
|
+
return encodeBase58(signatureBytes);
|
|
1213
|
+
}
|
|
1214
|
+
throw new Error("Solana signer missing signMessage or signMessages method");
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// src/sign-in-with-x/client.ts
|
|
1218
|
+
async function createSIWxPayload(serverExtension, signer) {
|
|
1219
|
+
const isSolana = serverExtension.chainId.startsWith("solana:");
|
|
1220
|
+
const address = isSolana ? getSolanaAddress(signer) : getEVMAddress(signer);
|
|
1221
|
+
const message = createSIWxMessage(serverExtension, address);
|
|
1222
|
+
const signature = isSolana ? await signSolanaMessage(message, signer) : await signEVMMessage(message, signer);
|
|
1223
|
+
return {
|
|
1224
|
+
domain: serverExtension.domain,
|
|
1225
|
+
address,
|
|
1226
|
+
statement: serverExtension.statement,
|
|
1227
|
+
uri: serverExtension.uri,
|
|
1228
|
+
version: serverExtension.version,
|
|
1229
|
+
chainId: serverExtension.chainId,
|
|
1230
|
+
type: serverExtension.type,
|
|
1231
|
+
nonce: serverExtension.nonce,
|
|
1232
|
+
issuedAt: serverExtension.issuedAt,
|
|
1233
|
+
expirationTime: serverExtension.expirationTime,
|
|
1234
|
+
notBefore: serverExtension.notBefore,
|
|
1235
|
+
requestId: serverExtension.requestId,
|
|
1236
|
+
resources: serverExtension.resources,
|
|
1237
|
+
signatureScheme: serverExtension.signatureScheme,
|
|
1238
|
+
signature
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
// src/sign-in-with-x/encode.ts
|
|
1243
|
+
var import_utils2 = require("@bankofai/x402-core/utils");
|
|
1244
|
+
function encodeSIWxHeader(payload) {
|
|
1245
|
+
return (0, import_utils2.safeBase64Encode)(JSON.stringify(payload));
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
// src/sign-in-with-x/fetch.ts
|
|
1249
|
+
var import_http = require("@bankofai/x402-core/http");
|
|
1250
|
+
function wrapFetchWithSIWx(fetch2, signer) {
|
|
1251
|
+
return async (input, init) => {
|
|
1252
|
+
const request = new Request(input, init);
|
|
1253
|
+
const clonedRequest = request.clone();
|
|
1254
|
+
const response = await fetch2(request);
|
|
1255
|
+
if (response.status !== 402) {
|
|
1256
|
+
return response;
|
|
1257
|
+
}
|
|
1258
|
+
const paymentRequiredHeader = response.headers.get("PAYMENT-REQUIRED");
|
|
1259
|
+
if (!paymentRequiredHeader) {
|
|
1260
|
+
return response;
|
|
1261
|
+
}
|
|
1262
|
+
const paymentRequired = (0, import_http.decodePaymentRequiredHeader)(paymentRequiredHeader);
|
|
1263
|
+
const siwxExtension = paymentRequired.extensions?.[SIGN_IN_WITH_X];
|
|
1264
|
+
if (!siwxExtension?.supportedChains) {
|
|
1265
|
+
return response;
|
|
1266
|
+
}
|
|
1267
|
+
if (clonedRequest.headers.has(SIGN_IN_WITH_X)) {
|
|
1268
|
+
throw new Error("SIWX authentication already attempted");
|
|
1269
|
+
}
|
|
1270
|
+
const paymentNetwork = paymentRequired.accepts?.[0]?.network;
|
|
1271
|
+
if (!paymentNetwork) {
|
|
1272
|
+
return response;
|
|
1273
|
+
}
|
|
1274
|
+
const matchingChain = siwxExtension.supportedChains.find(
|
|
1275
|
+
(chain) => chain.chainId === paymentNetwork
|
|
1276
|
+
);
|
|
1277
|
+
if (!matchingChain) {
|
|
1278
|
+
return response;
|
|
1279
|
+
}
|
|
1280
|
+
const completeInfo = {
|
|
1281
|
+
...siwxExtension.info,
|
|
1282
|
+
chainId: matchingChain.chainId,
|
|
1283
|
+
type: matchingChain.type
|
|
1284
|
+
};
|
|
1285
|
+
const payload = await createSIWxPayload(completeInfo, signer);
|
|
1286
|
+
const siwxHeader = encodeSIWxHeader(payload);
|
|
1287
|
+
clonedRequest.headers.set(SIGN_IN_WITH_X, siwxHeader);
|
|
1288
|
+
return fetch2(clonedRequest);
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// src/sign-in-with-x/storage.ts
|
|
1293
|
+
var InMemorySIWxStorage = class {
|
|
1294
|
+
constructor() {
|
|
1295
|
+
this.paidAddresses = /* @__PURE__ */ new Map();
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Check if an address has paid for a resource.
|
|
1299
|
+
*
|
|
1300
|
+
* @param resource - The resource path
|
|
1301
|
+
* @param address - The wallet address to check
|
|
1302
|
+
* @returns True if the address has paid
|
|
1303
|
+
*/
|
|
1304
|
+
hasPaid(resource, address) {
|
|
1305
|
+
return this.paidAddresses.get(resource)?.has(address.toLowerCase()) ?? false;
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Record that an address has paid for a resource.
|
|
1309
|
+
*
|
|
1310
|
+
* @param resource - The resource path
|
|
1311
|
+
* @param address - The wallet address that paid
|
|
1312
|
+
*/
|
|
1313
|
+
recordPayment(resource, address) {
|
|
1314
|
+
if (!this.paidAddresses.has(resource)) {
|
|
1315
|
+
this.paidAddresses.set(resource, /* @__PURE__ */ new Set());
|
|
1316
|
+
}
|
|
1317
|
+
this.paidAddresses.get(resource).add(address.toLowerCase());
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1321
|
+
// src/sign-in-with-x/hooks.ts
|
|
1322
|
+
function createSIWxSettleHook(options) {
|
|
1323
|
+
const { storage, onEvent } = options;
|
|
1324
|
+
return async (ctx) => {
|
|
1325
|
+
if (!ctx.result.success) return;
|
|
1326
|
+
const address = ctx.result.payer;
|
|
1327
|
+
if (!address) return;
|
|
1328
|
+
const resourceUrl = ctx.paymentPayload.resource?.url;
|
|
1329
|
+
if (!resourceUrl) return;
|
|
1330
|
+
const resource = new URL(resourceUrl).pathname;
|
|
1331
|
+
await storage.recordPayment(resource, address);
|
|
1332
|
+
onEvent?.({ type: "payment_recorded", resource, address });
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
function createSIWxRequestHook(options) {
|
|
1336
|
+
const { storage, verifyOptions, onEvent } = options;
|
|
1337
|
+
const hasUsedNonce = typeof storage.hasUsedNonce === "function";
|
|
1338
|
+
const hasRecordNonce = typeof storage.recordNonce === "function";
|
|
1339
|
+
if (hasUsedNonce !== hasRecordNonce) {
|
|
1340
|
+
throw new Error(
|
|
1341
|
+
"SIWxStorage nonce tracking requires both hasUsedNonce and recordNonce to be implemented"
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
return async (context) => {
|
|
1345
|
+
const header = context.adapter.getHeader(SIGN_IN_WITH_X) || context.adapter.getHeader(SIGN_IN_WITH_X.toLowerCase());
|
|
1346
|
+
if (!header) return;
|
|
1347
|
+
try {
|
|
1348
|
+
const payload = parseSIWxHeader(header);
|
|
1349
|
+
const resourceUri = context.adapter.getUrl();
|
|
1350
|
+
const validation = await validateSIWxMessage(payload, resourceUri);
|
|
1351
|
+
if (!validation.valid) {
|
|
1352
|
+
onEvent?.({ type: "validation_failed", resource: context.path, error: validation.error });
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
const verification = await verifySIWxSignature(payload, verifyOptions);
|
|
1356
|
+
if (!verification.valid || !verification.address) {
|
|
1357
|
+
onEvent?.({ type: "validation_failed", resource: context.path, error: verification.error });
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
if (storage.hasUsedNonce) {
|
|
1361
|
+
const nonceUsed = await storage.hasUsedNonce(payload.nonce);
|
|
1362
|
+
if (nonceUsed) {
|
|
1363
|
+
onEvent?.({ type: "nonce_reused", resource: context.path, nonce: payload.nonce });
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
const hasPaid = await storage.hasPaid(context.path, verification.address);
|
|
1368
|
+
if (hasPaid) {
|
|
1369
|
+
if (storage.recordNonce) {
|
|
1370
|
+
await storage.recordNonce(payload.nonce);
|
|
1371
|
+
}
|
|
1372
|
+
onEvent?.({
|
|
1373
|
+
type: "access_granted",
|
|
1374
|
+
resource: context.path,
|
|
1375
|
+
address: verification.address
|
|
1376
|
+
});
|
|
1377
|
+
return { grantAccess: true };
|
|
1378
|
+
}
|
|
1379
|
+
} catch (err) {
|
|
1380
|
+
onEvent?.({
|
|
1381
|
+
type: "validation_failed",
|
|
1382
|
+
resource: context.path,
|
|
1383
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
function createSIWxClientHook(signer) {
|
|
1389
|
+
const signerIsSolana = isSolanaSigner(signer);
|
|
1390
|
+
const expectedSignatureType = signerIsSolana ? "ed25519" : "eip191";
|
|
1391
|
+
return async (context) => {
|
|
1392
|
+
const extensions = context.paymentRequired.extensions ?? {};
|
|
1393
|
+
const siwxExtension = extensions[SIGN_IN_WITH_X];
|
|
1394
|
+
if (!siwxExtension?.supportedChains) return;
|
|
1395
|
+
try {
|
|
1396
|
+
const matchingChain = siwxExtension.supportedChains.find(
|
|
1397
|
+
(chain) => chain.type === expectedSignatureType
|
|
1398
|
+
);
|
|
1399
|
+
if (!matchingChain) {
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
const completeInfo = {
|
|
1403
|
+
...siwxExtension.info,
|
|
1404
|
+
chainId: matchingChain.chainId,
|
|
1405
|
+
type: matchingChain.type
|
|
1406
|
+
};
|
|
1407
|
+
const payload = await createSIWxPayload(completeInfo, signer);
|
|
1408
|
+
const header = encodeSIWxHeader(payload);
|
|
1409
|
+
return { headers: { [SIGN_IN_WITH_X]: header } };
|
|
1410
|
+
} catch {
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// src/payment-identifier/types.ts
|
|
1416
|
+
var PAYMENT_IDENTIFIER = "payment-identifier";
|
|
1417
|
+
var PAYMENT_ID_MIN_LENGTH = 16;
|
|
1418
|
+
var PAYMENT_ID_MAX_LENGTH = 128;
|
|
1419
|
+
var PAYMENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
1420
|
+
|
|
1421
|
+
// src/payment-identifier/schema.ts
|
|
1422
|
+
var paymentIdentifierSchema = {
|
|
1423
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1424
|
+
type: "object",
|
|
1425
|
+
properties: {
|
|
1426
|
+
required: {
|
|
1427
|
+
type: "boolean"
|
|
1428
|
+
},
|
|
1429
|
+
id: {
|
|
1430
|
+
type: "string",
|
|
1431
|
+
minLength: PAYMENT_ID_MIN_LENGTH,
|
|
1432
|
+
maxLength: PAYMENT_ID_MAX_LENGTH,
|
|
1433
|
+
pattern: "^[a-zA-Z0-9_-]+$"
|
|
1434
|
+
}
|
|
1435
|
+
},
|
|
1436
|
+
required: ["required"]
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1439
|
+
// src/payment-identifier/utils.ts
|
|
1440
|
+
function generatePaymentId(prefix = "pay_") {
|
|
1441
|
+
const uuid = crypto.randomUUID().replace(/-/g, "");
|
|
1442
|
+
return `${prefix}${uuid}`;
|
|
1443
|
+
}
|
|
1444
|
+
function isValidPaymentId(id) {
|
|
1445
|
+
if (typeof id !== "string") {
|
|
1446
|
+
return false;
|
|
1447
|
+
}
|
|
1448
|
+
if (id.length < PAYMENT_ID_MIN_LENGTH || id.length > PAYMENT_ID_MAX_LENGTH) {
|
|
1449
|
+
return false;
|
|
1450
|
+
}
|
|
1451
|
+
return PAYMENT_ID_PATTERN.test(id);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// src/payment-identifier/validation.ts
|
|
1455
|
+
var import__2 = __toESM(require("ajv/dist/2020.js"));
|
|
1456
|
+
function isPaymentIdentifierExtension(extension) {
|
|
1457
|
+
if (!extension || typeof extension !== "object") {
|
|
1458
|
+
return false;
|
|
1459
|
+
}
|
|
1460
|
+
const ext = extension;
|
|
1461
|
+
if (!ext.info || typeof ext.info !== "object") {
|
|
1462
|
+
return false;
|
|
1463
|
+
}
|
|
1464
|
+
const info = ext.info;
|
|
1465
|
+
if (typeof info.required !== "boolean") {
|
|
1466
|
+
return false;
|
|
1467
|
+
}
|
|
1468
|
+
return true;
|
|
1469
|
+
}
|
|
1470
|
+
function validatePaymentIdentifier(extension) {
|
|
1471
|
+
if (!extension || typeof extension !== "object") {
|
|
1472
|
+
return {
|
|
1473
|
+
valid: false,
|
|
1474
|
+
errors: ["Extension must be an object"]
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
const ext = extension;
|
|
1478
|
+
if (!ext.info || typeof ext.info !== "object") {
|
|
1479
|
+
return {
|
|
1480
|
+
valid: false,
|
|
1481
|
+
errors: ["Extension must have an 'info' property"]
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
const info = ext.info;
|
|
1485
|
+
if (typeof info.required !== "boolean") {
|
|
1486
|
+
return {
|
|
1487
|
+
valid: false,
|
|
1488
|
+
errors: ["Extension info must have a 'required' boolean property"]
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
if (info.id !== void 0 && typeof info.id !== "string") {
|
|
1492
|
+
return {
|
|
1493
|
+
valid: false,
|
|
1494
|
+
errors: ["Extension info 'id' must be a string if provided"]
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
if (info.id !== void 0 && !isValidPaymentId(info.id)) {
|
|
1498
|
+
return {
|
|
1499
|
+
valid: false,
|
|
1500
|
+
errors: [
|
|
1501
|
+
`Invalid payment ID format. ID must be 16-128 characters and contain only alphanumeric characters, hyphens, and underscores.`
|
|
1502
|
+
]
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
if (ext.schema) {
|
|
1506
|
+
try {
|
|
1507
|
+
const ajv = new import__2.default({ strict: false, allErrors: true });
|
|
1508
|
+
const validate = ajv.compile(ext.schema);
|
|
1509
|
+
const valid = validate(ext.info);
|
|
1510
|
+
if (!valid && validate.errors) {
|
|
1511
|
+
const errors = validate.errors?.map((err) => {
|
|
1512
|
+
const path = err.instancePath || "(root)";
|
|
1513
|
+
return `${path}: ${err.message}`;
|
|
1514
|
+
}) || ["Unknown validation error"];
|
|
1515
|
+
return { valid: false, errors };
|
|
1516
|
+
}
|
|
1517
|
+
} catch (error) {
|
|
1518
|
+
return {
|
|
1519
|
+
valid: false,
|
|
1520
|
+
errors: [
|
|
1521
|
+
`Schema validation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1522
|
+
]
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
return { valid: true };
|
|
1527
|
+
}
|
|
1528
|
+
function extractPaymentIdentifier(paymentPayload, validate = true) {
|
|
1529
|
+
if (!paymentPayload.extensions) {
|
|
1530
|
+
return null;
|
|
1531
|
+
}
|
|
1532
|
+
const extension = paymentPayload.extensions[PAYMENT_IDENTIFIER];
|
|
1533
|
+
if (!extension || typeof extension !== "object") {
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
const ext = extension;
|
|
1537
|
+
if (!ext.info || typeof ext.info !== "object") {
|
|
1538
|
+
return null;
|
|
1539
|
+
}
|
|
1540
|
+
const info = ext.info;
|
|
1541
|
+
if (typeof info.id !== "string") {
|
|
1542
|
+
return null;
|
|
1543
|
+
}
|
|
1544
|
+
if (validate && !isValidPaymentId(info.id)) {
|
|
1545
|
+
return null;
|
|
1546
|
+
}
|
|
1547
|
+
return info.id;
|
|
1548
|
+
}
|
|
1549
|
+
function extractAndValidatePaymentIdentifier(paymentPayload) {
|
|
1550
|
+
if (!paymentPayload.extensions) {
|
|
1551
|
+
return { id: null, validation: { valid: true } };
|
|
1552
|
+
}
|
|
1553
|
+
const extension = paymentPayload.extensions[PAYMENT_IDENTIFIER];
|
|
1554
|
+
if (!extension) {
|
|
1555
|
+
return { id: null, validation: { valid: true } };
|
|
1556
|
+
}
|
|
1557
|
+
const validation = validatePaymentIdentifier(extension);
|
|
1558
|
+
if (!validation.valid) {
|
|
1559
|
+
return { id: null, validation };
|
|
1560
|
+
}
|
|
1561
|
+
const ext = extension;
|
|
1562
|
+
return { id: ext.info.id ?? null, validation: { valid: true } };
|
|
1563
|
+
}
|
|
1564
|
+
function hasPaymentIdentifier(paymentPayload) {
|
|
1565
|
+
return !!(paymentPayload.extensions && paymentPayload.extensions[PAYMENT_IDENTIFIER]);
|
|
1566
|
+
}
|
|
1567
|
+
function isPaymentIdentifierRequired(extension) {
|
|
1568
|
+
if (!extension || typeof extension !== "object") {
|
|
1569
|
+
return false;
|
|
1570
|
+
}
|
|
1571
|
+
const ext = extension;
|
|
1572
|
+
if (!ext.info || typeof ext.info !== "object") {
|
|
1573
|
+
return false;
|
|
1574
|
+
}
|
|
1575
|
+
return ext.info.required === true;
|
|
1576
|
+
}
|
|
1577
|
+
function validatePaymentIdentifierRequirement(paymentPayload, serverRequired) {
|
|
1578
|
+
if (!serverRequired) {
|
|
1579
|
+
return { valid: true };
|
|
1580
|
+
}
|
|
1581
|
+
const id = extractPaymentIdentifier(paymentPayload, false);
|
|
1582
|
+
if (!id) {
|
|
1583
|
+
return {
|
|
1584
|
+
valid: false,
|
|
1585
|
+
errors: ["Server requires a payment identifier but none was provided"]
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
if (!isValidPaymentId(id)) {
|
|
1589
|
+
return {
|
|
1590
|
+
valid: false,
|
|
1591
|
+
errors: [
|
|
1592
|
+
`Invalid payment ID format. ID must be 16-128 characters and contain only alphanumeric characters, hyphens, and underscores.`
|
|
1593
|
+
]
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
return { valid: true };
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
// src/payment-identifier/client.ts
|
|
1600
|
+
function appendPaymentIdentifierToExtensions(extensions, id) {
|
|
1601
|
+
const extension = extensions[PAYMENT_IDENTIFIER];
|
|
1602
|
+
if (!isPaymentIdentifierExtension(extension)) {
|
|
1603
|
+
return extensions;
|
|
1604
|
+
}
|
|
1605
|
+
const paymentId = id ?? generatePaymentId();
|
|
1606
|
+
if (!isValidPaymentId(paymentId)) {
|
|
1607
|
+
throw new Error(
|
|
1608
|
+
`Invalid payment ID: "${paymentId}". ID must be 16-128 characters and contain only alphanumeric characters, hyphens, and underscores.`
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
extension.info.id = paymentId;
|
|
1612
|
+
return extensions;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// src/payment-identifier/resourceServer.ts
|
|
1616
|
+
function declarePaymentIdentifierExtension(required = false) {
|
|
1617
|
+
return {
|
|
1618
|
+
info: { required },
|
|
1619
|
+
schema: paymentIdentifierSchema
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
var paymentIdentifierResourceServerExtension = {
|
|
1623
|
+
key: PAYMENT_IDENTIFIER
|
|
1624
|
+
// No enrichment needed - the declaration is static
|
|
1625
|
+
// Future hooks for idempotency could be added here if needed
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
|
+
// src/eip2612-gas-sponsoring/types.ts
|
|
1629
|
+
var EIP2612_GAS_SPONSORING = { key: "eip2612GasSponsoring" };
|
|
1630
|
+
|
|
1631
|
+
// src/eip2612-gas-sponsoring/resourceService.ts
|
|
1632
|
+
var eip2612GasSponsoringSchema = {
|
|
1633
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1634
|
+
type: "object",
|
|
1635
|
+
properties: {
|
|
1636
|
+
from: {
|
|
1637
|
+
type: "string",
|
|
1638
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1639
|
+
description: "The address of the sender."
|
|
1640
|
+
},
|
|
1641
|
+
asset: {
|
|
1642
|
+
type: "string",
|
|
1643
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1644
|
+
description: "The address of the ERC-20 token contract."
|
|
1645
|
+
},
|
|
1646
|
+
spender: {
|
|
1647
|
+
type: "string",
|
|
1648
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1649
|
+
description: "The address of the spender (Canonical Permit2)."
|
|
1650
|
+
},
|
|
1651
|
+
amount: {
|
|
1652
|
+
type: "string",
|
|
1653
|
+
pattern: "^[0-9]+$",
|
|
1654
|
+
description: "The amount to approve (uint256). Typically MaxUint."
|
|
1655
|
+
},
|
|
1656
|
+
nonce: {
|
|
1657
|
+
type: "string",
|
|
1658
|
+
pattern: "^[0-9]+$",
|
|
1659
|
+
description: "The current nonce of the sender."
|
|
1660
|
+
},
|
|
1661
|
+
deadline: {
|
|
1662
|
+
type: "string",
|
|
1663
|
+
pattern: "^[0-9]+$",
|
|
1664
|
+
description: "The timestamp at which the signature expires."
|
|
1665
|
+
},
|
|
1666
|
+
signature: {
|
|
1667
|
+
type: "string",
|
|
1668
|
+
pattern: "^0x[a-fA-F0-9]+$",
|
|
1669
|
+
description: "The 65-byte concatenated signature (r, s, v) as a hex string."
|
|
1670
|
+
},
|
|
1671
|
+
version: {
|
|
1672
|
+
type: "string",
|
|
1673
|
+
pattern: "^[0-9]+(\\.[0-9]+)*$",
|
|
1674
|
+
description: "Schema version identifier."
|
|
1675
|
+
}
|
|
1676
|
+
},
|
|
1677
|
+
required: ["from", "asset", "spender", "amount", "nonce", "deadline", "signature", "version"]
|
|
1678
|
+
};
|
|
1679
|
+
function declareEip2612GasSponsoringExtension() {
|
|
1680
|
+
const key = EIP2612_GAS_SPONSORING.key;
|
|
1681
|
+
return {
|
|
1682
|
+
[key]: {
|
|
1683
|
+
info: {
|
|
1684
|
+
description: "The facilitator accepts EIP-2612 gasless Permit to `Permit2` canonical contract.",
|
|
1685
|
+
version: "1"
|
|
1686
|
+
},
|
|
1687
|
+
schema: eip2612GasSponsoringSchema
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// src/eip2612-gas-sponsoring/facilitator.ts
|
|
1693
|
+
function extractEip2612GasSponsoringInfo(paymentPayload) {
|
|
1694
|
+
if (!paymentPayload.extensions) {
|
|
1695
|
+
return null;
|
|
1696
|
+
}
|
|
1697
|
+
const extension = paymentPayload.extensions[EIP2612_GAS_SPONSORING.key];
|
|
1698
|
+
if (!extension?.info) {
|
|
1699
|
+
return null;
|
|
1700
|
+
}
|
|
1701
|
+
const info = extension.info;
|
|
1702
|
+
if (!info.from || !info.asset || !info.spender || !info.amount || !info.nonce || !info.deadline || !info.signature || !info.version) {
|
|
1703
|
+
return null;
|
|
1704
|
+
}
|
|
1705
|
+
return info;
|
|
1706
|
+
}
|
|
1707
|
+
function validateEip2612GasSponsoringInfo(info) {
|
|
1708
|
+
const addressPattern = /^0x[a-fA-F0-9]{40}$/;
|
|
1709
|
+
const numericPattern = /^[0-9]+$/;
|
|
1710
|
+
const hexPattern = /^0x[a-fA-F0-9]+$/;
|
|
1711
|
+
const versionPattern = /^[0-9]+(\.[0-9]+)*$/;
|
|
1712
|
+
return addressPattern.test(info.from) && addressPattern.test(info.asset) && addressPattern.test(info.spender) && numericPattern.test(info.amount) && numericPattern.test(info.nonce) && numericPattern.test(info.deadline) && hexPattern.test(info.signature) && versionPattern.test(info.version);
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
// src/erc20-approval-gas-sponsoring/types.ts
|
|
1716
|
+
var ERC20_APPROVAL_GAS_SPONSORING = {
|
|
1717
|
+
key: "erc20ApprovalGasSponsoring"
|
|
1718
|
+
};
|
|
1719
|
+
var ERC20_APPROVAL_GAS_SPONSORING_VERSION = "1";
|
|
1720
|
+
function createErc20ApprovalGasSponsoringExtension(signer, client) {
|
|
1721
|
+
return {
|
|
1722
|
+
...ERC20_APPROVAL_GAS_SPONSORING,
|
|
1723
|
+
signer: {
|
|
1724
|
+
...signer,
|
|
1725
|
+
sendRawTransaction: client.sendRawTransaction.bind(client)
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
// src/erc20-approval-gas-sponsoring/resourceService.ts
|
|
1731
|
+
var erc20ApprovalGasSponsoringSchema = {
|
|
1732
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1733
|
+
type: "object",
|
|
1734
|
+
properties: {
|
|
1735
|
+
from: {
|
|
1736
|
+
type: "string",
|
|
1737
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1738
|
+
description: "The address of the sender (token owner)."
|
|
1739
|
+
},
|
|
1740
|
+
asset: {
|
|
1741
|
+
type: "string",
|
|
1742
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1743
|
+
description: "The address of the ERC-20 token contract."
|
|
1744
|
+
},
|
|
1745
|
+
spender: {
|
|
1746
|
+
type: "string",
|
|
1747
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1748
|
+
description: "The address of the spender (Canonical Permit2)."
|
|
1749
|
+
},
|
|
1750
|
+
amount: {
|
|
1751
|
+
type: "string",
|
|
1752
|
+
pattern: "^[0-9]+$",
|
|
1753
|
+
description: "The amount approved (uint256). Always MaxUint256."
|
|
1754
|
+
},
|
|
1755
|
+
signedTransaction: {
|
|
1756
|
+
type: "string",
|
|
1757
|
+
pattern: "^0x[a-fA-F0-9]+$",
|
|
1758
|
+
description: "The RLP-encoded signed EIP-1559 transaction as a hex string."
|
|
1759
|
+
},
|
|
1760
|
+
version: {
|
|
1761
|
+
type: "string",
|
|
1762
|
+
pattern: "^[0-9]+(\\.[0-9]+)*$",
|
|
1763
|
+
description: "Schema version identifier."
|
|
1764
|
+
}
|
|
1765
|
+
},
|
|
1766
|
+
required: ["from", "asset", "spender", "amount", "signedTransaction", "version"]
|
|
1767
|
+
};
|
|
1768
|
+
function declareErc20ApprovalGasSponsoringExtension() {
|
|
1769
|
+
const key = ERC20_APPROVAL_GAS_SPONSORING.key;
|
|
1770
|
+
return {
|
|
1771
|
+
[key]: {
|
|
1772
|
+
info: {
|
|
1773
|
+
description: "The facilitator broadcasts a pre-signed ERC-20 approve() transaction to grant Permit2 allowance.",
|
|
1774
|
+
version: ERC20_APPROVAL_GAS_SPONSORING_VERSION
|
|
1775
|
+
},
|
|
1776
|
+
schema: erc20ApprovalGasSponsoringSchema
|
|
1777
|
+
}
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
// src/erc20-approval-gas-sponsoring/facilitator.ts
|
|
1782
|
+
var import__3 = __toESM(require("ajv/dist/2020.js"));
|
|
1783
|
+
function extractErc20ApprovalGasSponsoringInfo(paymentPayload) {
|
|
1784
|
+
if (!paymentPayload.extensions) {
|
|
1785
|
+
return null;
|
|
1786
|
+
}
|
|
1787
|
+
const extension = paymentPayload.extensions[ERC20_APPROVAL_GAS_SPONSORING.key];
|
|
1788
|
+
if (!extension?.info) {
|
|
1789
|
+
return null;
|
|
1790
|
+
}
|
|
1791
|
+
const info = extension.info;
|
|
1792
|
+
if (!info.from || !info.asset || !info.spender || !info.amount || !info.signedTransaction || !info.version) {
|
|
1793
|
+
return null;
|
|
1794
|
+
}
|
|
1795
|
+
return info;
|
|
1796
|
+
}
|
|
1797
|
+
function validateErc20ApprovalGasSponsoringInfo(info) {
|
|
1798
|
+
const ajv = new import__3.default({ strict: false, allErrors: true });
|
|
1799
|
+
const validate = ajv.compile(erc20ApprovalGasSponsoringSchema);
|
|
1800
|
+
return validate(info);
|
|
1801
|
+
}
|
|
1802
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1803
|
+
0 && (module.exports = {
|
|
1804
|
+
BAZAAR,
|
|
1805
|
+
EIP2612_GAS_SPONSORING,
|
|
1806
|
+
ERC20_APPROVAL_GAS_SPONSORING,
|
|
1807
|
+
ERC20_APPROVAL_GAS_SPONSORING_VERSION,
|
|
1808
|
+
InMemorySIWxStorage,
|
|
1809
|
+
PAYMENT_IDENTIFIER,
|
|
1810
|
+
PAYMENT_ID_MAX_LENGTH,
|
|
1811
|
+
PAYMENT_ID_MIN_LENGTH,
|
|
1812
|
+
PAYMENT_ID_PATTERN,
|
|
1813
|
+
SIGN_IN_WITH_X,
|
|
1814
|
+
SIWxPayloadSchema,
|
|
1815
|
+
SOLANA_DEVNET,
|
|
1816
|
+
SOLANA_MAINNET,
|
|
1817
|
+
SOLANA_TESTNET,
|
|
1818
|
+
appendPaymentIdentifierToExtensions,
|
|
1819
|
+
bazaarResourceServerExtension,
|
|
1820
|
+
buildSIWxSchema,
|
|
1821
|
+
createErc20ApprovalGasSponsoringExtension,
|
|
1822
|
+
createSIWxClientHook,
|
|
1823
|
+
createSIWxMessage,
|
|
1824
|
+
createSIWxPayload,
|
|
1825
|
+
createSIWxRequestHook,
|
|
1826
|
+
createSIWxSettleHook,
|
|
1827
|
+
declareDiscoveryExtension,
|
|
1828
|
+
declareEip2612GasSponsoringExtension,
|
|
1829
|
+
declareErc20ApprovalGasSponsoringExtension,
|
|
1830
|
+
declarePaymentIdentifierExtension,
|
|
1831
|
+
declareSIWxExtension,
|
|
1832
|
+
decodeBase58,
|
|
1833
|
+
encodeBase58,
|
|
1834
|
+
encodeSIWxHeader,
|
|
1835
|
+
erc20ApprovalGasSponsoringSchema,
|
|
1836
|
+
extractAndValidatePaymentIdentifier,
|
|
1837
|
+
extractDiscoveryInfo,
|
|
1838
|
+
extractDiscoveryInfoFromExtension,
|
|
1839
|
+
extractDiscoveryInfoV1,
|
|
1840
|
+
extractEVMChainId,
|
|
1841
|
+
extractEip2612GasSponsoringInfo,
|
|
1842
|
+
extractErc20ApprovalGasSponsoringInfo,
|
|
1843
|
+
extractPaymentIdentifier,
|
|
1844
|
+
extractResourceMetadataV1,
|
|
1845
|
+
extractSolanaChainReference,
|
|
1846
|
+
formatSIWEMessage,
|
|
1847
|
+
formatSIWSMessage,
|
|
1848
|
+
generatePaymentId,
|
|
1849
|
+
getEVMAddress,
|
|
1850
|
+
getSolanaAddress,
|
|
1851
|
+
hasPaymentIdentifier,
|
|
1852
|
+
isBodyExtensionConfig,
|
|
1853
|
+
isDiscoverableV1,
|
|
1854
|
+
isEVMSigner,
|
|
1855
|
+
isMcpExtensionConfig,
|
|
1856
|
+
isPaymentIdentifierExtension,
|
|
1857
|
+
isPaymentIdentifierRequired,
|
|
1858
|
+
isQueryExtensionConfig,
|
|
1859
|
+
isSolanaSigner,
|
|
1860
|
+
isValidPaymentId,
|
|
1861
|
+
parseSIWxHeader,
|
|
1862
|
+
paymentIdentifierResourceServerExtension,
|
|
1863
|
+
paymentIdentifierSchema,
|
|
1864
|
+
signEVMMessage,
|
|
1865
|
+
signSolanaMessage,
|
|
1866
|
+
siwxResourceServerExtension,
|
|
1867
|
+
validateAndExtract,
|
|
1868
|
+
validateDiscoveryExtension,
|
|
1869
|
+
validateEip2612GasSponsoringInfo,
|
|
1870
|
+
validateErc20ApprovalGasSponsoringInfo,
|
|
1871
|
+
validatePaymentIdentifier,
|
|
1872
|
+
validatePaymentIdentifierRequirement,
|
|
1873
|
+
validateSIWxMessage,
|
|
1874
|
+
verifyEVMSignature,
|
|
1875
|
+
verifySIWxSignature,
|
|
1876
|
+
verifySolanaSignature,
|
|
1877
|
+
withBazaar,
|
|
1878
|
+
wrapFetchWithSIWx
|
|
1879
|
+
});
|
|
1880
|
+
//# sourceMappingURL=index.js.map
|