@metamask-previews/assets-controllers 45.1.1-preview-e1a582c9 → 45.1.1-preview-e644b4f

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.
Files changed (57) hide show
  1. package/dist/index.cjs +1 -9
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +0 -2
  4. package/dist/index.d.cts.map +1 -1
  5. package/dist/index.d.mts +0 -2
  6. package/dist/index.d.mts.map +1 -1
  7. package/dist/index.mjs +0 -3
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +1 -5
  10. package/dist/MultichainBalancesController/BalancesTracker.cjs +0 -117
  11. package/dist/MultichainBalancesController/BalancesTracker.cjs.map +0 -1
  12. package/dist/MultichainBalancesController/BalancesTracker.d.cts +0 -54
  13. package/dist/MultichainBalancesController/BalancesTracker.d.cts.map +0 -1
  14. package/dist/MultichainBalancesController/BalancesTracker.d.mts +0 -54
  15. package/dist/MultichainBalancesController/BalancesTracker.d.mts.map +0 -1
  16. package/dist/MultichainBalancesController/BalancesTracker.mjs +0 -113
  17. package/dist/MultichainBalancesController/BalancesTracker.mjs.map +0 -1
  18. package/dist/MultichainBalancesController/MultichainBalancesController.cjs +0 -203
  19. package/dist/MultichainBalancesController/MultichainBalancesController.cjs.map +0 -1
  20. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts +0 -89
  21. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts.map +0 -1
  22. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts +0 -89
  23. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts.map +0 -1
  24. package/dist/MultichainBalancesController/MultichainBalancesController.mjs +0 -201
  25. package/dist/MultichainBalancesController/MultichainBalancesController.mjs.map +0 -1
  26. package/dist/MultichainBalancesController/Poller.cjs +0 -42
  27. package/dist/MultichainBalancesController/Poller.cjs.map +0 -1
  28. package/dist/MultichainBalancesController/Poller.d.cts +0 -7
  29. package/dist/MultichainBalancesController/Poller.d.cts.map +0 -1
  30. package/dist/MultichainBalancesController/Poller.d.mts +0 -7
  31. package/dist/MultichainBalancesController/Poller.d.mts.map +0 -1
  32. package/dist/MultichainBalancesController/Poller.mjs +0 -38
  33. package/dist/MultichainBalancesController/Poller.mjs.map +0 -1
  34. package/dist/MultichainBalancesController/constants.cjs +0 -45
  35. package/dist/MultichainBalancesController/constants.cjs.map +0 -1
  36. package/dist/MultichainBalancesController/constants.d.cts +0 -29
  37. package/dist/MultichainBalancesController/constants.d.cts.map +0 -1
  38. package/dist/MultichainBalancesController/constants.d.mts +0 -29
  39. package/dist/MultichainBalancesController/constants.d.mts.map +0 -1
  40. package/dist/MultichainBalancesController/constants.mjs +0 -43
  41. package/dist/MultichainBalancesController/constants.mjs.map +0 -1
  42. package/dist/MultichainBalancesController/index.cjs +0 -13
  43. package/dist/MultichainBalancesController/index.cjs.map +0 -1
  44. package/dist/MultichainBalancesController/index.d.cts +0 -5
  45. package/dist/MultichainBalancesController/index.d.cts.map +0 -1
  46. package/dist/MultichainBalancesController/index.d.mts +0 -5
  47. package/dist/MultichainBalancesController/index.d.mts.map +0 -1
  48. package/dist/MultichainBalancesController/index.mjs +0 -4
  49. package/dist/MultichainBalancesController/index.mjs.map +0 -1
  50. package/dist/MultichainBalancesController/utils.cjs +0 -60
  51. package/dist/MultichainBalancesController/utils.cjs.map +0 -1
  52. package/dist/MultichainBalancesController/utils.d.cts +0 -29
  53. package/dist/MultichainBalancesController/utils.d.cts.map +0 -1
  54. package/dist/MultichainBalancesController/utils.d.mts +0 -29
  55. package/dist/MultichainBalancesController/utils.d.mts.map +0 -1
  56. package/dist/MultichainBalancesController/utils.mjs +0 -55
  57. package/dist/MultichainBalancesController/utils.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"MultichainBalancesController.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/MultichainBalancesController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EACL,cAAc,EAIf,kCAAkC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AC/D,MAAM,EAAE,MAAgB;YACxB,MAAM,EAAE,UAAU;YAClB,OAAO,EAAE,WAAW,CAAC,gBAAgB;YACrC,OAAO;SACR,CAAC,CAAkB;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport {\n BaseController,\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport {\n KeyringClient,\n type Balance,\n type CaipAssetType,\n type InternalAccount,\n isEvmAccountType,\n} from '@metamask/keyring-api';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport {\n BalancesTracker,\n BALANCE_UPDATE_INTERVALS,\n NETWORK_ASSETS_MAP,\n} from '.';\nimport { getScopeForAddress } from './utils';\n\nconst controllerName = 'MultichainBalancesController';\n\n/**\n * State used by the {@link MultichainBalancesController} to cache account balances.\n */\nexport type MultichainBalancesControllerState = {\n balances: {\n [account: string]: {\n [asset: string]: {\n amount: string;\n unit: string;\n };\n };\n };\n};\n\n/**\n * Default state of the {@link MultichainBalancesController}.\n */\nexport const defaultState: MultichainBalancesControllerState = { balances: {} };\n\n/**\n * Returns the state of the {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MultichainBalancesControllerState\n >;\n\n/**\n * Updates the balances of all supported accounts in {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerUpdateBalancesAction = {\n type: `${typeof controllerName}:updateBalances`;\n handler: MultichainBalancesController['updateBalances'];\n};\n\n/**\n * Event emitted when the state of the {@link MultichainBalancesController} changes.\n */\nexport type MultichainBalancesControllerStateChange =\n ControllerStateChangeEvent<\n typeof controllerName,\n MultichainBalancesControllerState\n >;\n\n/**\n * Actions exposed by the {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerActions =\n | MultichainBalancesControllerGetStateAction\n | MultichainBalancesControllerUpdateBalancesAction;\n\n/**\n * Events emitted by {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerEvents =\n MultichainBalancesControllerStateChange;\n\n/**\n * Actions that this controller is allowed to call.\n */\nexport type AllowedActions =\n | HandleSnapRequest\n | AccountsControllerListMultichainAccountsAction;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\nexport type AllowedEvents =\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent;\n\n/**\n * Messenger type for the MultichainBalancesController.\n */\nexport type MultichainBalancesControllerMessenger =\n RestrictedControllerMessenger<\n typeof controllerName,\n MultichainBalancesControllerActions | AllowedActions,\n MultichainBalancesControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n >;\n\n/**\n * {@link multichainBalancesController}'s metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst multichainBalancesControllerMetadata = {\n balances: {\n persist: true,\n anonymous: false,\n },\n};\n\n/**\n * The MultichainBalancesController is responsible for fetching and caching account\n * balances.\n */\nexport class MultichainBalancesController extends BaseController<\n typeof controllerName,\n MultichainBalancesControllerState,\n MultichainBalancesControllerMessenger\n> {\n readonly #tracker: BalancesTracker;\n\n // As a temporary solution, we are using a map to store the assets\n // that are hardcoded in the module. In the future, this mapping\n // should be dynamic to allow a client to register and unregister assets\n readonly #networkAssetsMap: Record<string, string[]> = NETWORK_ASSETS_MAP;\n\n constructor({\n messenger,\n state,\n }: {\n messenger: MultichainBalancesControllerMessenger;\n state: MultichainBalancesControllerState;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: multichainBalancesControllerMetadata,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#tracker = new BalancesTracker(\n async (accountId: string) => await this.#updateBalance(accountId),\n );\n\n // Register all non-EVM accounts into the tracker\n for (const account of this.#listAccounts()) {\n this.#trackAccount(account);\n }\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountAdded',\n (account) => this.#handleOnAccountAdded(account),\n );\n this.messagingSystem.subscribe(\n 'AccountsController:accountRemoved',\n (account) => this.#handleOnAccountRemoved(account),\n );\n }\n\n /**\n * Starts the polling process.\n */\n start(): void {\n this.#tracker.start();\n }\n\n /**\n * Stops the polling process.\n */\n stop(): void {\n this.#tracker.stop();\n }\n\n /**\n * Tracks an account to get its balances.\n *\n * @param account - The account to track.\n */\n #trackAccount(account: InternalAccount): void {\n if (!this.#isNonEvmAccount(account)) {\n // Nothing to do here for EVM accounts\n return;\n }\n\n const updateTime =\n // @ts-expect-error - For the moment we are only tracking non-EVM accounts and this is\n // checked with the method `#isNonEvmAccount`. We can ignore this error since\n // eip155:eoa and eip155:erc4337 account type balances are not tracked here.\n BALANCE_UPDATE_INTERVALS[this.#getAccount(account.id).type];\n this.#tracker.track(account.id, updateTime);\n }\n\n /**\n * Lists the multichain accounts coming from the `AccountsController`.\n *\n * @returns A list of multichain accounts.\n */\n #listMultichainAccounts(): InternalAccount[] {\n return this.messagingSystem.call(\n 'AccountsController:listMultichainAccounts',\n );\n }\n\n /**\n * Lists the accounts that we should get balances for.\n *\n * Currently, we only get balances for non-EVM accounts.\n *\n * @returns A list of accounts that we should get balances for.\n */\n #listAccounts(): InternalAccount[] {\n const accounts = this.#listMultichainAccounts();\n\n return accounts.filter((account) => this.#isNonEvmAccount(account));\n }\n\n /**\n * Get a non-EVM account from its ID.\n *\n * @param accountId - The account ID.\n * @returns The non-EVM account.\n */\n #getAccount(accountId: string): InternalAccount {\n const account: InternalAccount | undefined =\n this.#listMultichainAccounts().find(\n (multichainAccount) => multichainAccount.id === accountId,\n );\n\n if (!account) {\n throw new Error(`Unknown account: ${accountId}`);\n }\n if (!this.#isNonEvmAccount(account)) {\n throw new Error(`Account is not a non-EVM account: ${accountId}`);\n }\n return account;\n }\n\n /**\n * Updates the balances of one account. This method doesn't return\n * anything, but it updates the state of the controller.\n *\n * @param accountId - The account ID.\n */\n async #updateBalance(accountId: string) {\n const account = this.#getAccount(accountId);\n const partialState: MultichainBalancesControllerState = { balances: {} };\n\n const scope = getScopeForAddress(account);\n const assetsList = this.#networkAssetsMap[scope];\n\n if (account.metadata.snap) {\n partialState.balances[account.id] = await this.#getBalances(\n account.id,\n account.metadata.snap.id,\n assetsList,\n );\n }\n\n this.update((state: Draft<MultichainBalancesControllerState>) => ({\n ...state,\n balances: {\n ...state.balances,\n ...partialState.balances,\n },\n }));\n }\n\n /**\n * Updates the balances of one account. This method doesn't return\n * anything, but it updates the state of the controller.\n *\n * @param accountId - The account ID.\n */\n async updateBalance(accountId: string) {\n // NOTE: No need to track the account here, since we start tracking those when\n // the \"AccountsController:accountAdded\" is fired.\n await this.#tracker.updateBalance(accountId);\n }\n\n /**\n * Updates the balances of all supported accounts. This method doesn't return\n * anything, but it updates the state of the controller.\n */\n async updateBalances() {\n await this.#tracker.updateBalances();\n }\n\n /**\n * Checks for non-EVM accounts.\n *\n * @param account - The new account to be checked.\n * @returns True if the account is a non-EVM account, false otherwise.\n */\n #isNonEvmAccount(account: InternalAccount): boolean {\n return (\n !isEvmAccountType(account.type) &&\n // Non-EVM accounts are backed by a Snap for now\n account.metadata.snap !== undefined\n );\n }\n\n /**\n * Handles changes when a new account has been added.\n *\n * @param account - The new account being added.\n */\n async #handleOnAccountAdded(account: InternalAccount) {\n this.#trackAccount(account);\n // NOTE: Unfortunately, we cannot update the balance right away here, because\n // messenger's events are running synchronously and fetching the balance is\n // asynchronous.\n // Updating the balance here would resume at some point but the event emitter\n // will not `await` this (so we have no real control \"when\" the balance will\n // really be updated), see:\n // - https://github.com/MetaMask/core/blob/v213.0.0/packages/accounts-controller/src/AccountsController.ts#L1036-L1039\n }\n\n /**\n * Handles changes when a new account has been removed.\n *\n * @param accountId - The account ID being removed.\n */\n async #handleOnAccountRemoved(accountId: string) {\n if (this.#tracker.isTracked(accountId)) {\n this.#tracker.untrack(accountId);\n }\n\n if (accountId in this.state.balances) {\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n delete state.balances[accountId];\n return state;\n });\n }\n }\n\n /**\n * Get the balances for an account.\n *\n * @param accountId - ID of the account to get balances for.\n * @param snapId - ID of the Snap which manages the account.\n * @param assetTypes - Array of asset types to get balances for.\n * @returns A map of asset types to balances.\n */\n async #getBalances(\n accountId: string,\n snapId: string,\n assetTypes: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return await this.#getClient(snapId).getAccountBalances(\n accountId,\n assetTypes,\n );\n }\n\n /**\n * Gets a `KeyringClient` for a Snap.\n *\n * @param snapId - ID of the Snap to get the client for.\n * @returns A `KeyringClient` for the Snap.\n */\n #getClient(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) =>\n (await this.messagingSystem.call('SnapController:handleRequest', {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n })) as Promise<Json>,\n });\n }\n}\n"]}
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- 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");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- 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");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _Poller_interval, _Poller_callback, _Poller_handle;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Poller = void 0;
16
- class Poller {
17
- constructor(callback, interval) {
18
- _Poller_interval.set(this, void 0);
19
- _Poller_callback.set(this, void 0);
20
- _Poller_handle.set(this, undefined);
21
- __classPrivateFieldSet(this, _Poller_interval, interval, "f");
22
- __classPrivateFieldSet(this, _Poller_callback, callback, "f");
23
- }
24
- start() {
25
- if (__classPrivateFieldGet(this, _Poller_handle, "f")) {
26
- return;
27
- }
28
- __classPrivateFieldSet(this, _Poller_handle, setInterval(() => {
29
- __classPrivateFieldGet(this, _Poller_callback, "f").call(this).catch(console.error);
30
- }, __classPrivateFieldGet(this, _Poller_interval, "f")), "f");
31
- }
32
- stop() {
33
- if (!__classPrivateFieldGet(this, _Poller_handle, "f")) {
34
- return;
35
- }
36
- clearInterval(__classPrivateFieldGet(this, _Poller_handle, "f"));
37
- __classPrivateFieldSet(this, _Poller_handle, undefined, "f");
38
- }
39
- }
40
- exports.Poller = Poller;
41
- _Poller_interval = new WeakMap(), _Poller_callback = new WeakMap(), _Poller_handle = new WeakMap();
42
- //# sourceMappingURL=Poller.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Poller.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/Poller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,MAAa,MAAM;IAOjB,YAAY,QAA6B,EAAE,QAAgB;QAN3D,mCAAkB;QAElB,mCAA+B;QAE/B,yBAAsC,SAAS,EAAC;QAG9C,uBAAA,IAAI,oBAAa,QAAQ,MAAA,CAAC;QAC1B,uBAAA,IAAI,oBAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,uBAAA,IAAI,sBAAQ,EAAE;YAChB,OAAO;SACR;QAED,uBAAA,IAAI,kBAAW,WAAW,CAAC,GAAG,EAAE;YAC9B,uBAAA,IAAI,wBAAU,MAAd,IAAI,CAAY,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC,EAAE,uBAAA,IAAI,wBAAU,CAAC,MAAA,CAAC;IACrB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,uBAAA,IAAI,sBAAQ,EAAE;YACjB,OAAO;SACR;QACD,aAAa,CAAC,uBAAA,IAAI,sBAAQ,CAAC,CAAC;QAC5B,uBAAA,IAAI,kBAAW,SAAS,MAAA,CAAC;IAC3B,CAAC;CACF;AA7BD,wBA6BC","sourcesContent":["export class Poller {\n #interval: number;\n\n #callback: () => Promise<void>;\n\n #handle: NodeJS.Timeout | undefined = undefined;\n\n constructor(callback: () => Promise<void>, interval: number) {\n this.#interval = interval;\n this.#callback = callback;\n }\n\n start() {\n if (this.#handle) {\n return;\n }\n\n this.#handle = setInterval(() => {\n this.#callback().catch(console.error);\n }, this.#interval);\n }\n\n stop() {\n if (!this.#handle) {\n return;\n }\n clearInterval(this.#handle);\n this.#handle = undefined;\n }\n}\n"]}
@@ -1,7 +0,0 @@
1
- export declare class Poller {
2
- #private;
3
- constructor(callback: () => Promise<void>, interval: number);
4
- start(): void;
5
- stop(): void;
6
- }
7
- //# sourceMappingURL=Poller.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Poller.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/Poller.ts"],"names":[],"mappings":"AAAA,qBAAa,MAAM;;gBAOL,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM;IAK3D,KAAK;IAUL,IAAI;CAOL"}
@@ -1,7 +0,0 @@
1
- export declare class Poller {
2
- #private;
3
- constructor(callback: () => Promise<void>, interval: number);
4
- start(): void;
5
- stop(): void;
6
- }
7
- //# sourceMappingURL=Poller.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Poller.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/Poller.ts"],"names":[],"mappings":"AAAA,qBAAa,MAAM;;gBAOL,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM;IAK3D,KAAK;IAUL,IAAI;CAOL"}
@@ -1,38 +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 _Poller_interval, _Poller_callback, _Poller_handle;
13
- export class Poller {
14
- constructor(callback, interval) {
15
- _Poller_interval.set(this, void 0);
16
- _Poller_callback.set(this, void 0);
17
- _Poller_handle.set(this, undefined);
18
- __classPrivateFieldSet(this, _Poller_interval, interval, "f");
19
- __classPrivateFieldSet(this, _Poller_callback, callback, "f");
20
- }
21
- start() {
22
- if (__classPrivateFieldGet(this, _Poller_handle, "f")) {
23
- return;
24
- }
25
- __classPrivateFieldSet(this, _Poller_handle, setInterval(() => {
26
- __classPrivateFieldGet(this, _Poller_callback, "f").call(this).catch(console.error);
27
- }, __classPrivateFieldGet(this, _Poller_interval, "f")), "f");
28
- }
29
- stop() {
30
- if (!__classPrivateFieldGet(this, _Poller_handle, "f")) {
31
- return;
32
- }
33
- clearInterval(__classPrivateFieldGet(this, _Poller_handle, "f"));
34
- __classPrivateFieldSet(this, _Poller_handle, undefined, "f");
35
- }
36
- }
37
- _Poller_interval = new WeakMap(), _Poller_callback = new WeakMap(), _Poller_handle = new WeakMap();
38
- //# sourceMappingURL=Poller.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Poller.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/Poller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,OAAO,MAAM;IAOjB,YAAY,QAA6B,EAAE,QAAgB;QAN3D,mCAAkB;QAElB,mCAA+B;QAE/B,yBAAsC,SAAS,EAAC;QAG9C,uBAAA,IAAI,oBAAa,QAAQ,MAAA,CAAC;QAC1B,uBAAA,IAAI,oBAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,uBAAA,IAAI,sBAAQ,EAAE;YAChB,OAAO;SACR;QAED,uBAAA,IAAI,kBAAW,WAAW,CAAC,GAAG,EAAE;YAC9B,uBAAA,IAAI,wBAAU,MAAd,IAAI,CAAY,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC,EAAE,uBAAA,IAAI,wBAAU,CAAC,MAAA,CAAC;IACrB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,uBAAA,IAAI,sBAAQ,EAAE;YACjB,OAAO;SACR;QACD,aAAa,CAAC,uBAAA,IAAI,sBAAQ,CAAC,CAAC;QAC5B,uBAAA,IAAI,kBAAW,SAAS,MAAA,CAAC;IAC3B,CAAC;CACF","sourcesContent":["export class Poller {\n #interval: number;\n\n #callback: () => Promise<void>;\n\n #handle: NodeJS.Timeout | undefined = undefined;\n\n constructor(callback: () => Promise<void>, interval: number) {\n this.#interval = interval;\n this.#callback = callback;\n }\n\n start() {\n if (this.#handle) {\n return;\n }\n\n this.#handle = setInterval(() => {\n this.#callback().catch(console.error);\n }, this.#interval);\n }\n\n stop() {\n if (!this.#handle) {\n return;\n }\n clearInterval(this.#handle);\n this.#handle = undefined;\n }\n}\n"]}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NETWORK_ASSETS_MAP = exports.MultichainNativeAssets = exports.MultichainNetworks = exports.BALANCE_UPDATE_INTERVALS = void 0;
4
- const keyring_api_1 = require("@metamask/keyring-api");
5
- const BTC_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds
6
- const SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds
7
- exports.BALANCE_UPDATE_INTERVALS = {
8
- // NOTE: We set an interval of half the average block time fot bitcoin
9
- // to mitigate when our interval is de-synchronized with the actual block time.
10
- [keyring_api_1.BtcAccountType.P2wpkh]: BTC_AVG_BLOCK_TIME / 2,
11
- [keyring_api_1.SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME,
12
- };
13
- /**
14
- * The network identifiers for supported networks in CAIP-2 format.
15
- * Note: This is a temporary workaround until we have a more robust
16
- * solution for network identifiers.
17
- */
18
- var MultichainNetworks;
19
- (function (MultichainNetworks) {
20
- MultichainNetworks["Bitcoin"] = "bip122:000000000019d6689c085ae165831e93";
21
- MultichainNetworks["BitcoinTestnet"] = "bip122:000000000933ea01ad0ee984209779ba";
22
- MultichainNetworks["Solana"] = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
23
- MultichainNetworks["SolanaDevnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
24
- MultichainNetworks["SolanaTestnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
25
- })(MultichainNetworks || (exports.MultichainNetworks = MultichainNetworks = {}));
26
- var MultichainNativeAssets;
27
- (function (MultichainNativeAssets) {
28
- MultichainNativeAssets["Bitcoin"] = "bip122:000000000019d6689c085ae165831e93/slip44:0";
29
- MultichainNativeAssets["BitcoinTestnet"] = "bip122:000000000933ea01ad0ee984209779ba/slip44:0";
30
- MultichainNativeAssets["Solana"] = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501";
31
- MultichainNativeAssets["SolanaDevnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501";
32
- MultichainNativeAssets["SolanaTestnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501";
33
- })(MultichainNativeAssets || (exports.MultichainNativeAssets = MultichainNativeAssets = {}));
34
- /**
35
- * Maps network identifiers to their corresponding native asset types.
36
- * Each network is mapped to an array containing its native asset for consistency.
37
- */
38
- exports.NETWORK_ASSETS_MAP = {
39
- [MultichainNetworks.Solana]: [MultichainNativeAssets.Solana],
40
- [MultichainNetworks.SolanaTestnet]: [MultichainNativeAssets.SolanaTestnet],
41
- [MultichainNetworks.SolanaDevnet]: [MultichainNativeAssets.SolanaDevnet],
42
- [MultichainNetworks.Bitcoin]: [MultichainNativeAssets.Bitcoin],
43
- [MultichainNetworks.BitcoinTestnet]: [MultichainNativeAssets.BitcoinTestnet],
44
- };
45
- //# sourceMappingURL=constants.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/constants.ts"],"names":[],"mappings":";;;AAAA,uDAAuE;AAEvE,MAAM,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,6BAA6B;AACxE,MAAM,qBAAqB,GAAG,GAAG,CAAC,CAAC,mBAAmB;AAEzC,QAAA,wBAAwB,GAAG;IACtC,sEAAsE;IACtE,+EAA+E;IAC/E,CAAC,4BAAc,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,CAAC;IAC/C,CAAC,4BAAc,CAAC,WAAW,CAAC,EAAE,qBAAqB;CACpD,CAAC;AAEF;;;;GAIG;AACH,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,yEAAmD,CAAA;IACnD,gFAA0D,CAAA;IAC1D,wEAAkD,CAAA;IAClD,8EAAwD,CAAA;IACxD,+EAAyD,CAAA;AAC3D,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B;AAED,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,sFAAkD,CAAA;IAClD,6FAAgE,CAAA;IAChE,uFAAkD,CAAA;IAClD,6FAA8D,CAAA;IAC9D,8FAAgE,CAAA;AAClE,CAAC,EANW,sBAAsB,sCAAtB,sBAAsB,QAMjC;AAED;;;GAGG;AACU,QAAA,kBAAkB,GAA6C;IAC1E,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC;IAC5D,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAAC,sBAAsB,CAAC,aAAa,CAAC;IAC1E,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC,sBAAsB,CAAC,YAAY,CAAC;IACxE,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC;IAC9D,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,CAAC,sBAAsB,CAAC,cAAc,CAAC;CAC7E,CAAC","sourcesContent":["import { BtcAccountType, SolAccountType } from '@metamask/keyring-api';\n\nconst BTC_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds\nconst SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds\n\nexport const BALANCE_UPDATE_INTERVALS = {\n // NOTE: We set an interval of half the average block time fot bitcoin\n // to mitigate when our interval is de-synchronized with the actual block time.\n [BtcAccountType.P2wpkh]: BTC_AVG_BLOCK_TIME / 2,\n [SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME,\n};\n\n/**\n * The network identifiers for supported networks in CAIP-2 format.\n * Note: This is a temporary workaround until we have a more robust\n * solution for network identifiers.\n */\nexport enum MultichainNetworks {\n Bitcoin = 'bip122:000000000019d6689c085ae165831e93',\n BitcoinTestnet = 'bip122:000000000933ea01ad0ee984209779ba',\n Solana = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n SolanaDevnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',\n SolanaTestnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',\n}\n\nexport enum MultichainNativeAssets {\n Bitcoin = `${MultichainNetworks.Bitcoin}/slip44:0`,\n BitcoinTestnet = `${MultichainNetworks.BitcoinTestnet}/slip44:0`,\n Solana = `${MultichainNetworks.Solana}/slip44:501`,\n SolanaDevnet = `${MultichainNetworks.SolanaDevnet}/slip44:501`,\n SolanaTestnet = `${MultichainNetworks.SolanaTestnet}/slip44:501`,\n}\n\n/**\n * Maps network identifiers to their corresponding native asset types.\n * Each network is mapped to an array containing its native asset for consistency.\n */\nexport const NETWORK_ASSETS_MAP: Record<string, MultichainNativeAssets[]> = {\n [MultichainNetworks.Solana]: [MultichainNativeAssets.Solana],\n [MultichainNetworks.SolanaTestnet]: [MultichainNativeAssets.SolanaTestnet],\n [MultichainNetworks.SolanaDevnet]: [MultichainNativeAssets.SolanaDevnet],\n [MultichainNetworks.Bitcoin]: [MultichainNativeAssets.Bitcoin],\n [MultichainNetworks.BitcoinTestnet]: [MultichainNativeAssets.BitcoinTestnet],\n};\n"]}
@@ -1,29 +0,0 @@
1
- export declare const BALANCE_UPDATE_INTERVALS: {
2
- "bip122:p2wpkh": number;
3
- "solana:data-account": number;
4
- };
5
- /**
6
- * The network identifiers for supported networks in CAIP-2 format.
7
- * Note: This is a temporary workaround until we have a more robust
8
- * solution for network identifiers.
9
- */
10
- export declare enum MultichainNetworks {
11
- Bitcoin = "bip122:000000000019d6689c085ae165831e93",
12
- BitcoinTestnet = "bip122:000000000933ea01ad0ee984209779ba",
13
- Solana = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
14
- SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
15
- SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
16
- }
17
- export declare enum MultichainNativeAssets {
18
- Bitcoin = "bip122:000000000019d6689c085ae165831e93/slip44:0",
19
- BitcoinTestnet = "bip122:000000000933ea01ad0ee984209779ba/slip44:0",
20
- Solana = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501",
21
- SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501",
22
- SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501"
23
- }
24
- /**
25
- * Maps network identifiers to their corresponding native asset types.
26
- * Each network is mapped to an array containing its native asset for consistency.
27
- */
28
- export declare const NETWORK_ASSETS_MAP: Record<string, MultichainNativeAssets[]>;
29
- //# sourceMappingURL=constants.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB;;;CAKpC,CAAC;AAEF;;;;GAIG;AACH,oBAAY,kBAAkB;IAC5B,OAAO,4CAA4C;IACnD,cAAc,4CAA4C;IAC1D,MAAM,4CAA4C;IAClD,YAAY,4CAA4C;IACxD,aAAa,4CAA4C;CAC1D;AAED,oBAAY,sBAAsB;IAChC,OAAO,qDAA2C;IAClD,cAAc,qDAAkD;IAChE,MAAM,uDAA4C;IAClD,YAAY,uDAAkD;IAC9D,aAAa,uDAAmD;CACjE;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,EAAE,CAMvE,CAAC"}
@@ -1,29 +0,0 @@
1
- export declare const BALANCE_UPDATE_INTERVALS: {
2
- "bip122:p2wpkh": number;
3
- "solana:data-account": number;
4
- };
5
- /**
6
- * The network identifiers for supported networks in CAIP-2 format.
7
- * Note: This is a temporary workaround until we have a more robust
8
- * solution for network identifiers.
9
- */
10
- export declare enum MultichainNetworks {
11
- Bitcoin = "bip122:000000000019d6689c085ae165831e93",
12
- BitcoinTestnet = "bip122:000000000933ea01ad0ee984209779ba",
13
- Solana = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
14
- SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
15
- SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
16
- }
17
- export declare enum MultichainNativeAssets {
18
- Bitcoin = "bip122:000000000019d6689c085ae165831e93/slip44:0",
19
- BitcoinTestnet = "bip122:000000000933ea01ad0ee984209779ba/slip44:0",
20
- Solana = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501",
21
- SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501",
22
- SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501"
23
- }
24
- /**
25
- * Maps network identifiers to their corresponding native asset types.
26
- * Each network is mapped to an array containing its native asset for consistency.
27
- */
28
- export declare const NETWORK_ASSETS_MAP: Record<string, MultichainNativeAssets[]>;
29
- //# sourceMappingURL=constants.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB;;;CAKpC,CAAC;AAEF;;;;GAIG;AACH,oBAAY,kBAAkB;IAC5B,OAAO,4CAA4C;IACnD,cAAc,4CAA4C;IAC1D,MAAM,4CAA4C;IAClD,YAAY,4CAA4C;IACxD,aAAa,4CAA4C;CAC1D;AAED,oBAAY,sBAAsB;IAChC,OAAO,qDAA2C;IAClD,cAAc,qDAAkD;IAChE,MAAM,uDAA4C;IAClD,YAAY,uDAAkD;IAC9D,aAAa,uDAAmD;CACjE;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,EAAE,CAMvE,CAAC"}
@@ -1,43 +0,0 @@
1
- import $metamaskkeyringapi from "@metamask/keyring-api";
2
- const { BtcAccountType, SolAccountType } = $metamaskkeyringapi;
3
- const BTC_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds
4
- const SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds
5
- export const BALANCE_UPDATE_INTERVALS = {
6
- // NOTE: We set an interval of half the average block time fot bitcoin
7
- // to mitigate when our interval is de-synchronized with the actual block time.
8
- [BtcAccountType.P2wpkh]: BTC_AVG_BLOCK_TIME / 2,
9
- [SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME,
10
- };
11
- /**
12
- * The network identifiers for supported networks in CAIP-2 format.
13
- * Note: This is a temporary workaround until we have a more robust
14
- * solution for network identifiers.
15
- */
16
- export var MultichainNetworks;
17
- (function (MultichainNetworks) {
18
- MultichainNetworks["Bitcoin"] = "bip122:000000000019d6689c085ae165831e93";
19
- MultichainNetworks["BitcoinTestnet"] = "bip122:000000000933ea01ad0ee984209779ba";
20
- MultichainNetworks["Solana"] = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
21
- MultichainNetworks["SolanaDevnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
22
- MultichainNetworks["SolanaTestnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
23
- })(MultichainNetworks || (MultichainNetworks = {}));
24
- export var MultichainNativeAssets;
25
- (function (MultichainNativeAssets) {
26
- MultichainNativeAssets["Bitcoin"] = "bip122:000000000019d6689c085ae165831e93/slip44:0";
27
- MultichainNativeAssets["BitcoinTestnet"] = "bip122:000000000933ea01ad0ee984209779ba/slip44:0";
28
- MultichainNativeAssets["Solana"] = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501";
29
- MultichainNativeAssets["SolanaDevnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501";
30
- MultichainNativeAssets["SolanaTestnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501";
31
- })(MultichainNativeAssets || (MultichainNativeAssets = {}));
32
- /**
33
- * Maps network identifiers to their corresponding native asset types.
34
- * Each network is mapped to an array containing its native asset for consistency.
35
- */
36
- export const NETWORK_ASSETS_MAP = {
37
- [MultichainNetworks.Solana]: [MultichainNativeAssets.Solana],
38
- [MultichainNetworks.SolanaTestnet]: [MultichainNativeAssets.SolanaTestnet],
39
- [MultichainNetworks.SolanaDevnet]: [MultichainNativeAssets.SolanaDevnet],
40
- [MultichainNetworks.Bitcoin]: [MultichainNativeAssets.Bitcoin],
41
- [MultichainNetworks.BitcoinTestnet]: [MultichainNativeAssets.BitcoinTestnet],
42
- };
43
- //# sourceMappingURL=constants.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/constants.ts"],"names":[],"mappings":";;AAEA,MAAM,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,6BAA6B;AACxE,MAAM,qBAAqB,GAAG,GAAG,CAAC,CAAC,mBAAmB;AAEtD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,sEAAsE;IACtE,+EAA+E;IAC/E,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,CAAC;IAC/C,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,qBAAqB;CACpD,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,yEAAmD,CAAA;IACnD,gFAA0D,CAAA;IAC1D,wEAAkD,CAAA;IAClD,8EAAwD,CAAA;IACxD,+EAAyD,CAAA;AAC3D,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B;AAED,MAAM,CAAN,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,sFAAkD,CAAA;IAClD,6FAAgE,CAAA;IAChE,uFAAkD,CAAA;IAClD,6FAA8D,CAAA;IAC9D,8FAAgE,CAAA;AAClE,CAAC,EANW,sBAAsB,KAAtB,sBAAsB,QAMjC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA6C;IAC1E,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC;IAC5D,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAAC,sBAAsB,CAAC,aAAa,CAAC;IAC1E,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC,sBAAsB,CAAC,YAAY,CAAC;IACxE,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC;IAC9D,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,CAAC,sBAAsB,CAAC,cAAc,CAAC;CAC7E,CAAC","sourcesContent":["import { BtcAccountType, SolAccountType } from '@metamask/keyring-api';\n\nconst BTC_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds\nconst SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds\n\nexport const BALANCE_UPDATE_INTERVALS = {\n // NOTE: We set an interval of half the average block time fot bitcoin\n // to mitigate when our interval is de-synchronized with the actual block time.\n [BtcAccountType.P2wpkh]: BTC_AVG_BLOCK_TIME / 2,\n [SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME,\n};\n\n/**\n * The network identifiers for supported networks in CAIP-2 format.\n * Note: This is a temporary workaround until we have a more robust\n * solution for network identifiers.\n */\nexport enum MultichainNetworks {\n Bitcoin = 'bip122:000000000019d6689c085ae165831e93',\n BitcoinTestnet = 'bip122:000000000933ea01ad0ee984209779ba',\n Solana = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n SolanaDevnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',\n SolanaTestnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',\n}\n\nexport enum MultichainNativeAssets {\n Bitcoin = `${MultichainNetworks.Bitcoin}/slip44:0`,\n BitcoinTestnet = `${MultichainNetworks.BitcoinTestnet}/slip44:0`,\n Solana = `${MultichainNetworks.Solana}/slip44:501`,\n SolanaDevnet = `${MultichainNetworks.SolanaDevnet}/slip44:501`,\n SolanaTestnet = `${MultichainNetworks.SolanaTestnet}/slip44:501`,\n}\n\n/**\n * Maps network identifiers to their corresponding native asset types.\n * Each network is mapped to an array containing its native asset for consistency.\n */\nexport const NETWORK_ASSETS_MAP: Record<string, MultichainNativeAssets[]> = {\n [MultichainNetworks.Solana]: [MultichainNativeAssets.Solana],\n [MultichainNetworks.SolanaTestnet]: [MultichainNativeAssets.SolanaTestnet],\n [MultichainNetworks.SolanaDevnet]: [MultichainNativeAssets.SolanaDevnet],\n [MultichainNetworks.Bitcoin]: [MultichainNativeAssets.Bitcoin],\n [MultichainNetworks.BitcoinTestnet]: [MultichainNativeAssets.BitcoinTestnet],\n};\n"]}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MultichainNativeAssets = exports.MultichainNetworks = exports.NETWORK_ASSETS_MAP = exports.BALANCE_UPDATE_INTERVALS = exports.MultichainBalancesController = exports.BalancesTracker = void 0;
4
- var BalancesTracker_1 = require("./BalancesTracker.cjs");
5
- Object.defineProperty(exports, "BalancesTracker", { enumerable: true, get: function () { return BalancesTracker_1.BalancesTracker; } });
6
- var MultichainBalancesController_1 = require("./MultichainBalancesController.cjs");
7
- Object.defineProperty(exports, "MultichainBalancesController", { enumerable: true, get: function () { return MultichainBalancesController_1.MultichainBalancesController; } });
8
- var constants_1 = require("./constants.cjs");
9
- Object.defineProperty(exports, "BALANCE_UPDATE_INTERVALS", { enumerable: true, get: function () { return constants_1.BALANCE_UPDATE_INTERVALS; } });
10
- Object.defineProperty(exports, "NETWORK_ASSETS_MAP", { enumerable: true, get: function () { return constants_1.NETWORK_ASSETS_MAP; } });
11
- Object.defineProperty(exports, "MultichainNetworks", { enumerable: true, get: function () { return constants_1.MultichainNetworks; } });
12
- Object.defineProperty(exports, "MultichainNativeAssets", { enumerable: true, get: function () { return constants_1.MultichainNativeAssets; } });
13
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/index.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,mFAA8E;AAArE,4IAAA,4BAA4B,OAAA;AACrC,6CAKqB;AAJnB,qHAAA,wBAAwB,OAAA;AACxB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA","sourcesContent":["export { BalancesTracker } from './BalancesTracker';\nexport { MultichainBalancesController } from './MultichainBalancesController';\nexport {\n BALANCE_UPDATE_INTERVALS,\n NETWORK_ASSETS_MAP,\n MultichainNetworks,\n MultichainNativeAssets,\n} from './constants';\nexport type {\n MultichainBalancesControllerState,\n MultichainBalancesControllerGetStateAction,\n MultichainBalancesControllerUpdateBalancesAction,\n MultichainBalancesControllerStateChange,\n MultichainBalancesControllerActions,\n MultichainBalancesControllerEvents,\n MultichainBalancesControllerMessenger,\n} from './MultichainBalancesController';\n"]}
@@ -1,5 +0,0 @@
1
- export { BalancesTracker } from "./BalancesTracker.cjs";
2
- export { MultichainBalancesController } from "./MultichainBalancesController.cjs";
3
- export { BALANCE_UPDATE_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetworks, MultichainNativeAssets, } from "./constants.cjs";
4
- export type { MultichainBalancesControllerState, MultichainBalancesControllerGetStateAction, MultichainBalancesControllerUpdateBalancesAction, MultichainBalancesControllerStateChange, MultichainBalancesControllerActions, MultichainBalancesControllerEvents, MultichainBalancesControllerMessenger, } from "./MultichainBalancesController.cjs";
5
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,OAAO,EAAE,4BAA4B,EAAE,2CAAuC;AAC9E,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,wBAAoB;AACrB,YAAY,EACV,iCAAiC,EACjC,0CAA0C,EAC1C,gDAAgD,EAChD,uCAAuC,EACvC,mCAAmC,EACnC,kCAAkC,EAClC,qCAAqC,GACtC,2CAAuC"}
@@ -1,5 +0,0 @@
1
- export { BalancesTracker } from "./BalancesTracker.mjs";
2
- export { MultichainBalancesController } from "./MultichainBalancesController.mjs";
3
- export { BALANCE_UPDATE_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetworks, MultichainNativeAssets, } from "./constants.mjs";
4
- export type { MultichainBalancesControllerState, MultichainBalancesControllerGetStateAction, MultichainBalancesControllerUpdateBalancesAction, MultichainBalancesControllerStateChange, MultichainBalancesControllerActions, MultichainBalancesControllerEvents, MultichainBalancesControllerMessenger, } from "./MultichainBalancesController.mjs";
5
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,OAAO,EAAE,4BAA4B,EAAE,2CAAuC;AAC9E,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,wBAAoB;AACrB,YAAY,EACV,iCAAiC,EACjC,0CAA0C,EAC1C,gDAAgD,EAChD,uCAAuC,EACvC,mCAAmC,EACnC,kCAAkC,EAClC,qCAAqC,GACtC,2CAAuC"}
@@ -1,4 +0,0 @@
1
- export { BalancesTracker } from "./BalancesTracker.mjs";
2
- export { MultichainBalancesController } from "./MultichainBalancesController.mjs";
3
- export { BALANCE_UPDATE_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetworks, MultichainNativeAssets } from "./constants.mjs";
4
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,OAAO,EAAE,4BAA4B,EAAE,2CAAuC;AAC9E,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACvB,wBAAoB","sourcesContent":["export { BalancesTracker } from './BalancesTracker';\nexport { MultichainBalancesController } from './MultichainBalancesController';\nexport {\n BALANCE_UPDATE_INTERVALS,\n NETWORK_ASSETS_MAP,\n MultichainNetworks,\n MultichainNativeAssets,\n} from './constants';\nexport type {\n MultichainBalancesControllerState,\n MultichainBalancesControllerGetStateAction,\n MultichainBalancesControllerUpdateBalancesAction,\n MultichainBalancesControllerStateChange,\n MultichainBalancesControllerActions,\n MultichainBalancesControllerEvents,\n MultichainBalancesControllerMessenger,\n} from './MultichainBalancesController';\n"]}
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getScopeForAddress = exports.getScopeForSolAddress = exports.getScopeForBtcAddress = void 0;
4
- const keyring_api_1 = require("@metamask/keyring-api");
5
- const bitcoin_address_validation_1 = require("bitcoin-address-validation");
6
- const constants_1 = require("./constants.cjs");
7
- /**
8
- * Gets the scope for a specific and supported Bitcoin account.
9
- * Note: This is a temporary method and will be replaced by a more robust solution
10
- * once the new `account.scopes` is available in the `@metamask/keyring-api` module.
11
- *
12
- * @param account - Bitcoin account
13
- * @returns The scope for the given account.
14
- */
15
- const getScopeForBtcAddress = (account) => {
16
- if ((0, bitcoin_address_validation_1.validate)(account.address, bitcoin_address_validation_1.Network.mainnet)) {
17
- return constants_1.MultichainNetworks.Bitcoin;
18
- }
19
- if ((0, bitcoin_address_validation_1.validate)(account.address, bitcoin_address_validation_1.Network.testnet)) {
20
- return constants_1.MultichainNetworks.BitcoinTestnet;
21
- }
22
- throw new Error(`Invalid Bitcoin address: ${account.address}`);
23
- };
24
- exports.getScopeForBtcAddress = getScopeForBtcAddress;
25
- /**
26
- * Gets the scope for a specific and supported Solana account.
27
- * Note: This is a temporary method and will be replaced by a more robust solution
28
- * once the new `account.scopes` is available in the `keyring-api`.
29
- *
30
- * @param account - Solana account
31
- * @returns The scope for the given account.
32
- */
33
- const getScopeForSolAddress = (account) => {
34
- // For Solana accounts, we know we have a `scope` on the account's `options` bag.
35
- if (!account.options.scope) {
36
- throw new Error('Solana account scope is undefined');
37
- }
38
- return account.options.scope;
39
- };
40
- exports.getScopeForSolAddress = getScopeForSolAddress;
41
- /**
42
- * Get the scope for a given address.
43
- * Note: This is a temporary method and will be replaced by a more robust solution
44
- * once the new `account.scopes` is available in the `keyring-api`.
45
- *
46
- * @param account - The account to get the scope for.
47
- * @returns The scope for the given account.
48
- */
49
- const getScopeForAddress = (account) => {
50
- switch (account.type) {
51
- case keyring_api_1.BtcAccountType.P2wpkh:
52
- return (0, exports.getScopeForBtcAddress)(account);
53
- case keyring_api_1.SolAccountType.DataAccount:
54
- return (0, exports.getScopeForSolAddress)(account);
55
- default:
56
- throw new Error(`Unsupported non-EVM account type: ${account.type}`);
57
- }
58
- };
59
- exports.getScopeForAddress = getScopeForAddress;
60
- //# sourceMappingURL=utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/utils.ts"],"names":[],"mappings":";;;AACA,uDAAuE;AACvE,2EAA+D;AAE/D,+CAAiD;AAEjD;;;;;;;GAOG;AACI,MAAM,qBAAqB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACxE,IAAI,IAAA,qCAAQ,EAAC,OAAO,CAAC,OAAO,EAAE,oCAAO,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,8BAAkB,CAAC,OAAO,CAAC;KACnC;IAED,IAAI,IAAA,qCAAQ,EAAC,OAAO,CAAC,OAAO,EAAE,oCAAO,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,8BAAkB,CAAC,cAAc,CAAC;KAC1C;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC,CAAC;AAVW,QAAA,qBAAqB,yBAUhC;AAEF;;;;;;;GAOG;AACI,MAAM,qBAAqB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACxE,iFAAiF;IACjF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAe,CAAC;AACzC,CAAC,CAAC;AANW,QAAA,qBAAqB,yBAMhC;AAEF;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACrE,QAAQ,OAAO,CAAC,IAAI,EAAE;QACpB,KAAK,4BAAc,CAAC,MAAM;YACxB,OAAO,IAAA,6BAAqB,EAAC,OAAO,CAAC,CAAC;QACxC,KAAK,4BAAc,CAAC,WAAW;YAC7B,OAAO,IAAA,6BAAqB,EAAC,OAAO,CAAC,CAAC;QACxC;YACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACxE;AACH,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-api';\nimport { BtcAccountType, SolAccountType } from '@metamask/keyring-api';\nimport { validate, Network } from 'bitcoin-address-validation';\n\nimport { MultichainNetworks } from './constants';\n\n/**\n * Gets the scope for a specific and supported Bitcoin account.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `@metamask/keyring-api` module.\n *\n * @param account - Bitcoin account\n * @returns The scope for the given account.\n */\nexport const getScopeForBtcAddress = (account: InternalAccount): string => {\n if (validate(account.address, Network.mainnet)) {\n return MultichainNetworks.Bitcoin;\n }\n\n if (validate(account.address, Network.testnet)) {\n return MultichainNetworks.BitcoinTestnet;\n }\n\n throw new Error(`Invalid Bitcoin address: ${account.address}`);\n};\n\n/**\n * Gets the scope for a specific and supported Solana account.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `keyring-api`.\n *\n * @param account - Solana account\n * @returns The scope for the given account.\n */\nexport const getScopeForSolAddress = (account: InternalAccount): string => {\n // For Solana accounts, we know we have a `scope` on the account's `options` bag.\n if (!account.options.scope) {\n throw new Error('Solana account scope is undefined');\n }\n return account.options.scope as string;\n};\n\n/**\n * Get the scope for a given address.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `keyring-api`.\n *\n * @param account - The account to get the scope for.\n * @returns The scope for the given account.\n */\nexport const getScopeForAddress = (account: InternalAccount): string => {\n switch (account.type) {\n case BtcAccountType.P2wpkh:\n return getScopeForBtcAddress(account);\n case SolAccountType.DataAccount:\n return getScopeForSolAddress(account);\n default:\n throw new Error(`Unsupported non-EVM account type: ${account.type}`);\n }\n};\n"]}
@@ -1,29 +0,0 @@
1
- import type { InternalAccount } from "@metamask/keyring-api";
2
- /**
3
- * Gets the scope for a specific and supported Bitcoin account.
4
- * Note: This is a temporary method and will be replaced by a more robust solution
5
- * once the new `account.scopes` is available in the `@metamask/keyring-api` module.
6
- *
7
- * @param account - Bitcoin account
8
- * @returns The scope for the given account.
9
- */
10
- export declare const getScopeForBtcAddress: (account: InternalAccount) => string;
11
- /**
12
- * Gets the scope for a specific and supported Solana account.
13
- * Note: This is a temporary method and will be replaced by a more robust solution
14
- * once the new `account.scopes` is available in the `keyring-api`.
15
- *
16
- * @param account - Solana account
17
- * @returns The scope for the given account.
18
- */
19
- export declare const getScopeForSolAddress: (account: InternalAccount) => string;
20
- /**
21
- * Get the scope for a given address.
22
- * Note: This is a temporary method and will be replaced by a more robust solution
23
- * once the new `account.scopes` is available in the `keyring-api`.
24
- *
25
- * @param account - The account to get the scope for.
26
- * @returns The scope for the given account.
27
- */
28
- export declare const getScopeForAddress: (account: InternalAccount) => string;
29
- //# sourceMappingURL=utils.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAM7D;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,eAAe,KAAG,MAUhE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,eAAe,KAAG,MAMhE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,YAAa,eAAe,KAAG,MAS7D,CAAC"}
@@ -1,29 +0,0 @@
1
- import type { InternalAccount } from "@metamask/keyring-api";
2
- /**
3
- * Gets the scope for a specific and supported Bitcoin account.
4
- * Note: This is a temporary method and will be replaced by a more robust solution
5
- * once the new `account.scopes` is available in the `@metamask/keyring-api` module.
6
- *
7
- * @param account - Bitcoin account
8
- * @returns The scope for the given account.
9
- */
10
- export declare const getScopeForBtcAddress: (account: InternalAccount) => string;
11
- /**
12
- * Gets the scope for a specific and supported Solana account.
13
- * Note: This is a temporary method and will be replaced by a more robust solution
14
- * once the new `account.scopes` is available in the `keyring-api`.
15
- *
16
- * @param account - Solana account
17
- * @returns The scope for the given account.
18
- */
19
- export declare const getScopeForSolAddress: (account: InternalAccount) => string;
20
- /**
21
- * Get the scope for a given address.
22
- * Note: This is a temporary method and will be replaced by a more robust solution
23
- * once the new `account.scopes` is available in the `keyring-api`.
24
- *
25
- * @param account - The account to get the scope for.
26
- * @returns The scope for the given account.
27
- */
28
- export declare const getScopeForAddress: (account: InternalAccount) => string;
29
- //# sourceMappingURL=utils.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAM7D;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,eAAe,KAAG,MAUhE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,eAAe,KAAG,MAMhE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,YAAa,eAAe,KAAG,MAS7D,CAAC"}
@@ -1,55 +0,0 @@
1
- import $metamaskkeyringapi from "@metamask/keyring-api";
2
- const { BtcAccountType, SolAccountType } = $metamaskkeyringapi;
3
- import { validate, Network } from "bitcoin-address-validation";
4
- import { MultichainNetworks } from "./constants.mjs";
5
- /**
6
- * Gets the scope for a specific and supported Bitcoin account.
7
- * Note: This is a temporary method and will be replaced by a more robust solution
8
- * once the new `account.scopes` is available in the `@metamask/keyring-api` module.
9
- *
10
- * @param account - Bitcoin account
11
- * @returns The scope for the given account.
12
- */
13
- export const getScopeForBtcAddress = (account) => {
14
- if (validate(account.address, Network.mainnet)) {
15
- return MultichainNetworks.Bitcoin;
16
- }
17
- if (validate(account.address, Network.testnet)) {
18
- return MultichainNetworks.BitcoinTestnet;
19
- }
20
- throw new Error(`Invalid Bitcoin address: ${account.address}`);
21
- };
22
- /**
23
- * Gets the scope for a specific and supported Solana account.
24
- * Note: This is a temporary method and will be replaced by a more robust solution
25
- * once the new `account.scopes` is available in the `keyring-api`.
26
- *
27
- * @param account - Solana account
28
- * @returns The scope for the given account.
29
- */
30
- export const getScopeForSolAddress = (account) => {
31
- // For Solana accounts, we know we have a `scope` on the account's `options` bag.
32
- if (!account.options.scope) {
33
- throw new Error('Solana account scope is undefined');
34
- }
35
- return account.options.scope;
36
- };
37
- /**
38
- * Get the scope for a given address.
39
- * Note: This is a temporary method and will be replaced by a more robust solution
40
- * once the new `account.scopes` is available in the `keyring-api`.
41
- *
42
- * @param account - The account to get the scope for.
43
- * @returns The scope for the given account.
44
- */
45
- export const getScopeForAddress = (account) => {
46
- switch (account.type) {
47
- case BtcAccountType.P2wpkh:
48
- return getScopeForBtcAddress(account);
49
- case SolAccountType.DataAccount:
50
- return getScopeForSolAddress(account);
51
- default:
52
- throw new Error(`Unsupported non-EVM account type: ${account.type}`);
53
- }
54
- };
55
- //# sourceMappingURL=utils.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/utils.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,mCAAmC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,wBAAoB;AAEjD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACxE,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,kBAAkB,CAAC,OAAO,CAAC;KACnC;IAED,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,kBAAkB,CAAC,cAAc,CAAC;KAC1C;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACxE,iFAAiF;IACjF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAe,CAAC;AACzC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACrE,QAAQ,OAAO,CAAC,IAAI,EAAE;QACpB,KAAK,cAAc,CAAC,MAAM;YACxB,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACxC,KAAK,cAAc,CAAC,WAAW;YAC7B,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACxC;YACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACxE;AACH,CAAC,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-api';\nimport { BtcAccountType, SolAccountType } from '@metamask/keyring-api';\nimport { validate, Network } from 'bitcoin-address-validation';\n\nimport { MultichainNetworks } from './constants';\n\n/**\n * Gets the scope for a specific and supported Bitcoin account.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `@metamask/keyring-api` module.\n *\n * @param account - Bitcoin account\n * @returns The scope for the given account.\n */\nexport const getScopeForBtcAddress = (account: InternalAccount): string => {\n if (validate(account.address, Network.mainnet)) {\n return MultichainNetworks.Bitcoin;\n }\n\n if (validate(account.address, Network.testnet)) {\n return MultichainNetworks.BitcoinTestnet;\n }\n\n throw new Error(`Invalid Bitcoin address: ${account.address}`);\n};\n\n/**\n * Gets the scope for a specific and supported Solana account.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `keyring-api`.\n *\n * @param account - Solana account\n * @returns The scope for the given account.\n */\nexport const getScopeForSolAddress = (account: InternalAccount): string => {\n // For Solana accounts, we know we have a `scope` on the account's `options` bag.\n if (!account.options.scope) {\n throw new Error('Solana account scope is undefined');\n }\n return account.options.scope as string;\n};\n\n/**\n * Get the scope for a given address.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `keyring-api`.\n *\n * @param account - The account to get the scope for.\n * @returns The scope for the given account.\n */\nexport const getScopeForAddress = (account: InternalAccount): string => {\n switch (account.type) {\n case BtcAccountType.P2wpkh:\n return getScopeForBtcAddress(account);\n case SolAccountType.DataAccount:\n return getScopeForSolAddress(account);\n default:\n throw new Error(`Unsupported non-EVM account type: ${account.type}`);\n }\n};\n"]}