@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientTestHelpers.d.ts","sourceRoot":"","sources":["../src/clientTestHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,MAA8B,EAAE,YAAY,GAAE,MAAe,EAAE,aAAa,GAAE,MAAqC,aAqB/K;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,MAAqC,EAAE,eAAe,GAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAM,aAqExJ"}
|
package/dist/index.cjs
CHANGED
|
@@ -373,30 +373,38 @@ class ATXPFetcher {
|
|
|
373
373
|
}
|
|
374
374
|
// Try each destination in order
|
|
375
375
|
for (const dest of paymentRequestData.destinations) {
|
|
376
|
-
|
|
376
|
+
// Convert amount to BigNumber since it comes as a string from JSON
|
|
377
|
+
const amount = new BigNumber.BigNumber(dest.amount);
|
|
378
|
+
// Resolve atxp_base destinations to real base network destinations
|
|
379
|
+
let destinationAddress = dest.address;
|
|
380
|
+
let destinationNetwork = dest.network;
|
|
381
|
+
const resolved = await this.resolveAtxpBaseDestination(dest.network, dest.address, paymentRequestId, amount, dest.currency, dest.address, paymentRequestData.iss);
|
|
382
|
+
if (resolved) {
|
|
383
|
+
destinationAddress = resolved.destinationAddress;
|
|
384
|
+
destinationNetwork = resolved.network;
|
|
385
|
+
}
|
|
386
|
+
const paymentMaker = this.paymentMakers.get(destinationNetwork);
|
|
377
387
|
if (!paymentMaker) {
|
|
378
|
-
this.logger.debug(`ATXP: payment network '${
|
|
388
|
+
this.logger.debug(`ATXP: payment network '${destinationNetwork}' not available, trying next destination`);
|
|
379
389
|
continue;
|
|
380
390
|
}
|
|
381
|
-
// Convert amount to BigNumber since it comes as a string from JSON
|
|
382
|
-
const amount = new BigNumber.BigNumber(dest.amount);
|
|
383
391
|
const prospectivePayment = {
|
|
384
392
|
accountId: this.accountId,
|
|
385
393
|
resourceUrl: paymentRequestData.resource?.toString() ?? '',
|
|
386
394
|
resourceName: paymentRequestData.resourceName ?? '',
|
|
387
|
-
network:
|
|
395
|
+
network: destinationNetwork,
|
|
388
396
|
currency: dest.currency,
|
|
389
397
|
amount: amount,
|
|
390
398
|
iss: paymentRequestData.iss ?? '',
|
|
391
399
|
};
|
|
392
400
|
if (!await this.approvePayment(prospectivePayment)) {
|
|
393
|
-
this.logger.info(`ATXP: payment request denied by callback function for destination on ${
|
|
401
|
+
this.logger.info(`ATXP: payment request denied by callback function for destination on ${destinationNetwork}`);
|
|
394
402
|
continue;
|
|
395
403
|
}
|
|
396
404
|
let paymentId;
|
|
397
405
|
try {
|
|
398
|
-
paymentId = await paymentMaker.makePayment(amount, dest.currency,
|
|
399
|
-
this.logger.info(`ATXP: made payment of ${amount.toString()} ${dest.currency} on ${
|
|
406
|
+
paymentId = await paymentMaker.makePayment(amount, dest.currency, destinationAddress, paymentRequestData.iss);
|
|
407
|
+
this.logger.info(`ATXP: made payment of ${amount.toString()} ${dest.currency} on ${destinationNetwork}: ${paymentId}`);
|
|
400
408
|
await this.onPayment({ payment: prospectivePayment });
|
|
401
409
|
// Submit payment to the server
|
|
402
410
|
const jwt = await paymentMaker.generateJWT({ paymentRequestId, codeChallenge: '' });
|
|
@@ -408,7 +416,7 @@ class ATXPFetcher {
|
|
|
408
416
|
},
|
|
409
417
|
body: JSON.stringify({
|
|
410
418
|
transactionId: paymentId,
|
|
411
|
-
network:
|
|
419
|
+
network: destinationNetwork,
|
|
412
420
|
currency: dest.currency
|
|
413
421
|
})
|
|
414
422
|
});
|
|
@@ -422,7 +430,7 @@ class ATXPFetcher {
|
|
|
422
430
|
}
|
|
423
431
|
catch (error) {
|
|
424
432
|
const typedError = error;
|
|
425
|
-
this.logger.warn(`ATXP: payment failed on ${
|
|
433
|
+
this.logger.warn(`ATXP: payment failed on ${destinationNetwork}: ${typedError.message}`);
|
|
426
434
|
await this.onPaymentFailure({ payment: prospectivePayment, error: typedError });
|
|
427
435
|
// Try next destination
|
|
428
436
|
continue;
|
|
@@ -481,16 +489,24 @@ class ATXPFetcher {
|
|
|
481
489
|
if (!currency) {
|
|
482
490
|
throw new Error(`Currency not provided`);
|
|
483
491
|
}
|
|
484
|
-
|
|
492
|
+
// Resolve atxp_base destinations to real base network destinations
|
|
493
|
+
let destinationAddress = destination;
|
|
494
|
+
let destinationNetwork = requestedNetwork;
|
|
495
|
+
const resolved = await this.resolveAtxpBaseDestination(requestedNetwork, destination, paymentRequestId, amount, currency, destination, paymentRequestData.iss);
|
|
496
|
+
if (resolved) {
|
|
497
|
+
destinationAddress = resolved.destinationAddress;
|
|
498
|
+
destinationNetwork = resolved.network;
|
|
499
|
+
}
|
|
500
|
+
const paymentMaker = this.paymentMakers.get(destinationNetwork);
|
|
485
501
|
if (!paymentMaker) {
|
|
486
|
-
this.logger.info(`ATXP: payment network '${
|
|
502
|
+
this.logger.info(`ATXP: payment network '${destinationNetwork}' not set up for this client (available networks: ${Array.from(this.paymentMakers.keys()).join(', ')})`);
|
|
487
503
|
return false;
|
|
488
504
|
}
|
|
489
505
|
const prospectivePayment = {
|
|
490
506
|
accountId: this.accountId,
|
|
491
507
|
resourceUrl: paymentRequestData.resource?.toString() ?? '',
|
|
492
508
|
resourceName: paymentRequestData.resourceName ?? '',
|
|
493
|
-
network:
|
|
509
|
+
network: destinationNetwork,
|
|
494
510
|
currency,
|
|
495
511
|
amount,
|
|
496
512
|
iss: paymentRequestData.iss ?? '',
|
|
@@ -501,8 +517,8 @@ class ATXPFetcher {
|
|
|
501
517
|
}
|
|
502
518
|
let paymentId;
|
|
503
519
|
try {
|
|
504
|
-
paymentId = await paymentMaker.makePayment(amount, currency,
|
|
505
|
-
this.logger.info(`ATXP: made payment of ${amount} ${currency} on ${
|
|
520
|
+
paymentId = await paymentMaker.makePayment(amount, currency, destinationAddress, paymentRequestData.iss);
|
|
521
|
+
this.logger.info(`ATXP: made payment of ${amount} ${currency} on ${destinationNetwork}: ${paymentId}`);
|
|
506
522
|
// Call onPayment callback after successful payment
|
|
507
523
|
await this.onPayment({ payment: prospectivePayment });
|
|
508
524
|
}
|
|
@@ -532,7 +548,7 @@ class ATXPFetcher {
|
|
|
532
548
|
},
|
|
533
549
|
body: JSON.stringify({
|
|
534
550
|
transactionId: paymentId,
|
|
535
|
-
network:
|
|
551
|
+
network: destinationNetwork,
|
|
536
552
|
currency: currency
|
|
537
553
|
})
|
|
538
554
|
});
|
|
@@ -781,6 +797,79 @@ class ATXPFetcher {
|
|
|
781
797
|
this.onPayment = onPayment;
|
|
782
798
|
this.onPaymentFailure = onPaymentFailure || this.defaultPaymentFailureHandler;
|
|
783
799
|
}
|
|
800
|
+
/**
|
|
801
|
+
* Resolves atxp_base or atxp_base_sepolia destinations to real base network destinations
|
|
802
|
+
* by calling the payment_info endpoint to get the destination address and network
|
|
803
|
+
*/
|
|
804
|
+
async resolveAtxpBaseDestination(network, paymentInfoUrl, paymentRequestId, amount, currency, receiver, memo) {
|
|
805
|
+
// Check if this is an atxp_base network that needs resolution
|
|
806
|
+
if (network !== 'atxp_base' && network !== 'atxp_base_sepolia') {
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
// Map atxp_base networks to their real counterparts
|
|
810
|
+
const realNetwork = network === 'atxp_base' ? 'base' : 'base_sepolia';
|
|
811
|
+
// Get the payment maker for the real network
|
|
812
|
+
const paymentMaker = this.paymentMakers.get(realNetwork);
|
|
813
|
+
if (!paymentMaker) {
|
|
814
|
+
this.logger.debug(`ATXP: payment network '${realNetwork}' not available for atxp_base resolution`);
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
// Get the buyer address (source address) from the payment maker
|
|
818
|
+
let buyerAddress;
|
|
819
|
+
try {
|
|
820
|
+
buyerAddress = await paymentMaker.getSourceAddress({
|
|
821
|
+
amount,
|
|
822
|
+
currency,
|
|
823
|
+
receiver,
|
|
824
|
+
memo
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
catch (error) {
|
|
828
|
+
this.logger.warn(`ATXP: failed to get source address from payment maker for ${realNetwork}: ${error.message}`);
|
|
829
|
+
return null;
|
|
830
|
+
}
|
|
831
|
+
// Call the payment_info endpoint
|
|
832
|
+
this.logger.debug(`ATXP: resolving ${network} destination via ${paymentInfoUrl}`);
|
|
833
|
+
try {
|
|
834
|
+
const response = await this.sideChannelFetch(paymentInfoUrl, {
|
|
835
|
+
method: 'POST',
|
|
836
|
+
headers: {
|
|
837
|
+
'Content-Type': 'application/json',
|
|
838
|
+
},
|
|
839
|
+
body: JSON.stringify({
|
|
840
|
+
paymentRequestId,
|
|
841
|
+
buyerAddress,
|
|
842
|
+
}),
|
|
843
|
+
});
|
|
844
|
+
if (!response.ok) {
|
|
845
|
+
const text = await response.text();
|
|
846
|
+
this.logger.warn(`ATXP: payment_info endpoint failed: ${response.status} ${response.statusText} ${text}`);
|
|
847
|
+
return null;
|
|
848
|
+
}
|
|
849
|
+
const data = await response.json();
|
|
850
|
+
if (data.status !== 'success') {
|
|
851
|
+
this.logger.warn(`ATXP: payment_info endpoint returned non-success status: ${JSON.stringify(data)}`);
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
if (!data.destinationAddress) {
|
|
855
|
+
this.logger.warn(`ATXP: payment_info endpoint did not return destinationAddress`);
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
if (!data.network) {
|
|
859
|
+
this.logger.warn(`ATXP: payment_info endpoint did not return network`);
|
|
860
|
+
return null;
|
|
861
|
+
}
|
|
862
|
+
this.logger.info(`ATXP: resolved ${network} destination to ${data.destinationAddress} on ${data.network}`);
|
|
863
|
+
return {
|
|
864
|
+
destinationAddress: data.destinationAddress,
|
|
865
|
+
network: data.network,
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
catch (error) {
|
|
869
|
+
this.logger.warn(`ATXP: failed to resolve ${network} destination: ${error.message}`);
|
|
870
|
+
return null;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
784
873
|
}
|
|
785
874
|
|
|
786
875
|
var util$1;
|
|
@@ -15996,6 +16085,9 @@ class SolanaPaymentMaker {
|
|
|
15996
16085
|
this.source = web3_js.Keypair.fromSecretKey(bs58.decode(sourceSecretKey));
|
|
15997
16086
|
this.logger = logger ?? new common.ConsoleLogger();
|
|
15998
16087
|
}
|
|
16088
|
+
getSourceAddress(_params) {
|
|
16089
|
+
return this.source.publicKey.toBase58();
|
|
16090
|
+
}
|
|
15999
16091
|
}
|
|
16000
16092
|
|
|
16001
16093
|
const USDC_CONTRACT_ADDRESS_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"; // USDC on Base mainnet
|
|
@@ -16072,6 +16164,9 @@ class BasePaymentMaker {
|
|
|
16072
16164
|
this.signingClient = walletClient.extend(viem.publicActions);
|
|
16073
16165
|
this.logger = logger ?? new common.ConsoleLogger();
|
|
16074
16166
|
}
|
|
16167
|
+
getSourceAddress(_params) {
|
|
16168
|
+
return this.signingClient.account.address;
|
|
16169
|
+
}
|
|
16075
16170
|
async generateJWT({ paymentRequestId, codeChallenge }) {
|
|
16076
16171
|
const headerObj = { alg: 'ES256K' };
|
|
16077
16172
|
const payloadObj = {
|
|
@@ -16294,6 +16389,31 @@ class ATXPHttpPaymentMaker {
|
|
|
16294
16389
|
this.token = token;
|
|
16295
16390
|
this.fetchFn = fetchFn;
|
|
16296
16391
|
}
|
|
16392
|
+
async getSourceAddress(params) {
|
|
16393
|
+
// Call the /address_for_payment endpoint to get the source address for this account
|
|
16394
|
+
const response = await this.fetchFn(`${this.origin}/address_for_payment`, {
|
|
16395
|
+
method: 'POST',
|
|
16396
|
+
headers: {
|
|
16397
|
+
'Authorization': toBasicAuth(this.token),
|
|
16398
|
+
'Content-Type': 'application/json',
|
|
16399
|
+
},
|
|
16400
|
+
body: JSON.stringify({
|
|
16401
|
+
amount: params.amount.toString(),
|
|
16402
|
+
currency: params.currency,
|
|
16403
|
+
receiver: params.receiver,
|
|
16404
|
+
memo: params.memo,
|
|
16405
|
+
}),
|
|
16406
|
+
});
|
|
16407
|
+
if (!response.ok) {
|
|
16408
|
+
const text = await response.text();
|
|
16409
|
+
throw new Error(`ATXPAccount: /address_for_payment failed: ${response.status} ${response.statusText} ${text}`);
|
|
16410
|
+
}
|
|
16411
|
+
const json = await response.json();
|
|
16412
|
+
if (!json?.sourceAddress) {
|
|
16413
|
+
throw new Error('ATXPAccount: /address_for_payment did not return sourceAddress');
|
|
16414
|
+
}
|
|
16415
|
+
return json.sourceAddress;
|
|
16416
|
+
}
|
|
16297
16417
|
async makePayment(amount, currency, receiver, memo) {
|
|
16298
16418
|
// Make a regular payment via the /pay endpoint
|
|
16299
16419
|
const response = await this.fetchFn(`${this.origin}/pay`, {
|