@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.
- package/README.md +293 -0
- package/dist/cjs/client/index.d.ts +103 -0
- package/dist/cjs/client/index.js +510 -0
- package/dist/cjs/client/index.js.map +1 -0
- package/dist/cjs/facilitator/index.d.ts +192 -0
- package/dist/cjs/facilitator/index.js +398 -0
- package/dist/cjs/facilitator/index.js.map +1 -0
- package/dist/cjs/http/index.d.ts +52 -0
- package/dist/cjs/http/index.js +763 -0
- package/dist/cjs/http/index.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/mechanisms-CmrqNl1M.d.ts +238 -0
- package/dist/cjs/mechanisms-DsJn3ZiM.d.ts +238 -0
- package/dist/cjs/server/index.d.ts +2 -0
- package/dist/cjs/server/index.js +1241 -0
- package/dist/cjs/server/index.js.map +1 -0
- package/dist/cjs/t402HTTPClient-m6cjzTek.d.ts +243 -0
- package/dist/cjs/t402HTTPResourceServer-B-xmYMwj.d.ts +719 -0
- package/dist/cjs/t402HTTPResourceServer-Bcfxp2UO.d.ts +719 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.js +19 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/v1/index.d.ts +1 -0
- package/dist/cjs/types/v1/index.js +19 -0
- package/dist/cjs/types/v1/index.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +48 -0
- package/dist/cjs/utils/index.js +108 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/esm/chunk-3IUBYRYG.mjs +78 -0
- package/dist/esm/chunk-3IUBYRYG.mjs.map +1 -0
- package/dist/esm/chunk-3VTYR43U.mjs +7 -0
- package/dist/esm/chunk-3VTYR43U.mjs.map +1 -0
- package/dist/esm/chunk-BJTO5JO5.mjs +11 -0
- package/dist/esm/chunk-BJTO5JO5.mjs.map +1 -0
- package/dist/esm/chunk-D5DYKKCZ.mjs +722 -0
- package/dist/esm/chunk-D5DYKKCZ.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +103 -0
- package/dist/esm/client/index.mjs +356 -0
- package/dist/esm/client/index.mjs.map +1 -0
- package/dist/esm/facilitator/index.d.mts +192 -0
- package/dist/esm/facilitator/index.mjs +373 -0
- package/dist/esm/facilitator/index.mjs.map +1 -0
- package/dist/esm/http/index.d.mts +52 -0
- package/dist/esm/http/index.mjs +28 -0
- package/dist/esm/http/index.mjs.map +1 -0
- package/dist/esm/index.d.mts +3 -0
- package/dist/esm/index.mjs +8 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/mechanisms-CmrqNl1M.d.mts +238 -0
- package/dist/esm/server/index.d.mts +2 -0
- package/dist/esm/server/index.mjs +562 -0
- package/dist/esm/server/index.mjs.map +1 -0
- package/dist/esm/t402HTTPClient-C285YGCp.d.mts +243 -0
- package/dist/esm/t402HTTPResourceServer-k_l3d8ua.d.mts +719 -0
- package/dist/esm/types/index.d.mts +1 -0
- package/dist/esm/types/index.mjs +1 -0
- package/dist/esm/types/index.mjs.map +1 -0
- package/dist/esm/types/v1/index.d.mts +1 -0
- package/dist/esm/types/v1/index.mjs +1 -0
- package/dist/esm/types/v1/index.mjs.map +1 -0
- package/dist/esm/utils/index.d.mts +48 -0
- package/dist/esm/utils/index.mjs +20 -0
- package/dist/esm/utils/index.mjs.map +1 -0
- package/package.json +129 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HTTPFacilitatorClient,
|
|
3
|
+
RouteConfigurationError,
|
|
4
|
+
decodePaymentRequiredHeader,
|
|
5
|
+
decodePaymentResponseHeader,
|
|
6
|
+
decodePaymentSignatureHeader,
|
|
7
|
+
encodePaymentRequiredHeader,
|
|
8
|
+
encodePaymentResponseHeader,
|
|
9
|
+
encodePaymentSignatureHeader,
|
|
10
|
+
t402HTTPClient,
|
|
11
|
+
t402HTTPResourceServer
|
|
12
|
+
} from "../chunk-D5DYKKCZ.mjs";
|
|
13
|
+
import "../chunk-3VTYR43U.mjs";
|
|
14
|
+
import "../chunk-3IUBYRYG.mjs";
|
|
15
|
+
import "../chunk-BJTO5JO5.mjs";
|
|
16
|
+
export {
|
|
17
|
+
HTTPFacilitatorClient,
|
|
18
|
+
RouteConfigurationError,
|
|
19
|
+
decodePaymentRequiredHeader,
|
|
20
|
+
decodePaymentResponseHeader,
|
|
21
|
+
decodePaymentSignatureHeader,
|
|
22
|
+
encodePaymentRequiredHeader,
|
|
23
|
+
encodePaymentResponseHeader,
|
|
24
|
+
encodePaymentSignatureHeader,
|
|
25
|
+
t402HTTPClient,
|
|
26
|
+
t402HTTPResourceServer
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,238 @@
|
|
|
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 };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { C as CompiledRoute, F as FacilitatorClient, o as FacilitatorConfig, H as HTTPAdapter, n as HTTPFacilitatorClient, c as HTTPProcessResult, a as HTTPRequestContext, b as HTTPResponseInstructions, P as PaywallConfig, d as PaywallProvider, k as ProcessSettleFailureResponse, i as ProcessSettleResultResponse, j as ProcessSettleSuccessResponse, q as ResourceConfig, r as ResourceInfo, R as RouteConfig, m as RouteConfigurationError, l as RouteValidationError, f as RoutesConfig, U as UnpaidResponseBody, h as UnpaidResponseResult, t as t402HTTPResourceServer, p as t402ResourceServer } from '../t402HTTPResourceServer-k_l3d8ua.mjs';
|
|
2
|
+
import '../mechanisms-CmrqNl1M.mjs';
|