@atxp/client 0.7.4 → 0.8.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.
Files changed (55) hide show
  1. package/dist/atxpClient.d.ts +1 -1
  2. package/dist/atxpClient.d.ts.map +1 -1
  3. package/dist/atxpClient.js +17 -2
  4. package/dist/atxpClient.js.map +1 -1
  5. package/dist/atxpFetcher.d.ts +5 -15
  6. package/dist/atxpFetcher.d.ts.map +1 -1
  7. package/dist/atxpFetcher.js +95 -229
  8. package/dist/atxpFetcher.js.map +1 -1
  9. package/dist/baseAccount.d.ts +10 -7
  10. package/dist/baseAccount.d.ts.map +1 -1
  11. package/dist/baseAccount.js +18 -8
  12. package/dist/baseAccount.js.map +1 -1
  13. package/dist/basePaymentMaker.d.ts +4 -3
  14. package/dist/basePaymentMaker.d.ts.map +1 -1
  15. package/dist/basePaymentMaker.js +20 -3
  16. package/dist/basePaymentMaker.js.map +1 -1
  17. package/dist/clientTestHelpers.d.ts.map +1 -1
  18. package/dist/destinationMakers/atxpDestinationMaker.d.ts +15 -0
  19. package/dist/destinationMakers/atxpDestinationMaker.d.ts.map +1 -0
  20. package/dist/destinationMakers/atxpDestinationMaker.js +128 -0
  21. package/dist/destinationMakers/atxpDestinationMaker.js.map +1 -0
  22. package/dist/destinationMakers/index.d.ts +9 -0
  23. package/dist/destinationMakers/index.d.ts.map +1 -0
  24. package/dist/destinationMakers/index.js +45 -0
  25. package/dist/destinationMakers/index.js.map +1 -0
  26. package/dist/destinationMakers/passthroughDestinationMaker.d.ts +8 -0
  27. package/dist/destinationMakers/passthroughDestinationMaker.d.ts.map +1 -0
  28. package/dist/destinationMakers/passthroughDestinationMaker.js +27 -0
  29. package/dist/destinationMakers/passthroughDestinationMaker.js.map +1 -0
  30. package/dist/index.cjs +566 -466
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +102 -55
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +555 -467
  35. package/dist/index.js.map +1 -1
  36. package/dist/polygonConstants.d.ts +53 -0
  37. package/dist/polygonConstants.d.ts.map +1 -0
  38. package/dist/polygonConstants.js +84 -0
  39. package/dist/polygonConstants.js.map +1 -0
  40. package/dist/solanaAccount.d.ts +8 -4
  41. package/dist/solanaAccount.d.ts.map +1 -1
  42. package/dist/solanaAccount.js +16 -4
  43. package/dist/solanaAccount.js.map +1 -1
  44. package/dist/solanaPaymentMaker.d.ts +4 -3
  45. package/dist/solanaPaymentMaker.d.ts.map +1 -1
  46. package/dist/solanaPaymentMaker.js +24 -5
  47. package/dist/solanaPaymentMaker.js.map +1 -1
  48. package/dist/types.d.ts +5 -23
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/types.js.map +1 -1
  51. package/package.json +2 -2
  52. package/dist/atxpAccount.d.ts +0 -18
  53. package/dist/atxpAccount.d.ts.map +0 -1
  54. package/dist/atxpAccount.js +0 -123
  55. package/dist/atxpAccount.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Currency, AuthorizationServerUrl, Network, OAuthDb, FetchLike, Logger, OAuthResourceClient, ClientCredentials, PKCEValues, AccessToken } from '@atxp/common';
1
+ import { Account, Network, DestinationMaker, AuthorizationServerUrl, AccountId, Currency, OAuthDb, FetchLike, Logger, OAuthResourceClient, ClientCredentials, PKCEValues, AccessToken, PaymentMaker, Destination, PaymentIdentifier, Source, PaymentRequestOption } from '@atxp/common';
2
+ export { ATXPAccount, Account, PaymentMaker } from '@atxp/common';
2
3
  import { ClientOptions, Client } from '@modelcontextprotocol/sdk/client/index.js';
3
4
  import { Implementation } from '@modelcontextprotocol/sdk/types.js';
4
5
  import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
@@ -10,17 +11,10 @@ import { WalletClient, PublicActions, LocalAccount, Address, TypedData, Hex as H
10
11
  type Hex = `0x${string}`;
11
12
  type AccountPrefix = Network;
12
13
  type AccountIdString = `${AccountPrefix}${string}`;
13
- type Account = {
14
- accountId: string;
15
- paymentMakers: {
16
- [key: string]: PaymentMaker;
17
- };
18
- };
19
14
  type ProspectivePayment = {
20
- accountId: string;
15
+ accountId: AccountId;
21
16
  resourceUrl: string;
22
17
  resourceName: string;
23
- network: Network;
24
18
  currency: Currency;
25
19
  amount: BigNumber;
26
20
  iss: string;
@@ -28,6 +22,8 @@ type ProspectivePayment = {
28
22
  type ClientConfig = {
29
23
  mcpServer: string;
30
24
  account: Account;
25
+ atxpAccountsServer: string;
26
+ destinationMakers: Map<Network, DestinationMaker>;
31
27
  allowedAuthorizationServers: AuthorizationServerUrl[];
32
28
  approvePayment: (payment: ProspectivePayment) => Promise<boolean>;
33
29
  oAuthDb: OAuthDb;
@@ -70,23 +66,10 @@ declare class PaymentNetworkError extends Error {
70
66
  readonly originalError?: Error | undefined;
71
67
  constructor(message: string, originalError?: Error | undefined);
72
68
  }
73
- interface PaymentMaker {
74
- makePayment: (amount: BigNumber, currency: Currency, receiver: string, memo: string) => Promise<string>;
75
- generateJWT: (params: {
76
- paymentRequestId: string;
77
- codeChallenge: string;
78
- }) => Promise<string>;
79
- getSourceAddress: (params: {
80
- amount: BigNumber;
81
- currency: Currency;
82
- receiver: string;
83
- memo: string;
84
- }) => string | Promise<string>;
85
- }
86
69
 
87
70
  type RequiredClientConfigFields = 'mcpServer' | 'account';
88
71
  type OptionalClientConfig = Omit<ClientConfig, RequiredClientConfigFields>;
89
- type BuildableClientConfigFields = 'oAuthDb' | 'logger';
72
+ type BuildableClientConfigFields = 'oAuthDb' | 'logger' | 'destinationMakers';
90
73
  declare const DEFAULT_CLIENT_CONFIG: Required<Omit<OptionalClientConfig, BuildableClientConfigFields>>;
91
74
  declare function buildClientConfig(args: ClientArgs): ClientConfig;
92
75
  declare function buildStreamableTransport(args: ClientArgs): StreamableHTTPClientTransport;
@@ -154,11 +137,12 @@ declare class SolanaPaymentMaker implements PaymentMaker {
154
137
  receiver: string;
155
138
  memo: string;
156
139
  }): string;
157
- generateJWT: ({ paymentRequestId, codeChallenge }: {
140
+ generateJWT: ({ paymentRequestId, codeChallenge, accountId }: {
158
141
  paymentRequestId: string;
159
142
  codeChallenge: string;
143
+ accountId?: AccountId | null;
160
144
  }) => Promise<string>;
161
- makePayment: (amount: BigNumber$1, currency: Currency, receiver: string, memo: string) => Promise<string>;
145
+ makePayment: (destinations: Destination[], memo: string, _paymentRequestId?: string) => Promise<PaymentIdentifier | null>;
162
146
  }
163
147
 
164
148
  type ExtendedWalletClient = WalletClient & PublicActions;
@@ -172,34 +156,23 @@ declare class BasePaymentMaker implements PaymentMaker {
172
156
  receiver: string;
173
157
  memo: string;
174
158
  }): string;
175
- generateJWT({ paymentRequestId, codeChallenge }: {
159
+ generateJWT({ paymentRequestId, codeChallenge, accountId }: {
176
160
  paymentRequestId: string;
177
161
  codeChallenge: string;
162
+ accountId?: AccountId | null;
178
163
  }): Promise<string>;
179
- makePayment(amount: BigNumber, currency: Currency, receiver: string): Promise<string>;
164
+ makePayment(destinations: Destination[], _memo: string, _paymentRequestId?: string): Promise<PaymentIdentifier | null>;
180
165
  }
181
166
 
182
167
  declare class SolanaAccount implements Account {
183
- accountId: string;
184
- paymentMakers: {
185
- [key: string]: PaymentMaker;
186
- };
168
+ accountId: AccountId;
169
+ paymentMakers: PaymentMaker[];
170
+ private sourcePublicKey;
187
171
  constructor(solanaEndpoint: string, sourceSecretKey: string);
188
- }
189
-
190
- declare class ATXPAccount implements Account {
191
- accountId: string;
192
- paymentMakers: {
193
- [key: string]: PaymentMaker;
194
- };
195
- origin: string;
196
- token: string;
197
- fetchFn: FetchLike;
198
- constructor(connectionString: string, opts?: {
199
- fetchFn?: FetchLike;
200
- network?: Network;
201
- });
202
- getSigner(): Promise<LocalAccount>;
172
+ /**
173
+ * Get sources for this account
174
+ */
175
+ getSources(): Promise<Source[]>;
203
176
  }
204
177
 
205
178
  declare const USDC_CONTRACT_ADDRESS_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
@@ -265,19 +238,74 @@ declare const getWorldChainByChainId: (chainId: number) => WorldChain;
265
238
  */
266
239
  declare const getWorldChainUSDCAddress: (chainId: number) => string;
267
240
 
268
- declare class BaseAccount implements Account {
269
- accountId: string;
270
- paymentMakers: {
271
- [key: string]: PaymentMaker;
241
+ /**
242
+ * Polygon Chain configuration type, compatible with viem's Chain interface
243
+ */
244
+ type PolygonChain = {
245
+ readonly id: number;
246
+ readonly name: string;
247
+ readonly nativeCurrency: {
248
+ readonly name: string;
249
+ readonly symbol: string;
250
+ readonly decimals: number;
251
+ };
252
+ readonly rpcUrls: {
253
+ readonly default: {
254
+ readonly http: readonly string[];
255
+ };
272
256
  };
257
+ readonly blockExplorers: {
258
+ readonly default: {
259
+ readonly name: string;
260
+ readonly url: string;
261
+ };
262
+ };
263
+ readonly testnet?: boolean;
264
+ };
265
+ declare const USDC_CONTRACT_ADDRESS_POLYGON_MAINNET = "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359";
266
+ declare const USDC_CONTRACT_ADDRESS_POLYGON_AMOY = "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582";
267
+ declare const POLYGON_MAINNET: PolygonChain;
268
+ declare const POLYGON_AMOY: PolygonChain;
269
+ /**
270
+ * Get Polygon Mainnet configuration with custom RPC URL (e.g., with API key)
271
+ * @param rpcUrl - Custom RPC URL, e.g., 'https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY'
272
+ */
273
+ declare const getPolygonMainnetWithRPC: (rpcUrl: string) => PolygonChain;
274
+ /**
275
+ * Get Polygon Amoy Testnet configuration with custom RPC URL (e.g., with API key)
276
+ * @param rpcUrl - Custom RPC URL, e.g., 'https://polygon-amoy.g.alchemy.com/v2/YOUR_API_KEY'
277
+ */
278
+ declare const getPolygonAmoyWithRPC: (rpcUrl: string) => PolygonChain;
279
+ /**
280
+ * Get Polygon Chain configuration by chain ID
281
+ * @param chainId - Chain ID (137 for mainnet, 80002 for Amoy testnet)
282
+ * @returns Polygon Chain configuration
283
+ * @throws Error if chain ID is not supported
284
+ */
285
+ declare const getPolygonByChainId: (chainId: number) => PolygonChain;
286
+ /**
287
+ * Get USDC contract address for Polygon by chain ID
288
+ * @param chainId - Chain ID (137 for mainnet, 80002 for Amoy testnet)
289
+ * @returns USDC contract address
290
+ * @throws Error if chain ID is not supported
291
+ */
292
+ declare const getPolygonUSDCAddress: (chainId: number) => string;
293
+
294
+ declare class BaseAccount implements Account {
295
+ accountId: AccountId;
296
+ paymentMakers: PaymentMaker[];
273
297
  private walletClient;
274
298
  private account;
275
299
  constructor(baseRPCUrl: string, sourceSecretKey: string);
276
300
  /**
277
- * Get a signer that can be used with the x402 library
278
- * This is only available for EVM-based accounts
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
279
307
  */
280
- getSigner(): LocalAccount;
308
+ getSources(): Promise<Source[]>;
281
309
  }
282
310
 
283
311
  /**
@@ -328,5 +356,24 @@ declare class ATXPLocalAccount implements LocalAccount {
328
356
  readonly source: "custom";
329
357
  }
330
358
 
331
- export { ATXPAccount, ATXPLocalAccount, BaseAccount, BasePaymentMaker, DEFAULT_CLIENT_CONFIG, InsufficientFundsError, OAuthAuthenticationRequiredError, OAuthClient, PaymentNetworkError, SolanaAccount, SolanaPaymentMaker, USDC_CONTRACT_ADDRESS_BASE, USDC_CONTRACT_ADDRESS_BASE_SEPOLIA, USDC_CONTRACT_ADDRESS_WORLD_MAINNET, USDC_CONTRACT_ADDRESS_WORLD_SEPOLIA, ValidateTransferError, WORLD_CHAIN_MAINNET, WORLD_CHAIN_SEPOLIA, atxpClient, atxpFetch, buildClientConfig, buildStreamableTransport, getBaseUSDCAddress, getWorldChainByChainId, getWorldChainMainnetWithRPC, getWorldChainSepoliaWithRPC, getWorldChainUSDCAddress };
332
- export type { Account, AccountIdString, ClientArgs, ClientConfig, FetchWrapper, Hex, OAuthClientConfig, PaymentMaker, ProspectivePayment, WorldChain };
359
+ /**
360
+ * Destination mapper for ATXP network destinations.
361
+ * Converts destinations with network='atxp' to actual blockchain network destinations
362
+ * by resolving the account ID to its associated blockchain addresses.
363
+ */
364
+ declare class ATXPDestinationMaker implements DestinationMaker {
365
+ private accountsServiceUrl;
366
+ private fetchFn;
367
+ constructor(accountsServiceUrl: string, fetchFn?: FetchLike);
368
+ makeDestinations(option: PaymentRequestOption, logger: Logger, paymentRequestId: string, sources: Source[]): Promise<Destination[]>;
369
+ private getDestinations;
370
+ }
371
+
372
+ declare class PassthroughDestinationMaker implements DestinationMaker {
373
+ private network;
374
+ constructor(network: Network);
375
+ makeDestinations(option: PaymentRequestOption, _logger: Logger, _paymentRequestId: string, _sources: Source[]): Promise<Destination[]>;
376
+ }
377
+
378
+ export { ATXPDestinationMaker, ATXPLocalAccount, BaseAccount, BasePaymentMaker, DEFAULT_CLIENT_CONFIG, InsufficientFundsError, OAuthAuthenticationRequiredError, OAuthClient, POLYGON_AMOY, POLYGON_MAINNET, PassthroughDestinationMaker, PaymentNetworkError, SolanaAccount, SolanaPaymentMaker, USDC_CONTRACT_ADDRESS_BASE, USDC_CONTRACT_ADDRESS_BASE_SEPOLIA, USDC_CONTRACT_ADDRESS_POLYGON_AMOY, USDC_CONTRACT_ADDRESS_POLYGON_MAINNET, USDC_CONTRACT_ADDRESS_WORLD_MAINNET, USDC_CONTRACT_ADDRESS_WORLD_SEPOLIA, ValidateTransferError, WORLD_CHAIN_MAINNET, WORLD_CHAIN_SEPOLIA, atxpClient, atxpFetch, buildClientConfig, buildStreamableTransport, getBaseUSDCAddress, getPolygonAmoyWithRPC, getPolygonByChainId, getPolygonMainnetWithRPC, getPolygonUSDCAddress, getWorldChainByChainId, getWorldChainMainnetWithRPC, getWorldChainSepoliaWithRPC, getWorldChainUSDCAddress };
379
+ export type { AccountIdString, ClientArgs, ClientConfig, FetchWrapper, Hex, OAuthClientConfig, PolygonChain, ProspectivePayment, WorldChain };
@@ -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,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,EAClC,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,mCAAmC,EACnC,mCAAmC,EACnC,mBAAmB,EACnB,mBAAmB,EACnB,2BAA2B,EAC3B,2BAA2B,EAC3B,sBAAsB,EACtB,wBAAwB,EACxB,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,KAAK,GAAG,EACR,KAAK,eAAe,EACpB,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gBAAgB,EACjB,MAAM,uBAAuB,CAAC"}
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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