@atxp/client 0.7.3 → 0.7.4
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/atxpAccount.d.ts +18 -0
- package/dist/atxpAccount.d.ts.map +1 -0
- package/dist/atxpAccount.js +25 -0
- package/dist/atxpAccount.js.map +1 -1
- package/dist/atxpClient.d.ts +12 -0
- package/dist/atxpClient.d.ts.map +1 -0
- package/dist/atxpFetcher.d.ts +87 -0
- package/dist/atxpFetcher.d.ts.map +1 -0
- package/dist/atxpFetcher.js +105 -16
- package/dist/atxpFetcher.js.map +1 -1
- package/dist/atxpLocalAccount.d.ts +50 -0
- package/dist/atxpLocalAccount.d.ts.map +1 -0
- package/dist/baseAccount.d.ts +17 -0
- package/dist/baseAccount.d.ts.map +1 -0
- package/dist/baseConstants.d.ts +10 -0
- package/dist/baseConstants.d.ts.map +1 -0
- package/dist/basePaymentMaker.d.ts +22 -0
- package/dist/basePaymentMaker.d.ts.map +1 -0
- package/dist/basePaymentMaker.js +3 -0
- package/dist/basePaymentMaker.js.map +1 -1
- package/dist/clientTestHelpers.d.ts +6 -0
- package/dist/clientTestHelpers.d.ts.map +1 -0
- package/dist/index.cjs +136 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +136 -16
- package/dist/index.js.map +1 -1
- package/dist/oAuth.d.ts +44 -0
- package/dist/oAuth.d.ts.map +1 -0
- package/dist/setup.expo.d.ts +2 -0
- package/dist/setup.expo.d.ts.map +1 -0
- package/dist/solanaAccount.d.ts +9 -0
- package/dist/solanaAccount.d.ts.map +1 -0
- package/dist/solanaPaymentMaker.d.ts +24 -0
- package/dist/solanaPaymentMaker.d.ts.map +1 -0
- package/dist/solanaPaymentMaker.js +3 -0
- package/dist/solanaPaymentMaker.js.map +1 -1
- package/dist/types.d.ts +81 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/worldConstants.d.ts +53 -0
- package/dist/worldConstants.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -76,6 +76,12 @@ interface PaymentMaker {
|
|
|
76
76
|
paymentRequestId: string;
|
|
77
77
|
codeChallenge: string;
|
|
78
78
|
}) => Promise<string>;
|
|
79
|
+
getSourceAddress: (params: {
|
|
80
|
+
amount: BigNumber;
|
|
81
|
+
currency: Currency;
|
|
82
|
+
receiver: string;
|
|
83
|
+
memo: string;
|
|
84
|
+
}) => string | Promise<string>;
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
type RequiredClientConfigFields = 'mcpServer' | 'account';
|
|
@@ -142,6 +148,12 @@ declare class SolanaPaymentMaker implements PaymentMaker {
|
|
|
142
148
|
private source;
|
|
143
149
|
private logger;
|
|
144
150
|
constructor(solanaEndpoint: string, sourceSecretKey: string, logger?: Logger);
|
|
151
|
+
getSourceAddress(_params: {
|
|
152
|
+
amount: BigNumber$1;
|
|
153
|
+
currency: Currency;
|
|
154
|
+
receiver: string;
|
|
155
|
+
memo: string;
|
|
156
|
+
}): string;
|
|
145
157
|
generateJWT: ({ paymentRequestId, codeChallenge }: {
|
|
146
158
|
paymentRequestId: string;
|
|
147
159
|
codeChallenge: string;
|
|
@@ -154,6 +166,12 @@ declare class BasePaymentMaker implements PaymentMaker {
|
|
|
154
166
|
protected signingClient: ExtendedWalletClient;
|
|
155
167
|
protected logger: Logger;
|
|
156
168
|
constructor(baseRPCUrl: string, walletClient: WalletClient, logger?: Logger);
|
|
169
|
+
getSourceAddress(_params: {
|
|
170
|
+
amount: BigNumber;
|
|
171
|
+
currency: Currency;
|
|
172
|
+
receiver: string;
|
|
173
|
+
memo: string;
|
|
174
|
+
}): string;
|
|
157
175
|
generateJWT({ paymentRequestId, codeChallenge }: {
|
|
158
176
|
paymentRequestId: string;
|
|
159
177
|
codeChallenge: string;
|
|
@@ -0,0 +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"}
|
package/dist/index.js
CHANGED
|
@@ -352,30 +352,38 @@ class ATXPFetcher {
|
|
|
352
352
|
}
|
|
353
353
|
// Try each destination in order
|
|
354
354
|
for (const dest of paymentRequestData.destinations) {
|
|
355
|
-
|
|
355
|
+
// Convert amount to BigNumber since it comes as a string from JSON
|
|
356
|
+
const amount = new BigNumber(dest.amount);
|
|
357
|
+
// Resolve atxp_base destinations to real base network destinations
|
|
358
|
+
let destinationAddress = dest.address;
|
|
359
|
+
let destinationNetwork = dest.network;
|
|
360
|
+
const resolved = await this.resolveAtxpBaseDestination(dest.network, dest.address, paymentRequestId, amount, dest.currency, dest.address, paymentRequestData.iss);
|
|
361
|
+
if (resolved) {
|
|
362
|
+
destinationAddress = resolved.destinationAddress;
|
|
363
|
+
destinationNetwork = resolved.network;
|
|
364
|
+
}
|
|
365
|
+
const paymentMaker = this.paymentMakers.get(destinationNetwork);
|
|
356
366
|
if (!paymentMaker) {
|
|
357
|
-
this.logger.debug(`ATXP: payment network '${
|
|
367
|
+
this.logger.debug(`ATXP: payment network '${destinationNetwork}' not available, trying next destination`);
|
|
358
368
|
continue;
|
|
359
369
|
}
|
|
360
|
-
// Convert amount to BigNumber since it comes as a string from JSON
|
|
361
|
-
const amount = new BigNumber(dest.amount);
|
|
362
370
|
const prospectivePayment = {
|
|
363
371
|
accountId: this.accountId,
|
|
364
372
|
resourceUrl: paymentRequestData.resource?.toString() ?? '',
|
|
365
373
|
resourceName: paymentRequestData.resourceName ?? '',
|
|
366
|
-
network:
|
|
374
|
+
network: destinationNetwork,
|
|
367
375
|
currency: dest.currency,
|
|
368
376
|
amount: amount,
|
|
369
377
|
iss: paymentRequestData.iss ?? '',
|
|
370
378
|
};
|
|
371
379
|
if (!await this.approvePayment(prospectivePayment)) {
|
|
372
|
-
this.logger.info(`ATXP: payment request denied by callback function for destination on ${
|
|
380
|
+
this.logger.info(`ATXP: payment request denied by callback function for destination on ${destinationNetwork}`);
|
|
373
381
|
continue;
|
|
374
382
|
}
|
|
375
383
|
let paymentId;
|
|
376
384
|
try {
|
|
377
|
-
paymentId = await paymentMaker.makePayment(amount, dest.currency,
|
|
378
|
-
this.logger.info(`ATXP: made payment of ${amount.toString()} ${dest.currency} on ${
|
|
385
|
+
paymentId = await paymentMaker.makePayment(amount, dest.currency, destinationAddress, paymentRequestData.iss);
|
|
386
|
+
this.logger.info(`ATXP: made payment of ${amount.toString()} ${dest.currency} on ${destinationNetwork}: ${paymentId}`);
|
|
379
387
|
await this.onPayment({ payment: prospectivePayment });
|
|
380
388
|
// Submit payment to the server
|
|
381
389
|
const jwt = await paymentMaker.generateJWT({ paymentRequestId, codeChallenge: '' });
|
|
@@ -387,7 +395,7 @@ class ATXPFetcher {
|
|
|
387
395
|
},
|
|
388
396
|
body: JSON.stringify({
|
|
389
397
|
transactionId: paymentId,
|
|
390
|
-
network:
|
|
398
|
+
network: destinationNetwork,
|
|
391
399
|
currency: dest.currency
|
|
392
400
|
})
|
|
393
401
|
});
|
|
@@ -401,7 +409,7 @@ class ATXPFetcher {
|
|
|
401
409
|
}
|
|
402
410
|
catch (error) {
|
|
403
411
|
const typedError = error;
|
|
404
|
-
this.logger.warn(`ATXP: payment failed on ${
|
|
412
|
+
this.logger.warn(`ATXP: payment failed on ${destinationNetwork}: ${typedError.message}`);
|
|
405
413
|
await this.onPaymentFailure({ payment: prospectivePayment, error: typedError });
|
|
406
414
|
// Try next destination
|
|
407
415
|
continue;
|
|
@@ -460,16 +468,24 @@ class ATXPFetcher {
|
|
|
460
468
|
if (!currency) {
|
|
461
469
|
throw new Error(`Currency not provided`);
|
|
462
470
|
}
|
|
463
|
-
|
|
471
|
+
// Resolve atxp_base destinations to real base network destinations
|
|
472
|
+
let destinationAddress = destination;
|
|
473
|
+
let destinationNetwork = requestedNetwork;
|
|
474
|
+
const resolved = await this.resolveAtxpBaseDestination(requestedNetwork, destination, paymentRequestId, amount, currency, destination, paymentRequestData.iss);
|
|
475
|
+
if (resolved) {
|
|
476
|
+
destinationAddress = resolved.destinationAddress;
|
|
477
|
+
destinationNetwork = resolved.network;
|
|
478
|
+
}
|
|
479
|
+
const paymentMaker = this.paymentMakers.get(destinationNetwork);
|
|
464
480
|
if (!paymentMaker) {
|
|
465
|
-
this.logger.info(`ATXP: payment network '${
|
|
481
|
+
this.logger.info(`ATXP: payment network '${destinationNetwork}' not set up for this client (available networks: ${Array.from(this.paymentMakers.keys()).join(', ')})`);
|
|
466
482
|
return false;
|
|
467
483
|
}
|
|
468
484
|
const prospectivePayment = {
|
|
469
485
|
accountId: this.accountId,
|
|
470
486
|
resourceUrl: paymentRequestData.resource?.toString() ?? '',
|
|
471
487
|
resourceName: paymentRequestData.resourceName ?? '',
|
|
472
|
-
network:
|
|
488
|
+
network: destinationNetwork,
|
|
473
489
|
currency,
|
|
474
490
|
amount,
|
|
475
491
|
iss: paymentRequestData.iss ?? '',
|
|
@@ -480,8 +496,8 @@ class ATXPFetcher {
|
|
|
480
496
|
}
|
|
481
497
|
let paymentId;
|
|
482
498
|
try {
|
|
483
|
-
paymentId = await paymentMaker.makePayment(amount, currency,
|
|
484
|
-
this.logger.info(`ATXP: made payment of ${amount} ${currency} on ${
|
|
499
|
+
paymentId = await paymentMaker.makePayment(amount, currency, destinationAddress, paymentRequestData.iss);
|
|
500
|
+
this.logger.info(`ATXP: made payment of ${amount} ${currency} on ${destinationNetwork}: ${paymentId}`);
|
|
485
501
|
// Call onPayment callback after successful payment
|
|
486
502
|
await this.onPayment({ payment: prospectivePayment });
|
|
487
503
|
}
|
|
@@ -511,7 +527,7 @@ class ATXPFetcher {
|
|
|
511
527
|
},
|
|
512
528
|
body: JSON.stringify({
|
|
513
529
|
transactionId: paymentId,
|
|
514
|
-
network:
|
|
530
|
+
network: destinationNetwork,
|
|
515
531
|
currency: currency
|
|
516
532
|
})
|
|
517
533
|
});
|
|
@@ -760,6 +776,79 @@ class ATXPFetcher {
|
|
|
760
776
|
this.onPayment = onPayment;
|
|
761
777
|
this.onPaymentFailure = onPaymentFailure || this.defaultPaymentFailureHandler;
|
|
762
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* Resolves atxp_base or atxp_base_sepolia destinations to real base network destinations
|
|
781
|
+
* by calling the payment_info endpoint to get the destination address and network
|
|
782
|
+
*/
|
|
783
|
+
async resolveAtxpBaseDestination(network, paymentInfoUrl, paymentRequestId, amount, currency, receiver, memo) {
|
|
784
|
+
// Check if this is an atxp_base network that needs resolution
|
|
785
|
+
if (network !== 'atxp_base' && network !== 'atxp_base_sepolia') {
|
|
786
|
+
return null;
|
|
787
|
+
}
|
|
788
|
+
// Map atxp_base networks to their real counterparts
|
|
789
|
+
const realNetwork = network === 'atxp_base' ? 'base' : 'base_sepolia';
|
|
790
|
+
// Get the payment maker for the real network
|
|
791
|
+
const paymentMaker = this.paymentMakers.get(realNetwork);
|
|
792
|
+
if (!paymentMaker) {
|
|
793
|
+
this.logger.debug(`ATXP: payment network '${realNetwork}' not available for atxp_base resolution`);
|
|
794
|
+
return null;
|
|
795
|
+
}
|
|
796
|
+
// Get the buyer address (source address) from the payment maker
|
|
797
|
+
let buyerAddress;
|
|
798
|
+
try {
|
|
799
|
+
buyerAddress = await paymentMaker.getSourceAddress({
|
|
800
|
+
amount,
|
|
801
|
+
currency,
|
|
802
|
+
receiver,
|
|
803
|
+
memo
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
catch (error) {
|
|
807
|
+
this.logger.warn(`ATXP: failed to get source address from payment maker for ${realNetwork}: ${error.message}`);
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
810
|
+
// Call the payment_info endpoint
|
|
811
|
+
this.logger.debug(`ATXP: resolving ${network} destination via ${paymentInfoUrl}`);
|
|
812
|
+
try {
|
|
813
|
+
const response = await this.sideChannelFetch(paymentInfoUrl, {
|
|
814
|
+
method: 'POST',
|
|
815
|
+
headers: {
|
|
816
|
+
'Content-Type': 'application/json',
|
|
817
|
+
},
|
|
818
|
+
body: JSON.stringify({
|
|
819
|
+
paymentRequestId,
|
|
820
|
+
buyerAddress,
|
|
821
|
+
}),
|
|
822
|
+
});
|
|
823
|
+
if (!response.ok) {
|
|
824
|
+
const text = await response.text();
|
|
825
|
+
this.logger.warn(`ATXP: payment_info endpoint failed: ${response.status} ${response.statusText} ${text}`);
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
const data = await response.json();
|
|
829
|
+
if (data.status !== 'success') {
|
|
830
|
+
this.logger.warn(`ATXP: payment_info endpoint returned non-success status: ${JSON.stringify(data)}`);
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
833
|
+
if (!data.destinationAddress) {
|
|
834
|
+
this.logger.warn(`ATXP: payment_info endpoint did not return destinationAddress`);
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
if (!data.network) {
|
|
838
|
+
this.logger.warn(`ATXP: payment_info endpoint did not return network`);
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
this.logger.info(`ATXP: resolved ${network} destination to ${data.destinationAddress} on ${data.network}`);
|
|
842
|
+
return {
|
|
843
|
+
destinationAddress: data.destinationAddress,
|
|
844
|
+
network: data.network,
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
catch (error) {
|
|
848
|
+
this.logger.warn(`ATXP: failed to resolve ${network} destination: ${error.message}`);
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
763
852
|
}
|
|
764
853
|
|
|
765
854
|
var util$1;
|
|
@@ -15975,6 +16064,9 @@ class SolanaPaymentMaker {
|
|
|
15975
16064
|
this.source = Keypair.fromSecretKey(bs58.decode(sourceSecretKey));
|
|
15976
16065
|
this.logger = logger ?? new ConsoleLogger();
|
|
15977
16066
|
}
|
|
16067
|
+
getSourceAddress(_params) {
|
|
16068
|
+
return this.source.publicKey.toBase58();
|
|
16069
|
+
}
|
|
15978
16070
|
}
|
|
15979
16071
|
|
|
15980
16072
|
const USDC_CONTRACT_ADDRESS_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"; // USDC on Base mainnet
|
|
@@ -16051,6 +16143,9 @@ class BasePaymentMaker {
|
|
|
16051
16143
|
this.signingClient = walletClient.extend(publicActions);
|
|
16052
16144
|
this.logger = logger ?? new ConsoleLogger();
|
|
16053
16145
|
}
|
|
16146
|
+
getSourceAddress(_params) {
|
|
16147
|
+
return this.signingClient.account.address;
|
|
16148
|
+
}
|
|
16054
16149
|
async generateJWT({ paymentRequestId, codeChallenge }) {
|
|
16055
16150
|
const headerObj = { alg: 'ES256K' };
|
|
16056
16151
|
const payloadObj = {
|
|
@@ -16273,6 +16368,31 @@ class ATXPHttpPaymentMaker {
|
|
|
16273
16368
|
this.token = token;
|
|
16274
16369
|
this.fetchFn = fetchFn;
|
|
16275
16370
|
}
|
|
16371
|
+
async getSourceAddress(params) {
|
|
16372
|
+
// Call the /address_for_payment endpoint to get the source address for this account
|
|
16373
|
+
const response = await this.fetchFn(`${this.origin}/address_for_payment`, {
|
|
16374
|
+
method: 'POST',
|
|
16375
|
+
headers: {
|
|
16376
|
+
'Authorization': toBasicAuth(this.token),
|
|
16377
|
+
'Content-Type': 'application/json',
|
|
16378
|
+
},
|
|
16379
|
+
body: JSON.stringify({
|
|
16380
|
+
amount: params.amount.toString(),
|
|
16381
|
+
currency: params.currency,
|
|
16382
|
+
receiver: params.receiver,
|
|
16383
|
+
memo: params.memo,
|
|
16384
|
+
}),
|
|
16385
|
+
});
|
|
16386
|
+
if (!response.ok) {
|
|
16387
|
+
const text = await response.text();
|
|
16388
|
+
throw new Error(`ATXPAccount: /address_for_payment failed: ${response.status} ${response.statusText} ${text}`);
|
|
16389
|
+
}
|
|
16390
|
+
const json = await response.json();
|
|
16391
|
+
if (!json?.sourceAddress) {
|
|
16392
|
+
throw new Error('ATXPAccount: /address_for_payment did not return sourceAddress');
|
|
16393
|
+
}
|
|
16394
|
+
return json.sourceAddress;
|
|
16395
|
+
}
|
|
16276
16396
|
async makePayment(amount, currency, receiver, memo) {
|
|
16277
16397
|
// Make a regular payment via the /pay endpoint
|
|
16278
16398
|
const response = await this.fetchFn(`${this.origin}/pay`, {
|