@wtflabs/x402 0.0.1-beta.0 → 0.0.1-beta.1
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/esm/client/index.d.mts +64 -0
- package/dist/esm/config-CFBSAuxW.d.mts +10 -0
- package/dist/esm/config-Dfuvno71.d.mts +19 -0
- package/dist/esm/facilitator/index.d.mts +42 -0
- package/dist/esm/index.d.mts +16 -0
- package/dist/esm/middleware-BSjsPDKM.d.mts +93 -0
- package/dist/esm/network-FrFmmiyj.d.mts +11 -0
- package/dist/esm/paywall/index.d.mts +30 -0
- package/dist/esm/rpc-DyKXu0SX.d.mts +35 -0
- package/dist/esm/schemes/index.d.mts +533 -0
- package/dist/esm/shared/evm/index.d.mts +71 -0
- package/dist/esm/shared/index.d.mts +182 -0
- package/dist/esm/types/index.d.mts +1515 -0
- package/dist/esm/verify/index.d.mts +7 -0
- package/dist/esm/wallet-BTqCm9Zp.d.mts +27 -0
- package/dist/esm/wallet-KorGgbAj.d.mts +88 -0
- package/dist/esm/wallet-SJKJpUgQ.d.mts +167 -0
- package/dist/esm/x402Specs-CYq5tSY1.d.mts +1745 -0
- package/package.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { X as X402Config } from '../config-Dfuvno71.mjs';
|
|
2
|
+
import { P as PaymentRequirements, p as UnsignedEip3009PaymentPayload } from '../x402Specs-CYq5tSY1.mjs';
|
|
3
|
+
import { S as Signer, M as MultiNetworkSigner } from '../wallet-KorGgbAj.mjs';
|
|
4
|
+
import { Address } from 'viem';
|
|
5
|
+
import { N as Network } from '../network-FrFmmiyj.mjs';
|
|
6
|
+
import 'zod';
|
|
7
|
+
import '../wallet-SJKJpUgQ.mjs';
|
|
8
|
+
import 'viem/chains';
|
|
9
|
+
import '../wallet-BTqCm9Zp.mjs';
|
|
10
|
+
import '@solana/kit';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a payment header based on the provided client and payment requirements.
|
|
14
|
+
*
|
|
15
|
+
* @param client - The signer wallet instance used to create the payment header
|
|
16
|
+
* @param x402Version - The version of the X402 protocol to use
|
|
17
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
18
|
+
* @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
|
|
19
|
+
* @returns A promise that resolves to the created payment header string
|
|
20
|
+
*/
|
|
21
|
+
declare function createPaymentHeader(client: Signer | MultiNetworkSigner, x402Version: number, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<string>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Prepares a payment header with the given sender address and payment requirements.
|
|
25
|
+
*
|
|
26
|
+
* @param from - The sender's address from which the payment will be made
|
|
27
|
+
* @param x402Version - The version of the X402 protocol to use
|
|
28
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
29
|
+
* @returns An unsigned payment payload that can be used to create a payment header
|
|
30
|
+
*/
|
|
31
|
+
declare function preparePaymentHeader(from: Address, x402Version: number, paymentRequirements: PaymentRequirements): UnsignedEip3009PaymentPayload;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Default selector for payment requirements.
|
|
35
|
+
* Default behavior is to select the first payment requirement that has a USDC asset.
|
|
36
|
+
* If no USDC payment requirement is found, the first payment requirement is selected.
|
|
37
|
+
*
|
|
38
|
+
* @param paymentRequirements - The payment requirements to select from.
|
|
39
|
+
* @param network - The network to check against. If not provided, the network will not be checked.
|
|
40
|
+
* @param scheme - The scheme to check against. If not provided, the scheme will not be checked.
|
|
41
|
+
* @returns The payment requirement that is the most appropriate for the user.
|
|
42
|
+
*/
|
|
43
|
+
declare function selectPaymentRequirements(paymentRequirements: PaymentRequirements[], network?: Network | Network[], scheme?: "exact"): PaymentRequirements;
|
|
44
|
+
/**
|
|
45
|
+
* Selector for payment requirements.
|
|
46
|
+
*
|
|
47
|
+
* @param paymentRequirements - The payment requirements to select from.
|
|
48
|
+
* @param network - The network to check against. If not provided, the network will not be checked.
|
|
49
|
+
* @param scheme - The scheme to check against. If not provided, the scheme will not be checked.
|
|
50
|
+
* @returns The payment requirement that is the most appropriate for the user.
|
|
51
|
+
*/
|
|
52
|
+
type PaymentRequirementsSelector = (paymentRequirements: PaymentRequirements[], network?: Network | Network[], scheme?: "exact") => PaymentRequirements;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Signs a payment header using the provided client and payment requirements.
|
|
56
|
+
*
|
|
57
|
+
* @param client - The signer wallet instance used to sign the payment header
|
|
58
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
59
|
+
* @param unsignedPaymentHeader - The unsigned payment payload to be signed
|
|
60
|
+
* @returns A promise that resolves to the encoded signed payment header string
|
|
61
|
+
*/
|
|
62
|
+
declare function signPaymentHeader(client: Signer | MultiNetworkSigner, paymentRequirements: PaymentRequirements, unsignedPaymentHeader: UnsignedEip3009PaymentPayload): Promise<string>;
|
|
63
|
+
|
|
64
|
+
export { type PaymentRequirementsSelector, createPaymentHeader, preparePaymentHeader, selectPaymentRequirements, signPaymentHeader };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { Address as Address$1 } from '@solana/kit';
|
|
3
|
+
|
|
4
|
+
declare const config: Record<string, ChainConfig>;
|
|
5
|
+
type ChainConfig = {
|
|
6
|
+
usdcAddress: Address | Address$1;
|
|
7
|
+
usdcName: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { type ChainConfig as C, config as c };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for Solana (SVM) RPC connections.
|
|
3
|
+
*/
|
|
4
|
+
interface SvmConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Custom RPC URL for Solana connections.
|
|
7
|
+
* If not provided, defaults to public Solana RPC endpoints based on network.
|
|
8
|
+
*/
|
|
9
|
+
rpcUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for X402 client and facilitator operations.
|
|
13
|
+
*/
|
|
14
|
+
interface X402Config {
|
|
15
|
+
/** Configuration for Solana (SVM) operations */
|
|
16
|
+
svmConfig?: SvmConfig;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type { SvmConfig as S, X402Config as X };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { X as X402Config } from '../config-Dfuvno71.mjs';
|
|
2
|
+
import { C as ConnectedClient, S as Signer } from '../wallet-KorGgbAj.mjs';
|
|
3
|
+
import { a as PaymentPayload, P as PaymentRequirements, J as VerifyResponse, S as SettleResponse } from '../x402Specs-CYq5tSY1.mjs';
|
|
4
|
+
import { Transport, Chain, Account } from 'viem';
|
|
5
|
+
import '../wallet-SJKJpUgQ.mjs';
|
|
6
|
+
import 'viem/chains';
|
|
7
|
+
import '../wallet-BTqCm9Zp.mjs';
|
|
8
|
+
import '@solana/kit';
|
|
9
|
+
import 'zod';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Verifies a payment payload against the required payment details regardless of the scheme
|
|
13
|
+
* this function wraps all verify functions for each specific scheme
|
|
14
|
+
*
|
|
15
|
+
* @param client - The public client used for blockchain interactions
|
|
16
|
+
* @param payload - The signed payment payload containing transfer parameters and signature
|
|
17
|
+
* @param paymentRequirements - The payment requirements that the payload must satisfy
|
|
18
|
+
* @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
|
|
19
|
+
* @returns A ValidPaymentRequest indicating if the payment is valid and any invalidation reason
|
|
20
|
+
*/
|
|
21
|
+
declare function verify<transport extends Transport, chain extends Chain, account extends Account | undefined>(client: ConnectedClient | Signer, payload: PaymentPayload, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<VerifyResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Settles a payment payload against the required payment details regardless of the scheme
|
|
24
|
+
* this function wraps all settle functions for each specific scheme
|
|
25
|
+
*
|
|
26
|
+
* @param client - The signer wallet used for blockchain interactions
|
|
27
|
+
* @param payload - The signed payment payload containing transfer parameters and signature
|
|
28
|
+
* @param paymentRequirements - The payment requirements that the payload must satisfy
|
|
29
|
+
* @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
|
|
30
|
+
* @returns A SettleResponse indicating if the payment is settled and any settlement reason
|
|
31
|
+
*/
|
|
32
|
+
declare function settle<transport extends Transport, chain extends Chain>(client: Signer, payload: PaymentPayload, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<SettleResponse>;
|
|
33
|
+
type Supported = {
|
|
34
|
+
x402Version: number;
|
|
35
|
+
kind: {
|
|
36
|
+
scheme: string;
|
|
37
|
+
networkId: string;
|
|
38
|
+
extra: object;
|
|
39
|
+
}[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { type Supported, settle, verify };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { PaymentRequirementsSelector, createPaymentHeader, preparePaymentHeader, selectPaymentRequirements, signPaymentHeader } from './client/index.mjs';
|
|
2
|
+
export { Supported, settle, verify } from './facilitator/index.mjs';
|
|
3
|
+
import './config-Dfuvno71.mjs';
|
|
4
|
+
import './x402Specs-CYq5tSY1.mjs';
|
|
5
|
+
import 'zod';
|
|
6
|
+
import './wallet-KorGgbAj.mjs';
|
|
7
|
+
import './wallet-SJKJpUgQ.mjs';
|
|
8
|
+
import 'viem';
|
|
9
|
+
import 'viem/chains';
|
|
10
|
+
import './wallet-BTqCm9Zp.mjs';
|
|
11
|
+
import '@solana/kit';
|
|
12
|
+
import './network-FrFmmiyj.mjs';
|
|
13
|
+
|
|
14
|
+
declare const x402Version = 1;
|
|
15
|
+
|
|
16
|
+
export { x402Version };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { N as Network } from './network-FrFmmiyj.mjs';
|
|
3
|
+
import { E as EvmSigner } from './wallet-SJKJpUgQ.mjs';
|
|
4
|
+
import { a as PaymentPayload, P as PaymentRequirements, J as VerifyResponse, S as SettleResponse, X as SupportedPaymentKindsResponse, M as ListDiscoveryResourcesRequest, O as ListDiscoveryResourcesResponse, z as HTTPRequestStructure } from './x402Specs-CYq5tSY1.mjs';
|
|
5
|
+
|
|
6
|
+
declare const moneySchema: z.ZodPipeline<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodNumber]>, z.ZodNumber>;
|
|
7
|
+
type Money = z.input<typeof moneySchema>;
|
|
8
|
+
|
|
9
|
+
type Resource = `${string}://${string}`;
|
|
10
|
+
|
|
11
|
+
type CreateHeaders = () => Promise<{
|
|
12
|
+
verify: Record<string, string>;
|
|
13
|
+
settle: Record<string, string>;
|
|
14
|
+
supported: Record<string, string>;
|
|
15
|
+
list?: Record<string, string>;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a facilitator client for interacting with the X402 payment facilitator service
|
|
19
|
+
*
|
|
20
|
+
* @param facilitator - The facilitator config to use. If not provided, the default facilitator will be used.
|
|
21
|
+
* @returns An object containing verify and settle functions for interacting with the facilitator
|
|
22
|
+
*/
|
|
23
|
+
declare function useFacilitator(facilitator?: FacilitatorConfig): {
|
|
24
|
+
verify: (payload: PaymentPayload, paymentRequirements: PaymentRequirements) => Promise<VerifyResponse>;
|
|
25
|
+
settle: (payload: PaymentPayload, paymentRequirements: PaymentRequirements) => Promise<SettleResponse>;
|
|
26
|
+
supported: () => Promise<SupportedPaymentKindsResponse>;
|
|
27
|
+
list: (config?: ListDiscoveryResourcesRequest) => Promise<ListDiscoveryResourcesResponse>;
|
|
28
|
+
};
|
|
29
|
+
declare const verify: (payload: PaymentPayload, paymentRequirements: PaymentRequirements) => Promise<VerifyResponse>;
|
|
30
|
+
declare const settle: (payload: PaymentPayload, paymentRequirements: PaymentRequirements) => Promise<SettleResponse>;
|
|
31
|
+
declare const supported: () => Promise<SupportedPaymentKindsResponse>;
|
|
32
|
+
declare const list: (config?: ListDiscoveryResourcesRequest) => Promise<ListDiscoveryResourcesResponse>;
|
|
33
|
+
|
|
34
|
+
type FacilitatorConfig = {
|
|
35
|
+
url: Resource;
|
|
36
|
+
createAuthHeaders?: CreateHeaders;
|
|
37
|
+
};
|
|
38
|
+
type PaywallConfig = {
|
|
39
|
+
cdpClientKey?: string;
|
|
40
|
+
appName?: string;
|
|
41
|
+
appLogo?: string;
|
|
42
|
+
sessionTokenEndpoint?: string;
|
|
43
|
+
};
|
|
44
|
+
type PaymentMiddlewareConfig = {
|
|
45
|
+
description?: string;
|
|
46
|
+
mimeType?: string;
|
|
47
|
+
maxTimeoutSeconds?: number;
|
|
48
|
+
inputSchema?: Omit<HTTPRequestStructure, "type" | "method">;
|
|
49
|
+
outputSchema?: object;
|
|
50
|
+
discoverable?: boolean;
|
|
51
|
+
customPaywallHtml?: string;
|
|
52
|
+
resource?: Resource;
|
|
53
|
+
errorMessages?: {
|
|
54
|
+
paymentRequired?: string;
|
|
55
|
+
invalidPayment?: string;
|
|
56
|
+
noMatchingRequirements?: string;
|
|
57
|
+
verificationFailed?: string;
|
|
58
|
+
settlementFailed?: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
interface ERC20TokenAmount {
|
|
62
|
+
amount: string;
|
|
63
|
+
asset: {
|
|
64
|
+
address: `0x${string}`;
|
|
65
|
+
decimals: number;
|
|
66
|
+
eip712: {
|
|
67
|
+
name: string;
|
|
68
|
+
version: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
interface SPLTokenAmount {
|
|
73
|
+
amount: string;
|
|
74
|
+
asset: {
|
|
75
|
+
address: string;
|
|
76
|
+
decimals: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
type Price = Money | ERC20TokenAmount | SPLTokenAmount;
|
|
80
|
+
interface RouteConfig {
|
|
81
|
+
price: Price;
|
|
82
|
+
network: Network;
|
|
83
|
+
config?: PaymentMiddlewareConfig;
|
|
84
|
+
}
|
|
85
|
+
type RoutesConfig = Record<string, Price | RouteConfig>;
|
|
86
|
+
interface RoutePattern {
|
|
87
|
+
verb: string;
|
|
88
|
+
pattern: RegExp;
|
|
89
|
+
config: RouteConfig;
|
|
90
|
+
}
|
|
91
|
+
type Wallet = EvmSigner;
|
|
92
|
+
|
|
93
|
+
export { type CreateHeaders as C, type ERC20TokenAmount as E, type FacilitatorConfig as F, type Money as M, type Price as P, type RoutesConfig as R, type SPLTokenAmount as S, type Wallet as W, type RoutePattern as a, type Resource as b, type PaywallConfig as c, type PaymentMiddlewareConfig as d, type RouteConfig as e, supported as f, list as l, moneySchema as m, settle as s, useFacilitator as u, verify as v };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const NetworkSchema: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
|
|
4
|
+
type Network = z.infer<typeof NetworkSchema>;
|
|
5
|
+
declare const SupportedEVMNetworks: Network[];
|
|
6
|
+
declare const EvmNetworkToChainId: Map<"base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana", number>;
|
|
7
|
+
declare const SupportedSVMNetworks: Network[];
|
|
8
|
+
declare const SvmNetworkToChainId: Map<"base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana", number>;
|
|
9
|
+
declare const ChainIdToNetwork: Record<number, Network>;
|
|
10
|
+
|
|
11
|
+
export { ChainIdToNetwork as C, EvmNetworkToChainId as E, type Network as N, SupportedEVMNetworks as S, NetworkSchema as a, SupportedSVMNetworks as b, SvmNetworkToChainId as c };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { P as PaymentRequirements } from '../x402Specs-CYq5tSY1.mjs';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
interface PaywallOptions {
|
|
5
|
+
amount: number;
|
|
6
|
+
paymentRequirements: PaymentRequirements[];
|
|
7
|
+
currentUrl: string;
|
|
8
|
+
testnet: boolean;
|
|
9
|
+
cdpClientKey?: string;
|
|
10
|
+
appName?: string;
|
|
11
|
+
appLogo?: string;
|
|
12
|
+
sessionTokenEndpoint?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generates an HTML paywall page that allows users to pay for content access
|
|
16
|
+
*
|
|
17
|
+
* @param options - The options for generating the paywall
|
|
18
|
+
* @param options.amount - The amount to be paid in USD
|
|
19
|
+
* @param options.paymentRequirements - The payment requirements for the content
|
|
20
|
+
* @param options.currentUrl - The URL of the content being accessed
|
|
21
|
+
* @param options.testnet - Whether to use testnet or mainnet
|
|
22
|
+
* @param options.cdpClientKey - CDP client API key for OnchainKit
|
|
23
|
+
* @param options.appName - The name of the application to display in the wallet connection modal
|
|
24
|
+
* @param options.appLogo - The logo of the application to display in the wallet connection modal
|
|
25
|
+
* @param options.sessionTokenEndpoint - The API endpoint for generating session tokens for Onramp authentication
|
|
26
|
+
* @returns An HTML string containing the paywall page
|
|
27
|
+
*/
|
|
28
|
+
declare function getPaywallHtml({ amount, testnet, paymentRequirements, currentUrl, cdpClientKey, appName, appLogo, sessionTokenEndpoint, }: PaywallOptions): string;
|
|
29
|
+
|
|
30
|
+
export { getPaywallHtml };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RpcDevnet, SolanaRpcApiDevnet, RpcMainnet, SolanaRpcApiMainnet, RpcSubscriptionsFromTransport, SolanaRpcSubscriptionsApi, RpcSubscriptionsTransportFromClusterUrl, ClusterUrl } from '@solana/kit';
|
|
2
|
+
import { N as Network } from './network-FrFmmiyj.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Solana RPC client for the devnet network.
|
|
6
|
+
*
|
|
7
|
+
* @param url - Optional URL of the devnet network.
|
|
8
|
+
* @returns A Solana RPC client.
|
|
9
|
+
*/
|
|
10
|
+
declare function createDevnetRpcClient(url?: string): RpcDevnet<SolanaRpcApiDevnet>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Solana RPC client for the mainnet network.
|
|
13
|
+
*
|
|
14
|
+
* @param url - Optional URL of the mainnet network.
|
|
15
|
+
* @returns A Solana RPC client.
|
|
16
|
+
*/
|
|
17
|
+
declare function createMainnetRpcClient(url?: string): RpcMainnet<SolanaRpcApiMainnet>;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the RPC client for the given network.
|
|
20
|
+
*
|
|
21
|
+
* @param network - The network to get the RPC client for
|
|
22
|
+
* @param url - Optional URL of the network. If not provided, the default URL will be used.
|
|
23
|
+
* @returns The RPC client for the given network
|
|
24
|
+
*/
|
|
25
|
+
declare function getRpcClient(network: Network, url?: string): RpcDevnet<SolanaRpcApiDevnet> | RpcMainnet<SolanaRpcApiMainnet>;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the RPC subscriptions for the given network.
|
|
28
|
+
*
|
|
29
|
+
* @param network - The network to get the RPC subscriptions for
|
|
30
|
+
* @param url - Optional URL of the network. If not provided, the default URL will be used.
|
|
31
|
+
* @returns The RPC subscriptions for the given network
|
|
32
|
+
*/
|
|
33
|
+
declare function getRpcSubscriptions(network: Network, url?: string): RpcSubscriptionsFromTransport<SolanaRpcSubscriptionsApi, RpcSubscriptionsTransportFromClusterUrl<ClusterUrl>>;
|
|
34
|
+
|
|
35
|
+
export { createMainnetRpcClient as a, getRpcSubscriptions as b, createDevnetRpcClient as c, getRpcClient as g };
|