@atxp/client 0.8.0 → 0.8.2
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 +1 -2
- package/dist/atxpClient.js.map +1 -1
- package/dist/baseAccount.d.ts +3 -3
- package/dist/baseAccount.d.ts.map +1 -1
- package/dist/baseAccount.js +3 -4
- package/dist/baseAccount.js.map +1 -1
- package/dist/destinationMakers/index.d.ts.map +1 -1
- package/dist/destinationMakers/index.js +3 -0
- package/dist/destinationMakers/index.js.map +1 -1
- package/dist/index.cjs +149 -268
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +144 -268
- package/dist/index.js.map +1 -1
- package/dist/polygonConstants.d.ts +9 -2
- package/dist/polygonConstants.d.ts.map +1 -1
- package/dist/polygonConstants.js +36 -6
- package/dist/polygonConstants.js.map +1 -1
- package/package.json +2 -2
- package/dist/atxpAccount.d.ts +0 -20
- package/dist/atxpAccount.d.ts.map +0 -1
- package/dist/atxpAccount.js +0 -161
- package/dist/atxpAccount.js.map +0 -1
|
@@ -23,22 +23,29 @@ export type PolygonChain = {
|
|
|
23
23
|
readonly testnet?: boolean;
|
|
24
24
|
};
|
|
25
25
|
export declare const USDC_CONTRACT_ADDRESS_POLYGON_MAINNET = "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359";
|
|
26
|
+
export declare const USDC_CONTRACT_ADDRESS_POLYGON_AMOY = "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582";
|
|
26
27
|
export declare const POLYGON_MAINNET: PolygonChain;
|
|
28
|
+
export declare const POLYGON_AMOY: PolygonChain;
|
|
27
29
|
/**
|
|
28
30
|
* Get Polygon Mainnet configuration with custom RPC URL (e.g., with API key)
|
|
29
31
|
* @param rpcUrl - Custom RPC URL, e.g., 'https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY'
|
|
30
32
|
*/
|
|
31
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;
|
|
32
39
|
/**
|
|
33
40
|
* Get Polygon Chain configuration by chain ID
|
|
34
|
-
* @param chainId - Chain ID (137 for mainnet)
|
|
41
|
+
* @param chainId - Chain ID (137 for mainnet, 80002 for Amoy testnet)
|
|
35
42
|
* @returns Polygon Chain configuration
|
|
36
43
|
* @throws Error if chain ID is not supported
|
|
37
44
|
*/
|
|
38
45
|
export declare const getPolygonByChainId: (chainId: number) => PolygonChain;
|
|
39
46
|
/**
|
|
40
47
|
* Get USDC contract address for Polygon by chain ID
|
|
41
|
-
* @param chainId - Chain ID (137 for mainnet)
|
|
48
|
+
* @param chainId - Chain ID (137 for mainnet, 80002 for Amoy testnet)
|
|
42
49
|
* @returns USDC contract address
|
|
43
50
|
* @throws Error if chain ID is not supported
|
|
44
51
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polygonConstants.d.ts","sourceRoot":"","sources":["../src/polygonConstants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,cAAc,EAAE;QACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,QAAQ,CAAC,OAAO,EAAE;QA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/F,eAAO,MAAM,eAAe,EAAE,YAUpB,CAAC;AAIX,eAAO,MAAM,YAAY,EAAE,YAWjB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,YAKxD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,KAAG,YAKrD,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,KAAG,YASrD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM,KAAG,MASvD,CAAC"}
|
package/dist/polygonConstants.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const USDC_CONTRACT_ADDRESS_POLYGON_MAINNET = "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"; // Native USDC on Polygon mainnet
|
|
2
|
+
const USDC_CONTRACT_ADDRESS_POLYGON_AMOY = "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582"; // USDC on Polygon Amoy testnet
|
|
2
3
|
// Polygon Mainnet (Chain ID: 137)
|
|
4
|
+
// Note: Native currency upgraded from MATIC to POL on September 4, 2024
|
|
3
5
|
const POLYGON_MAINNET = {
|
|
4
6
|
id: 137,
|
|
5
7
|
name: 'Polygon',
|
|
6
|
-
nativeCurrency: { name: '
|
|
8
|
+
nativeCurrency: { name: 'POL', symbol: 'POL', decimals: 18 },
|
|
7
9
|
rpcUrls: {
|
|
8
10
|
default: { http: ['https://polygon-rpc.com'] }
|
|
9
11
|
},
|
|
@@ -11,6 +13,20 @@ const POLYGON_MAINNET = {
|
|
|
11
13
|
default: { name: 'PolygonScan', url: 'https://polygonscan.com' }
|
|
12
14
|
}
|
|
13
15
|
};
|
|
16
|
+
// Polygon Amoy Testnet (Chain ID: 80002)
|
|
17
|
+
// Note: Amoy testnet also uses POL as native currency (following mainnet upgrade)
|
|
18
|
+
const POLYGON_AMOY = {
|
|
19
|
+
id: 80002,
|
|
20
|
+
name: 'Polygon Amoy',
|
|
21
|
+
nativeCurrency: { name: 'POL', symbol: 'POL', decimals: 18 },
|
|
22
|
+
rpcUrls: {
|
|
23
|
+
default: { http: ['https://rpc-amoy.polygon.technology'] }
|
|
24
|
+
},
|
|
25
|
+
blockExplorers: {
|
|
26
|
+
default: { name: 'PolygonScan Amoy', url: 'https://amoy.polygonscan.com' }
|
|
27
|
+
},
|
|
28
|
+
testnet: true
|
|
29
|
+
};
|
|
14
30
|
/**
|
|
15
31
|
* Get Polygon Mainnet configuration with custom RPC URL (e.g., with API key)
|
|
16
32
|
* @param rpcUrl - Custom RPC URL, e.g., 'https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY'
|
|
@@ -21,9 +37,19 @@ const getPolygonMainnetWithRPC = (rpcUrl) => ({
|
|
|
21
37
|
default: { http: [rpcUrl] }
|
|
22
38
|
}
|
|
23
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* Get Polygon Amoy Testnet configuration with custom RPC URL (e.g., with API key)
|
|
42
|
+
* @param rpcUrl - Custom RPC URL, e.g., 'https://polygon-amoy.g.alchemy.com/v2/YOUR_API_KEY'
|
|
43
|
+
*/
|
|
44
|
+
const getPolygonAmoyWithRPC = (rpcUrl) => ({
|
|
45
|
+
...POLYGON_AMOY,
|
|
46
|
+
rpcUrls: {
|
|
47
|
+
default: { http: [rpcUrl] }
|
|
48
|
+
}
|
|
49
|
+
});
|
|
24
50
|
/**
|
|
25
51
|
* Get Polygon Chain configuration by chain ID
|
|
26
|
-
* @param chainId - Chain ID (137 for mainnet)
|
|
52
|
+
* @param chainId - Chain ID (137 for mainnet, 80002 for Amoy testnet)
|
|
27
53
|
* @returns Polygon Chain configuration
|
|
28
54
|
* @throws Error if chain ID is not supported
|
|
29
55
|
*/
|
|
@@ -31,13 +57,15 @@ const getPolygonByChainId = (chainId) => {
|
|
|
31
57
|
switch (chainId) {
|
|
32
58
|
case 137:
|
|
33
59
|
return POLYGON_MAINNET;
|
|
60
|
+
case 80002:
|
|
61
|
+
return POLYGON_AMOY;
|
|
34
62
|
default:
|
|
35
|
-
throw new Error(`Unsupported Polygon Chain ID: ${chainId}. Supported chains: 137 (mainnet)`);
|
|
63
|
+
throw new Error(`Unsupported Polygon Chain ID: ${chainId}. Supported chains: 137 (mainnet), 80002 (Amoy testnet)`);
|
|
36
64
|
}
|
|
37
65
|
};
|
|
38
66
|
/**
|
|
39
67
|
* Get USDC contract address for Polygon by chain ID
|
|
40
|
-
* @param chainId - Chain ID (137 for mainnet)
|
|
68
|
+
* @param chainId - Chain ID (137 for mainnet, 80002 for Amoy testnet)
|
|
41
69
|
* @returns USDC contract address
|
|
42
70
|
* @throws Error if chain ID is not supported
|
|
43
71
|
*/
|
|
@@ -45,10 +73,12 @@ const getPolygonUSDCAddress = (chainId) => {
|
|
|
45
73
|
switch (chainId) {
|
|
46
74
|
case 137:
|
|
47
75
|
return USDC_CONTRACT_ADDRESS_POLYGON_MAINNET;
|
|
76
|
+
case 80002:
|
|
77
|
+
return USDC_CONTRACT_ADDRESS_POLYGON_AMOY;
|
|
48
78
|
default:
|
|
49
|
-
throw new Error(`Unsupported Polygon Chain ID: ${chainId}. Supported chains: 137 (mainnet)`);
|
|
79
|
+
throw new Error(`Unsupported Polygon Chain ID: ${chainId}. Supported chains: 137 (mainnet), 80002 (Amoy testnet)`);
|
|
50
80
|
}
|
|
51
81
|
};
|
|
52
82
|
|
|
53
|
-
export { POLYGON_MAINNET, USDC_CONTRACT_ADDRESS_POLYGON_MAINNET, getPolygonByChainId, getPolygonMainnetWithRPC, getPolygonUSDCAddress };
|
|
83
|
+
export { POLYGON_AMOY, POLYGON_MAINNET, USDC_CONTRACT_ADDRESS_POLYGON_AMOY, USDC_CONTRACT_ADDRESS_POLYGON_MAINNET, getPolygonAmoyWithRPC, getPolygonByChainId, getPolygonMainnetWithRPC, getPolygonUSDCAddress };
|
|
54
84
|
//# sourceMappingURL=polygonConstants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polygonConstants.js","sources":["../src/polygonConstants.ts"],"sourcesContent":[null],"names":[],"mappings":"AAoBO,MAAM,qCAAqC,GAAG,6CAA6C;
|
|
1
|
+
{"version":3,"file":"polygonConstants.js","sources":["../src/polygonConstants.ts"],"sourcesContent":[null],"names":[],"mappings":"AAoBO,MAAM,qCAAqC,GAAG,6CAA6C;AAC3F,MAAM,kCAAkC,GAAG,6CAA6C;AAE/F;AACA;AACO,MAAM,eAAe,GAAiB;AAC3C,IAAA,EAAE,EAAE,GAAG;AACP,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,cAAc,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;AAC5D,IAAA,OAAO,EAAE;AACP,QAAA,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,yBAAyB,CAAC;AAC7C,KAAA;AACD,IAAA,cAAc,EAAE;QACd,OAAO,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,yBAAyB;AAC/D;;AAGH;AACA;AACO,MAAM,YAAY,GAAiB;AACxC,IAAA,EAAE,EAAE,KAAK;AACT,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,cAAc,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;AAC5D,IAAA,OAAO,EAAE;AACP,QAAA,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,qCAAqC,CAAC;AACzD,KAAA;AACD,IAAA,cAAc,EAAE;QACd,OAAO,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,GAAG,EAAE,8BAA8B;AACzE,KAAA;AACD,IAAA,OAAO,EAAE;;AAGX;;;AAGG;MACU,wBAAwB,GAAG,CAAC,MAAc,MAAoB;AACzE,IAAA,GAAG,eAAe;AAClB,IAAA,OAAO,EAAE;AACP,QAAA,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC;AAC1B;AACF,CAAA;AAED;;;AAGG;MACU,qBAAqB,GAAG,CAAC,MAAc,MAAoB;AACtE,IAAA,GAAG,YAAY;AACf,IAAA,OAAO,EAAE;AACP,QAAA,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC;AAC1B;AACF,CAAA;AAED;;;;;AAKG;AACI,MAAM,mBAAmB,GAAG,CAAC,OAAe,KAAkB;IACnE,QAAQ,OAAO;AACb,QAAA,KAAK,GAAG;AACN,YAAA,OAAO,eAAe;AACxB,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,YAAY;AACrB,QAAA;AACE,YAAA,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,CAAA,uDAAA,CAAyD,CAAC;;AAExH;AAEA;;;;;AAKG;AACI,MAAM,qBAAqB,GAAG,CAAC,OAAe,KAAY;IAC/D,QAAQ,OAAO;AACb,QAAA,KAAK,GAAG;AACN,YAAA,OAAO,qCAAqC;AAC9C,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,kCAAkC;AAC3C,QAAA;AACE,YAAA,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,CAAA,uDAAA,CAAyD,CAAC;;AAExH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atxp/client",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "ATXP Client - MCP client with OAuth authentication and payment processing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"pack:dry": "npm pack --dry-run"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@atxp/common": "0.8.
|
|
36
|
+
"@atxp/common": "0.8.2",
|
|
37
37
|
"@modelcontextprotocol/sdk": "^1.15.0",
|
|
38
38
|
"bignumber.js": "^9.3.0",
|
|
39
39
|
"oauth4webapi": "^3.5.0"
|
package/dist/atxpAccount.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Account, PaymentMaker } from './types.js';
|
|
2
|
-
import type { FetchLike, AccountId, Source } from '@atxp/common';
|
|
3
|
-
import { LocalAccount } from 'viem';
|
|
4
|
-
export declare class ATXPAccount implements Account {
|
|
5
|
-
accountId: AccountId;
|
|
6
|
-
paymentMakers: PaymentMaker[];
|
|
7
|
-
origin: string;
|
|
8
|
-
token: string;
|
|
9
|
-
fetchFn: FetchLike;
|
|
10
|
-
private unqualifiedAccountId;
|
|
11
|
-
constructor(connectionString: string, opts?: {
|
|
12
|
-
fetchFn?: FetchLike;
|
|
13
|
-
});
|
|
14
|
-
getSigner(): Promise<LocalAccount>;
|
|
15
|
-
/**
|
|
16
|
-
* Get sources for this account by calling the accounts service
|
|
17
|
-
*/
|
|
18
|
-
getSources(): Promise<Source[]>;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=atxpAccount.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"atxpAccount.d.ts","sourceRoot":"","sources":["../src/atxpAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAY,SAAS,EAAyC,MAAM,EAAE,MAAM,cAAc,CAAC;AAElH,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AA2IpC,qBAAa,WAAY,YAAW,OAAO;IACzC,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,SAAS,CAAC;IACnB,OAAO,CAAC,oBAAoB,CAAS;gBAEzB,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,SAAS,CAAC;KAAE;IAmB/D,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAQxC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAuBtC"}
|
package/dist/atxpAccount.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { ATXPLocalAccount } from './atxpLocalAccount.js';
|
|
2
|
-
|
|
3
|
-
function toBasicAuth(token) {
|
|
4
|
-
// Basic auth is base64("username:password"), password is blank
|
|
5
|
-
const b64 = Buffer.from(`${token}:`).toString('base64');
|
|
6
|
-
return `Basic ${b64}`;
|
|
7
|
-
}
|
|
8
|
-
function parseConnectionString(connectionString) {
|
|
9
|
-
const url = new URL(connectionString);
|
|
10
|
-
const origin = url.origin;
|
|
11
|
-
const token = url.searchParams.get('connection_token') || '';
|
|
12
|
-
const accountId = url.searchParams.get('account_id');
|
|
13
|
-
if (!token) {
|
|
14
|
-
throw new Error('ATXPAccount: connection string missing connection token');
|
|
15
|
-
}
|
|
16
|
-
if (!accountId) {
|
|
17
|
-
throw new Error('ATXPAccount: connection string missing account id');
|
|
18
|
-
}
|
|
19
|
-
return { origin, token, accountId };
|
|
20
|
-
}
|
|
21
|
-
class ATXPHttpPaymentMaker {
|
|
22
|
-
constructor(origin, token, fetchFn = fetch) {
|
|
23
|
-
this.origin = origin;
|
|
24
|
-
this.token = token;
|
|
25
|
-
this.fetchFn = fetchFn;
|
|
26
|
-
}
|
|
27
|
-
async getSourceAddress(params) {
|
|
28
|
-
// Call the /address_for_payment endpoint to get the source address for this account
|
|
29
|
-
const response = await this.fetchFn(`${this.origin}/address_for_payment`, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Authorization': toBasicAuth(this.token),
|
|
33
|
-
'Content-Type': 'application/json',
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify({
|
|
36
|
-
amount: params.amount.toString(),
|
|
37
|
-
currency: params.currency,
|
|
38
|
-
receiver: params.receiver,
|
|
39
|
-
memo: params.memo,
|
|
40
|
-
}),
|
|
41
|
-
});
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
const text = await response.text();
|
|
44
|
-
throw new Error(`ATXPAccount: /address_for_payment failed: ${response.status} ${response.statusText} ${text}`);
|
|
45
|
-
}
|
|
46
|
-
const json = await response.json();
|
|
47
|
-
if (!json?.sourceAddress) {
|
|
48
|
-
throw new Error('ATXPAccount: /address_for_payment did not return sourceAddress');
|
|
49
|
-
}
|
|
50
|
-
return json.sourceAddress;
|
|
51
|
-
}
|
|
52
|
-
async makePayment(destinations, memo, paymentRequestId) {
|
|
53
|
-
// Make a payment via the /pay endpoint with multiple destinations
|
|
54
|
-
const response = await this.fetchFn(`${this.origin}/pay`, {
|
|
55
|
-
method: 'POST',
|
|
56
|
-
headers: {
|
|
57
|
-
'Authorization': toBasicAuth(this.token),
|
|
58
|
-
'Content-Type': 'application/json',
|
|
59
|
-
},
|
|
60
|
-
body: JSON.stringify({
|
|
61
|
-
destinations: destinations.map(d => ({
|
|
62
|
-
chain: d.chain,
|
|
63
|
-
address: d.address,
|
|
64
|
-
amount: d.amount.toString(),
|
|
65
|
-
currency: d.currency
|
|
66
|
-
})),
|
|
67
|
-
memo,
|
|
68
|
-
...(paymentRequestId && { paymentRequestId })
|
|
69
|
-
}),
|
|
70
|
-
});
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
const text = await response.text();
|
|
73
|
-
throw new Error(`ATXPAccount: /pay failed: ${response.status} ${response.statusText} ${text}`);
|
|
74
|
-
}
|
|
75
|
-
const json = await response.json();
|
|
76
|
-
const transactionId = json.transactionId;
|
|
77
|
-
if (!transactionId) {
|
|
78
|
-
throw new Error('ATXPAccount: /pay did not return transactionId or txHash');
|
|
79
|
-
}
|
|
80
|
-
if (!json?.chain) {
|
|
81
|
-
throw new Error('ATXPAccount: /pay did not return chain');
|
|
82
|
-
}
|
|
83
|
-
if (!json?.currency) {
|
|
84
|
-
throw new Error('ATXPAccount: /pay did not return currency');
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
transactionId,
|
|
88
|
-
...(json.transactionSubId ? { transactionSubId: json.transactionSubId } : {}),
|
|
89
|
-
chain: json.chain,
|
|
90
|
-
currency: json.currency
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
async generateJWT(params) {
|
|
94
|
-
const response = await this.fetchFn(`${this.origin}/sign`, {
|
|
95
|
-
method: 'POST',
|
|
96
|
-
headers: {
|
|
97
|
-
'Authorization': toBasicAuth(this.token),
|
|
98
|
-
'Content-Type': 'application/json',
|
|
99
|
-
},
|
|
100
|
-
body: JSON.stringify({
|
|
101
|
-
paymentRequestId: params.paymentRequestId,
|
|
102
|
-
codeChallenge: params.codeChallenge,
|
|
103
|
-
...(params.accountId ? { accountId: params.accountId } : {}),
|
|
104
|
-
}),
|
|
105
|
-
});
|
|
106
|
-
if (!response.ok) {
|
|
107
|
-
const text = await response.text();
|
|
108
|
-
throw new Error(`ATXPAccount: /sign failed: ${response.status} ${response.statusText} ${text}`);
|
|
109
|
-
}
|
|
110
|
-
const json = await response.json();
|
|
111
|
-
if (!json?.jwt) {
|
|
112
|
-
throw new Error('ATXPAccount: /sign did not return jwt');
|
|
113
|
-
}
|
|
114
|
-
return json.jwt;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
class ATXPAccount {
|
|
118
|
-
constructor(connectionString, opts) {
|
|
119
|
-
const { origin, token, accountId } = parseConnectionString(connectionString);
|
|
120
|
-
const fetchFn = opts?.fetchFn ?? fetch;
|
|
121
|
-
// Store for use in X402 payment creation
|
|
122
|
-
this.origin = origin;
|
|
123
|
-
this.token = token;
|
|
124
|
-
this.fetchFn = fetchFn;
|
|
125
|
-
// Format accountId as network:address
|
|
126
|
-
// Connection string provides just the atxp_acct_xxx part (no prefix for UI)
|
|
127
|
-
this.unqualifiedAccountId = accountId;
|
|
128
|
-
this.accountId = `atxp:${accountId}`;
|
|
129
|
-
this.paymentMakers = [
|
|
130
|
-
new ATXPHttpPaymentMaker(origin, token, fetchFn)
|
|
131
|
-
];
|
|
132
|
-
}
|
|
133
|
-
async getSigner() {
|
|
134
|
-
return ATXPLocalAccount.create(this.origin, this.token, this.fetchFn);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get sources for this account by calling the accounts service
|
|
138
|
-
*/
|
|
139
|
-
async getSources() {
|
|
140
|
-
// Use the unqualified account ID (without atxp: prefix) for the API call
|
|
141
|
-
const response = await this.fetchFn(`${this.origin}/account/${this.unqualifiedAccountId}/sources`, {
|
|
142
|
-
method: 'GET',
|
|
143
|
-
headers: {
|
|
144
|
-
'Accept': 'application/json',
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
if (!response.ok) {
|
|
148
|
-
const text = await response.text();
|
|
149
|
-
throw new Error(`ATXPAccount: /account/${this.unqualifiedAccountId}/sources failed: ${response.status} ${response.statusText} ${text}`);
|
|
150
|
-
}
|
|
151
|
-
const json = await response.json();
|
|
152
|
-
// The accounts service returns the sources array directly, not wrapped in an object
|
|
153
|
-
if (!Array.isArray(json)) {
|
|
154
|
-
throw new Error(`ATXPAccount: /account/${this.unqualifiedAccountId}/sources did not return sources array`);
|
|
155
|
-
}
|
|
156
|
-
return json;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export { ATXPAccount };
|
|
161
|
-
//# sourceMappingURL=atxpAccount.js.map
|
package/dist/atxpAccount.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"atxpAccount.js","sources":["../src/atxpAccount.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAMA,SAAS,WAAW,CAAC,KAAa,EAAA;;AAEhC,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA,EAAG,KAAK,CAAA,CAAA,CAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;IACvD,OAAO,CAAA,MAAA,EAAS,GAAG,CAAA,C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