@atxp/client 0.8.3 → 0.9.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/atxpClient.d.ts.map +1 -1
- package/dist/atxpClient.js +2 -1
- package/dist/atxpClient.js.map +1 -1
- package/dist/atxpFetcher.d.ts +13 -5
- package/dist/atxpFetcher.d.ts.map +1 -1
- package/dist/atxpFetcher.js +67 -18
- package/dist/atxpFetcher.js.map +1 -1
- package/dist/errors.d.ts +117 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +152 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +213 -386
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +144 -96
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +205 -378
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +25 -13
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -11
- package/dist/baseAccount.d.ts +0 -20
- package/dist/baseAccount.d.ts.map +0 -1
- package/dist/baseAccount.js +0 -46
- package/dist/baseAccount.js.map +0 -1
- package/dist/baseConstants.d.ts +0 -10
- package/dist/baseConstants.d.ts.map +0 -1
- package/dist/baseConstants.js +0 -21
- package/dist/baseConstants.js.map +0 -1
- package/dist/basePaymentMaker.d.ts +0 -23
- package/dist/basePaymentMaker.d.ts.map +0 -1
- package/dist/basePaymentMaker.js +0 -169
- package/dist/basePaymentMaker.js.map +0 -1
- package/dist/solanaAccount.d.ts +0 -13
- package/dist/solanaAccount.d.ts.map +0 -1
- package/dist/solanaAccount.js +0 -34
- package/dist/solanaAccount.js.map +0 -1
- package/dist/solanaPaymentMaker.d.ts +0 -25
- package/dist/solanaPaymentMaker.d.ts.map +0 -1
- package/dist/solanaPaymentMaker.js +0 -108
- package/dist/solanaPaymentMaker.js.map +0 -1
- package/dist/types.js +0 -24
- package/dist/types.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,126 @@
|
|
|
1
|
-
import { Account, Network, DestinationMaker, AuthorizationServerUrl, AccountId,
|
|
1
|
+
import { Currency, Account, Network, DestinationMaker, AuthorizationServerUrl, AccountId, OAuthDb, FetchLike, Logger, OAuthResourceClient, ClientCredentials, PKCEValues, AccessToken, PaymentRequestOption, Source, Destination } from '@atxp/common';
|
|
2
2
|
export { ATXPAccount, Account, PaymentMaker } from '@atxp/common';
|
|
3
3
|
import { ClientOptions, Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
4
|
import { Implementation } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
6
6
|
import * as oauth from 'oauth4webapi';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import { LocalAccount, Address, TypedData, Hex as Hex$1, SignableMessage, TransactionSerializable } from 'viem';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Base class for all ATXP payment errors with structured error codes and actionable guidance
|
|
11
|
+
*/
|
|
12
|
+
declare abstract class ATXPPaymentError extends Error {
|
|
13
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
14
|
+
abstract readonly code: string;
|
|
15
|
+
abstract readonly retryable: boolean;
|
|
16
|
+
abstract readonly actionableMessage: string;
|
|
17
|
+
constructor(message: string, context?: Record<string, unknown> | undefined);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when the user's wallet has insufficient funds for a payment
|
|
21
|
+
*/
|
|
22
|
+
declare class InsufficientFundsError extends ATXPPaymentError {
|
|
23
|
+
readonly currency: Currency;
|
|
24
|
+
readonly required: BigNumber;
|
|
25
|
+
readonly available?: BigNumber | undefined;
|
|
26
|
+
readonly network?: string | undefined;
|
|
27
|
+
readonly code = "INSUFFICIENT_FUNDS";
|
|
28
|
+
readonly retryable = true;
|
|
29
|
+
readonly actionableMessage: string;
|
|
30
|
+
constructor(currency: Currency, required: BigNumber, available?: BigNumber | undefined, network?: string | undefined);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown when a blockchain transaction is reverted
|
|
34
|
+
*/
|
|
35
|
+
declare class TransactionRevertedError extends ATXPPaymentError {
|
|
36
|
+
readonly transactionHash: string;
|
|
37
|
+
readonly network: string;
|
|
38
|
+
readonly revertReason?: string | undefined;
|
|
39
|
+
readonly code = "TRANSACTION_REVERTED";
|
|
40
|
+
readonly retryable = false;
|
|
41
|
+
readonly actionableMessage: string;
|
|
42
|
+
constructor(transactionHash: string, network: string, revertReason?: string | undefined);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when an unsupported currency is requested
|
|
46
|
+
*/
|
|
47
|
+
declare class UnsupportedCurrencyError extends ATXPPaymentError {
|
|
48
|
+
readonly currency: string;
|
|
49
|
+
readonly network: string;
|
|
50
|
+
readonly supportedCurrencies: string[];
|
|
51
|
+
readonly code = "UNSUPPORTED_CURRENCY";
|
|
52
|
+
readonly retryable = false;
|
|
53
|
+
readonly actionableMessage: string;
|
|
54
|
+
constructor(currency: string, network: string, supportedCurrencies: string[]);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Thrown when gas estimation fails for a transaction
|
|
58
|
+
*/
|
|
59
|
+
declare class GasEstimationError extends ATXPPaymentError {
|
|
60
|
+
readonly network: string;
|
|
61
|
+
readonly reason?: string | undefined;
|
|
62
|
+
readonly code = "GAS_ESTIMATION_FAILED";
|
|
63
|
+
readonly retryable = true;
|
|
64
|
+
readonly actionableMessage = "Unable to estimate gas for this transaction. Ensure you have sufficient funds for both the payment amount and gas fees, then try again.";
|
|
65
|
+
constructor(network: string, reason?: string | undefined);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Thrown when RPC/network connectivity fails
|
|
69
|
+
*/
|
|
70
|
+
declare class RpcError extends ATXPPaymentError {
|
|
71
|
+
readonly network: string;
|
|
72
|
+
readonly rpcUrl?: string | undefined;
|
|
73
|
+
readonly originalError?: Error | undefined;
|
|
74
|
+
readonly code = "RPC_ERROR";
|
|
75
|
+
readonly retryable = true;
|
|
76
|
+
readonly actionableMessage = "Unable to connect to the blockchain network. Please check your internet connection and try again.";
|
|
77
|
+
constructor(network: string, rpcUrl?: string | undefined, originalError?: Error | undefined);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Thrown when the user rejects a transaction in their wallet
|
|
81
|
+
*/
|
|
82
|
+
declare class UserRejectedError extends ATXPPaymentError {
|
|
83
|
+
readonly network: string;
|
|
84
|
+
readonly code = "USER_REJECTED";
|
|
85
|
+
readonly retryable = true;
|
|
86
|
+
readonly actionableMessage = "You cancelled the transaction. To complete the payment, please approve the transaction in your wallet.";
|
|
87
|
+
constructor(network: string);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Thrown when the payment server returns an error
|
|
91
|
+
*/
|
|
92
|
+
declare class PaymentServerError extends ATXPPaymentError {
|
|
93
|
+
readonly statusCode: number;
|
|
94
|
+
readonly endpoint: string;
|
|
95
|
+
readonly serverMessage?: string | undefined;
|
|
96
|
+
readonly details?: unknown | undefined;
|
|
97
|
+
readonly code: string;
|
|
98
|
+
readonly retryable = true;
|
|
99
|
+
readonly actionableMessage = "The payment server encountered an error. Please try again in a few moments.";
|
|
100
|
+
constructor(statusCode: number, endpoint: string, serverMessage?: string | undefined, errorCode?: string, details?: unknown | undefined);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Thrown when a payment request has expired
|
|
104
|
+
*/
|
|
105
|
+
declare class PaymentExpiredError extends ATXPPaymentError {
|
|
106
|
+
readonly paymentRequestId: string;
|
|
107
|
+
readonly expiresAt?: Date | undefined;
|
|
108
|
+
readonly code = "PAYMENT_EXPIRED";
|
|
109
|
+
readonly retryable = false;
|
|
110
|
+
readonly actionableMessage = "This payment request has expired. Please make a new request to the service.";
|
|
111
|
+
constructor(paymentRequestId: string, expiresAt?: Date | undefined);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Generic network error for backward compatibility and uncategorized errors
|
|
115
|
+
*/
|
|
116
|
+
declare class PaymentNetworkError extends ATXPPaymentError {
|
|
117
|
+
readonly network: string;
|
|
118
|
+
readonly originalError?: Error | undefined;
|
|
119
|
+
readonly code = "NETWORK_ERROR";
|
|
120
|
+
readonly retryable = true;
|
|
121
|
+
readonly actionableMessage = "A network error occurred during payment processing. Please try again.";
|
|
122
|
+
constructor(network: string, message: string, originalError?: Error | undefined);
|
|
123
|
+
}
|
|
10
124
|
|
|
11
125
|
type Hex = `0x${string}`;
|
|
12
126
|
type AccountPrefix = Network;
|
|
@@ -19,6 +133,23 @@ type ProspectivePayment = {
|
|
|
19
133
|
amount: BigNumber;
|
|
20
134
|
iss: string;
|
|
21
135
|
};
|
|
136
|
+
/**
|
|
137
|
+
* Rich context provided when a payment fails
|
|
138
|
+
*/
|
|
139
|
+
interface PaymentFailureContext {
|
|
140
|
+
/** The payment that failed */
|
|
141
|
+
payment: ProspectivePayment;
|
|
142
|
+
/** The error that caused the failure */
|
|
143
|
+
error: Error;
|
|
144
|
+
/** Networks that were attempted for payment */
|
|
145
|
+
attemptedNetworks: string[];
|
|
146
|
+
/** Map of network to error for each failed attempt */
|
|
147
|
+
failureReasons: Map<string, Error>;
|
|
148
|
+
/** Whether the payment can be retried */
|
|
149
|
+
retryable: boolean;
|
|
150
|
+
/** Timestamp when the failure occurred */
|
|
151
|
+
timestamp: Date;
|
|
152
|
+
}
|
|
22
153
|
type ClientConfig = {
|
|
23
154
|
mcpServer: string;
|
|
24
155
|
account: Account;
|
|
@@ -44,10 +175,15 @@ type ClientConfig = {
|
|
|
44
175
|
}) => Promise<void>;
|
|
45
176
|
onPayment: (args: {
|
|
46
177
|
payment: ProspectivePayment;
|
|
178
|
+
transactionHash: string;
|
|
179
|
+
network: string;
|
|
47
180
|
}) => Promise<void>;
|
|
48
|
-
onPaymentFailure: (
|
|
49
|
-
|
|
181
|
+
onPaymentFailure: (context: PaymentFailureContext) => Promise<void>;
|
|
182
|
+
/** Optional callback when a single payment attempt fails (before trying other networks) */
|
|
183
|
+
onPaymentAttemptFailed?: (args: {
|
|
184
|
+
network: string;
|
|
50
185
|
error: Error;
|
|
186
|
+
remainingNetworks: string[];
|
|
51
187
|
}) => Promise<void>;
|
|
52
188
|
};
|
|
53
189
|
type RequiredClientConfigFields$1 = 'mcpServer' | 'account';
|
|
@@ -55,17 +191,6 @@ type RequiredClientConfig = Pick<ClientConfig, RequiredClientConfigFields$1>;
|
|
|
55
191
|
type OptionalClientConfig$1 = Omit<ClientConfig, RequiredClientConfigFields$1>;
|
|
56
192
|
type ClientArgs = RequiredClientConfig & Partial<OptionalClientConfig$1>;
|
|
57
193
|
type FetchWrapper = (config: ClientArgs) => FetchLike;
|
|
58
|
-
declare class InsufficientFundsError extends Error {
|
|
59
|
-
readonly currency: Currency;
|
|
60
|
-
readonly required: BigNumber;
|
|
61
|
-
readonly available?: BigNumber | undefined;
|
|
62
|
-
readonly network?: string | undefined;
|
|
63
|
-
constructor(currency: Currency, required: BigNumber, available?: BigNumber | undefined, network?: string | undefined);
|
|
64
|
-
}
|
|
65
|
-
declare class PaymentNetworkError extends Error {
|
|
66
|
-
readonly originalError?: Error | undefined;
|
|
67
|
-
constructor(message: string, originalError?: Error | undefined);
|
|
68
|
-
}
|
|
69
194
|
|
|
70
195
|
type RequiredClientConfigFields = 'mcpServer' | 'account';
|
|
71
196
|
type OptionalClientConfig = Omit<ClientConfig, RequiredClientConfigFields>;
|
|
@@ -125,66 +250,6 @@ declare class OAuthClient extends OAuthResourceClient {
|
|
|
125
250
|
*/
|
|
126
251
|
declare function atxpFetch(config: ClientConfig): FetchLike;
|
|
127
252
|
|
|
128
|
-
declare const ValidateTransferError: typeof ValidateTransferError$1;
|
|
129
|
-
declare class SolanaPaymentMaker implements PaymentMaker {
|
|
130
|
-
private connection;
|
|
131
|
-
private source;
|
|
132
|
-
private logger;
|
|
133
|
-
constructor(solanaEndpoint: string, sourceSecretKey: string, logger?: Logger);
|
|
134
|
-
getSourceAddress(_params: {
|
|
135
|
-
amount: BigNumber$1;
|
|
136
|
-
currency: Currency;
|
|
137
|
-
receiver: string;
|
|
138
|
-
memo: string;
|
|
139
|
-
}): string;
|
|
140
|
-
generateJWT: ({ paymentRequestId, codeChallenge, accountId }: {
|
|
141
|
-
paymentRequestId: string;
|
|
142
|
-
codeChallenge: string;
|
|
143
|
-
accountId?: AccountId | null;
|
|
144
|
-
}) => Promise<string>;
|
|
145
|
-
makePayment: (destinations: Destination[], memo: string, _paymentRequestId?: string) => Promise<PaymentIdentifier | null>;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
type ExtendedWalletClient = WalletClient & PublicActions;
|
|
149
|
-
declare class BasePaymentMaker implements PaymentMaker {
|
|
150
|
-
protected signingClient: ExtendedWalletClient;
|
|
151
|
-
protected logger: Logger;
|
|
152
|
-
constructor(baseRPCUrl: string, walletClient: WalletClient, logger?: Logger);
|
|
153
|
-
getSourceAddress(_params: {
|
|
154
|
-
amount: BigNumber;
|
|
155
|
-
currency: Currency;
|
|
156
|
-
receiver: string;
|
|
157
|
-
memo: string;
|
|
158
|
-
}): string;
|
|
159
|
-
generateJWT({ paymentRequestId, codeChallenge, accountId }: {
|
|
160
|
-
paymentRequestId: string;
|
|
161
|
-
codeChallenge: string;
|
|
162
|
-
accountId?: AccountId | null;
|
|
163
|
-
}): Promise<string>;
|
|
164
|
-
makePayment(destinations: Destination[], _memo: string, _paymentRequestId?: string): Promise<PaymentIdentifier | null>;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
declare class SolanaAccount implements Account {
|
|
168
|
-
accountId: AccountId;
|
|
169
|
-
paymentMakers: PaymentMaker[];
|
|
170
|
-
private sourcePublicKey;
|
|
171
|
-
constructor(solanaEndpoint: string, sourceSecretKey: string);
|
|
172
|
-
/**
|
|
173
|
-
* Get sources for this account
|
|
174
|
-
*/
|
|
175
|
-
getSources(): Promise<Source[]>;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
declare const USDC_CONTRACT_ADDRESS_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
179
|
-
declare const USDC_CONTRACT_ADDRESS_BASE_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
|
|
180
|
-
/**
|
|
181
|
-
* Get USDC contract address for Base chain by chain ID
|
|
182
|
-
* @param chainId - Chain ID (8453 for mainnet, 84532 for sepolia)
|
|
183
|
-
* @returns USDC contract address
|
|
184
|
-
* @throws Error if chain ID is not supported
|
|
185
|
-
*/
|
|
186
|
-
declare const getBaseUSDCAddress: (chainId: number) => string;
|
|
187
|
-
|
|
188
253
|
/**
|
|
189
254
|
* World Chain configuration type, compatible with viem's Chain interface
|
|
190
255
|
*/
|
|
@@ -291,23 +356,6 @@ declare const getPolygonByChainId: (chainId: number) => PolygonChain;
|
|
|
291
356
|
*/
|
|
292
357
|
declare const getPolygonUSDCAddress: (chainId: number) => string;
|
|
293
358
|
|
|
294
|
-
declare class BaseAccount implements Account {
|
|
295
|
-
accountId: AccountId;
|
|
296
|
-
paymentMakers: PaymentMaker[];
|
|
297
|
-
private walletClient;
|
|
298
|
-
private account;
|
|
299
|
-
constructor(baseRPCUrl: string, sourceSecretKey: string);
|
|
300
|
-
/**
|
|
301
|
-
* Get the LocalAccount (signer) for this account.
|
|
302
|
-
* This can be used with the x402 library or other signing operations.
|
|
303
|
-
*/
|
|
304
|
-
getLocalAccount(): LocalAccount;
|
|
305
|
-
/**
|
|
306
|
-
* Get sources for this account
|
|
307
|
-
*/
|
|
308
|
-
getSources(): Promise<Source[]>;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
359
|
/**
|
|
312
360
|
* ATXP implementation of viem's LocalAccount interface.
|
|
313
361
|
* Delegates signing operations to the accounts-x402 API.
|
|
@@ -375,5 +423,5 @@ declare class PassthroughDestinationMaker implements DestinationMaker {
|
|
|
375
423
|
makeDestinations(option: PaymentRequestOption, _logger: Logger, _paymentRequestId: string, _sources: Source[]): Promise<Destination[]>;
|
|
376
424
|
}
|
|
377
425
|
|
|
378
|
-
export { ATXPDestinationMaker, ATXPLocalAccount,
|
|
379
|
-
export type { AccountIdString, ClientArgs, ClientConfig, FetchWrapper, Hex, OAuthClientConfig, PolygonChain, ProspectivePayment, WorldChain };
|
|
426
|
+
export { ATXPDestinationMaker, ATXPLocalAccount, ATXPPaymentError, DEFAULT_CLIENT_CONFIG, GasEstimationError, InsufficientFundsError, OAuthAuthenticationRequiredError, OAuthClient, POLYGON_AMOY, POLYGON_MAINNET, PassthroughDestinationMaker, PaymentExpiredError, PaymentNetworkError, PaymentServerError, RpcError, TransactionRevertedError, USDC_CONTRACT_ADDRESS_POLYGON_AMOY, USDC_CONTRACT_ADDRESS_POLYGON_MAINNET, USDC_CONTRACT_ADDRESS_WORLD_MAINNET, USDC_CONTRACT_ADDRESS_WORLD_SEPOLIA, UnsupportedCurrencyError, UserRejectedError, WORLD_CHAIN_MAINNET, WORLD_CHAIN_SEPOLIA, atxpClient, atxpFetch, buildClientConfig, buildStreamableTransport, getPolygonAmoyWithRPC, getPolygonByChainId, getPolygonMainnetWithRPC, getPolygonUSDCAddress, getWorldChainByChainId, getWorldChainMainnetWithRPC, getWorldChainSepoliaWithRPC, getWorldChainUSDCAddress };
|
|
427
|
+
export type { AccountIdString, ClientArgs, ClientConfig, FetchWrapper, Hex, OAuthClientConfig, PaymentFailureContext, PolygonChain, ProspectivePayment, WorldChain };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,EACxB,UAAU,EACX,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gCAAgC,EAChC,KAAK,iBAAiB,EACtB,WAAW,EACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,SAAS,EACV,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,EACxB,UAAU,EACX,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gCAAgC,EAChC,KAAK,iBAAiB,EACtB,WAAW,EACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,SAAS,EACV,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACZ,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,mCAAmC,EACnC,mCAAmC,EACnC,mBAAmB,EACnB,mBAAmB,EACnB,2BAA2B,EAC3B,2BAA2B,EAC3B,sBAAsB,EACtB,wBAAwB,EACxB,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,qCAAqC,EACrC,kCAAkC,EAClC,eAAe,EACf,YAAY,EACZ,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,KAAK,GAAG,EACR,KAAK,eAAe,EACpB,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC"}
|