@atxp/client 0.10.7 → 0.10.10
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/_virtual/index10.js +2 -2
- package/dist/_virtual/index11.js +2 -2
- package/dist/_virtual/index17.js +2 -2
- package/dist/_virtual/index18.js +2 -2
- package/dist/_virtual/index8.js +2 -2
- package/dist/_virtual/index9.js +2 -2
- package/dist/atxpClient.d.ts +1 -1
- package/dist/atxpClient.d.ts.map +1 -1
- package/dist/atxpFetcher.d.ts +18 -1
- package/dist/atxpFetcher.d.ts.map +1 -1
- package/dist/atxpFetcher.js +65 -2
- package/dist/atxpFetcher.js.map +1 -1
- package/dist/atxpProtocolHandler.d.ts +17 -0
- package/dist/atxpProtocolHandler.d.ts.map +1 -0
- package/dist/atxpProtocolHandler.js +77 -0
- package/dist/atxpProtocolHandler.js.map +1 -0
- package/dist/destinationMakers/index.d.ts.map +1 -1
- package/dist/destinationMakers/index.js +6 -0
- package/dist/destinationMakers/index.js.map +1 -1
- package/dist/index.cjs +558 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +183 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +555 -4
- package/dist/index.js.map +1 -1
- package/dist/mppProtocolHandler.d.ts +46 -0
- package/dist/mppProtocolHandler.d.ts.map +1 -0
- package/dist/mppProtocolHandler.js +182 -0
- package/dist/mppProtocolHandler.js.map +1 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/validation/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/index.js +1 -1
- package/dist/paymentClient.d.ts +55 -0
- package/dist/paymentClient.d.ts.map +1 -0
- package/dist/paymentClient.js +75 -0
- package/dist/paymentClient.js.map +1 -0
- package/dist/protocolHandler.d.ts +41 -0
- package/dist/protocolHandler.d.ts.map +1 -0
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/x402ProtocolHandler.d.ts +22 -0
- package/dist/x402ProtocolHandler.d.ts.map +1 -0
- package/dist/x402ProtocolHandler.js +166 -0
- package/dist/x402ProtocolHandler.js.map +1 -0
- package/package.json +5 -3
- package/dist/atxpLocalAccount.d.ts +0 -50
- package/dist/clientTestHelpers.d.ts +0 -6
- package/dist/destinationMakers/atxpDestinationMaker.d.ts +0 -15
- package/dist/destinationMakers/index.d.ts +0 -9
- package/dist/destinationMakers/passthroughDestinationMaker.d.ts +0 -8
- package/dist/errors.d.ts +0 -117
- package/dist/polygonConstants.d.ts +0 -53
- package/dist/setup.expo.d.ts +0 -2
- package/dist/worldConstants.d.ts +0 -53
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { ATXPPaymentError } from './errors.js';
|
|
2
|
+
import { BigNumber } from 'bignumber.js';
|
|
3
|
+
import { PaymentClient, buildPaymentHeaders } from './paymentClient.js';
|
|
4
|
+
|
|
5
|
+
function isX402Challenge(obj) {
|
|
6
|
+
if (typeof obj !== 'object' || obj === null)
|
|
7
|
+
return false;
|
|
8
|
+
const candidate = obj;
|
|
9
|
+
return (typeof candidate.x402Version !== 'undefined' &&
|
|
10
|
+
Array.isArray(candidate.accepts));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Protocol handler for X402 payment challenges.
|
|
14
|
+
*
|
|
15
|
+
* Detects HTTP 402 responses with x402Version in the JSON body.
|
|
16
|
+
* Creates payment headers using the x402 library and retries the request.
|
|
17
|
+
*/
|
|
18
|
+
class X402ProtocolHandler {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.protocol = 'x402';
|
|
21
|
+
this.accountsServer = config?.accountsServer ?? 'https://accounts.atxp.ai';
|
|
22
|
+
}
|
|
23
|
+
async canHandle(response) {
|
|
24
|
+
if (response.status !== 402)
|
|
25
|
+
return false;
|
|
26
|
+
try {
|
|
27
|
+
const cloned = response.clone();
|
|
28
|
+
const body = await cloned.text();
|
|
29
|
+
const parsed = JSON.parse(body);
|
|
30
|
+
return isX402Challenge(parsed);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async handlePaymentChallenge(response, originalRequest, config) {
|
|
37
|
+
const { account, logger, fetchFn, approvePayment, onPayment, onPaymentFailure } = config;
|
|
38
|
+
const responseBody = await response.text();
|
|
39
|
+
let paymentChallenge;
|
|
40
|
+
try {
|
|
41
|
+
paymentChallenge = JSON.parse(responseBody);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
logger.error('X402: failed to parse challenge body');
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (!isX402Challenge(paymentChallenge)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const { selectPaymentRequirements } = await import('x402/client');
|
|
52
|
+
const selectedPaymentRequirements = selectPaymentRequirements(paymentChallenge.accepts, undefined, 'exact');
|
|
53
|
+
if (!selectedPaymentRequirements) {
|
|
54
|
+
logger.info('X402: no suitable payment option found');
|
|
55
|
+
return this.reconstructResponse(responseBody, response);
|
|
56
|
+
}
|
|
57
|
+
const amountInUsdc = Number(selectedPaymentRequirements.maxAmountRequired) / (10 ** 6);
|
|
58
|
+
const network = selectedPaymentRequirements.network;
|
|
59
|
+
logger.debug(`X402: payment required: ${amountInUsdc} USDC on ${network} to ${selectedPaymentRequirements.payTo}`);
|
|
60
|
+
const url = typeof originalRequest.url === 'string' ? originalRequest.url : originalRequest.url.toString();
|
|
61
|
+
const accountId = await account.getAccountId();
|
|
62
|
+
const prospectivePayment = {
|
|
63
|
+
accountId,
|
|
64
|
+
resourceUrl: url,
|
|
65
|
+
resourceName: selectedPaymentRequirements.description || url,
|
|
66
|
+
currency: 'USDC',
|
|
67
|
+
amount: new BigNumber(amountInUsdc),
|
|
68
|
+
iss: selectedPaymentRequirements.payTo
|
|
69
|
+
};
|
|
70
|
+
const approved = await approvePayment(prospectivePayment);
|
|
71
|
+
if (!approved) {
|
|
72
|
+
logger.info('X402: payment not approved');
|
|
73
|
+
const error = new Error('Payment not approved');
|
|
74
|
+
await onPaymentFailure({
|
|
75
|
+
payment: prospectivePayment,
|
|
76
|
+
error,
|
|
77
|
+
attemptedNetworks: [network],
|
|
78
|
+
failureReasons: new Map([[network, error]]),
|
|
79
|
+
retryable: true,
|
|
80
|
+
timestamp: new Date()
|
|
81
|
+
});
|
|
82
|
+
return this.reconstructResponse(responseBody, response);
|
|
83
|
+
}
|
|
84
|
+
// Authorize via account.authorize() — ATXPAccount calls the accounts
|
|
85
|
+
// service, BaseAccount signs locally. No fallback — each account type
|
|
86
|
+
// handles authorization according to its capabilities.
|
|
87
|
+
const client = new PaymentClient({
|
|
88
|
+
accountsServer: this.accountsServer,
|
|
89
|
+
logger,
|
|
90
|
+
fetchFn,
|
|
91
|
+
});
|
|
92
|
+
const authorizeResult = await client.authorize({
|
|
93
|
+
account,
|
|
94
|
+
userId: accountId,
|
|
95
|
+
destination: url,
|
|
96
|
+
protocol: 'x402',
|
|
97
|
+
paymentRequirements: selectedPaymentRequirements,
|
|
98
|
+
});
|
|
99
|
+
const paymentHeader = authorizeResult.credential;
|
|
100
|
+
// Retry with X-PAYMENT header
|
|
101
|
+
const retryHeaders = buildPaymentHeaders({ protocol: 'x402', credential: paymentHeader }, originalRequest.init?.headers);
|
|
102
|
+
const retryInit = { ...originalRequest.init, headers: retryHeaders };
|
|
103
|
+
logger.info('X402: retrying request with X-PAYMENT header');
|
|
104
|
+
const retryResponse = await fetchFn(originalRequest.url, retryInit);
|
|
105
|
+
if (retryResponse.ok) {
|
|
106
|
+
logger.info('X402: payment accepted');
|
|
107
|
+
await onPayment({
|
|
108
|
+
payment: prospectivePayment,
|
|
109
|
+
transactionHash: paymentHeader.substring(0, 66),
|
|
110
|
+
network
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
logger.warn(`X402: request failed after payment with status ${retryResponse.status}`);
|
|
115
|
+
const error = new Error(`Request failed with status ${retryResponse.status}`);
|
|
116
|
+
await onPaymentFailure({
|
|
117
|
+
payment: prospectivePayment,
|
|
118
|
+
error,
|
|
119
|
+
attemptedNetworks: [network],
|
|
120
|
+
failureReasons: new Map([[network, error]]),
|
|
121
|
+
retryable: false,
|
|
122
|
+
timestamp: new Date()
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return retryResponse;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
logger.error(`X402: failed to handle payment challenge: ${error}`);
|
|
129
|
+
if (isX402Challenge(paymentChallenge) && paymentChallenge.accepts[0]) {
|
|
130
|
+
const firstOption = paymentChallenge.accepts[0];
|
|
131
|
+
const amount = firstOption.maxAmountRequired ? Number(firstOption.maxAmountRequired) / (10 ** 6) : 0;
|
|
132
|
+
const url = typeof originalRequest.url === 'string' ? originalRequest.url : originalRequest.url.toString();
|
|
133
|
+
const accountId = await account.getAccountId();
|
|
134
|
+
const errorNetwork = firstOption.network || 'unknown';
|
|
135
|
+
const typedError = error;
|
|
136
|
+
const isRetryable = typedError instanceof ATXPPaymentError ? typedError.retryable : true;
|
|
137
|
+
await onPaymentFailure({
|
|
138
|
+
payment: {
|
|
139
|
+
accountId,
|
|
140
|
+
resourceUrl: url,
|
|
141
|
+
resourceName: firstOption.description || url,
|
|
142
|
+
currency: 'USDC',
|
|
143
|
+
amount: new BigNumber(amount),
|
|
144
|
+
iss: firstOption.payTo || ''
|
|
145
|
+
},
|
|
146
|
+
error: typedError,
|
|
147
|
+
attemptedNetworks: [errorNetwork],
|
|
148
|
+
failureReasons: new Map([[errorNetwork, typedError]]),
|
|
149
|
+
retryable: isRetryable,
|
|
150
|
+
timestamp: new Date()
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return this.reconstructResponse(responseBody, response);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
reconstructResponse(body, original) {
|
|
157
|
+
return new Response(body, {
|
|
158
|
+
status: original.status,
|
|
159
|
+
statusText: original.statusText,
|
|
160
|
+
headers: original.headers
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { X402ProtocolHandler };
|
|
166
|
+
//# sourceMappingURL=x402ProtocolHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402ProtocolHandler.js","sources":["../src/x402ProtocolHandler.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAoBA,SAAS,eAAe,CAAC,GAAY,EAAA;AACnC,IAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;AAAE,QAAA,OAAO,KAAK;IACzD,MAAM,SAAS,GAAG,GAA8B;AAChD,IAAA,QACE,OAAO,SAAS,CAAC,WAAW,KAAK,WAAW;QAC5C,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;AAEpC;AAMA;;;;;AAKG;MACU,mBAAmB,CAAA;AAI9B,IAAA,WAAA,CAAY,MAAkC,EAAA;QAHrC,IAAA,CAAA,QAAQ,GAAG,MAAM;QAIxB,IAAI,CAAC,cAAc,GAAG,MAAM,EAAE,cAAc,IAAI,0BAA0B;IAC5E;IAEA,MAAM,SAAS,CAAC,QAAkB,EAAA;AAChC,QAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;AAAE,YAAA,OAAO,KAAK;AAEzC,QAAA,IAAI;AACF,YAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE;AAC/B,YAAA,MAAM,IAAI,GAAG,MAAM,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AC7B,wBAAA,GAAG,EAAE,WAAW,CAAC,KAAK,IAAI;AAC3B,qBAAA;AACD,oBAAA,KAAK,EAAE,UAAU;oBACjB,iBAAiB,EAAE,CAAC,YAAY,CAAC;oBACjC,cAAc,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;AACrD,oBAAA,SAAS,EAAE,WAAW;oBACtB,SAAS,EAAE,IAAI,IAAI;AACpB,iBAAA,CAAC;YACJ;YAEA,OAAO,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC;QACzD;IACF;IAEQ,mBAAmB,CAAC,IAAY,EAAE,QAAkB,EAAA;AAC1D,QAAA,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;YACxB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE,QAAQ,CAAC;AACnB,SAAA,CAAC;IACJ;AAED;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atxp/client",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.10",
|
|
4
4
|
"description": "ATXP Client - MCP client with OAuth authentication and payment processing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,10 +33,12 @@
|
|
|
33
33
|
"pack:dry": "npm pack --dry-run"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@atxp/common": "0.10.
|
|
36
|
+
"@atxp/common": "0.10.10",
|
|
37
|
+
"@atxp/mpp": "0.10.7",
|
|
37
38
|
"@modelcontextprotocol/sdk": "^1.15.0",
|
|
38
39
|
"bignumber.js": "^9.3.0",
|
|
39
|
-
"oauth4webapi": "^3.8.3"
|
|
40
|
+
"oauth4webapi": "^3.8.3",
|
|
41
|
+
"x402": "^1.1.0"
|
|
40
42
|
},
|
|
41
43
|
"peerDependencies": {
|
|
42
44
|
"expo-crypto": ">=14.0.0",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Hex, Address, LocalAccount, SignableMessage, TypedData, TransactionSerializable } from 'viem';
|
|
2
|
-
import { FetchLike } from '@atxp/common';
|
|
3
|
-
/**
|
|
4
|
-
* ATXP implementation of viem's LocalAccount interface.
|
|
5
|
-
* Delegates signing operations to the accounts-x402 API.
|
|
6
|
-
* Includes properties needed by x402 library for wallet client compatibility.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ATXPLocalAccount implements LocalAccount {
|
|
9
|
-
readonly address: Address;
|
|
10
|
-
private origin;
|
|
11
|
-
private token;
|
|
12
|
-
private fetchFn;
|
|
13
|
-
readonly type: "local";
|
|
14
|
-
readonly account: LocalAccount;
|
|
15
|
-
readonly chain: {
|
|
16
|
-
id: number;
|
|
17
|
-
};
|
|
18
|
-
readonly transport: object;
|
|
19
|
-
constructor(address: Address, origin: string, token: string, fetchFn?: FetchLike);
|
|
20
|
-
/**
|
|
21
|
-
* Fetch the wallet address from the /address endpoint
|
|
22
|
-
*/
|
|
23
|
-
static create(origin: string, token: string, fetchFn?: FetchLike): Promise<ATXPLocalAccount>;
|
|
24
|
-
/**
|
|
25
|
-
* Sign a typed data structure using EIP-712
|
|
26
|
-
* This is what x402 library will call for EIP-3009 authorization
|
|
27
|
-
*/
|
|
28
|
-
signTypedData<const TTypedData extends TypedData | {
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
}>(typedData: TTypedData): Promise<Hex>;
|
|
31
|
-
/**
|
|
32
|
-
* Sign a message - required by LocalAccount interface but not used for X402
|
|
33
|
-
*/
|
|
34
|
-
signMessage(_: {
|
|
35
|
-
message: SignableMessage;
|
|
36
|
-
}): Promise<Hex>;
|
|
37
|
-
/**
|
|
38
|
-
* Sign a transaction - required by LocalAccount interface but not used for X402
|
|
39
|
-
*/
|
|
40
|
-
signTransaction(_transaction: TransactionSerializable, _args?: unknown): Promise<Hex>;
|
|
41
|
-
/**
|
|
42
|
-
* Get public key - required by LocalAccount interface
|
|
43
|
-
*/
|
|
44
|
-
readonly publicKey: Hex;
|
|
45
|
-
/**
|
|
46
|
-
* Source - required by LocalAccount interface (set to 'custom')
|
|
47
|
-
*/
|
|
48
|
-
readonly source: "custom";
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=atxpLocalAccount.d.ts.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { FetchMock } from 'fetch-mock';
|
|
2
|
-
export declare function mockResourceServer(mock: FetchMock, baseUrl?: string, resourcePath?: string, authServerUrl?: string): FetchMock;
|
|
3
|
-
export declare function mockAuthorizationServer(mock: FetchMock, baseUrl?: string, paymentRequests?: {
|
|
4
|
-
[key: string]: BigNumber;
|
|
5
|
-
}): FetchMock;
|
|
6
|
-
//# sourceMappingURL=clientTestHelpers.d.ts.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { FetchLike, Logger, Source } from '@atxp/common';
|
|
2
|
-
import { Destination, PaymentRequestOption, DestinationMaker } from '@atxp/common';
|
|
3
|
-
/**
|
|
4
|
-
* Destination mapper for ATXP network destinations.
|
|
5
|
-
* Converts destinations with network='atxp' to actual blockchain network destinations
|
|
6
|
-
* by resolving the account ID to its associated blockchain addresses.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ATXPDestinationMaker implements DestinationMaker {
|
|
9
|
-
private accountsServiceUrl;
|
|
10
|
-
private fetchFn;
|
|
11
|
-
constructor(accountsServiceUrl: string, fetchFn?: FetchLike);
|
|
12
|
-
makeDestinations(option: PaymentRequestOption, logger: Logger, paymentRequestId: string, sources: Source[]): Promise<Destination[]>;
|
|
13
|
-
private getDestinations;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=atxpDestinationMaker.d.ts.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Network, DestinationMaker, FetchLike } from '@atxp/common';
|
|
2
|
-
export { ATXPDestinationMaker } from './atxpDestinationMaker.js';
|
|
3
|
-
export { PassthroughDestinationMaker } from './passthroughDestinationMaker.js';
|
|
4
|
-
export interface DestinationMakerFactoryConfig {
|
|
5
|
-
atxpAccountsServer: string;
|
|
6
|
-
fetchFn?: FetchLike;
|
|
7
|
-
}
|
|
8
|
-
export declare function createDestinationMakers(config: DestinationMakerFactoryConfig): Map<Network, DestinationMaker>;
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Logger, Source } from '@atxp/common';
|
|
2
|
-
import { Network, Destination, PaymentRequestOption, DestinationMaker } from '@atxp/common';
|
|
3
|
-
export declare class PassthroughDestinationMaker implements DestinationMaker {
|
|
4
|
-
private network;
|
|
5
|
-
constructor(network: Network);
|
|
6
|
-
makeDestinations(option: PaymentRequestOption, _logger: Logger, _paymentRequestId: string, _sources: Source[]): Promise<Destination[]>;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=passthroughDestinationMaker.d.ts.map
|
package/dist/errors.d.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Currency } from "@atxp/common";
|
|
2
|
-
/**
|
|
3
|
-
* Base class for all ATXP payment errors with structured error codes and actionable guidance
|
|
4
|
-
*/
|
|
5
|
-
export declare abstract class ATXPPaymentError extends Error {
|
|
6
|
-
readonly context?: Record<string, unknown> | undefined;
|
|
7
|
-
abstract readonly code: string;
|
|
8
|
-
abstract readonly retryable: boolean;
|
|
9
|
-
abstract readonly actionableMessage: string;
|
|
10
|
-
constructor(message: string, context?: Record<string, unknown> | undefined);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Thrown when the user's wallet has insufficient funds for a payment
|
|
14
|
-
*/
|
|
15
|
-
export declare class InsufficientFundsError extends ATXPPaymentError {
|
|
16
|
-
readonly currency: Currency;
|
|
17
|
-
readonly required: BigNumber;
|
|
18
|
-
readonly available?: BigNumber | undefined;
|
|
19
|
-
readonly network?: string | undefined;
|
|
20
|
-
readonly code = "INSUFFICIENT_FUNDS";
|
|
21
|
-
readonly retryable = true;
|
|
22
|
-
readonly actionableMessage: string;
|
|
23
|
-
constructor(currency: Currency, required: BigNumber, available?: BigNumber | undefined, network?: string | undefined);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Thrown when a blockchain transaction is reverted
|
|
27
|
-
*/
|
|
28
|
-
export declare class TransactionRevertedError extends ATXPPaymentError {
|
|
29
|
-
readonly transactionHash: string;
|
|
30
|
-
readonly network: string;
|
|
31
|
-
readonly revertReason?: string | undefined;
|
|
32
|
-
readonly code = "TRANSACTION_REVERTED";
|
|
33
|
-
readonly retryable = false;
|
|
34
|
-
readonly actionableMessage: string;
|
|
35
|
-
constructor(transactionHash: string, network: string, revertReason?: string | undefined);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Thrown when an unsupported currency is requested
|
|
39
|
-
*/
|
|
40
|
-
export declare class UnsupportedCurrencyError extends ATXPPaymentError {
|
|
41
|
-
readonly currency: string;
|
|
42
|
-
readonly network: string;
|
|
43
|
-
readonly supportedCurrencies: string[];
|
|
44
|
-
readonly code = "UNSUPPORTED_CURRENCY";
|
|
45
|
-
readonly retryable = false;
|
|
46
|
-
readonly actionableMessage: string;
|
|
47
|
-
constructor(currency: string, network: string, supportedCurrencies: string[]);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Thrown when gas estimation fails for a transaction
|
|
51
|
-
*/
|
|
52
|
-
export declare class GasEstimationError extends ATXPPaymentError {
|
|
53
|
-
readonly network: string;
|
|
54
|
-
readonly reason?: string | undefined;
|
|
55
|
-
readonly code = "GAS_ESTIMATION_FAILED";
|
|
56
|
-
readonly retryable = true;
|
|
57
|
-
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.";
|
|
58
|
-
constructor(network: string, reason?: string | undefined);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Thrown when RPC/network connectivity fails
|
|
62
|
-
*/
|
|
63
|
-
export declare class RpcError extends ATXPPaymentError {
|
|
64
|
-
readonly network: string;
|
|
65
|
-
readonly rpcUrl?: string | undefined;
|
|
66
|
-
readonly originalError?: Error | undefined;
|
|
67
|
-
readonly code = "RPC_ERROR";
|
|
68
|
-
readonly retryable = true;
|
|
69
|
-
readonly actionableMessage = "Unable to connect to the blockchain network. Please check your internet connection and try again.";
|
|
70
|
-
constructor(network: string, rpcUrl?: string | undefined, originalError?: Error | undefined);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Thrown when the user rejects a transaction in their wallet
|
|
74
|
-
*/
|
|
75
|
-
export declare class UserRejectedError extends ATXPPaymentError {
|
|
76
|
-
readonly network: string;
|
|
77
|
-
readonly code = "USER_REJECTED";
|
|
78
|
-
readonly retryable = true;
|
|
79
|
-
readonly actionableMessage = "You cancelled the transaction. To complete the payment, please approve the transaction in your wallet.";
|
|
80
|
-
constructor(network: string);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Thrown when the payment server returns an error
|
|
84
|
-
*/
|
|
85
|
-
export declare class PaymentServerError extends ATXPPaymentError {
|
|
86
|
-
readonly statusCode: number;
|
|
87
|
-
readonly endpoint: string;
|
|
88
|
-
readonly serverMessage?: string | undefined;
|
|
89
|
-
readonly details?: unknown | undefined;
|
|
90
|
-
readonly code: string;
|
|
91
|
-
readonly retryable = true;
|
|
92
|
-
readonly actionableMessage = "The payment server encountered an error. Please try again in a few moments.";
|
|
93
|
-
constructor(statusCode: number, endpoint: string, serverMessage?: string | undefined, errorCode?: string, details?: unknown | undefined);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Thrown when a payment request has expired
|
|
97
|
-
*/
|
|
98
|
-
export declare class PaymentExpiredError extends ATXPPaymentError {
|
|
99
|
-
readonly paymentRequestId: string;
|
|
100
|
-
readonly expiresAt?: Date | undefined;
|
|
101
|
-
readonly code = "PAYMENT_EXPIRED";
|
|
102
|
-
readonly retryable = false;
|
|
103
|
-
readonly actionableMessage = "This payment request has expired. Please make a new request to the service.";
|
|
104
|
-
constructor(paymentRequestId: string, expiresAt?: Date | undefined);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Generic network error for backward compatibility and uncategorized errors
|
|
108
|
-
*/
|
|
109
|
-
export declare class PaymentNetworkError extends ATXPPaymentError {
|
|
110
|
-
readonly network: string;
|
|
111
|
-
readonly originalError?: Error | undefined;
|
|
112
|
-
readonly code = "NETWORK_ERROR";
|
|
113
|
-
readonly retryable = true;
|
|
114
|
-
readonly actionableMessage = "A network error occurred during payment processing. Please try again.";
|
|
115
|
-
constructor(network: string, message: string, originalError?: Error | undefined);
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Polygon Chain configuration type, compatible with viem's Chain interface
|
|
3
|
-
*/
|
|
4
|
-
export type PolygonChain = {
|
|
5
|
-
readonly id: number;
|
|
6
|
-
readonly name: string;
|
|
7
|
-
readonly nativeCurrency: {
|
|
8
|
-
readonly name: string;
|
|
9
|
-
readonly symbol: string;
|
|
10
|
-
readonly decimals: number;
|
|
11
|
-
};
|
|
12
|
-
readonly rpcUrls: {
|
|
13
|
-
readonly default: {
|
|
14
|
-
readonly http: readonly string[];
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
readonly blockExplorers: {
|
|
18
|
-
readonly default: {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly url: string;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
readonly testnet?: boolean;
|
|
24
|
-
};
|
|
25
|
-
export declare const USDC_CONTRACT_ADDRESS_POLYGON_MAINNET = "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359";
|
|
26
|
-
export declare const USDC_CONTRACT_ADDRESS_POLYGON_AMOY = "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582";
|
|
27
|
-
export declare const POLYGON_MAINNET: PolygonChain;
|
|
28
|
-
export declare const POLYGON_AMOY: PolygonChain;
|
|
29
|
-
/**
|
|
30
|
-
* Get Polygon Mainnet configuration with custom RPC URL (e.g., with API key)
|
|
31
|
-
* @param rpcUrl - Custom RPC URL, e.g., 'https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY'
|
|
32
|
-
*/
|
|
33
|
-
export declare const getPolygonMainnetWithRPC: (rpcUrl: string) => PolygonChain;
|
|
34
|
-
/**
|
|
35
|
-
* Get Polygon Amoy Testnet configuration with custom RPC URL (e.g., with API key)
|
|
36
|
-
* @param rpcUrl - Custom RPC URL, e.g., 'https://polygon-amoy.g.alchemy.com/v2/YOUR_API_KEY'
|
|
37
|
-
*/
|
|
38
|
-
export declare const getPolygonAmoyWithRPC: (rpcUrl: string) => PolygonChain;
|
|
39
|
-
/**
|
|
40
|
-
* Get Polygon Chain configuration by chain ID
|
|
41
|
-
* @param chainId - Chain ID (137 for mainnet, 80002 for Amoy testnet)
|
|
42
|
-
* @returns Polygon Chain configuration
|
|
43
|
-
* @throws Error if chain ID is not supported
|
|
44
|
-
*/
|
|
45
|
-
export declare const getPolygonByChainId: (chainId: number) => PolygonChain;
|
|
46
|
-
/**
|
|
47
|
-
* Get USDC contract address for Polygon by chain ID
|
|
48
|
-
* @param chainId - Chain ID (137 for mainnet, 80002 for Amoy testnet)
|
|
49
|
-
* @returns USDC contract address
|
|
50
|
-
* @throws Error if chain ID is not supported
|
|
51
|
-
*/
|
|
52
|
-
export declare const getPolygonUSDCAddress: (chainId: number) => string;
|
|
53
|
-
//# sourceMappingURL=polygonConstants.d.ts.map
|
package/dist/setup.expo.d.ts
DELETED
package/dist/worldConstants.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* World Chain configuration type, compatible with viem's Chain interface
|
|
3
|
-
*/
|
|
4
|
-
export type WorldChain = {
|
|
5
|
-
readonly id: number;
|
|
6
|
-
readonly name: string;
|
|
7
|
-
readonly nativeCurrency: {
|
|
8
|
-
readonly name: string;
|
|
9
|
-
readonly symbol: string;
|
|
10
|
-
readonly decimals: number;
|
|
11
|
-
};
|
|
12
|
-
readonly rpcUrls: {
|
|
13
|
-
readonly default: {
|
|
14
|
-
readonly http: readonly string[];
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
readonly blockExplorers: {
|
|
18
|
-
readonly default: {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly url: string;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
readonly testnet?: boolean;
|
|
24
|
-
};
|
|
25
|
-
export declare const USDC_CONTRACT_ADDRESS_WORLD_MAINNET = "0x79A02482A880bCE3F13e09Da970dC34db4CD24d1";
|
|
26
|
-
export declare const USDC_CONTRACT_ADDRESS_WORLD_SEPOLIA = "0x79A02482A880bCE3F13e09Da970dC34db4CD24d1";
|
|
27
|
-
export declare const WORLD_CHAIN_MAINNET: WorldChain;
|
|
28
|
-
export declare const WORLD_CHAIN_SEPOLIA: WorldChain;
|
|
29
|
-
/**
|
|
30
|
-
* Get World Chain Mainnet configuration with custom RPC URL (e.g., with API key)
|
|
31
|
-
* @param rpcUrl - Custom RPC URL, e.g., 'https://worldchain-mainnet.g.alchemy.com/v2/YOUR_API_KEY'
|
|
32
|
-
*/
|
|
33
|
-
export declare const getWorldChainMainnetWithRPC: (rpcUrl: string) => WorldChain;
|
|
34
|
-
/**
|
|
35
|
-
* Get World Chain Sepolia configuration with custom RPC URL (e.g., with API key)
|
|
36
|
-
* @param rpcUrl - Custom RPC URL, e.g., 'https://worldchain-sepolia.g.alchemy.com/v2/YOUR_API_KEY'
|
|
37
|
-
*/
|
|
38
|
-
export declare const getWorldChainSepoliaWithRPC: (rpcUrl: string) => WorldChain;
|
|
39
|
-
/**
|
|
40
|
-
* Get World Chain configuration by chain ID
|
|
41
|
-
* @param chainId - Chain ID (480 for mainnet, 4801 for sepolia)
|
|
42
|
-
* @returns World Chain configuration
|
|
43
|
-
* @throws Error if chain ID is not supported
|
|
44
|
-
*/
|
|
45
|
-
export declare const getWorldChainByChainId: (chainId: number) => WorldChain;
|
|
46
|
-
/**
|
|
47
|
-
* Get USDC contract address for World Chain by chain ID
|
|
48
|
-
* @param chainId - Chain ID (480 for mainnet, 4801 for sepolia)
|
|
49
|
-
* @returns USDC contract address
|
|
50
|
-
* @throws Error if chain ID is not supported
|
|
51
|
-
*/
|
|
52
|
-
export declare const getWorldChainUSDCAddress: (chainId: number) => string;
|
|
53
|
-
//# sourceMappingURL=worldConstants.d.ts.map
|