@metamask-previews/multichain-network-controller 0.4.0-preview-a9741b3a → 0.4.0-preview-fa52096c
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/CHANGELOG.md +0 -10
- package/dist/{MultichainNetworkController/MultichainNetworkController.cjs → MultichainNetworkController.cjs} +6 -37
- package/dist/MultichainNetworkController.cjs.map +1 -0
- package/dist/{MultichainNetworkController/MultichainNetworkController.d.cts → MultichainNetworkController.d.cts} +2 -12
- package/dist/MultichainNetworkController.d.cts.map +1 -0
- package/dist/{MultichainNetworkController/MultichainNetworkController.d.mts → MultichainNetworkController.d.mts} +2 -12
- package/dist/MultichainNetworkController.d.mts.map +1 -0
- package/dist/{MultichainNetworkController/MultichainNetworkController.mjs → MultichainNetworkController.mjs} +6 -37
- package/dist/MultichainNetworkController.mjs.map +1 -0
- package/dist/constants.cjs +0 -2
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +0 -4
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +0 -4
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +0 -2
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +2 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +4 -14
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +4 -14
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +1 -12
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -8
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +1 -8
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +0 -10
- package/dist/utils.mjs.map +1 -1
- package/package.json +2 -5
- package/dist/MultichainNetworkController/MultichainNetworkController.cjs.map +0 -1
- package/dist/MultichainNetworkController/MultichainNetworkController.d.cts.map +0 -1
- package/dist/MultichainNetworkController/MultichainNetworkController.d.mts.map +0 -1
- package/dist/MultichainNetworkController/MultichainNetworkController.mjs.map +0 -1
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.cjs +0 -3
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.cjs.map +0 -1
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.cts +0 -7
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.cts.map +0 -1
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.mts +0 -7
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.mts.map +0 -1
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.mjs +0 -2
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.mjs.map +0 -1
- package/dist/MultichainNetworkService/MultichainNetworkService.cjs +0 -63
- package/dist/MultichainNetworkService/MultichainNetworkService.cjs.map +0 -1
- package/dist/MultichainNetworkService/MultichainNetworkService.d.cts +0 -20
- package/dist/MultichainNetworkService/MultichainNetworkService.d.cts.map +0 -1
- package/dist/MultichainNetworkService/MultichainNetworkService.d.mts +0 -20
- package/dist/MultichainNetworkService/MultichainNetworkService.d.mts.map +0 -1
- package/dist/MultichainNetworkService/MultichainNetworkService.mjs +0 -59
- package/dist/MultichainNetworkService/MultichainNetworkService.mjs.map +0 -1
- package/dist/api/accounts-api.cjs +0 -82
- package/dist/api/accounts-api.cjs.map +0 -1
- package/dist/api/accounts-api.d.cts +0 -55
- package/dist/api/accounts-api.d.cts.map +0 -1
- package/dist/api/accounts-api.d.mts +0 -55
- package/dist/api/accounts-api.d.mts.map +0 -1
- package/dist/api/accounts-api.mjs +0 -76
- package/dist/api/accounts-api.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainNetwork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sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { CaipAccountId } from '@metamask/utils';\n\nimport {\n type ActiveNetworksResponse,\n ActiveNetworksResponseStruct,\n buildActiveNetworksUrl,\n MULTICHAIN_ACCOUNTS_CLIENT_HEADER,\n MULTICHAIN_ACCOUNTS_CLIENT_ID,\n} from '../api/accounts-api';\n\n/**\n * Service responsible for fetching network activity data from the API.\n */\nexport class MultichainNetworkService {\n readonly #fetch: typeof fetch;\n\n constructor({ fetch: fetchFunction }: { fetch: typeof fetch }) {\n this.#fetch = fetchFunction;\n }\n\n /**\n * Fetches active networks for the given account IDs.\n *\n * @param accountIds - Array of CAIP-10 account IDs to fetch activity for.\n * @returns Promise resolving to the active networks response.\n * @throws Error if the response format is invalid or the request fails.\n */\n async fetchNetworkActivity(\n accountIds: CaipAccountId[],\n ): Promise<ActiveNetworksResponse> {\n try {\n const url = buildActiveNetworksUrl(accountIds);\n\n const response = await this.#fetch(url.toString(), {\n method: 'GET',\n headers: {\n [MULTICHAIN_ACCOUNTS_CLIENT_HEADER]: MULTICHAIN_ACCOUNTS_CLIENT_ID,\n Accept: 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const data: unknown = await response.json();\n\n assert(data, ActiveNetworksResponseStruct);\n return data;\n } catch (error) {\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout: Failed to fetch active networks');\n }\n throw error;\n }\n\n throw new Error(`Failed to fetch active networks: ${String(error)}`);\n }\n }\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { CaipAccountId } from "@metamask/utils";
|
|
2
|
-
import { type ActiveNetworksResponse } from "../api/accounts-api.cjs";
|
|
3
|
-
/**
|
|
4
|
-
* Service responsible for fetching network activity data from the API.
|
|
5
|
-
*/
|
|
6
|
-
export declare class MultichainNetworkService {
|
|
7
|
-
#private;
|
|
8
|
-
constructor({ fetch: fetchFunction }: {
|
|
9
|
-
fetch: typeof fetch;
|
|
10
|
-
});
|
|
11
|
-
/**
|
|
12
|
-
* Fetches active networks for the given account IDs.
|
|
13
|
-
*
|
|
14
|
-
* @param accountIds - Array of CAIP-10 account IDs to fetch activity for.
|
|
15
|
-
* @returns Promise resolving to the active networks response.
|
|
16
|
-
* @throws Error if the response format is invalid or the request fails.
|
|
17
|
-
*/
|
|
18
|
-
fetchNetworkActivity(accountIds: CaipAccountId[]): Promise<ActiveNetworksResponse>;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=MultichainNetworkService.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainNetworkService.d.cts","sourceRoot":"","sources":["../../src/MultichainNetworkService/MultichainNetworkService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,EACL,KAAK,sBAAsB,EAK5B,gCAA4B;AAE7B;;GAEG;AACH,qBAAa,wBAAwB;;gBAGvB,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE;QAAE,KAAK,EAAE,OAAO,KAAK,CAAA;KAAE;IAI7D;;;;;;OAMG;IACG,oBAAoB,CACxB,UAAU,EAAE,aAAa,EAAE,GAC1B,OAAO,CAAC,sBAAsB,CAAC;CA+BnC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { CaipAccountId } from "@metamask/utils";
|
|
2
|
-
import { type ActiveNetworksResponse } from "../api/accounts-api.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* Service responsible for fetching network activity data from the API.
|
|
5
|
-
*/
|
|
6
|
-
export declare class MultichainNetworkService {
|
|
7
|
-
#private;
|
|
8
|
-
constructor({ fetch: fetchFunction }: {
|
|
9
|
-
fetch: typeof fetch;
|
|
10
|
-
});
|
|
11
|
-
/**
|
|
12
|
-
* Fetches active networks for the given account IDs.
|
|
13
|
-
*
|
|
14
|
-
* @param accountIds - Array of CAIP-10 account IDs to fetch activity for.
|
|
15
|
-
* @returns Promise resolving to the active networks response.
|
|
16
|
-
* @throws Error if the response format is invalid or the request fails.
|
|
17
|
-
*/
|
|
18
|
-
fetchNetworkActivity(accountIds: CaipAccountId[]): Promise<ActiveNetworksResponse>;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=MultichainNetworkService.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainNetworkService.d.mts","sourceRoot":"","sources":["../../src/MultichainNetworkService/MultichainNetworkService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,EACL,KAAK,sBAAsB,EAK5B,gCAA4B;AAE7B;;GAEG;AACH,qBAAa,wBAAwB;;gBAGvB,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE;QAAE,KAAK,EAAE,OAAO,KAAK,CAAA;KAAE;IAI7D;;;;;;OAMG;IACG,oBAAoB,CACxB,UAAU,EAAE,aAAa,EAAE,GAC1B,OAAO,CAAC,sBAAsB,CAAC;CA+BnC"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _MultichainNetworkService_fetch;
|
|
13
|
-
import { assert } from "@metamask/superstruct";
|
|
14
|
-
import { ActiveNetworksResponseStruct, buildActiveNetworksUrl, MULTICHAIN_ACCOUNTS_CLIENT_HEADER, MULTICHAIN_ACCOUNTS_CLIENT_ID } from "../api/accounts-api.mjs";
|
|
15
|
-
/**
|
|
16
|
-
* Service responsible for fetching network activity data from the API.
|
|
17
|
-
*/
|
|
18
|
-
export class MultichainNetworkService {
|
|
19
|
-
constructor({ fetch: fetchFunction }) {
|
|
20
|
-
_MultichainNetworkService_fetch.set(this, void 0);
|
|
21
|
-
__classPrivateFieldSet(this, _MultichainNetworkService_fetch, fetchFunction, "f");
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Fetches active networks for the given account IDs.
|
|
25
|
-
*
|
|
26
|
-
* @param accountIds - Array of CAIP-10 account IDs to fetch activity for.
|
|
27
|
-
* @returns Promise resolving to the active networks response.
|
|
28
|
-
* @throws Error if the response format is invalid or the request fails.
|
|
29
|
-
*/
|
|
30
|
-
async fetchNetworkActivity(accountIds) {
|
|
31
|
-
try {
|
|
32
|
-
const url = buildActiveNetworksUrl(accountIds);
|
|
33
|
-
const response = await __classPrivateFieldGet(this, _MultichainNetworkService_fetch, "f").call(this, url.toString(), {
|
|
34
|
-
method: 'GET',
|
|
35
|
-
headers: {
|
|
36
|
-
[MULTICHAIN_ACCOUNTS_CLIENT_HEADER]: MULTICHAIN_ACCOUNTS_CLIENT_ID,
|
|
37
|
-
Accept: 'application/json',
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
42
|
-
}
|
|
43
|
-
const data = await response.json();
|
|
44
|
-
assert(data, ActiveNetworksResponseStruct);
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
if (error instanceof Error) {
|
|
49
|
-
if (error.name === 'AbortError') {
|
|
50
|
-
throw new Error('Request timeout: Failed to fetch active networks');
|
|
51
|
-
}
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
throw new Error(`Failed to fetch active networks: ${String(error)}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
_MultichainNetworkService_fetch = new WeakMap();
|
|
59
|
-
//# sourceMappingURL=MultichainNetworkService.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainNetworkService.mjs","sourceRoot":"","sources":["../../src/MultichainNetworkService/MultichainNetworkService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAG/C,OAAO,EAEL,4BAA4B,EAC5B,sBAAsB,EACtB,iCAAiC,EACjC,6BAA6B,EAC9B,gCAA4B;AAE7B;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAGnC,YAAY,EAAE,KAAK,EAAE,aAAa,EAA2B;QAFpD,kDAAqB;QAG5B,uBAAA,IAAI,mCAAU,aAAa,MAAA,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,oBAAoB,CACxB,UAA2B;QAE3B,IAAI;YACF,MAAM,GAAG,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC;YAE/C,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,uCAAO,MAAX,IAAI,EAAQ,GAAG,CAAC,QAAQ,EAAE,EAAE;gBACjD,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,CAAC,iCAAiC,CAAC,EAAE,6BAA6B;oBAClE,MAAM,EAAE,kBAAkB;iBAC3B;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;gBAChB,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;aAC3D;YAED,MAAM,IAAI,GAAY,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAE5C,MAAM,CAAC,IAAI,EAAE,4BAA4B,CAAC,CAAC;YAC3C,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,KAAK,YAAY,KAAK,EAAE;gBAC1B,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;oBAC/B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;iBACrE;gBACD,MAAM,KAAK,CAAC;aACb;YAED,MAAM,IAAI,KAAK,CAAC,oCAAoC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;SACtE;IACH,CAAC;CACF","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { CaipAccountId } from '@metamask/utils';\n\nimport {\n type ActiveNetworksResponse,\n ActiveNetworksResponseStruct,\n buildActiveNetworksUrl,\n MULTICHAIN_ACCOUNTS_CLIENT_HEADER,\n MULTICHAIN_ACCOUNTS_CLIENT_ID,\n} from '../api/accounts-api';\n\n/**\n * Service responsible for fetching network activity data from the API.\n */\nexport class MultichainNetworkService {\n readonly #fetch: typeof fetch;\n\n constructor({ fetch: fetchFunction }: { fetch: typeof fetch }) {\n this.#fetch = fetchFunction;\n }\n\n /**\n * Fetches active networks for the given account IDs.\n *\n * @param accountIds - Array of CAIP-10 account IDs to fetch activity for.\n * @returns Promise resolving to the active networks response.\n * @throws Error if the response format is invalid or the request fails.\n */\n async fetchNetworkActivity(\n accountIds: CaipAccountId[],\n ): Promise<ActiveNetworksResponse> {\n try {\n const url = buildActiveNetworksUrl(accountIds);\n\n const response = await this.#fetch(url.toString(), {\n method: 'GET',\n headers: {\n [MULTICHAIN_ACCOUNTS_CLIENT_HEADER]: MULTICHAIN_ACCOUNTS_CLIENT_ID,\n Accept: 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const data: unknown = await response.json();\n\n assert(data, ActiveNetworksResponseStruct);\n return data;\n } catch (error) {\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout: Failed to fetch active networks');\n }\n throw error;\n }\n\n throw new Error(`Failed to fetch active networks: ${String(error)}`);\n }\n }\n}\n"]}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildActiveNetworksUrl = exports.toActiveNetworksByAddress = exports.toAllowedCaipAccountIds = exports.MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = exports.MULTICHAIN_ACCOUNTS_CLIENT_ID = exports.MULTICHAIN_ACCOUNTS_CLIENT_HEADER = exports.MULTICHAIN_ACCOUNTS_BASE_URL = exports.ActiveNetworksResponseStruct = void 0;
|
|
4
|
-
const keyring_api_1 = require("@metamask/keyring-api");
|
|
5
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
6
|
-
const utils_1 = require("@metamask/utils");
|
|
7
|
-
exports.ActiveNetworksResponseStruct = (0, superstruct_1.object)({
|
|
8
|
-
activeNetworks: (0, superstruct_1.array)(utils_1.CaipAccountIdStruct),
|
|
9
|
-
});
|
|
10
|
-
/**
|
|
11
|
-
* The domain for multichain accounts API.
|
|
12
|
-
*/
|
|
13
|
-
exports.MULTICHAIN_ACCOUNTS_BASE_URL = 'https://accounts.api.cx.metamask.io';
|
|
14
|
-
/**
|
|
15
|
-
* The client header for the multichain accounts API.
|
|
16
|
-
*/
|
|
17
|
-
exports.MULTICHAIN_ACCOUNTS_CLIENT_HEADER = 'x-metamask-clientproduct';
|
|
18
|
-
/**
|
|
19
|
-
* The client ID for the multichain accounts API.
|
|
20
|
-
*/
|
|
21
|
-
exports.MULTICHAIN_ACCOUNTS_CLIENT_ID = 'metamask-multichain-network-controller';
|
|
22
|
-
/**
|
|
23
|
-
* The allowed active network scopes for the multichain network controller.
|
|
24
|
-
*/
|
|
25
|
-
exports.MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = [
|
|
26
|
-
String(keyring_api_1.BtcScope.Mainnet),
|
|
27
|
-
String(keyring_api_1.SolScope.Mainnet),
|
|
28
|
-
String(keyring_api_1.EthScope.Mainnet),
|
|
29
|
-
String(keyring_api_1.EthScope.Testnet),
|
|
30
|
-
String(keyring_api_1.EthScope.Eoa),
|
|
31
|
-
];
|
|
32
|
-
/**
|
|
33
|
-
* Converts an internal account to an array of CAIP-10 account IDs.
|
|
34
|
-
*
|
|
35
|
-
* @param account - The internal account to convert
|
|
36
|
-
* @returns The CAIP-10 account IDs
|
|
37
|
-
*/
|
|
38
|
-
function toAllowedCaipAccountIds(account) {
|
|
39
|
-
const formattedAccounts = [];
|
|
40
|
-
for (const scope of account.scopes) {
|
|
41
|
-
if (exports.MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES.includes(scope)) {
|
|
42
|
-
formattedAccounts.push(`${scope}:${account.address}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return formattedAccounts;
|
|
46
|
-
}
|
|
47
|
-
exports.toAllowedCaipAccountIds = toAllowedCaipAccountIds;
|
|
48
|
-
/**
|
|
49
|
-
* Formats the API response into our state structure.
|
|
50
|
-
* Example input: ["eip155:1:0x123...", "eip155:137:0x123...", "solana:1:0xabc..."]
|
|
51
|
-
*
|
|
52
|
-
* @param response - The raw API response
|
|
53
|
-
* @returns Formatted networks by address
|
|
54
|
-
*/
|
|
55
|
-
function toActiveNetworksByAddress(response) {
|
|
56
|
-
const networksByAddress = {};
|
|
57
|
-
response.activeNetworks.forEach((network) => {
|
|
58
|
-
const { address, chain: { namespace, reference }, } = (0, utils_1.parseCaipAccountId)(network);
|
|
59
|
-
if (!networksByAddress[address]) {
|
|
60
|
-
networksByAddress[address] = {
|
|
61
|
-
namespace,
|
|
62
|
-
activeChains: [],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
networksByAddress[address].activeChains.push(reference);
|
|
66
|
-
});
|
|
67
|
-
return networksByAddress;
|
|
68
|
-
}
|
|
69
|
-
exports.toActiveNetworksByAddress = toActiveNetworksByAddress;
|
|
70
|
-
/**
|
|
71
|
-
* Constructs the URL for the active networks API endpoint.
|
|
72
|
-
*
|
|
73
|
-
* @param accountIds - Array of account IDs
|
|
74
|
-
* @returns URL object for the API endpoint
|
|
75
|
-
*/
|
|
76
|
-
function buildActiveNetworksUrl(accountIds) {
|
|
77
|
-
const url = new URL(`${exports.MULTICHAIN_ACCOUNTS_BASE_URL}/v2/activeNetworks`);
|
|
78
|
-
url.searchParams.append('accountIds', accountIds.join(','));
|
|
79
|
-
return url;
|
|
80
|
-
}
|
|
81
|
-
exports.buildActiveNetworksUrl = buildActiveNetworksUrl;
|
|
82
|
-
//# sourceMappingURL=accounts-api.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accounts-api.cjs","sourceRoot":"","sources":["../../src/api/accounts-api.ts"],"names":[],"mappings":";;;AAAA,uDAAqE;AAErE,uDAAkE;AAClE,2CAA0E;AAQ7D,QAAA,4BAA4B,GAAG,IAAA,oBAAM,EAAC;IACjD,cAAc,EAAE,IAAA,mBAAK,EAAC,2BAAmB,CAAC;CAC3C,CAAC,CAAC;AAiBH;;GAEG;AACU,QAAA,4BAA4B,GACvC,qCAAqC,CAAC;AAExC;;GAEG;AACU,QAAA,iCAAiC,GAAG,0BAA0B,CAAC;AAE5E;;GAEG;AACU,QAAA,6BAA6B,GACxC,wCAAwC,CAAC;AAE3C;;GAEG;AACU,QAAA,wCAAwC,GAAG;IACtD,MAAM,CAAC,sBAAQ,CAAC,OAAO,CAAC;IACxB,MAAM,CAAC,sBAAQ,CAAC,OAAO,CAAC;IACxB,MAAM,CAAC,sBAAQ,CAAC,OAAO,CAAC;IACxB,MAAM,CAAC,sBAAQ,CAAC,OAAO,CAAC;IACxB,MAAM,CAAC,sBAAQ,CAAC,GAAG,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,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ternalAccount } from '@metamask/keyring-internal-api';\nimport { type Infer, array, object } from '@metamask/superstruct';\nimport { CaipAccountIdStruct, parseCaipAccountId } from '@metamask/utils';\nimport type {\n CaipAccountAddress,\n CaipAccountId,\n CaipNamespace,\n CaipReference,\n} from '@metamask/utils';\n\nexport const ActiveNetworksResponseStruct = object({\n activeNetworks: array(CaipAccountIdStruct),\n});\n\nexport type ActiveNetworksResponse = Infer<typeof ActiveNetworksResponseStruct>;\n\n/**\n * The active networks for the currently selected account.\n */\nexport type ActiveNetworksByAddress = Record<\n CaipAccountAddress,\n {\n // CAIP-2 namespace of the network.\n namespace: CaipNamespace;\n // Active chain IDs (CAIP-2 references) on that network (primarily used for EVM networks).\n activeChains: CaipReference[];\n }\n>;\n\n/**\n * The domain for multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_BASE_URL =\n 'https://accounts.api.cx.metamask.io';\n\n/**\n * The client header for the multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_CLIENT_HEADER = 'x-metamask-clientproduct';\n\n/**\n * The client ID for the multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_CLIENT_ID =\n 'metamask-multichain-network-controller';\n\n/**\n * The allowed active network scopes for the multichain network controller.\n */\nexport const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = [\n String(BtcScope.Mainnet),\n String(SolScope.Mainnet),\n String(EthScope.Mainnet),\n String(EthScope.Testnet),\n String(EthScope.Eoa),\n];\n\n/**\n * Converts an internal account to an array of CAIP-10 account IDs.\n *\n * @param account - The internal account to convert\n * @returns The CAIP-10 account IDs\n */\nexport function toAllowedCaipAccountIds(\n account: InternalAccount,\n): CaipAccountId[] {\n const formattedAccounts: CaipAccountId[] = [];\n for (const scope of account.scopes) {\n if (MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES.includes(scope)) {\n formattedAccounts.push(`${scope}:${account.address}`);\n }\n }\n\n return formattedAccounts;\n}\n\n/**\n * Formats the API response into our state structure.\n * Example input: [\"eip155:1:0x123...\", \"eip155:137:0x123...\", \"solana:1:0xabc...\"]\n *\n * @param response - The raw API response\n * @returns Formatted networks by address\n */\nexport function toActiveNetworksByAddress(\n response: ActiveNetworksResponse,\n): ActiveNetworksByAddress {\n const networksByAddress: ActiveNetworksByAddress = {};\n\n response.activeNetworks.forEach((network) => {\n const {\n address,\n chain: { namespace, reference },\n } = parseCaipAccountId(network);\n\n if (!networksByAddress[address]) {\n networksByAddress[address] = {\n namespace,\n activeChains: [],\n };\n }\n networksByAddress[address].activeChains.push(reference);\n });\n\n return networksByAddress;\n}\n\n/**\n * Constructs the URL for the active networks API endpoint.\n *\n * @param accountIds - Array of account IDs\n * @returns URL object for the API endpoint\n */\nexport function buildActiveNetworksUrl(accountIds: CaipAccountId[]): URL {\n const url = new URL(`${MULTICHAIN_ACCOUNTS_BASE_URL}/v2/activeNetworks`);\n url.searchParams.append('accountIds', accountIds.join(','));\n return url;\n}\n"]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
-
import { type Infer } from "@metamask/superstruct";
|
|
3
|
-
import type { CaipAccountAddress, CaipAccountId, CaipNamespace, CaipReference } from "@metamask/utils";
|
|
4
|
-
export declare const ActiveNetworksResponseStruct: import("@metamask/superstruct").Struct<{
|
|
5
|
-
activeNetworks: `${string}:${string}:${string}`[];
|
|
6
|
-
}, {
|
|
7
|
-
activeNetworks: import("@metamask/superstruct").Struct<`${string}:${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}:${string}`, null>>;
|
|
8
|
-
}>;
|
|
9
|
-
export type ActiveNetworksResponse = Infer<typeof ActiveNetworksResponseStruct>;
|
|
10
|
-
/**
|
|
11
|
-
* The active networks for the currently selected account.
|
|
12
|
-
*/
|
|
13
|
-
export type ActiveNetworksByAddress = Record<CaipAccountAddress, {
|
|
14
|
-
namespace: CaipNamespace;
|
|
15
|
-
activeChains: CaipReference[];
|
|
16
|
-
}>;
|
|
17
|
-
/**
|
|
18
|
-
* The domain for multichain accounts API.
|
|
19
|
-
*/
|
|
20
|
-
export declare const MULTICHAIN_ACCOUNTS_BASE_URL = "https://accounts.api.cx.metamask.io";
|
|
21
|
-
/**
|
|
22
|
-
* The client header for the multichain accounts API.
|
|
23
|
-
*/
|
|
24
|
-
export declare const MULTICHAIN_ACCOUNTS_CLIENT_HEADER = "x-metamask-clientproduct";
|
|
25
|
-
/**
|
|
26
|
-
* The client ID for the multichain accounts API.
|
|
27
|
-
*/
|
|
28
|
-
export declare const MULTICHAIN_ACCOUNTS_CLIENT_ID = "metamask-multichain-network-controller";
|
|
29
|
-
/**
|
|
30
|
-
* The allowed active network scopes for the multichain network controller.
|
|
31
|
-
*/
|
|
32
|
-
export declare const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES: string[];
|
|
33
|
-
/**
|
|
34
|
-
* Converts an internal account to an array of CAIP-10 account IDs.
|
|
35
|
-
*
|
|
36
|
-
* @param account - The internal account to convert
|
|
37
|
-
* @returns The CAIP-10 account IDs
|
|
38
|
-
*/
|
|
39
|
-
export declare function toAllowedCaipAccountIds(account: InternalAccount): CaipAccountId[];
|
|
40
|
-
/**
|
|
41
|
-
* Formats the API response into our state structure.
|
|
42
|
-
* Example input: ["eip155:1:0x123...", "eip155:137:0x123...", "solana:1:0xabc..."]
|
|
43
|
-
*
|
|
44
|
-
* @param response - The raw API response
|
|
45
|
-
* @returns Formatted networks by address
|
|
46
|
-
*/
|
|
47
|
-
export declare function toActiveNetworksByAddress(response: ActiveNetworksResponse): ActiveNetworksByAddress;
|
|
48
|
-
/**
|
|
49
|
-
* Constructs the URL for the active networks API endpoint.
|
|
50
|
-
*
|
|
51
|
-
* @param accountIds - Array of account IDs
|
|
52
|
-
* @returns URL object for the API endpoint
|
|
53
|
-
*/
|
|
54
|
-
export declare function buildActiveNetworksUrl(accountIds: CaipAccountId[]): URL;
|
|
55
|
-
//# sourceMappingURL=accounts-api.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accounts-api.d.cts","sourceRoot":"","sources":["../../src/api/accounts-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,EAAE,KAAK,KAAK,EAAiB,8BAA8B;AAElE,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,aAAa,EACd,wBAAwB;AAEzB,eAAO,MAAM,4BAA4B;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAC1C,kBAAkB,EAClB;IAEE,SAAS,EAAE,aAAa,CAAC;IAEzB,YAAY,EAAE,aAAa,EAAE,CAAC;CAC/B,CACF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,wCACF,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,iCAAiC,6BAA6B,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,6BAA6B,2CACA,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,wCAAwC,UAMpD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,eAAe,GACvB,aAAa,EAAE,CASjB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,sBAAsB,GAC/B,uBAAuB,CAmBzB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,GAAG,CAIvE"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
-
import { type Infer } from "@metamask/superstruct";
|
|
3
|
-
import type { CaipAccountAddress, CaipAccountId, CaipNamespace, CaipReference } from "@metamask/utils";
|
|
4
|
-
export declare const ActiveNetworksResponseStruct: import("@metamask/superstruct").Struct<{
|
|
5
|
-
activeNetworks: `${string}:${string}:${string}`[];
|
|
6
|
-
}, {
|
|
7
|
-
activeNetworks: import("@metamask/superstruct").Struct<`${string}:${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}:${string}`, null>>;
|
|
8
|
-
}>;
|
|
9
|
-
export type ActiveNetworksResponse = Infer<typeof ActiveNetworksResponseStruct>;
|
|
10
|
-
/**
|
|
11
|
-
* The active networks for the currently selected account.
|
|
12
|
-
*/
|
|
13
|
-
export type ActiveNetworksByAddress = Record<CaipAccountAddress, {
|
|
14
|
-
namespace: CaipNamespace;
|
|
15
|
-
activeChains: CaipReference[];
|
|
16
|
-
}>;
|
|
17
|
-
/**
|
|
18
|
-
* The domain for multichain accounts API.
|
|
19
|
-
*/
|
|
20
|
-
export declare const MULTICHAIN_ACCOUNTS_BASE_URL = "https://accounts.api.cx.metamask.io";
|
|
21
|
-
/**
|
|
22
|
-
* The client header for the multichain accounts API.
|
|
23
|
-
*/
|
|
24
|
-
export declare const MULTICHAIN_ACCOUNTS_CLIENT_HEADER = "x-metamask-clientproduct";
|
|
25
|
-
/**
|
|
26
|
-
* The client ID for the multichain accounts API.
|
|
27
|
-
*/
|
|
28
|
-
export declare const MULTICHAIN_ACCOUNTS_CLIENT_ID = "metamask-multichain-network-controller";
|
|
29
|
-
/**
|
|
30
|
-
* The allowed active network scopes for the multichain network controller.
|
|
31
|
-
*/
|
|
32
|
-
export declare const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES: string[];
|
|
33
|
-
/**
|
|
34
|
-
* Converts an internal account to an array of CAIP-10 account IDs.
|
|
35
|
-
*
|
|
36
|
-
* @param account - The internal account to convert
|
|
37
|
-
* @returns The CAIP-10 account IDs
|
|
38
|
-
*/
|
|
39
|
-
export declare function toAllowedCaipAccountIds(account: InternalAccount): CaipAccountId[];
|
|
40
|
-
/**
|
|
41
|
-
* Formats the API response into our state structure.
|
|
42
|
-
* Example input: ["eip155:1:0x123...", "eip155:137:0x123...", "solana:1:0xabc..."]
|
|
43
|
-
*
|
|
44
|
-
* @param response - The raw API response
|
|
45
|
-
* @returns Formatted networks by address
|
|
46
|
-
*/
|
|
47
|
-
export declare function toActiveNetworksByAddress(response: ActiveNetworksResponse): ActiveNetworksByAddress;
|
|
48
|
-
/**
|
|
49
|
-
* Constructs the URL for the active networks API endpoint.
|
|
50
|
-
*
|
|
51
|
-
* @param accountIds - Array of account IDs
|
|
52
|
-
* @returns URL object for the API endpoint
|
|
53
|
-
*/
|
|
54
|
-
export declare function buildActiveNetworksUrl(accountIds: CaipAccountId[]): URL;
|
|
55
|
-
//# sourceMappingURL=accounts-api.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accounts-api.d.mts","sourceRoot":"","sources":["../../src/api/accounts-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,EAAE,KAAK,KAAK,EAAiB,8BAA8B;AAElE,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,aAAa,EACd,wBAAwB;AAEzB,eAAO,MAAM,4BAA4B;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAC1C,kBAAkB,EAClB;IAEE,SAAS,EAAE,aAAa,CAAC;IAEzB,YAAY,EAAE,aAAa,EAAE,CAAC;CAC/B,CACF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,wCACF,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,iCAAiC,6BAA6B,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,6BAA6B,2CACA,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,wCAAwC,UAMpD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,eAAe,GACvB,aAAa,EAAE,CASjB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,sBAAsB,GAC/B,uBAAuB,CAmBzB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,GAAG,CAIvE"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { BtcScope, SolScope, EthScope } from "@metamask/keyring-api";
|
|
2
|
-
import { array, object } from "@metamask/superstruct";
|
|
3
|
-
import { CaipAccountIdStruct, parseCaipAccountId } from "@metamask/utils";
|
|
4
|
-
export const ActiveNetworksResponseStruct = object({
|
|
5
|
-
activeNetworks: array(CaipAccountIdStruct),
|
|
6
|
-
});
|
|
7
|
-
/**
|
|
8
|
-
* The domain for multichain accounts API.
|
|
9
|
-
*/
|
|
10
|
-
export const MULTICHAIN_ACCOUNTS_BASE_URL = 'https://accounts.api.cx.metamask.io';
|
|
11
|
-
/**
|
|
12
|
-
* The client header for the multichain accounts API.
|
|
13
|
-
*/
|
|
14
|
-
export const MULTICHAIN_ACCOUNTS_CLIENT_HEADER = 'x-metamask-clientproduct';
|
|
15
|
-
/**
|
|
16
|
-
* The client ID for the multichain accounts API.
|
|
17
|
-
*/
|
|
18
|
-
export const MULTICHAIN_ACCOUNTS_CLIENT_ID = 'metamask-multichain-network-controller';
|
|
19
|
-
/**
|
|
20
|
-
* The allowed active network scopes for the multichain network controller.
|
|
21
|
-
*/
|
|
22
|
-
export const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = [
|
|
23
|
-
String(BtcScope.Mainnet),
|
|
24
|
-
String(SolScope.Mainnet),
|
|
25
|
-
String(EthScope.Mainnet),
|
|
26
|
-
String(EthScope.Testnet),
|
|
27
|
-
String(EthScope.Eoa),
|
|
28
|
-
];
|
|
29
|
-
/**
|
|
30
|
-
* Converts an internal account to an array of CAIP-10 account IDs.
|
|
31
|
-
*
|
|
32
|
-
* @param account - The internal account to convert
|
|
33
|
-
* @returns The CAIP-10 account IDs
|
|
34
|
-
*/
|
|
35
|
-
export function toAllowedCaipAccountIds(account) {
|
|
36
|
-
const formattedAccounts = [];
|
|
37
|
-
for (const scope of account.scopes) {
|
|
38
|
-
if (MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES.includes(scope)) {
|
|
39
|
-
formattedAccounts.push(`${scope}:${account.address}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return formattedAccounts;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Formats the API response into our state structure.
|
|
46
|
-
* Example input: ["eip155:1:0x123...", "eip155:137:0x123...", "solana:1:0xabc..."]
|
|
47
|
-
*
|
|
48
|
-
* @param response - The raw API response
|
|
49
|
-
* @returns Formatted networks by address
|
|
50
|
-
*/
|
|
51
|
-
export function toActiveNetworksByAddress(response) {
|
|
52
|
-
const networksByAddress = {};
|
|
53
|
-
response.activeNetworks.forEach((network) => {
|
|
54
|
-
const { address, chain: { namespace, reference }, } = parseCaipAccountId(network);
|
|
55
|
-
if (!networksByAddress[address]) {
|
|
56
|
-
networksByAddress[address] = {
|
|
57
|
-
namespace,
|
|
58
|
-
activeChains: [],
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
networksByAddress[address].activeChains.push(reference);
|
|
62
|
-
});
|
|
63
|
-
return networksByAddress;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Constructs the URL for the active networks API endpoint.
|
|
67
|
-
*
|
|
68
|
-
* @param accountIds - Array of account IDs
|
|
69
|
-
* @returns URL object for the API endpoint
|
|
70
|
-
*/
|
|
71
|
-
export function buildActiveNetworksUrl(accountIds) {
|
|
72
|
-
const url = new URL(`${MULTICHAIN_ACCOUNTS_BASE_URL}/v2/activeNetworks`);
|
|
73
|
-
url.searchParams.append('accountIds', accountIds.join(','));
|
|
74
|
-
return url;
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=accounts-api.mjs.map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GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAAgC;IAEhC,MAAM,iBAAiB,GAA4B,EAAE,CAAC;IAEtD,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC1C,MAAM,EACJ,OAAO,EACP,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,GAChC,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE;YAC/B,iBAAiB,CAAC,OAAO,CAAC,GAAG;gBAC3B,SAAS;gBACT,YAAY,EAAE,EAAE;aACjB,CAAC;SACH;QACD,iBAAiB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAA2B;IAChE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,4BAA4B,oBAAoB,CAAC,CAAC;IACzE,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { BtcScope, SolScope, EthScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { type Infer, array, object } from '@metamask/superstruct';\nimport { CaipAccountIdStruct, parseCaipAccountId } from '@metamask/utils';\nimport type {\n CaipAccountAddress,\n CaipAccountId,\n CaipNamespace,\n CaipReference,\n} from '@metamask/utils';\n\nexport const ActiveNetworksResponseStruct = object({\n activeNetworks: array(CaipAccountIdStruct),\n});\n\nexport type ActiveNetworksResponse = Infer<typeof ActiveNetworksResponseStruct>;\n\n/**\n * The active networks for the currently selected account.\n */\nexport type ActiveNetworksByAddress = Record<\n CaipAccountAddress,\n {\n // CAIP-2 namespace of the network.\n namespace: CaipNamespace;\n // Active chain IDs (CAIP-2 references) on that network (primarily used for EVM networks).\n activeChains: CaipReference[];\n }\n>;\n\n/**\n * The domain for multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_BASE_URL =\n 'https://accounts.api.cx.metamask.io';\n\n/**\n * The client header for the multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_CLIENT_HEADER = 'x-metamask-clientproduct';\n\n/**\n * The client ID for the multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_CLIENT_ID =\n 'metamask-multichain-network-controller';\n\n/**\n * The allowed active network scopes for the multichain network controller.\n */\nexport const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = [\n String(BtcScope.Mainnet),\n String(SolScope.Mainnet),\n String(EthScope.Mainnet),\n String(EthScope.Testnet),\n String(EthScope.Eoa),\n];\n\n/**\n * Converts an internal account to an array of CAIP-10 account IDs.\n *\n * @param account - The internal account to convert\n * @returns The CAIP-10 account IDs\n */\nexport function toAllowedCaipAccountIds(\n account: InternalAccount,\n): CaipAccountId[] {\n const formattedAccounts: CaipAccountId[] = [];\n for (const scope of account.scopes) {\n if (MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES.includes(scope)) {\n formattedAccounts.push(`${scope}:${account.address}`);\n }\n }\n\n return formattedAccounts;\n}\n\n/**\n * Formats the API response into our state structure.\n * Example input: [\"eip155:1:0x123...\", \"eip155:137:0x123...\", \"solana:1:0xabc...\"]\n *\n * @param response - The raw API response\n * @returns Formatted networks by address\n */\nexport function toActiveNetworksByAddress(\n response: ActiveNetworksResponse,\n): ActiveNetworksByAddress {\n const networksByAddress: ActiveNetworksByAddress = {};\n\n response.activeNetworks.forEach((network) => {\n const {\n address,\n chain: { namespace, reference },\n } = parseCaipAccountId(network);\n\n if (!networksByAddress[address]) {\n networksByAddress[address] = {\n namespace,\n activeChains: [],\n };\n }\n networksByAddress[address].activeChains.push(reference);\n });\n\n return networksByAddress;\n}\n\n/**\n * Constructs the URL for the active networks API endpoint.\n *\n * @param accountIds - Array of account IDs\n * @returns URL object for the API endpoint\n */\nexport function buildActiveNetworksUrl(accountIds: CaipAccountId[]): URL {\n const url = new URL(`${MULTICHAIN_ACCOUNTS_BASE_URL}/v2/activeNetworks`);\n url.searchParams.append('accountIds', accountIds.join(','));\n return url;\n}\n"]}
|