@t402/core 2.0.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.
Files changed (66) hide show
  1. package/README.md +293 -0
  2. package/dist/cjs/client/index.d.ts +103 -0
  3. package/dist/cjs/client/index.js +510 -0
  4. package/dist/cjs/client/index.js.map +1 -0
  5. package/dist/cjs/facilitator/index.d.ts +192 -0
  6. package/dist/cjs/facilitator/index.js +398 -0
  7. package/dist/cjs/facilitator/index.js.map +1 -0
  8. package/dist/cjs/http/index.d.ts +52 -0
  9. package/dist/cjs/http/index.js +763 -0
  10. package/dist/cjs/http/index.js.map +1 -0
  11. package/dist/cjs/index.d.ts +3 -0
  12. package/dist/cjs/index.js +31 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/mechanisms-CmrqNl1M.d.ts +238 -0
  15. package/dist/cjs/mechanisms-DsJn3ZiM.d.ts +238 -0
  16. package/dist/cjs/server/index.d.ts +2 -0
  17. package/dist/cjs/server/index.js +1241 -0
  18. package/dist/cjs/server/index.js.map +1 -0
  19. package/dist/cjs/t402HTTPClient-m6cjzTek.d.ts +243 -0
  20. package/dist/cjs/t402HTTPResourceServer-B-xmYMwj.d.ts +719 -0
  21. package/dist/cjs/t402HTTPResourceServer-Bcfxp2UO.d.ts +719 -0
  22. package/dist/cjs/types/index.d.ts +1 -0
  23. package/dist/cjs/types/index.js +19 -0
  24. package/dist/cjs/types/index.js.map +1 -0
  25. package/dist/cjs/types/v1/index.d.ts +1 -0
  26. package/dist/cjs/types/v1/index.js +19 -0
  27. package/dist/cjs/types/v1/index.js.map +1 -0
  28. package/dist/cjs/utils/index.d.ts +48 -0
  29. package/dist/cjs/utils/index.js +108 -0
  30. package/dist/cjs/utils/index.js.map +1 -0
  31. package/dist/esm/chunk-3IUBYRYG.mjs +78 -0
  32. package/dist/esm/chunk-3IUBYRYG.mjs.map +1 -0
  33. package/dist/esm/chunk-3VTYR43U.mjs +7 -0
  34. package/dist/esm/chunk-3VTYR43U.mjs.map +1 -0
  35. package/dist/esm/chunk-BJTO5JO5.mjs +11 -0
  36. package/dist/esm/chunk-BJTO5JO5.mjs.map +1 -0
  37. package/dist/esm/chunk-D5DYKKCZ.mjs +722 -0
  38. package/dist/esm/chunk-D5DYKKCZ.mjs.map +1 -0
  39. package/dist/esm/client/index.d.mts +103 -0
  40. package/dist/esm/client/index.mjs +356 -0
  41. package/dist/esm/client/index.mjs.map +1 -0
  42. package/dist/esm/facilitator/index.d.mts +192 -0
  43. package/dist/esm/facilitator/index.mjs +373 -0
  44. package/dist/esm/facilitator/index.mjs.map +1 -0
  45. package/dist/esm/http/index.d.mts +52 -0
  46. package/dist/esm/http/index.mjs +28 -0
  47. package/dist/esm/http/index.mjs.map +1 -0
  48. package/dist/esm/index.d.mts +3 -0
  49. package/dist/esm/index.mjs +8 -0
  50. package/dist/esm/index.mjs.map +1 -0
  51. package/dist/esm/mechanisms-CmrqNl1M.d.mts +238 -0
  52. package/dist/esm/server/index.d.mts +2 -0
  53. package/dist/esm/server/index.mjs +562 -0
  54. package/dist/esm/server/index.mjs.map +1 -0
  55. package/dist/esm/t402HTTPClient-C285YGCp.d.mts +243 -0
  56. package/dist/esm/t402HTTPResourceServer-k_l3d8ua.d.mts +719 -0
  57. package/dist/esm/types/index.d.mts +1 -0
  58. package/dist/esm/types/index.mjs +1 -0
  59. package/dist/esm/types/index.mjs.map +1 -0
  60. package/dist/esm/types/v1/index.d.mts +1 -0
  61. package/dist/esm/types/v1/index.mjs +1 -0
  62. package/dist/esm/types/v1/index.mjs.map +1 -0
  63. package/dist/esm/utils/index.d.mts +48 -0
  64. package/dist/esm/utils/index.mjs +20 -0
  65. package/dist/esm/utils/index.mjs.map +1 -0
  66. package/package.json +129 -0
@@ -0,0 +1,192 @@
1
+ import { a as PaymentPayload, P as PaymentRequirements, V as VerifyResponse, S as SettleResponse, N as Network, b as SchemeNetworkFacilitator } from '../mechanisms-CmrqNl1M.js';
2
+
3
+ /**
4
+ * Facilitator Hook Context Interfaces
5
+ */
6
+ interface FacilitatorVerifyContext {
7
+ paymentPayload: PaymentPayload;
8
+ requirements: PaymentRequirements;
9
+ }
10
+ interface FacilitatorVerifyResultContext extends FacilitatorVerifyContext {
11
+ result: VerifyResponse;
12
+ }
13
+ interface FacilitatorVerifyFailureContext extends FacilitatorVerifyContext {
14
+ error: Error;
15
+ }
16
+ interface FacilitatorSettleContext {
17
+ paymentPayload: PaymentPayload;
18
+ requirements: PaymentRequirements;
19
+ }
20
+ interface FacilitatorSettleResultContext extends FacilitatorSettleContext {
21
+ result: SettleResponse;
22
+ }
23
+ interface FacilitatorSettleFailureContext extends FacilitatorSettleContext {
24
+ error: Error;
25
+ }
26
+ /**
27
+ * Facilitator Hook Type Definitions
28
+ */
29
+ type FacilitatorBeforeVerifyHook = (context: FacilitatorVerifyContext) => Promise<void | {
30
+ abort: true;
31
+ reason: string;
32
+ }>;
33
+ type FacilitatorAfterVerifyHook = (context: FacilitatorVerifyResultContext) => Promise<void>;
34
+ type FacilitatorOnVerifyFailureHook = (context: FacilitatorVerifyFailureContext) => Promise<void | {
35
+ recovered: true;
36
+ result: VerifyResponse;
37
+ }>;
38
+ type FacilitatorBeforeSettleHook = (context: FacilitatorSettleContext) => Promise<void | {
39
+ abort: true;
40
+ reason: string;
41
+ }>;
42
+ type FacilitatorAfterSettleHook = (context: FacilitatorSettleResultContext) => Promise<void>;
43
+ type FacilitatorOnSettleFailureHook = (context: FacilitatorSettleFailureContext) => Promise<void | {
44
+ recovered: true;
45
+ result: SettleResponse;
46
+ }>;
47
+ /**
48
+ * Facilitator client for the t402 payment protocol.
49
+ * Manages payment scheme registration, verification, and settlement.
50
+ */
51
+ declare class t402Facilitator {
52
+ private readonly registeredFacilitatorSchemes;
53
+ private readonly extensions;
54
+ private beforeVerifyHooks;
55
+ private afterVerifyHooks;
56
+ private onVerifyFailureHooks;
57
+ private beforeSettleHooks;
58
+ private afterSettleHooks;
59
+ private onSettleFailureHooks;
60
+ /**
61
+ * Registers a scheme facilitator for the current t402 version.
62
+ * Networks are stored and used for getSupported() - no need to specify them later.
63
+ *
64
+ * @param networks - Single network or array of networks this facilitator supports
65
+ * @param facilitator - The scheme network facilitator to register
66
+ * @returns The t402Facilitator instance for chaining
67
+ */
68
+ register(networks: Network | Network[], facilitator: SchemeNetworkFacilitator): t402Facilitator;
69
+ /**
70
+ * Registers a scheme facilitator for t402 version 1.
71
+ * Networks are stored and used for getSupported() - no need to specify them later.
72
+ *
73
+ * @param networks - Single network or array of networks this facilitator supports
74
+ * @param facilitator - The scheme network facilitator to register
75
+ * @returns The t402Facilitator instance for chaining
76
+ */
77
+ registerV1(networks: Network | Network[], facilitator: SchemeNetworkFacilitator): t402Facilitator;
78
+ /**
79
+ * Registers a protocol extension.
80
+ *
81
+ * @param extension - The extension name to register (e.g., "bazaar", "sign_in_with_x")
82
+ * @returns The t402Facilitator instance for chaining
83
+ */
84
+ registerExtension(extension: string): t402Facilitator;
85
+ /**
86
+ * Gets the list of registered extensions.
87
+ *
88
+ * @returns Array of extension names
89
+ */
90
+ getExtensions(): string[];
91
+ /**
92
+ * Register a hook to execute before facilitator payment verification.
93
+ * Can abort verification by returning { abort: true, reason: string }
94
+ *
95
+ * @param hook - The hook function to register
96
+ * @returns The t402Facilitator instance for chaining
97
+ */
98
+ onBeforeVerify(hook: FacilitatorBeforeVerifyHook): t402Facilitator;
99
+ /**
100
+ * Register a hook to execute after successful facilitator payment verification (isValid: true).
101
+ * This hook is NOT called when verification fails (isValid: false) - use onVerifyFailure for that.
102
+ *
103
+ * @param hook - The hook function to register
104
+ * @returns The t402Facilitator instance for chaining
105
+ */
106
+ onAfterVerify(hook: FacilitatorAfterVerifyHook): t402Facilitator;
107
+ /**
108
+ * Register a hook to execute when facilitator payment verification fails.
109
+ * Called when: verification returns isValid: false, or an exception is thrown during verification.
110
+ * Can recover from failure by returning { recovered: true, result: VerifyResponse }
111
+ *
112
+ * @param hook - The hook function to register
113
+ * @returns The t402Facilitator instance for chaining
114
+ */
115
+ onVerifyFailure(hook: FacilitatorOnVerifyFailureHook): t402Facilitator;
116
+ /**
117
+ * Register a hook to execute before facilitator payment settlement.
118
+ * Can abort settlement by returning { abort: true, reason: string }
119
+ *
120
+ * @param hook - The hook function to register
121
+ * @returns The t402Facilitator instance for chaining
122
+ */
123
+ onBeforeSettle(hook: FacilitatorBeforeSettleHook): t402Facilitator;
124
+ /**
125
+ * Register a hook to execute after successful facilitator payment settlement.
126
+ *
127
+ * @param hook - The hook function to register
128
+ * @returns The t402Facilitator instance for chaining
129
+ */
130
+ onAfterSettle(hook: FacilitatorAfterSettleHook): t402Facilitator;
131
+ /**
132
+ * Register a hook to execute when facilitator payment settlement fails.
133
+ * Can recover from failure by returning { recovered: true, result: SettleResponse }
134
+ *
135
+ * @param hook - The hook function to register
136
+ * @returns The t402Facilitator instance for chaining
137
+ */
138
+ onSettleFailure(hook: FacilitatorOnSettleFailureHook): t402Facilitator;
139
+ /**
140
+ * Gets supported payment kinds, extensions, and signers.
141
+ * Uses networks registered during register() calls - no parameters needed.
142
+ * Returns flat array format for backward compatibility with V1 clients.
143
+ *
144
+ * @returns Supported response with kinds as array (with version in each element), extensions, and signers
145
+ */
146
+ getSupported(): {
147
+ kinds: Array<{
148
+ t402Version: number;
149
+ scheme: string;
150
+ network: string;
151
+ extra?: Record<string, unknown>;
152
+ }>;
153
+ extensions: string[];
154
+ signers: Record<string, string[]>;
155
+ };
156
+ /**
157
+ * Verifies a payment payload against requirements.
158
+ *
159
+ * @param paymentPayload - The payment payload to verify
160
+ * @param paymentRequirements - The payment requirements to verify against
161
+ * @returns Promise resolving to the verification response
162
+ */
163
+ verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
164
+ /**
165
+ * Settles a payment based on the payload and requirements.
166
+ *
167
+ * @param paymentPayload - The payment payload to settle
168
+ * @param paymentRequirements - The payment requirements for settlement
169
+ * @returns Promise resolving to the settlement response
170
+ */
171
+ settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
172
+ /**
173
+ * Internal method to register a scheme facilitator.
174
+ *
175
+ * @param t402Version - The t402 protocol version
176
+ * @param networks - Array of concrete networks this facilitator supports
177
+ * @param facilitator - The scheme network facilitator to register
178
+ * @returns The t402Facilitator instance for chaining
179
+ */
180
+ private _registerScheme;
181
+ /**
182
+ * Derives a wildcard pattern from an array of networks.
183
+ * If all networks share the same namespace, returns wildcard pattern.
184
+ * Otherwise returns the first network for exact matching.
185
+ *
186
+ * @param networks - Array of networks
187
+ * @returns Derived pattern for matching
188
+ */
189
+ private derivePattern;
190
+ }
191
+
192
+ export { type FacilitatorAfterSettleHook, type FacilitatorAfterVerifyHook, type FacilitatorBeforeSettleHook, type FacilitatorBeforeVerifyHook, type FacilitatorOnSettleFailureHook, type FacilitatorOnVerifyFailureHook, type FacilitatorSettleContext, type FacilitatorSettleFailureContext, type FacilitatorSettleResultContext, type FacilitatorVerifyContext, type FacilitatorVerifyFailureContext, type FacilitatorVerifyResultContext, t402Facilitator };
@@ -0,0 +1,398 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/facilitator/index.ts
21
+ var facilitator_exports = {};
22
+ __export(facilitator_exports, {
23
+ t402Facilitator: () => t402Facilitator
24
+ });
25
+ module.exports = __toCommonJS(facilitator_exports);
26
+
27
+ // src/index.ts
28
+ var t402Version = 2;
29
+
30
+ // src/facilitator/t402Facilitator.ts
31
+ var t402Facilitator = class {
32
+ constructor() {
33
+ this.registeredFacilitatorSchemes = /* @__PURE__ */ new Map();
34
+ this.extensions = [];
35
+ this.beforeVerifyHooks = [];
36
+ this.afterVerifyHooks = [];
37
+ this.onVerifyFailureHooks = [];
38
+ this.beforeSettleHooks = [];
39
+ this.afterSettleHooks = [];
40
+ this.onSettleFailureHooks = [];
41
+ }
42
+ /**
43
+ * Registers a scheme facilitator for the current t402 version.
44
+ * Networks are stored and used for getSupported() - no need to specify them later.
45
+ *
46
+ * @param networks - Single network or array of networks this facilitator supports
47
+ * @param facilitator - The scheme network facilitator to register
48
+ * @returns The t402Facilitator instance for chaining
49
+ */
50
+ register(networks, facilitator) {
51
+ const networksArray = Array.isArray(networks) ? networks : [networks];
52
+ return this._registerScheme(t402Version, networksArray, facilitator);
53
+ }
54
+ /**
55
+ * Registers a scheme facilitator for t402 version 1.
56
+ * Networks are stored and used for getSupported() - no need to specify them later.
57
+ *
58
+ * @param networks - Single network or array of networks this facilitator supports
59
+ * @param facilitator - The scheme network facilitator to register
60
+ * @returns The t402Facilitator instance for chaining
61
+ */
62
+ registerV1(networks, facilitator) {
63
+ const networksArray = Array.isArray(networks) ? networks : [networks];
64
+ return this._registerScheme(1, networksArray, facilitator);
65
+ }
66
+ /**
67
+ * Registers a protocol extension.
68
+ *
69
+ * @param extension - The extension name to register (e.g., "bazaar", "sign_in_with_x")
70
+ * @returns The t402Facilitator instance for chaining
71
+ */
72
+ registerExtension(extension) {
73
+ if (!this.extensions.includes(extension)) {
74
+ this.extensions.push(extension);
75
+ }
76
+ return this;
77
+ }
78
+ /**
79
+ * Gets the list of registered extensions.
80
+ *
81
+ * @returns Array of extension names
82
+ */
83
+ getExtensions() {
84
+ return [...this.extensions];
85
+ }
86
+ /**
87
+ * Register a hook to execute before facilitator payment verification.
88
+ * Can abort verification by returning { abort: true, reason: string }
89
+ *
90
+ * @param hook - The hook function to register
91
+ * @returns The t402Facilitator instance for chaining
92
+ */
93
+ onBeforeVerify(hook) {
94
+ this.beforeVerifyHooks.push(hook);
95
+ return this;
96
+ }
97
+ /**
98
+ * Register a hook to execute after successful facilitator payment verification (isValid: true).
99
+ * This hook is NOT called when verification fails (isValid: false) - use onVerifyFailure for that.
100
+ *
101
+ * @param hook - The hook function to register
102
+ * @returns The t402Facilitator instance for chaining
103
+ */
104
+ onAfterVerify(hook) {
105
+ this.afterVerifyHooks.push(hook);
106
+ return this;
107
+ }
108
+ /**
109
+ * Register a hook to execute when facilitator payment verification fails.
110
+ * Called when: verification returns isValid: false, or an exception is thrown during verification.
111
+ * Can recover from failure by returning { recovered: true, result: VerifyResponse }
112
+ *
113
+ * @param hook - The hook function to register
114
+ * @returns The t402Facilitator instance for chaining
115
+ */
116
+ onVerifyFailure(hook) {
117
+ this.onVerifyFailureHooks.push(hook);
118
+ return this;
119
+ }
120
+ /**
121
+ * Register a hook to execute before facilitator payment settlement.
122
+ * Can abort settlement by returning { abort: true, reason: string }
123
+ *
124
+ * @param hook - The hook function to register
125
+ * @returns The t402Facilitator instance for chaining
126
+ */
127
+ onBeforeSettle(hook) {
128
+ this.beforeSettleHooks.push(hook);
129
+ return this;
130
+ }
131
+ /**
132
+ * Register a hook to execute after successful facilitator payment settlement.
133
+ *
134
+ * @param hook - The hook function to register
135
+ * @returns The t402Facilitator instance for chaining
136
+ */
137
+ onAfterSettle(hook) {
138
+ this.afterSettleHooks.push(hook);
139
+ return this;
140
+ }
141
+ /**
142
+ * Register a hook to execute when facilitator payment settlement fails.
143
+ * Can recover from failure by returning { recovered: true, result: SettleResponse }
144
+ *
145
+ * @param hook - The hook function to register
146
+ * @returns The t402Facilitator instance for chaining
147
+ */
148
+ onSettleFailure(hook) {
149
+ this.onSettleFailureHooks.push(hook);
150
+ return this;
151
+ }
152
+ /**
153
+ * Gets supported payment kinds, extensions, and signers.
154
+ * Uses networks registered during register() calls - no parameters needed.
155
+ * Returns flat array format for backward compatibility with V1 clients.
156
+ *
157
+ * @returns Supported response with kinds as array (with version in each element), extensions, and signers
158
+ */
159
+ getSupported() {
160
+ const kinds = [];
161
+ const signersByFamily = {};
162
+ for (const [version, schemeDataArray] of this.registeredFacilitatorSchemes) {
163
+ for (const schemeData of schemeDataArray) {
164
+ const { facilitator, networks } = schemeData;
165
+ const scheme = facilitator.scheme;
166
+ for (const network of networks) {
167
+ const extra = facilitator.getExtra(network);
168
+ kinds.push({
169
+ t402Version: version,
170
+ scheme,
171
+ network,
172
+ ...extra && { extra }
173
+ });
174
+ const family = facilitator.caipFamily;
175
+ if (!signersByFamily[family]) {
176
+ signersByFamily[family] = /* @__PURE__ */ new Set();
177
+ }
178
+ facilitator.getSigners(network).forEach((signer) => signersByFamily[family].add(signer));
179
+ }
180
+ }
181
+ }
182
+ const signers = {};
183
+ for (const [family, signerSet] of Object.entries(signersByFamily)) {
184
+ signers[family] = Array.from(signerSet);
185
+ }
186
+ return {
187
+ kinds,
188
+ extensions: this.extensions,
189
+ signers
190
+ };
191
+ }
192
+ /**
193
+ * Verifies a payment payload against requirements.
194
+ *
195
+ * @param paymentPayload - The payment payload to verify
196
+ * @param paymentRequirements - The payment requirements to verify against
197
+ * @returns Promise resolving to the verification response
198
+ */
199
+ async verify(paymentPayload, paymentRequirements) {
200
+ const context = {
201
+ paymentPayload,
202
+ requirements: paymentRequirements
203
+ };
204
+ for (const hook of this.beforeVerifyHooks) {
205
+ const result = await hook(context);
206
+ if (result && "abort" in result && result.abort) {
207
+ return {
208
+ isValid: false,
209
+ invalidReason: result.reason
210
+ };
211
+ }
212
+ }
213
+ try {
214
+ const schemeDataArray = this.registeredFacilitatorSchemes.get(paymentPayload.t402Version);
215
+ if (!schemeDataArray) {
216
+ throw new Error(
217
+ `No facilitator registered for t402 version: ${paymentPayload.t402Version}`
218
+ );
219
+ }
220
+ let schemeNetworkFacilitator;
221
+ for (const schemeData of schemeDataArray) {
222
+ if (schemeData.facilitator.scheme === paymentRequirements.scheme) {
223
+ if (schemeData.networks.has(paymentRequirements.network)) {
224
+ schemeNetworkFacilitator = schemeData.facilitator;
225
+ break;
226
+ }
227
+ const patternRegex = new RegExp("^" + schemeData.pattern.replace("*", ".*") + "$");
228
+ if (patternRegex.test(paymentRequirements.network)) {
229
+ schemeNetworkFacilitator = schemeData.facilitator;
230
+ break;
231
+ }
232
+ }
233
+ }
234
+ if (!schemeNetworkFacilitator) {
235
+ throw new Error(
236
+ `No facilitator registered for scheme: ${paymentRequirements.scheme} and network: ${paymentRequirements.network}`
237
+ );
238
+ }
239
+ const verifyResult = await schemeNetworkFacilitator.verify(
240
+ paymentPayload,
241
+ paymentRequirements
242
+ );
243
+ if (!verifyResult.isValid) {
244
+ const failureContext = {
245
+ ...context,
246
+ error: new Error(verifyResult.invalidReason || "Verification failed")
247
+ };
248
+ for (const hook of this.onVerifyFailureHooks) {
249
+ const result = await hook(failureContext);
250
+ if (result && "recovered" in result && result.recovered) {
251
+ const recoveredContext = {
252
+ ...context,
253
+ result: result.result
254
+ };
255
+ for (const hook2 of this.afterVerifyHooks) {
256
+ await hook2(recoveredContext);
257
+ }
258
+ return result.result;
259
+ }
260
+ }
261
+ return verifyResult;
262
+ }
263
+ const resultContext = {
264
+ ...context,
265
+ result: verifyResult
266
+ };
267
+ for (const hook of this.afterVerifyHooks) {
268
+ await hook(resultContext);
269
+ }
270
+ return verifyResult;
271
+ } catch (error) {
272
+ const failureContext = {
273
+ ...context,
274
+ error
275
+ };
276
+ for (const hook of this.onVerifyFailureHooks) {
277
+ const result = await hook(failureContext);
278
+ if (result && "recovered" in result && result.recovered) {
279
+ return result.result;
280
+ }
281
+ }
282
+ throw error;
283
+ }
284
+ }
285
+ /**
286
+ * Settles a payment based on the payload and requirements.
287
+ *
288
+ * @param paymentPayload - The payment payload to settle
289
+ * @param paymentRequirements - The payment requirements for settlement
290
+ * @returns Promise resolving to the settlement response
291
+ */
292
+ async settle(paymentPayload, paymentRequirements) {
293
+ const context = {
294
+ paymentPayload,
295
+ requirements: paymentRequirements
296
+ };
297
+ for (const hook of this.beforeSettleHooks) {
298
+ const result = await hook(context);
299
+ if (result && "abort" in result && result.abort) {
300
+ throw new Error(`Settlement aborted: ${result.reason}`);
301
+ }
302
+ }
303
+ try {
304
+ const schemeDataArray = this.registeredFacilitatorSchemes.get(paymentPayload.t402Version);
305
+ if (!schemeDataArray) {
306
+ throw new Error(
307
+ `No facilitator registered for t402 version: ${paymentPayload.t402Version}`
308
+ );
309
+ }
310
+ let schemeNetworkFacilitator;
311
+ for (const schemeData of schemeDataArray) {
312
+ if (schemeData.facilitator.scheme === paymentRequirements.scheme) {
313
+ if (schemeData.networks.has(paymentRequirements.network)) {
314
+ schemeNetworkFacilitator = schemeData.facilitator;
315
+ break;
316
+ }
317
+ const patternRegex = new RegExp("^" + schemeData.pattern.replace("*", ".*") + "$");
318
+ if (patternRegex.test(paymentRequirements.network)) {
319
+ schemeNetworkFacilitator = schemeData.facilitator;
320
+ break;
321
+ }
322
+ }
323
+ }
324
+ if (!schemeNetworkFacilitator) {
325
+ throw new Error(
326
+ `No facilitator registered for scheme: ${paymentRequirements.scheme} and network: ${paymentRequirements.network}`
327
+ );
328
+ }
329
+ const settleResult = await schemeNetworkFacilitator.settle(
330
+ paymentPayload,
331
+ paymentRequirements
332
+ );
333
+ const resultContext = {
334
+ ...context,
335
+ result: settleResult
336
+ };
337
+ for (const hook of this.afterSettleHooks) {
338
+ await hook(resultContext);
339
+ }
340
+ return settleResult;
341
+ } catch (error) {
342
+ const failureContext = {
343
+ ...context,
344
+ error
345
+ };
346
+ for (const hook of this.onSettleFailureHooks) {
347
+ const result = await hook(failureContext);
348
+ if (result && "recovered" in result && result.recovered) {
349
+ return result.result;
350
+ }
351
+ }
352
+ throw error;
353
+ }
354
+ }
355
+ /**
356
+ * Internal method to register a scheme facilitator.
357
+ *
358
+ * @param t402Version - The t402 protocol version
359
+ * @param networks - Array of concrete networks this facilitator supports
360
+ * @param facilitator - The scheme network facilitator to register
361
+ * @returns The t402Facilitator instance for chaining
362
+ */
363
+ _registerScheme(t402Version2, networks, facilitator) {
364
+ if (!this.registeredFacilitatorSchemes.has(t402Version2)) {
365
+ this.registeredFacilitatorSchemes.set(t402Version2, []);
366
+ }
367
+ const schemeDataArray = this.registeredFacilitatorSchemes.get(t402Version2);
368
+ schemeDataArray.push({
369
+ facilitator,
370
+ networks: new Set(networks),
371
+ pattern: this.derivePattern(networks)
372
+ });
373
+ return this;
374
+ }
375
+ /**
376
+ * Derives a wildcard pattern from an array of networks.
377
+ * If all networks share the same namespace, returns wildcard pattern.
378
+ * Otherwise returns the first network for exact matching.
379
+ *
380
+ * @param networks - Array of networks
381
+ * @returns Derived pattern for matching
382
+ */
383
+ derivePattern(networks) {
384
+ if (networks.length === 0) return "";
385
+ if (networks.length === 1) return networks[0];
386
+ const namespaces = networks.map((n) => n.split(":")[0]);
387
+ const uniqueNamespaces = new Set(namespaces);
388
+ if (uniqueNamespaces.size === 1) {
389
+ return `${namespaces[0]}:*`;
390
+ }
391
+ return networks[0];
392
+ }
393
+ };
394
+ // Annotate the CommonJS export names for ESM import in node:
395
+ 0 && (module.exports = {
396
+ t402Facilitator
397
+ });
398
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/facilitator/index.ts","../../../src/index.ts","../../../src/facilitator/t402Facilitator.ts"],"sourcesContent":["export * from \"./t402Facilitator\";\n","export const t402Version = 2;\n","import { t402Version } from \"..\";\nimport { SettleResponse, VerifyResponse } from \"../types/facilitator\";\nimport { SchemeNetworkFacilitator } from \"../types/mechanisms\";\nimport { PaymentPayload, PaymentRequirements } from \"../types/payments\";\nimport { Network } from \"../types\";\nimport { type SchemeData } from \"../utils\";\n\n/**\n * Facilitator Hook Context Interfaces\n */\n\nexport interface FacilitatorVerifyContext {\n paymentPayload: PaymentPayload;\n requirements: PaymentRequirements;\n}\n\nexport interface FacilitatorVerifyResultContext extends FacilitatorVerifyContext {\n result: VerifyResponse;\n}\n\nexport interface FacilitatorVerifyFailureContext extends FacilitatorVerifyContext {\n error: Error;\n}\n\nexport interface FacilitatorSettleContext {\n paymentPayload: PaymentPayload;\n requirements: PaymentRequirements;\n}\n\nexport interface FacilitatorSettleResultContext extends FacilitatorSettleContext {\n result: SettleResponse;\n}\n\nexport interface FacilitatorSettleFailureContext extends FacilitatorSettleContext {\n error: Error;\n}\n\n/**\n * Facilitator Hook Type Definitions\n */\n\nexport type FacilitatorBeforeVerifyHook = (\n context: FacilitatorVerifyContext,\n) => Promise<void | { abort: true; reason: string }>;\n\nexport type FacilitatorAfterVerifyHook = (context: FacilitatorVerifyResultContext) => Promise<void>;\n\nexport type FacilitatorOnVerifyFailureHook = (\n context: FacilitatorVerifyFailureContext,\n) => Promise<void | { recovered: true; result: VerifyResponse }>;\n\nexport type FacilitatorBeforeSettleHook = (\n context: FacilitatorSettleContext,\n) => Promise<void | { abort: true; reason: string }>;\n\nexport type FacilitatorAfterSettleHook = (context: FacilitatorSettleResultContext) => Promise<void>;\n\nexport type FacilitatorOnSettleFailureHook = (\n context: FacilitatorSettleFailureContext,\n) => Promise<void | { recovered: true; result: SettleResponse }>;\n\n/**\n * Facilitator client for the t402 payment protocol.\n * Manages payment scheme registration, verification, and settlement.\n */\nexport class t402Facilitator {\n private readonly registeredFacilitatorSchemes: Map<\n number,\n SchemeData<SchemeNetworkFacilitator>[] // Array to support multiple facilitators per version\n > = new Map();\n private readonly extensions: string[] = [];\n\n private beforeVerifyHooks: FacilitatorBeforeVerifyHook[] = [];\n private afterVerifyHooks: FacilitatorAfterVerifyHook[] = [];\n private onVerifyFailureHooks: FacilitatorOnVerifyFailureHook[] = [];\n private beforeSettleHooks: FacilitatorBeforeSettleHook[] = [];\n private afterSettleHooks: FacilitatorAfterSettleHook[] = [];\n private onSettleFailureHooks: FacilitatorOnSettleFailureHook[] = [];\n\n /**\n * Registers a scheme facilitator for the current t402 version.\n * Networks are stored and used for getSupported() - no need to specify them later.\n *\n * @param networks - Single network or array of networks this facilitator supports\n * @param facilitator - The scheme network facilitator to register\n * @returns The t402Facilitator instance for chaining\n */\n register(networks: Network | Network[], facilitator: SchemeNetworkFacilitator): t402Facilitator {\n const networksArray = Array.isArray(networks) ? networks : [networks];\n return this._registerScheme(t402Version, networksArray, facilitator);\n }\n\n /**\n * Registers a scheme facilitator for t402 version 1.\n * Networks are stored and used for getSupported() - no need to specify them later.\n *\n * @param networks - Single network or array of networks this facilitator supports\n * @param facilitator - The scheme network facilitator to register\n * @returns The t402Facilitator instance for chaining\n */\n registerV1(\n networks: Network | Network[],\n facilitator: SchemeNetworkFacilitator,\n ): t402Facilitator {\n const networksArray = Array.isArray(networks) ? networks : [networks];\n return this._registerScheme(1, networksArray, facilitator);\n }\n\n /**\n * Registers a protocol extension.\n *\n * @param extension - The extension name to register (e.g., \"bazaar\", \"sign_in_with_x\")\n * @returns The t402Facilitator instance for chaining\n */\n registerExtension(extension: string): t402Facilitator {\n // Check if already registered\n if (!this.extensions.includes(extension)) {\n this.extensions.push(extension);\n }\n return this;\n }\n\n /**\n * Gets the list of registered extensions.\n *\n * @returns Array of extension names\n */\n getExtensions(): string[] {\n return [...this.extensions];\n }\n\n /**\n * Register a hook to execute before facilitator payment verification.\n * Can abort verification by returning { abort: true, reason: string }\n *\n * @param hook - The hook function to register\n * @returns The t402Facilitator instance for chaining\n */\n onBeforeVerify(hook: FacilitatorBeforeVerifyHook): t402Facilitator {\n this.beforeVerifyHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute after successful facilitator payment verification (isValid: true).\n * This hook is NOT called when verification fails (isValid: false) - use onVerifyFailure for that.\n *\n * @param hook - The hook function to register\n * @returns The t402Facilitator instance for chaining\n */\n onAfterVerify(hook: FacilitatorAfterVerifyHook): t402Facilitator {\n this.afterVerifyHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute when facilitator payment verification fails.\n * Called when: verification returns isValid: false, or an exception is thrown during verification.\n * Can recover from failure by returning { recovered: true, result: VerifyResponse }\n *\n * @param hook - The hook function to register\n * @returns The t402Facilitator instance for chaining\n */\n onVerifyFailure(hook: FacilitatorOnVerifyFailureHook): t402Facilitator {\n this.onVerifyFailureHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute before facilitator payment settlement.\n * Can abort settlement by returning { abort: true, reason: string }\n *\n * @param hook - The hook function to register\n * @returns The t402Facilitator instance for chaining\n */\n onBeforeSettle(hook: FacilitatorBeforeSettleHook): t402Facilitator {\n this.beforeSettleHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute after successful facilitator payment settlement.\n *\n * @param hook - The hook function to register\n * @returns The t402Facilitator instance for chaining\n */\n onAfterSettle(hook: FacilitatorAfterSettleHook): t402Facilitator {\n this.afterSettleHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute when facilitator payment settlement fails.\n * Can recover from failure by returning { recovered: true, result: SettleResponse }\n *\n * @param hook - The hook function to register\n * @returns The t402Facilitator instance for chaining\n */\n onSettleFailure(hook: FacilitatorOnSettleFailureHook): t402Facilitator {\n this.onSettleFailureHooks.push(hook);\n return this;\n }\n\n /**\n * Gets supported payment kinds, extensions, and signers.\n * Uses networks registered during register() calls - no parameters needed.\n * Returns flat array format for backward compatibility with V1 clients.\n *\n * @returns Supported response with kinds as array (with version in each element), extensions, and signers\n */\n getSupported(): {\n kinds: Array<{\n t402Version: number;\n scheme: string;\n network: string;\n extra?: Record<string, unknown>;\n }>;\n extensions: string[];\n signers: Record<string, string[]>;\n } {\n const kinds: Array<{\n t402Version: number;\n scheme: string;\n network: string;\n extra?: Record<string, unknown>;\n }> = [];\n const signersByFamily: Record<string, Set<string>> = {};\n\n // Iterate over registered scheme data (array supports multiple facilitators per version)\n for (const [version, schemeDataArray] of this.registeredFacilitatorSchemes) {\n for (const schemeData of schemeDataArray) {\n const { facilitator, networks } = schemeData;\n const scheme = facilitator.scheme;\n\n // Iterate over stored concrete networks\n for (const network of networks) {\n const extra = facilitator.getExtra(network);\n kinds.push({\n t402Version: version,\n scheme,\n network,\n ...(extra && { extra }),\n });\n\n // Collect signers by CAIP family for this network\n const family = facilitator.caipFamily;\n if (!signersByFamily[family]) {\n signersByFamily[family] = new Set();\n }\n facilitator.getSigners(network).forEach(signer => signersByFamily[family].add(signer));\n }\n }\n }\n\n // Convert signer sets to arrays\n const signers: Record<string, string[]> = {};\n for (const [family, signerSet] of Object.entries(signersByFamily)) {\n signers[family] = Array.from(signerSet);\n }\n\n return {\n kinds,\n extensions: this.extensions,\n signers,\n };\n }\n\n /**\n * Verifies a payment payload against requirements.\n *\n * @param paymentPayload - The payment payload to verify\n * @param paymentRequirements - The payment requirements to verify against\n * @returns Promise resolving to the verification response\n */\n async verify(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n const context: FacilitatorVerifyContext = {\n paymentPayload,\n requirements: paymentRequirements,\n };\n\n // Execute beforeVerify hooks\n for (const hook of this.beforeVerifyHooks) {\n const result = await hook(context);\n if (result && \"abort\" in result && result.abort) {\n return {\n isValid: false,\n invalidReason: result.reason,\n };\n }\n }\n\n try {\n const schemeDataArray = this.registeredFacilitatorSchemes.get(paymentPayload.t402Version);\n if (!schemeDataArray) {\n throw new Error(\n `No facilitator registered for t402 version: ${paymentPayload.t402Version}`,\n );\n }\n\n // Find matching facilitator from array\n let schemeNetworkFacilitator: SchemeNetworkFacilitator | undefined;\n for (const schemeData of schemeDataArray) {\n if (schemeData.facilitator.scheme === paymentRequirements.scheme) {\n // Check if network matches\n if (schemeData.networks.has(paymentRequirements.network)) {\n schemeNetworkFacilitator = schemeData.facilitator;\n break;\n }\n // Try pattern matching\n const patternRegex = new RegExp(\"^\" + schemeData.pattern.replace(\"*\", \".*\") + \"$\");\n if (patternRegex.test(paymentRequirements.network)) {\n schemeNetworkFacilitator = schemeData.facilitator;\n break;\n }\n }\n }\n\n if (!schemeNetworkFacilitator) {\n throw new Error(\n `No facilitator registered for scheme: ${paymentRequirements.scheme} and network: ${paymentRequirements.network}`,\n );\n }\n\n const verifyResult = await schemeNetworkFacilitator.verify(\n paymentPayload,\n paymentRequirements,\n );\n\n // Check if verification failed (isValid: false)\n if (!verifyResult.isValid) {\n const failureContext: FacilitatorVerifyFailureContext = {\n ...context,\n error: new Error(verifyResult.invalidReason || \"Verification failed\"),\n };\n\n // Execute onVerifyFailure hooks\n for (const hook of this.onVerifyFailureHooks) {\n const result = await hook(failureContext);\n if (result && \"recovered\" in result && result.recovered) {\n // If recovered, execute afterVerify hooks with recovered result\n const recoveredContext: FacilitatorVerifyResultContext = {\n ...context,\n result: result.result,\n };\n for (const hook of this.afterVerifyHooks) {\n await hook(recoveredContext);\n }\n return result.result;\n }\n }\n\n return verifyResult;\n }\n\n // Execute afterVerify hooks only for successful verification\n const resultContext: FacilitatorVerifyResultContext = {\n ...context,\n result: verifyResult,\n };\n\n for (const hook of this.afterVerifyHooks) {\n await hook(resultContext);\n }\n\n return verifyResult;\n } catch (error) {\n const failureContext: FacilitatorVerifyFailureContext = {\n ...context,\n error: error as Error,\n };\n\n // Execute onVerifyFailure hooks\n for (const hook of this.onVerifyFailureHooks) {\n const result = await hook(failureContext);\n if (result && \"recovered\" in result && result.recovered) {\n return result.result;\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Settles a payment based on the payload and requirements.\n *\n * @param paymentPayload - The payment payload to settle\n * @param paymentRequirements - The payment requirements for settlement\n * @returns Promise resolving to the settlement response\n */\n async settle(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n ): Promise<SettleResponse> {\n const context: FacilitatorSettleContext = {\n paymentPayload,\n requirements: paymentRequirements,\n };\n\n // Execute beforeSettle hooks\n for (const hook of this.beforeSettleHooks) {\n const result = await hook(context);\n if (result && \"abort\" in result && result.abort) {\n throw new Error(`Settlement aborted: ${result.reason}`);\n }\n }\n\n try {\n const schemeDataArray = this.registeredFacilitatorSchemes.get(paymentPayload.t402Version);\n if (!schemeDataArray) {\n throw new Error(\n `No facilitator registered for t402 version: ${paymentPayload.t402Version}`,\n );\n }\n\n // Find matching facilitator from array\n let schemeNetworkFacilitator: SchemeNetworkFacilitator | undefined;\n for (const schemeData of schemeDataArray) {\n if (schemeData.facilitator.scheme === paymentRequirements.scheme) {\n // Check if network matches\n if (schemeData.networks.has(paymentRequirements.network)) {\n schemeNetworkFacilitator = schemeData.facilitator;\n break;\n }\n // Try pattern matching\n const patternRegex = new RegExp(\"^\" + schemeData.pattern.replace(\"*\", \".*\") + \"$\");\n if (patternRegex.test(paymentRequirements.network)) {\n schemeNetworkFacilitator = schemeData.facilitator;\n break;\n }\n }\n }\n\n if (!schemeNetworkFacilitator) {\n throw new Error(\n `No facilitator registered for scheme: ${paymentRequirements.scheme} and network: ${paymentRequirements.network}`,\n );\n }\n\n const settleResult = await schemeNetworkFacilitator.settle(\n paymentPayload,\n paymentRequirements,\n );\n\n // Execute afterSettle hooks\n const resultContext: FacilitatorSettleResultContext = {\n ...context,\n result: settleResult,\n };\n\n for (const hook of this.afterSettleHooks) {\n await hook(resultContext);\n }\n\n return settleResult;\n } catch (error) {\n const failureContext: FacilitatorSettleFailureContext = {\n ...context,\n error: error as Error,\n };\n\n // Execute onSettleFailure hooks\n for (const hook of this.onSettleFailureHooks) {\n const result = await hook(failureContext);\n if (result && \"recovered\" in result && result.recovered) {\n return result.result;\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Internal method to register a scheme facilitator.\n *\n * @param t402Version - The t402 protocol version\n * @param networks - Array of concrete networks this facilitator supports\n * @param facilitator - The scheme network facilitator to register\n * @returns The t402Facilitator instance for chaining\n */\n private _registerScheme(\n t402Version: number,\n networks: Network[],\n facilitator: SchemeNetworkFacilitator,\n ): t402Facilitator {\n if (!this.registeredFacilitatorSchemes.has(t402Version)) {\n this.registeredFacilitatorSchemes.set(t402Version, []);\n }\n const schemeDataArray = this.registeredFacilitatorSchemes.get(t402Version)!;\n\n // Add new scheme data (supports multiple facilitators with same scheme name)\n schemeDataArray.push({\n facilitator,\n networks: new Set(networks),\n pattern: this.derivePattern(networks),\n });\n\n return this;\n }\n\n /**\n * Derives a wildcard pattern from an array of networks.\n * If all networks share the same namespace, returns wildcard pattern.\n * Otherwise returns the first network for exact matching.\n *\n * @param networks - Array of networks\n * @returns Derived pattern for matching\n */\n private derivePattern(networks: Network[]): Network {\n if (networks.length === 0) return \"\" as Network;\n if (networks.length === 1) return networks[0];\n\n // Extract namespaces (e.g., \"eip155\" from \"eip155:84532\")\n const namespaces = networks.map(n => n.split(\":\")[0]);\n const uniqueNamespaces = new Set(namespaces);\n\n // If all same namespace, use wildcard\n if (uniqueNamespaces.size === 1) {\n return `${namespaces[0]}:*` as Network;\n }\n\n // Mixed namespaces - use first network for exact matching\n return networks[0];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,cAAc;;;ACiEpB,IAAM,kBAAN,MAAsB;AAAA,EAAtB;AACL,SAAiB,+BAGb,oBAAI,IAAI;AACZ,SAAiB,aAAuB,CAAC;AAEzC,SAAQ,oBAAmD,CAAC;AAC5D,SAAQ,mBAAiD,CAAC;AAC1D,SAAQ,uBAAyD,CAAC;AAClE,SAAQ,oBAAmD,CAAC;AAC5D,SAAQ,mBAAiD,CAAC;AAC1D,SAAQ,uBAAyD,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUlE,SAAS,UAA+B,aAAwD;AAC9F,UAAM,gBAAgB,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;AACpE,WAAO,KAAK,gBAAgB,aAAa,eAAe,WAAW;AAAA,EACrE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,WACE,UACA,aACiB;AACjB,UAAM,gBAAgB,MAAM,QAAQ,QAAQ,IAAI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