@dexterai/x402 1.6.6 → 1.7.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/dist/adapters/index.d.cts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +6 -6
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.js.map +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +4 -4
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +122 -14
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +89 -7
- package/dist/server/index.d.ts +89 -7
- package/dist/server/index.js +121 -14
- package/dist/server/index.js.map +1 -1
- package/dist/{solana-Bve65qm4.d.ts → solana-CJdhHls8.d.ts} +2 -2
- package/dist/{solana-BYh8ehOi.d.cts → solana-CnW6P4lJ.d.cts} +2 -2
- package/dist/{types--r7urkVI.d.cts → types-BB-2vowq.d.cts} +1 -1
- package/dist/{types-CcVAaoro.d.cts → types-C6ty4U6C.d.cts} +39 -1
- package/dist/{types-CcVAaoro.d.ts → types-C6ty4U6C.d.ts} +39 -1
- package/dist/{types-BtpD4ULe.d.ts → types-ClEZ34n4.d.ts} +1 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/{x402-client-BxQWcK2Z.d.ts → x402-client-B9ECWy7k.d.ts} +2 -2
- package/dist/{x402-client-Dcm2FQ9f.d.cts → x402-client-BhLOoqwa.d.cts} +2 -2
- package/package.json +10 -2
package/dist/server/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PaymentRequired } from '../types-
|
|
2
|
-
export {
|
|
1
|
+
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-C6ty4U6C.cjs';
|
|
2
|
+
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-C6ty4U6C.cjs';
|
|
3
3
|
import { Request, RequestHandler } from 'express';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -131,8 +131,12 @@ interface AssetConfig {
|
|
|
131
131
|
* Server configuration
|
|
132
132
|
*/
|
|
133
133
|
interface X402ServerConfig {
|
|
134
|
-
/**
|
|
135
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Address to receive payments, or a dynamic provider function.
|
|
136
|
+
* Use a string for static wallet addresses.
|
|
137
|
+
* Use a PayToProvider (e.g., stripePayTo) for per-request addresses.
|
|
138
|
+
*/
|
|
139
|
+
payTo: string | PayToProvider;
|
|
136
140
|
/** Facilitator URL (defaults to Dexter) */
|
|
137
141
|
facilitatorUrl?: string;
|
|
138
142
|
/** CAIP-2 network identifier */
|
|
@@ -221,9 +225,22 @@ declare function createX402Server(config: X402ServerConfig): X402Server;
|
|
|
221
225
|
*/
|
|
222
226
|
interface X402MiddlewareConfig {
|
|
223
227
|
/**
|
|
224
|
-
* Address to receive payments
|
|
228
|
+
* Address to receive payments, or a dynamic provider function.
|
|
229
|
+
*
|
|
230
|
+
* - **Static address**: Pass a Solana pubkey or EVM address string.
|
|
231
|
+
* - **Stripe**: Use `stripePayTo(process.env.STRIPE_SECRET_KEY)` to generate
|
|
232
|
+
* per-request deposit addresses. Payments land in your Stripe Dashboard.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Static address
|
|
237
|
+
* payTo: '0xYourAddress...'
|
|
238
|
+
*
|
|
239
|
+
* // Stripe machine payments
|
|
240
|
+
* payTo: stripePayTo(process.env.STRIPE_SECRET_KEY)
|
|
241
|
+
* ```
|
|
225
242
|
*/
|
|
226
|
-
payTo: string;
|
|
243
|
+
payTo: string | PayToProvider;
|
|
227
244
|
/**
|
|
228
245
|
* Payment amount in USD (e.g., '0.01' for 1 cent)
|
|
229
246
|
* Will be converted to atomic units automatically.
|
|
@@ -903,4 +920,69 @@ declare const MODEL_PRICING_MAP: Record<string, {
|
|
|
903
920
|
tier: string;
|
|
904
921
|
}>;
|
|
905
922
|
|
|
906
|
-
|
|
923
|
+
/**
|
|
924
|
+
* Stripe Machine Payments — PayTo Provider
|
|
925
|
+
*
|
|
926
|
+
* Generates per-request Stripe deposit addresses via PaymentIntents.
|
|
927
|
+
* Payments land in your Stripe Dashboard with full reporting, taxes, and refunds.
|
|
928
|
+
*
|
|
929
|
+
* Requires `stripe` npm package as a peer dependency.
|
|
930
|
+
*
|
|
931
|
+
* @example
|
|
932
|
+
* ```typescript
|
|
933
|
+
* import { x402Middleware, stripePayTo } from '@dexterai/x402/server';
|
|
934
|
+
*
|
|
935
|
+
* app.use('/api/data', x402Middleware({
|
|
936
|
+
* amount: '0.01',
|
|
937
|
+
* payTo: stripePayTo(process.env.STRIPE_SECRET_KEY),
|
|
938
|
+
* }));
|
|
939
|
+
* ```
|
|
940
|
+
*
|
|
941
|
+
* @see https://docs.stripe.com/payments/machine
|
|
942
|
+
*/
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Configuration for the Stripe PayTo provider.
|
|
946
|
+
*/
|
|
947
|
+
interface StripePayToConfig {
|
|
948
|
+
/** Stripe secret key (sk_test_... or sk_live_...) */
|
|
949
|
+
secretKey: string;
|
|
950
|
+
/**
|
|
951
|
+
* Stripe API version to use.
|
|
952
|
+
* @default '2026-01-28.clover'
|
|
953
|
+
*/
|
|
954
|
+
apiVersion?: string;
|
|
955
|
+
/**
|
|
956
|
+
* Target network for deposit addresses.
|
|
957
|
+
* - 'base' → Base mainnet (eip155:8453)
|
|
958
|
+
* - 'base-sepolia' → Base Sepolia testnet (eip155:84532)
|
|
959
|
+
* @default 'base'
|
|
960
|
+
*/
|
|
961
|
+
network?: 'base' | 'base-sepolia';
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Create a Stripe-backed PayTo provider for x402 machine payments.
|
|
965
|
+
*
|
|
966
|
+
* On each new request, creates a Stripe PaymentIntent with a crypto deposit address.
|
|
967
|
+
* When the agent sends USDC to that address, Stripe auto-captures the payment.
|
|
968
|
+
* Payments appear in your Stripe Dashboard like any other transaction.
|
|
969
|
+
*
|
|
970
|
+
* @param secretKeyOrConfig - Stripe secret key string, or full config object
|
|
971
|
+
* @returns A PayToProvider function with auto-configuration defaults
|
|
972
|
+
*
|
|
973
|
+
* @example Minimal usage
|
|
974
|
+
* ```typescript
|
|
975
|
+
* const provider = stripePayTo('sk_test_...');
|
|
976
|
+
* ```
|
|
977
|
+
*
|
|
978
|
+
* @example With config
|
|
979
|
+
* ```typescript
|
|
980
|
+
* const provider = stripePayTo({
|
|
981
|
+
* secretKey: 'sk_test_...',
|
|
982
|
+
* network: 'base-sepolia', // testnet
|
|
983
|
+
* });
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
986
|
+
declare function stripePayTo(secretKeyOrConfig: string | StripePayToConfig): PayToProvider;
|
|
987
|
+
|
|
988
|
+
export { type AssetConfig, type BuildRequirementsOptions, type DynamicPricing, type DynamicPricingConfig, FacilitatorClient, MODEL_PRICING, MODEL_PRICING_MAP, MODEL_REGISTRY, type ModelApiType, type ModelDefinition, type ModelModality, type ModelParameters, type ModelPricing$1 as ModelPricing, type ModelTier, PayToProvider, PaymentAccept, PaymentRequired, type PriceQuote, type ModelPricing as RegistryModelPricing, SettleResponse, type StripePayToConfig, type SupportedKind, type SupportedResponse, type TokenPriceQuote, type TokenPricing, type TokenPricingConfig, VerifyResponse, type X402AccessPassConfig, type X402AccessPassRequest, type X402BrowserSupportConfig, type X402MiddlewareConfig, type X402Request, type X402Server, type X402ServerConfig, countTokens, createDynamicPricing, createTokenPricing, createX402Server, estimateCost, findModel, formatModelPricing, formatPricing, formatTokenPricing, getActiveModels, getAvailableModelIds, getAvailableModels, getCheapestModel, getModel, getModelsByFamily, getModelsByTier, getTextModels, isValidModel, isValidModelId, stripePayTo, x402AccessPass, x402BrowserSupport, x402Middleware };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PaymentRequired } from '../types-
|
|
2
|
-
export {
|
|
1
|
+
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-C6ty4U6C.js';
|
|
2
|
+
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-C6ty4U6C.js';
|
|
3
3
|
import { Request, RequestHandler } from 'express';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -131,8 +131,12 @@ interface AssetConfig {
|
|
|
131
131
|
* Server configuration
|
|
132
132
|
*/
|
|
133
133
|
interface X402ServerConfig {
|
|
134
|
-
/**
|
|
135
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Address to receive payments, or a dynamic provider function.
|
|
136
|
+
* Use a string for static wallet addresses.
|
|
137
|
+
* Use a PayToProvider (e.g., stripePayTo) for per-request addresses.
|
|
138
|
+
*/
|
|
139
|
+
payTo: string | PayToProvider;
|
|
136
140
|
/** Facilitator URL (defaults to Dexter) */
|
|
137
141
|
facilitatorUrl?: string;
|
|
138
142
|
/** CAIP-2 network identifier */
|
|
@@ -221,9 +225,22 @@ declare function createX402Server(config: X402ServerConfig): X402Server;
|
|
|
221
225
|
*/
|
|
222
226
|
interface X402MiddlewareConfig {
|
|
223
227
|
/**
|
|
224
|
-
* Address to receive payments
|
|
228
|
+
* Address to receive payments, or a dynamic provider function.
|
|
229
|
+
*
|
|
230
|
+
* - **Static address**: Pass a Solana pubkey or EVM address string.
|
|
231
|
+
* - **Stripe**: Use `stripePayTo(process.env.STRIPE_SECRET_KEY)` to generate
|
|
232
|
+
* per-request deposit addresses. Payments land in your Stripe Dashboard.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Static address
|
|
237
|
+
* payTo: '0xYourAddress...'
|
|
238
|
+
*
|
|
239
|
+
* // Stripe machine payments
|
|
240
|
+
* payTo: stripePayTo(process.env.STRIPE_SECRET_KEY)
|
|
241
|
+
* ```
|
|
225
242
|
*/
|
|
226
|
-
payTo: string;
|
|
243
|
+
payTo: string | PayToProvider;
|
|
227
244
|
/**
|
|
228
245
|
* Payment amount in USD (e.g., '0.01' for 1 cent)
|
|
229
246
|
* Will be converted to atomic units automatically.
|
|
@@ -903,4 +920,69 @@ declare const MODEL_PRICING_MAP: Record<string, {
|
|
|
903
920
|
tier: string;
|
|
904
921
|
}>;
|
|
905
922
|
|
|
906
|
-
|
|
923
|
+
/**
|
|
924
|
+
* Stripe Machine Payments — PayTo Provider
|
|
925
|
+
*
|
|
926
|
+
* Generates per-request Stripe deposit addresses via PaymentIntents.
|
|
927
|
+
* Payments land in your Stripe Dashboard with full reporting, taxes, and refunds.
|
|
928
|
+
*
|
|
929
|
+
* Requires `stripe` npm package as a peer dependency.
|
|
930
|
+
*
|
|
931
|
+
* @example
|
|
932
|
+
* ```typescript
|
|
933
|
+
* import { x402Middleware, stripePayTo } from '@dexterai/x402/server';
|
|
934
|
+
*
|
|
935
|
+
* app.use('/api/data', x402Middleware({
|
|
936
|
+
* amount: '0.01',
|
|
937
|
+
* payTo: stripePayTo(process.env.STRIPE_SECRET_KEY),
|
|
938
|
+
* }));
|
|
939
|
+
* ```
|
|
940
|
+
*
|
|
941
|
+
* @see https://docs.stripe.com/payments/machine
|
|
942
|
+
*/
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Configuration for the Stripe PayTo provider.
|
|
946
|
+
*/
|
|
947
|
+
interface StripePayToConfig {
|
|
948
|
+
/** Stripe secret key (sk_test_... or sk_live_...) */
|
|
949
|
+
secretKey: string;
|
|
950
|
+
/**
|
|
951
|
+
* Stripe API version to use.
|
|
952
|
+
* @default '2026-01-28.clover'
|
|
953
|
+
*/
|
|
954
|
+
apiVersion?: string;
|
|
955
|
+
/**
|
|
956
|
+
* Target network for deposit addresses.
|
|
957
|
+
* - 'base' → Base mainnet (eip155:8453)
|
|
958
|
+
* - 'base-sepolia' → Base Sepolia testnet (eip155:84532)
|
|
959
|
+
* @default 'base'
|
|
960
|
+
*/
|
|
961
|
+
network?: 'base' | 'base-sepolia';
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Create a Stripe-backed PayTo provider for x402 machine payments.
|
|
965
|
+
*
|
|
966
|
+
* On each new request, creates a Stripe PaymentIntent with a crypto deposit address.
|
|
967
|
+
* When the agent sends USDC to that address, Stripe auto-captures the payment.
|
|
968
|
+
* Payments appear in your Stripe Dashboard like any other transaction.
|
|
969
|
+
*
|
|
970
|
+
* @param secretKeyOrConfig - Stripe secret key string, or full config object
|
|
971
|
+
* @returns A PayToProvider function with auto-configuration defaults
|
|
972
|
+
*
|
|
973
|
+
* @example Minimal usage
|
|
974
|
+
* ```typescript
|
|
975
|
+
* const provider = stripePayTo('sk_test_...');
|
|
976
|
+
* ```
|
|
977
|
+
*
|
|
978
|
+
* @example With config
|
|
979
|
+
* ```typescript
|
|
980
|
+
* const provider = stripePayTo({
|
|
981
|
+
* secretKey: 'sk_test_...',
|
|
982
|
+
* network: 'base-sepolia', // testnet
|
|
983
|
+
* });
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
986
|
+
declare function stripePayTo(secretKeyOrConfig: string | StripePayToConfig): PayToProvider;
|
|
987
|
+
|
|
988
|
+
export { type AssetConfig, type BuildRequirementsOptions, type DynamicPricing, type DynamicPricingConfig, FacilitatorClient, MODEL_PRICING, MODEL_PRICING_MAP, MODEL_REGISTRY, type ModelApiType, type ModelDefinition, type ModelModality, type ModelParameters, type ModelPricing$1 as ModelPricing, type ModelTier, PayToProvider, PaymentAccept, PaymentRequired, type PriceQuote, type ModelPricing as RegistryModelPricing, SettleResponse, type StripePayToConfig, type SupportedKind, type SupportedResponse, type TokenPriceQuote, type TokenPricing, type TokenPricingConfig, VerifyResponse, type X402AccessPassConfig, type X402AccessPassRequest, type X402BrowserSupportConfig, type X402MiddlewareConfig, type X402Request, type X402Server, type X402ServerConfig, countTokens, createDynamicPricing, createTokenPricing, createX402Server, estimateCost, findModel, formatModelPricing, formatPricing, formatTokenPricing, getActiveModels, getAvailableModelIds, getAvailableModels, getCheapestModel, getModel, getModelsByFamily, getModelsByTier, getTextModels, isValidModel, isValidModelId, stripePayTo, x402AccessPass, x402BrowserSupport, x402Middleware };
|
package/dist/server/index.js
CHANGED
|
@@ -194,6 +194,10 @@ function createX402Server(config) {
|
|
|
194
194
|
} = config;
|
|
195
195
|
const facilitator = new FacilitatorClient(facilitatorUrl);
|
|
196
196
|
let cachedExtra = null;
|
|
197
|
+
async function resolvePayTo(context) {
|
|
198
|
+
if (typeof payTo === "string") return payTo;
|
|
199
|
+
return payTo(context || {});
|
|
200
|
+
}
|
|
197
201
|
async function getNetworkExtra() {
|
|
198
202
|
if (!cachedExtra) {
|
|
199
203
|
cachedExtra = await facilitator.getNetworkExtra(network);
|
|
@@ -209,7 +213,7 @@ function createX402Server(config) {
|
|
|
209
213
|
version: cachedExtra.version
|
|
210
214
|
};
|
|
211
215
|
}
|
|
212
|
-
async function
|
|
216
|
+
async function buildPaymentAccept(resolvedPayTo, options) {
|
|
213
217
|
const {
|
|
214
218
|
amountAtomic,
|
|
215
219
|
timeoutSeconds = defaultTimeoutSeconds
|
|
@@ -221,11 +225,18 @@ function createX402Server(config) {
|
|
|
221
225
|
amount: amountAtomic,
|
|
222
226
|
maxAmountRequired: amountAtomic,
|
|
223
227
|
asset: asset.address,
|
|
224
|
-
payTo,
|
|
228
|
+
payTo: resolvedPayTo,
|
|
225
229
|
maxTimeoutSeconds: timeoutSeconds,
|
|
226
230
|
extra
|
|
227
231
|
};
|
|
228
232
|
}
|
|
233
|
+
async function getPaymentAccept(options) {
|
|
234
|
+
const address = await resolvePayTo({
|
|
235
|
+
amountAtomic: options.amountAtomic,
|
|
236
|
+
resourceUrl: options.resourceUrl
|
|
237
|
+
});
|
|
238
|
+
return buildPaymentAccept(address, options);
|
|
239
|
+
}
|
|
229
240
|
async function buildRequirements(options) {
|
|
230
241
|
const {
|
|
231
242
|
resourceUrl,
|
|
@@ -258,18 +269,18 @@ function createX402Server(config) {
|
|
|
258
269
|
};
|
|
259
270
|
}
|
|
260
271
|
async function verifyPayment(paymentSignatureHeader, requirements) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
resourceUrl: ""
|
|
264
|
-
}
|
|
265
|
-
return facilitator.verifyPayment(paymentSignatureHeader,
|
|
272
|
+
if (!requirements) {
|
|
273
|
+
const address = await resolvePayTo({ paymentHeader: paymentSignatureHeader });
|
|
274
|
+
requirements = await buildPaymentAccept(address, { amountAtomic: "0", resourceUrl: "" });
|
|
275
|
+
}
|
|
276
|
+
return facilitator.verifyPayment(paymentSignatureHeader, requirements);
|
|
266
277
|
}
|
|
267
278
|
async function settlePayment(paymentSignatureHeader, requirements) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
resourceUrl: ""
|
|
271
|
-
}
|
|
272
|
-
return facilitator.settlePayment(paymentSignatureHeader,
|
|
279
|
+
if (!requirements) {
|
|
280
|
+
const address = await resolvePayTo({ paymentHeader: paymentSignatureHeader });
|
|
281
|
+
requirements = await buildPaymentAccept(address, { amountAtomic: "0", resourceUrl: "" });
|
|
282
|
+
}
|
|
283
|
+
return facilitator.settlePayment(paymentSignatureHeader, requirements);
|
|
273
284
|
}
|
|
274
285
|
return {
|
|
275
286
|
buildRequirements,
|
|
@@ -290,9 +301,7 @@ function x402Middleware(config) {
|
|
|
290
301
|
const {
|
|
291
302
|
payTo,
|
|
292
303
|
amount,
|
|
293
|
-
network = DEFAULT_NETWORK,
|
|
294
304
|
asset,
|
|
295
|
-
facilitatorUrl,
|
|
296
305
|
description,
|
|
297
306
|
resourceUrl: staticResourceUrl,
|
|
298
307
|
mimeType,
|
|
@@ -302,6 +311,9 @@ function x402Middleware(config) {
|
|
|
302
311
|
getAmount,
|
|
303
312
|
getDescription
|
|
304
313
|
} = config;
|
|
314
|
+
const providerDefaults = typeof payTo !== "string" ? payTo._x402Defaults : void 0;
|
|
315
|
+
const network = config.network ?? providerDefaults?.network ?? DEFAULT_NETWORK;
|
|
316
|
+
const facilitatorUrl = config.facilitatorUrl ?? providerDefaults?.facilitatorUrl;
|
|
305
317
|
const log = verbose ? console.log.bind(console, "[x402:middleware]") : () => {
|
|
306
318
|
};
|
|
307
319
|
const server = createX402Server({
|
|
@@ -1741,6 +1753,100 @@ function formatTokenPricing(model = DEFAULT_MODEL) {
|
|
|
1741
1753
|
const actualModel = MODEL_PRICING[model] ? model : DEFAULT_MODEL;
|
|
1742
1754
|
return `$${pricing.input.toFixed(2)} per 1M tokens (${actualModel})`;
|
|
1743
1755
|
}
|
|
1756
|
+
|
|
1757
|
+
// src/server/stripe-payto.ts
|
|
1758
|
+
var STRIPE_NETWORK_KEYS = {
|
|
1759
|
+
"base": "base",
|
|
1760
|
+
"base-sepolia": "base_sepolia"
|
|
1761
|
+
};
|
|
1762
|
+
var CAIP2_NETWORKS = {
|
|
1763
|
+
"base": "eip155:8453",
|
|
1764
|
+
"base-sepolia": "eip155:84532"
|
|
1765
|
+
};
|
|
1766
|
+
var USDC_DECIMALS3 = 6;
|
|
1767
|
+
function stripePayTo(secretKeyOrConfig) {
|
|
1768
|
+
const config = typeof secretKeyOrConfig === "string" ? { secretKey: secretKeyOrConfig } : secretKeyOrConfig;
|
|
1769
|
+
const networkName = config.network ?? "base";
|
|
1770
|
+
const stripeNetworkKey = STRIPE_NETWORK_KEYS[networkName] ?? "base";
|
|
1771
|
+
const caip2Network = CAIP2_NETWORKS[networkName] ?? "eip155:8453";
|
|
1772
|
+
const apiVersion = config.apiVersion ?? "2026-01-28.clover";
|
|
1773
|
+
let stripeClient = null;
|
|
1774
|
+
async function getStripe() {
|
|
1775
|
+
if (stripeClient) return stripeClient;
|
|
1776
|
+
try {
|
|
1777
|
+
const { default: Stripe } = await import("stripe");
|
|
1778
|
+
stripeClient = new Stripe(config.secretKey, {
|
|
1779
|
+
apiVersion,
|
|
1780
|
+
appInfo: {
|
|
1781
|
+
name: "@dexterai/x402",
|
|
1782
|
+
url: "https://dexter.cash/sdk"
|
|
1783
|
+
}
|
|
1784
|
+
});
|
|
1785
|
+
return stripeClient;
|
|
1786
|
+
} catch {
|
|
1787
|
+
throw new Error(
|
|
1788
|
+
'The "stripe" package is required for stripePayTo(). Install it with: npm install stripe'
|
|
1789
|
+
);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
const provider = async (context) => {
|
|
1793
|
+
if (context.paymentHeader) {
|
|
1794
|
+
try {
|
|
1795
|
+
const decoded = JSON.parse(
|
|
1796
|
+
Buffer.from(context.paymentHeader, "base64").toString()
|
|
1797
|
+
);
|
|
1798
|
+
const toAddress = decoded.payload?.authorization?.to;
|
|
1799
|
+
if (toAddress && typeof toAddress === "string") {
|
|
1800
|
+
return toAddress;
|
|
1801
|
+
}
|
|
1802
|
+
const acceptedPayTo = decoded.accepted?.payTo;
|
|
1803
|
+
if (acceptedPayTo && typeof acceptedPayTo === "string") {
|
|
1804
|
+
return acceptedPayTo;
|
|
1805
|
+
}
|
|
1806
|
+
} catch {
|
|
1807
|
+
}
|
|
1808
|
+
throw new Error(
|
|
1809
|
+
"Could not extract deposit address from payment header. Ensure the client is sending a valid x402 PAYMENT-SIGNATURE."
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
const stripe = await getStripe();
|
|
1813
|
+
const amountAtomic = context.amountAtomic ? parseInt(context.amountAtomic, 10) : 1e4;
|
|
1814
|
+
const amountInCents = Math.max(1, Math.round(amountAtomic / Math.pow(10, USDC_DECIMALS3 - 2)));
|
|
1815
|
+
const paymentIntent = await stripe.paymentIntents.create({
|
|
1816
|
+
amount: amountInCents,
|
|
1817
|
+
currency: "usd",
|
|
1818
|
+
payment_method_types: ["crypto"],
|
|
1819
|
+
payment_method_data: {
|
|
1820
|
+
type: "crypto"
|
|
1821
|
+
},
|
|
1822
|
+
payment_method_options: {
|
|
1823
|
+
crypto: {
|
|
1824
|
+
mode: "custom"
|
|
1825
|
+
}
|
|
1826
|
+
},
|
|
1827
|
+
confirm: true
|
|
1828
|
+
});
|
|
1829
|
+
const nextAction = paymentIntent.next_action;
|
|
1830
|
+
if (!nextAction?.crypto_collect_deposit_details) {
|
|
1831
|
+
throw new Error(
|
|
1832
|
+
"Stripe PaymentIntent did not return crypto deposit details. Ensure your Stripe account has crypto payins enabled: https://support.stripe.com/questions/get-started-with-pay-with-crypto"
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
const depositDetails = nextAction.crypto_collect_deposit_details;
|
|
1836
|
+
const payToAddress = depositDetails.deposit_addresses?.[stripeNetworkKey]?.address;
|
|
1837
|
+
if (!payToAddress) {
|
|
1838
|
+
throw new Error(
|
|
1839
|
+
`No deposit address found for network "${stripeNetworkKey}". Available networks: ${Object.keys(depositDetails.deposit_addresses || {}).join(", ")}`
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
return payToAddress;
|
|
1843
|
+
};
|
|
1844
|
+
provider._x402Defaults = {
|
|
1845
|
+
network: caip2Network,
|
|
1846
|
+
facilitatorUrl: "https://x402.dexter.cash"
|
|
1847
|
+
};
|
|
1848
|
+
return provider;
|
|
1849
|
+
}
|
|
1744
1850
|
export {
|
|
1745
1851
|
BASE_MAINNET_NETWORK,
|
|
1746
1852
|
DEXTER_FACILITATOR_URL,
|
|
@@ -1770,6 +1876,7 @@ export {
|
|
|
1770
1876
|
getTextModels,
|
|
1771
1877
|
isValidModel,
|
|
1772
1878
|
isValidModelId,
|
|
1879
|
+
stripePayTo,
|
|
1773
1880
|
x402AccessPass,
|
|
1774
1881
|
x402BrowserSupport,
|
|
1775
1882
|
x402Middleware
|