@t402/core 2.0.0 → 2.3.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 (50) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/client/index.d.ts +22 -2
  3. package/dist/cjs/client/index.js +9 -6
  4. package/dist/cjs/client/index.js.map +1 -1
  5. package/dist/cjs/facilitator/index.d.ts +1 -1
  6. package/dist/cjs/facilitator/index.js +10 -8
  7. package/dist/cjs/facilitator/index.js.map +1 -1
  8. package/dist/cjs/http/index.d.ts +3 -3
  9. package/dist/cjs/http/index.js +11 -2
  10. package/dist/cjs/http/index.js.map +1 -1
  11. package/dist/cjs/{mechanisms-CmrqNl1M.d.ts → mechanisms-B-vz5yOj.d.ts} +209 -4
  12. package/dist/cjs/server/index.d.ts +2 -2
  13. package/dist/cjs/server/index.js +22 -12
  14. package/dist/cjs/server/index.js.map +1 -1
  15. package/dist/cjs/{t402HTTPClient-m6cjzTek.d.ts → t402HTTPClient-GIweW6nh.d.ts} +1 -1
  16. package/dist/cjs/{t402HTTPResourceServer-B-xmYMwj.d.ts → t402HTTPResourceServer-CcpZF3af.d.ts} +2 -2
  17. package/dist/cjs/types/index.d.ts +1 -1
  18. package/dist/cjs/types/index.js +38 -0
  19. package/dist/cjs/types/index.js.map +1 -1
  20. package/dist/cjs/types/v1/index.d.ts +1 -1
  21. package/dist/cjs/utils/index.d.ts +1 -1
  22. package/dist/esm/chunk-4W2Y3RJM.mjs +15 -0
  23. package/dist/esm/{chunk-D5DYKKCZ.mjs → chunk-773TNE2Y.mjs} +12 -4
  24. package/dist/esm/{chunk-D5DYKKCZ.mjs.map → chunk-773TNE2Y.mjs.map} +1 -1
  25. package/dist/esm/client/index.d.mts +22 -2
  26. package/dist/esm/client/index.mjs +11 -8
  27. package/dist/esm/client/index.mjs.map +1 -1
  28. package/dist/esm/facilitator/index.d.mts +1 -1
  29. package/dist/esm/facilitator/index.mjs +11 -9
  30. package/dist/esm/facilitator/index.mjs.map +1 -1
  31. package/dist/esm/http/index.d.mts +3 -3
  32. package/dist/esm/http/index.mjs +2 -2
  33. package/dist/esm/index.mjs +1 -1
  34. package/dist/{cjs/mechanisms-DsJn3ZiM.d.ts → esm/mechanisms-B-vz5yOj.d.mts} +209 -4
  35. package/dist/esm/server/index.d.mts +2 -2
  36. package/dist/esm/server/index.mjs +15 -12
  37. package/dist/esm/server/index.mjs.map +1 -1
  38. package/dist/esm/{t402HTTPClient-C285YGCp.d.mts → t402HTTPClient-DbZqiMSO.d.mts} +1 -1
  39. package/dist/esm/{t402HTTPResourceServer-k_l3d8ua.d.mts → t402HTTPResourceServer-BbQ6HVBC.d.mts} +2 -2
  40. package/dist/esm/types/index.d.mts +1 -1
  41. package/dist/esm/types/index.mjs +28 -0
  42. package/dist/esm/types/index.mjs.map +1 -1
  43. package/dist/esm/types/v1/index.d.mts +1 -1
  44. package/dist/esm/utils/index.d.mts +1 -1
  45. package/dist/esm/utils/index.mjs +1 -1
  46. package/package.json +19 -18
  47. package/dist/cjs/t402HTTPResourceServer-Bcfxp2UO.d.ts +0 -719
  48. package/dist/esm/chunk-BJTO5JO5.mjs +0 -11
  49. package/dist/esm/mechanisms-CmrqNl1M.d.mts +0 -238
  50. /package/dist/esm/{chunk-BJTO5JO5.mjs.map → chunk-4W2Y3RJM.mjs.map} +0 -0
@@ -1,11 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- export {
9
- __require
10
- };
11
- //# sourceMappingURL=chunk-BJTO5JO5.mjs.map
@@ -1,238 +0,0 @@
1
- type PaymentRequirementsV1 = {
2
- scheme: string;
3
- network: Network;
4
- maxAmountRequired: string;
5
- resource: string;
6
- description: string;
7
- mimeType: string;
8
- outputSchema: Record<string, unknown>;
9
- payTo: string;
10
- maxTimeoutSeconds: number;
11
- asset: string;
12
- extra: Record<string, unknown>;
13
- };
14
- type PaymentRequiredV1 = {
15
- t402Version: 1;
16
- error?: string;
17
- accepts: PaymentRequirementsV1[];
18
- };
19
- type PaymentPayloadV1 = {
20
- t402Version: 1;
21
- scheme: string;
22
- network: Network;
23
- payload: Record<string, unknown>;
24
- };
25
- type VerifyRequestV1 = {
26
- paymentPayload: PaymentPayloadV1;
27
- paymentRequirements: PaymentRequirementsV1;
28
- };
29
- type SettleRequestV1 = {
30
- paymentPayload: PaymentPayloadV1;
31
- paymentRequirements: PaymentRequirementsV1;
32
- };
33
- type SettleResponseV1 = {
34
- success: boolean;
35
- errorReason?: string;
36
- payer?: string;
37
- transaction: string;
38
- network: Network;
39
- };
40
- type SupportedResponseV1 = {
41
- kinds: {
42
- t402Version: number;
43
- scheme: string;
44
- network: Network;
45
- extra?: Record<string, unknown>;
46
- }[];
47
- };
48
-
49
- interface ResourceServerExtension {
50
- key: string;
51
- enrichDeclaration?: (declaration: unknown, transportContext: unknown) => unknown;
52
- }
53
-
54
- type Network = `${string}:${string}`;
55
- type Money = string | number;
56
- type AssetAmount = {
57
- asset: string;
58
- amount: string;
59
- extra?: Record<string, unknown>;
60
- };
61
- type Price = Money | AssetAmount;
62
-
63
- interface ResourceInfo {
64
- url: string;
65
- description: string;
66
- mimeType: string;
67
- }
68
- type PaymentRequirements = {
69
- scheme: string;
70
- network: Network;
71
- asset: string;
72
- amount: string;
73
- payTo: string;
74
- maxTimeoutSeconds: number;
75
- extra: Record<string, unknown>;
76
- };
77
- type PaymentRequired = {
78
- t402Version: number;
79
- error?: string;
80
- resource: ResourceInfo;
81
- accepts: PaymentRequirements[];
82
- extensions?: Record<string, unknown>;
83
- };
84
- type PaymentPayload = {
85
- t402Version: number;
86
- resource: ResourceInfo;
87
- accepted: PaymentRequirements;
88
- payload: Record<string, unknown>;
89
- extensions?: Record<string, unknown>;
90
- };
91
-
92
- type VerifyRequest = {
93
- paymentPayload: PaymentPayload;
94
- paymentRequirements: PaymentRequirements;
95
- };
96
- type VerifyResponse = {
97
- isValid: boolean;
98
- invalidReason?: string;
99
- payer?: string;
100
- };
101
- type SettleRequest = {
102
- paymentPayload: PaymentPayload;
103
- paymentRequirements: PaymentRequirements;
104
- };
105
- type SettleResponse = {
106
- success: boolean;
107
- errorReason?: string;
108
- payer?: string;
109
- transaction: string;
110
- network: Network;
111
- };
112
- type SupportedKind = {
113
- t402Version: number;
114
- scheme: string;
115
- network: Network;
116
- extra?: Record<string, unknown>;
117
- };
118
- type SupportedResponse = {
119
- kinds: SupportedKind[];
120
- extensions: string[];
121
- signers: Record<string, string[]>;
122
- };
123
-
124
- /**
125
- * Money parser function that converts a numeric amount to an AssetAmount
126
- * Receives the amount as a decimal number (e.g., 1.50 for $1.50)
127
- * Returns null to indicate "cannot handle this amount", causing fallback to next parser
128
- * Always returns a Promise for consistency - use async/await
129
- *
130
- * @param amount - The decimal amount (e.g., 1.50)
131
- * @param network - The network identifier for context
132
- * @returns AssetAmount or null to try next parser
133
- */
134
- type MoneyParser = (amount: number, network: Network) => Promise<AssetAmount | null>;
135
- interface SchemeNetworkClient {
136
- readonly scheme: string;
137
- createPaymentPayload(t402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "t402Version" | "payload">>;
138
- }
139
- interface SchemeNetworkFacilitator {
140
- readonly scheme: string;
141
- /**
142
- * CAIP family pattern that this facilitator supports.
143
- * Used to group signers by blockchain family in the supported response.
144
- *
145
- * @example
146
- * // EVM facilitators
147
- * readonly caipFamily = "eip155:*";
148
- *
149
- * @example
150
- * // SVM facilitators
151
- * readonly caipFamily = "solana:*";
152
- */
153
- readonly caipFamily: string;
154
- /**
155
- * Get mechanism-specific extra data needed for the supported kinds endpoint.
156
- * This method is called when building the facilitator's supported response.
157
- *
158
- * @param network - The network identifier for context
159
- * @returns Extra data object or undefined if no extra data is needed
160
- *
161
- * @example
162
- * // EVM schemes return undefined (no extra data needed)
163
- * getExtra(network: Network): undefined {
164
- * return undefined;
165
- * }
166
- *
167
- * @example
168
- * // SVM schemes return feePayer address
169
- * getExtra(network: Network): Record<string, unknown> | undefined {
170
- * return { feePayer: this.signer.address };
171
- * }
172
- */
173
- getExtra(network: Network): Record<string, unknown> | undefined;
174
- /**
175
- * Get signer addresses used by this facilitator for a given network.
176
- * These are included in the supported response to help clients understand
177
- * which addresses might sign/pay for transactions.
178
- *
179
- * Supports multiple addresses for load balancing, key rotation, and high availability.
180
- *
181
- * @param network - The network identifier
182
- * @returns Array of signer addresses (wallet addresses, fee payer addresses, etc.)
183
- *
184
- * @example
185
- * // EVM facilitator
186
- * getSigners(network: string): string[] {
187
- * return [...this.signer.getAddresses()];
188
- * }
189
- *
190
- * @example
191
- * // SVM facilitator
192
- * getSigners(network: string): string[] {
193
- * return [...this.signer.getAddresses()];
194
- * }
195
- */
196
- getSigners(network: string): string[];
197
- verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
198
- settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
199
- }
200
- interface SchemeNetworkServer {
201
- readonly scheme: string;
202
- /**
203
- * Convert a user-friendly price to the scheme's specific amount and asset format
204
- * Always returns a Promise for consistency
205
- *
206
- * @param price - User-friendly price (e.g., "$0.10", "0.10", { amount: "100000", asset: "USDC" })
207
- * @param network - The network identifier for context
208
- * @returns Promise that resolves to the converted amount, asset identifier, and any extra metadata
209
- *
210
- * @example
211
- * // For EVM networks with USDC:
212
- * await parsePrice("$0.10", "eip155:8453") => { amount: "100000", asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" }
213
- *
214
- * // For custom schemes:
215
- * await parsePrice("10 points", "custom:network") => { amount: "10", asset: "points" }
216
- */
217
- parsePrice(price: Price, network: Network): Promise<AssetAmount>;
218
- /**
219
- * Build payment requirements for this scheme/network combination
220
- *
221
- * @param paymentRequirements - Base payment requirements with amount/asset already set
222
- * @param supportedKind - The supported kind from facilitator's /supported endpoint
223
- * @param supportedKind.t402Version - The t402 version
224
- * @param supportedKind.scheme - The payment scheme
225
- * @param supportedKind.network - The network identifier
226
- * @param supportedKind.extra - Optional extra metadata
227
- * @param facilitatorExtensions - Extensions supported by the facilitator
228
- * @returns Enhanced payment requirements ready to be sent to clients
229
- */
230
- enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
231
- t402Version: number;
232
- scheme: string;
233
- network: Network;
234
- extra?: Record<string, unknown>;
235
- }, facilitatorExtensions: string[]): Promise<PaymentRequirements>;
236
- }
237
-
238
- export type { AssetAmount as A, Money as M, Network as N, PaymentRequirements as P, ResourceServerExtension as R, SettleResponse as S, VerifyResponse as V, PaymentPayload as a, SchemeNetworkFacilitator as b, PaymentRequired as c, SchemeNetworkClient as d, SupportedResponse as e, SchemeNetworkServer as f, SupportedKind as g, Price as h, PaymentRequirementsV1 as i, PaymentRequiredV1 as j, PaymentPayloadV1 as k, VerifyRequestV1 as l, SettleRequestV1 as m, SettleResponseV1 as n, SupportedResponseV1 as o, VerifyRequest as p, SettleRequest as q, MoneyParser as r };