@metamask/multichain-account-service 7.0.0 → 8.0.0
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 +63 -1
- package/dist/MultichainAccountGroup.cjs +4 -69
- package/dist/MultichainAccountGroup.cjs.map +1 -1
- package/dist/MultichainAccountGroup.d.cts +0 -6
- package/dist/MultichainAccountGroup.d.cts.map +1 -1
- package/dist/MultichainAccountGroup.d.mts +0 -6
- package/dist/MultichainAccountGroup.d.mts.map +1 -1
- package/dist/MultichainAccountGroup.mjs +5 -70
- package/dist/MultichainAccountGroup.mjs.map +1 -1
- package/dist/MultichainAccountService-method-action-types.cjs +7 -0
- package/dist/MultichainAccountService-method-action-types.cjs.map +1 -0
- package/dist/MultichainAccountService-method-action-types.d.cts +177 -0
- package/dist/MultichainAccountService-method-action-types.d.cts.map +1 -0
- package/dist/MultichainAccountService-method-action-types.d.mts +177 -0
- package/dist/MultichainAccountService-method-action-types.d.mts.map +1 -0
- package/dist/MultichainAccountService-method-action-types.mjs +6 -0
- package/dist/MultichainAccountService-method-action-types.mjs.map +1 -0
- package/dist/MultichainAccountService.cjs +59 -28
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +24 -2
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +24 -2
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +60 -29
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs +302 -164
- package/dist/MultichainAccountWallet.cjs.map +1 -1
- package/dist/MultichainAccountWallet.d.cts +27 -7
- package/dist/MultichainAccountWallet.d.cts.map +1 -1
- package/dist/MultichainAccountWallet.d.mts +27 -7
- package/dist/MultichainAccountWallet.d.mts.map +1 -1
- package/dist/MultichainAccountWallet.mjs +303 -165
- package/dist/MultichainAccountWallet.mjs.map +1 -1
- package/dist/analytics/perf.cjs +65 -0
- package/dist/analytics/perf.cjs.map +1 -0
- package/dist/analytics/perf.d.cts +34 -0
- package/dist/analytics/perf.d.cts.map +1 -0
- package/dist/analytics/perf.d.mts +34 -0
- package/dist/analytics/perf.d.mts.map +1 -0
- package/dist/analytics/perf.mjs +59 -0
- package/dist/analytics/perf.mjs.map +1 -0
- package/dist/analytics/timer.cjs +14 -0
- package/dist/analytics/timer.cjs.map +1 -0
- package/dist/analytics/timer.d.cts +8 -0
- package/dist/analytics/timer.d.cts.map +1 -0
- package/dist/analytics/timer.d.mts +8 -0
- package/dist/analytics/timer.d.mts.map +1 -0
- package/dist/analytics/timer.mjs +10 -0
- package/dist/analytics/timer.mjs.map +1 -0
- package/dist/analytics/traces.cjs +49 -1
- package/dist/analytics/traces.cjs.map +1 -1
- package/dist/analytics/traces.d.cts +28 -0
- package/dist/analytics/traces.d.cts.map +1 -1
- package/dist/analytics/traces.d.mts +28 -0
- package/dist/analytics/traces.d.mts.map +1 -1
- package/dist/analytics/traces.mjs +46 -0
- package/dist/analytics/traces.mjs.map +1 -1
- package/dist/errors.cjs +32 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +16 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +16 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +28 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +14 -1
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +8 -0
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.mts +8 -0
- package/dist/logger.d.mts.map +1 -1
- package/dist/logger.mjs +12 -0
- package/dist/logger.mjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.cjs +5 -6
- package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.cts +5 -4
- package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.mts +5 -4
- package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
- package/dist/providers/AccountProviderWrapper.mjs +5 -6
- package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.cjs +0 -10
- package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.cts +1 -17
- package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.mts +1 -17
- package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.mjs +0 -10
- package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
- package/dist/providers/BtcAccountProvider.cjs +15 -33
- package/dist/providers/BtcAccountProvider.cjs.map +1 -1
- package/dist/providers/BtcAccountProvider.d.cts +6 -4
- package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
- package/dist/providers/BtcAccountProvider.d.mts +6 -4
- package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
- package/dist/providers/BtcAccountProvider.mjs +16 -34
- package/dist/providers/BtcAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs +44 -3
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs +44 -3
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SnapAccountProvider.cjs +111 -21
- package/dist/providers/SnapAccountProvider.cjs.map +1 -1
- package/dist/providers/SnapAccountProvider.d.cts +33 -2
- package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
- package/dist/providers/SnapAccountProvider.d.mts +33 -2
- package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
- package/dist/providers/SnapAccountProvider.mjs +113 -23
- package/dist/providers/SnapAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs +31 -39
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +10 -3
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +10 -3
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +32 -40
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/TrxAccountProvider.cjs +15 -37
- package/dist/providers/TrxAccountProvider.cjs.map +1 -1
- package/dist/providers/TrxAccountProvider.d.cts +6 -4
- package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
- package/dist/providers/TrxAccountProvider.d.mts +6 -4
- package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
- package/dist/providers/TrxAccountProvider.mjs +16 -38
- package/dist/providers/TrxAccountProvider.mjs.map +1 -1
- package/dist/providers/index.cjs +2 -1
- package/dist/providers/index.cjs.map +1 -1
- package/dist/providers/index.d.cts +1 -1
- package/dist/providers/index.d.cts.map +1 -1
- package/dist/providers/index.d.mts +1 -1
- package/dist/providers/index.d.mts.map +1 -1
- package/dist/providers/index.mjs +1 -1
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/utils.cjs +15 -5
- package/dist/providers/utils.cjs.map +1 -1
- package/dist/providers/utils.d.cts +9 -2
- package/dist/providers/utils.d.cts.map +1 -1
- package/dist/providers/utils.d.mts +9 -2
- package/dist/providers/utils.d.mts.map +1 -1
- package/dist/providers/utils.mjs +13 -4
- package/dist/providers/utils.mjs.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.cjs +72 -8
- package/dist/snaps/SnapPlatformWatcher.cjs.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.d.cts +15 -1
- package/dist/snaps/SnapPlatformWatcher.d.cts.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.d.mts +15 -1
- package/dist/snaps/SnapPlatformWatcher.d.mts.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.mjs +72 -8
- package/dist/snaps/SnapPlatformWatcher.mjs.map +1 -1
- package/dist/tests/accounts.cjs +7 -1
- package/dist/tests/accounts.cjs.map +1 -1
- package/dist/tests/accounts.d.cts +9 -0
- package/dist/tests/accounts.d.cts.map +1 -1
- package/dist/tests/accounts.d.mts +9 -0
- package/dist/tests/accounts.d.mts.map +1 -1
- package/dist/tests/accounts.mjs +6 -0
- package/dist/tests/accounts.mjs.map +1 -1
- package/dist/tests/index.cjs.map +1 -1
- package/dist/tests/index.d.cts +1 -0
- package/dist/tests/index.d.cts.map +1 -1
- package/dist/tests/index.d.mts +1 -0
- package/dist/tests/index.d.mts.map +1 -1
- package/dist/tests/index.mjs.map +1 -1
- package/dist/tests/providers.cjs +14 -16
- package/dist/tests/providers.cjs.map +1 -1
- package/dist/tests/providers.d.cts +11 -0
- package/dist/tests/providers.d.cts.map +1 -1
- package/dist/tests/providers.d.mts +11 -0
- package/dist/tests/providers.d.mts.map +1 -1
- package/dist/tests/providers.mjs +14 -17
- package/dist/tests/providers.mjs.map +1 -1
- package/dist/tests/types.cjs +3 -0
- package/dist/tests/types.cjs.map +1 -0
- package/dist/tests/types.d.cts +7 -0
- package/dist/tests/types.d.cts.map +1 -0
- package/dist/tests/types.d.mts +7 -0
- package/dist/tests/types.d.mts.map +1 -0
- package/dist/tests/types.mjs +2 -0
- package/dist/tests/types.mjs.map +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +13 -54
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +13 -54
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +49 -5
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +32 -5
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +32 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +45 -4
- package/dist/utils.mjs.map +1 -1
- package/package.json +9 -7
- package/dist/constants/traces.cjs +0 -9
- package/dist/constants/traces.cjs.map +0 -1
- package/dist/constants/traces.d.cts +0 -5
- package/dist/constants/traces.d.cts.map +0 -1
- package/dist/constants/traces.d.mts +0 -5
- package/dist/constants/traces.d.mts.map +0 -1
- package/dist/constants/traces.mjs +0 -6
- package/dist/constants/traces.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.cjs","sourceRoot":"","sources":["../../src/tests/providers.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"providers.cjs","sourceRoot":"","sources":["../../src/tests/providers.ts"],"names":[],"mappings":";;;AACA,uDAA+E;AAM/E,sDAA0E;AAsB1E,SAAgB,uBAAuB,CACrC,WAA6B,EAAE;IAE/B,OAAO;QACL,YAAY,EAAE,QAAQ;QACtB,QAAQ,EAAE,IAAI,GAAG,EAAE;QACnB,YAAY,EAAE;YACZ,MAAM,EAAE;gBACN,sBAAQ,CAAC,MAAM;gBACf,sBAAQ,CAAC,OAAO;gBAChB,sBAAQ,CAAC,OAAO;gBAChB,sBAAQ,CAAC,MAAM;gBACf,sBAAQ,CAAC,GAAG;aACb;YACD,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE;SAC7B;QACD,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE;QACtB,aAAa,EAAE,IAAI,CAAC,EAAE,EAAE;QACxB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;QACzB,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;QACrB,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE;QACtB,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;QACzB,gBAAgB,EAAE,IAAI,CAAC,EAAE,EAAE;QAC3B,mBAAmB,EAAE,IAAI,CAAC,EAAE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EAAE,CAAC,CAAC;QACrC,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;YACrB,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC5B,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC;AAnBD,wDAmBC;AAED;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CAAC,EACrC,IAAI,GAAG,CAAC,EACR,EAAE,GACc;IAChB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;AACnE,CAAC;AALD,wDAKC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { BtcScope, EthScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport type {\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\n\nimport { AccountProviderWrapper, EvmAccountProvider } from '../providers';\nimport { GroupIndexRange } from '../utils';\n\nexport type MockAccountProvider = {\n mockAccounts: KeyringAccount[];\n accounts: Set<KeyringAccount['id']>;\n capabilities: KeyringCapabilities;\n constructor: jest.Mock;\n alignAccounts: jest.Mock;\n init: jest.Mock;\n resyncAccounts: jest.Mock;\n getAccount: jest.Mock;\n getAccounts: jest.Mock;\n createAccounts: jest.Mock;\n discoverAccounts: jest.Mock;\n isAccountCompatible: jest.Mock;\n getName: jest.Mock;\n isEnabled: boolean;\n isDisabled: jest.Mock;\n setEnabled: jest.Mock;\n};\n\nexport function makeMockAccountProvider(\n accounts: KeyringAccount[] = [],\n): MockAccountProvider {\n return {\n mockAccounts: accounts,\n accounts: new Set(),\n capabilities: {\n scopes: [\n SolScope.Devnet,\n SolScope.Testnet,\n BtcScope.Testnet,\n TrxScope.Shasta,\n EthScope.Eoa,\n ],\n bip44: { deriveIndex: true },\n },\n constructor: jest.fn(),\n alignAccounts: jest.fn(),\n init: jest.fn(),\n resyncAccounts: jest.fn(),\n getAccount: jest.fn(),\n getAccounts: jest.fn(),\n createAccounts: jest.fn(),\n discoverAccounts: jest.fn(),\n isAccountCompatible: jest.fn(),\n getName: jest.fn(),\n isDisabled: jest.fn(),\n setEnabled: jest.fn(),\n isEnabled: true,\n };\n}\n\nexport function setupBip44AccountProvider({\n name = 'Mocked Provider',\n accounts,\n mocks = makeMockAccountProvider(),\n index,\n}: {\n name?: string;\n mocks?: MockAccountProvider;\n accounts: KeyringAccount[];\n filter?: (account: KeyringAccount) => boolean;\n index?: number;\n}): MockAccountProvider {\n // You can mock this and all other mocks will re-use that list\n // of accounts.\n mocks.mockAccounts = accounts;\n mocks.accounts = new Set(accounts.map((account) => account.id));\n // Toggle enabled state only\n mocks.setEnabled.mockImplementation((enabled: boolean) => {\n mocks.isEnabled = enabled;\n });\n mocks.isDisabled.mockImplementation(() => !mocks.isEnabled);\n\n const getAccounts = (): KeyringAccount[] =>\n mocks.mockAccounts.filter((account) =>\n [...mocks.accounts].includes(account.id),\n );\n\n mocks.getName.mockImplementation(() => name);\n\n mocks.getAccounts.mockImplementation(getAccounts);\n mocks.getAccount.mockImplementation(\n (id: Bip44Account<KeyringAccount>['id']) =>\n // Assuming this never fails.\n getAccounts().find((account) => account.id === id),\n );\n mocks.createAccounts.mockResolvedValue([]);\n mocks.init.mockImplementation(\n (accountIds: Bip44Account<KeyringAccount>['id'][]) => {\n accountIds.forEach((id) => mocks.accounts.add(id));\n },\n );\n\n if (index === 0) {\n // Make the first provider to always be an `EvmAccountProvider`, since we\n // check for this pre-condition in some methods.\n Object.setPrototypeOf(mocks, EvmAccountProvider.prototype);\n }\n\n if (index !== 0) {\n Object.setPrototypeOf(mocks, AccountProviderWrapper.prototype);\n }\n\n return mocks;\n}\n\n/**\n * Helper to mock a single createAccounts call while updating the provider's\n * internal state so subsequent getAccount/getAccounts can resolve the accounts.\n *\n * @param provider - The mock provider whose createAccounts call to mock.\n * @param created - The accounts to be returned and persisted in the mock state.\n */\nexport function mockCreateAccountsOnce(\n provider: MockAccountProvider,\n created: KeyringAccount[],\n): void {\n provider.createAccounts.mockImplementationOnce(async () => {\n // Add newly created accounts to the provider's internal store\n for (const acc of created) {\n if (!provider.mockAccounts.some((a) => a.id === acc.id)) {\n provider.mockAccounts.push(acc);\n }\n }\n // Merge IDs into the visible list used by getAccounts/getAccount\n const ids = created.map((a) => a.id);\n for (const id of ids) {\n provider.accounts.add(id);\n }\n\n return created;\n });\n}\n\n/**\n * Helper to convert a group index range to an array of group indices, inclusive of the\n * start and end indices.\n *\n * @param range - The range.\n * @param range.from - The starting index of the range (inclusive).\n * @param range.to - The ending index of the range (inclusive).\n * @returns An array of group indices from `from` to `to`, inclusive.\n */\nexport function toGroupIndexRangeArray({\n from = 0,\n to,\n}: GroupIndexRange): number[] {\n return Array.from({ length: to - from + 1 }, (_, i) => from + i);\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
2
|
import type { KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
|
|
3
|
+
import { GroupIndexRange } from "../utils.cjs";
|
|
3
4
|
export type MockAccountProvider = {
|
|
4
5
|
mockAccounts: KeyringAccount[];
|
|
5
6
|
accounts: Set<KeyringAccount['id']>;
|
|
@@ -34,4 +35,14 @@ export declare function setupBip44AccountProvider({ name, accounts, mocks, index
|
|
|
34
35
|
* @param created - The accounts to be returned and persisted in the mock state.
|
|
35
36
|
*/
|
|
36
37
|
export declare function mockCreateAccountsOnce(provider: MockAccountProvider, created: KeyringAccount[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* Helper to convert a group index range to an array of group indices, inclusive of the
|
|
40
|
+
* start and end indices.
|
|
41
|
+
*
|
|
42
|
+
* @param range - The range.
|
|
43
|
+
* @param range.from - The starting index of the range (inclusive).
|
|
44
|
+
* @param range.to - The ending index of the range (inclusive).
|
|
45
|
+
* @returns An array of group indices from `from` to `to`, inclusive.
|
|
46
|
+
*/
|
|
47
|
+
export declare function toGroupIndexRangeArray({ from, to, }: GroupIndexRange): number[];
|
|
37
48
|
//# sourceMappingURL=providers.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.cts","sourceRoot":"","sources":["../../src/tests/providers.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"providers.d.cts","sourceRoot":"","sources":["../../src/tests/providers.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAG/B,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,QAAQ,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;IACpC,YAAY,EAAE,mBAAmB,CAAC;IAClC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC;IACvB,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC;IACzB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;IAChB,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC;IAC1B,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;IACtB,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC;IACvB,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC;IAC1B,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC;IAC5B,mBAAmB,EAAE,IAAI,CAAC,IAAI,CAAC;IAC/B,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;IACtB,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;CACvB,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,QAAQ,GAAE,cAAc,EAAO,GAC9B,mBAAmB,CA4BrB;AAED,wBAAgB,yBAAyB,CAAC,EACxC,IAAwB,EACxB,QAAQ,EACR,KAAiC,EACjC,KAAK,GACN,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,mBAAmB,CA0CtB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,cAAc,EAAE,GACxB,IAAI,CAgBN;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,IAAQ,EACR,EAAE,GACH,EAAE,eAAe,GAAG,MAAM,EAAE,CAE5B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
2
|
import type { KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
|
|
3
|
+
import { GroupIndexRange } from "../utils.mjs";
|
|
3
4
|
export type MockAccountProvider = {
|
|
4
5
|
mockAccounts: KeyringAccount[];
|
|
5
6
|
accounts: Set<KeyringAccount['id']>;
|
|
@@ -34,4 +35,14 @@ export declare function setupBip44AccountProvider({ name, accounts, mocks, index
|
|
|
34
35
|
* @param created - The accounts to be returned and persisted in the mock state.
|
|
35
36
|
*/
|
|
36
37
|
export declare function mockCreateAccountsOnce(provider: MockAccountProvider, created: KeyringAccount[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* Helper to convert a group index range to an array of group indices, inclusive of the
|
|
40
|
+
* start and end indices.
|
|
41
|
+
*
|
|
42
|
+
* @param range - The range.
|
|
43
|
+
* @param range.from - The starting index of the range (inclusive).
|
|
44
|
+
* @param range.to - The ending index of the range (inclusive).
|
|
45
|
+
* @returns An array of group indices from `from` to `to`, inclusive.
|
|
46
|
+
*/
|
|
47
|
+
export declare function toGroupIndexRangeArray({ from, to, }: GroupIndexRange): number[];
|
|
37
48
|
//# sourceMappingURL=providers.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.mts","sourceRoot":"","sources":["../../src/tests/providers.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"providers.d.mts","sourceRoot":"","sources":["../../src/tests/providers.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAG/B,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,QAAQ,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;IACpC,YAAY,EAAE,mBAAmB,CAAC;IAClC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC;IACvB,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC;IACzB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;IAChB,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC;IAC1B,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;IACtB,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC;IACvB,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC;IAC1B,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC;IAC5B,mBAAmB,EAAE,IAAI,CAAC,IAAI,CAAC;IAC/B,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;IACtB,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;CACvB,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,QAAQ,GAAE,cAAc,EAAO,GAC9B,mBAAmB,CA4BrB;AAED,wBAAgB,yBAAyB,CAAC,EACxC,IAAwB,EACxB,QAAQ,EACR,KAAiC,EACjC,KAAK,GACN,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,mBAAmB,CA0CtB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,cAAc,EAAE,GACxB,IAAI,CAgBN;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,IAAQ,EACR,EAAE,GACH,EAAE,eAAe,GAAG,MAAM,EAAE,CAE5B"}
|
package/dist/tests/providers.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AccountProviderWrapper, EvmAccountProvider
|
|
1
|
+
import { BtcScope, EthScope, SolScope, TrxScope } from "@metamask/keyring-api";
|
|
2
|
+
import { AccountProviderWrapper, EvmAccountProvider } from "../providers/index.mjs";
|
|
3
3
|
export function makeMockAccountProvider(accounts = []) {
|
|
4
4
|
return {
|
|
5
5
|
mockAccounts: accounts,
|
|
@@ -46,21 +46,6 @@ export function setupBip44AccountProvider({ name = 'Mocked Provider', accounts,
|
|
|
46
46
|
// Assuming this never fails.
|
|
47
47
|
getAccounts().find((account) => account.id === id));
|
|
48
48
|
mocks.createAccounts.mockResolvedValue([]);
|
|
49
|
-
mocks.alignAccounts.mockImplementation(async ({ entropySource, groupIndex, }) => {
|
|
50
|
-
if (mocks.isDisabled()) {
|
|
51
|
-
const wrapperAlign = AccountProviderWrapper.prototype.alignAccounts;
|
|
52
|
-
const ids = await wrapperAlign.call({ isEnabled: false, isDisabled: () => true }, { entropySource, groupIndex });
|
|
53
|
-
return ids;
|
|
54
|
-
}
|
|
55
|
-
const createdAccounts = await mocks.createAccounts({
|
|
56
|
-
type: AccountCreationType.Bip44DeriveIndex,
|
|
57
|
-
entropySource,
|
|
58
|
-
groupIndex,
|
|
59
|
-
});
|
|
60
|
-
const baseAlign = BaseBip44AccountProvider.prototype.alignAccounts;
|
|
61
|
-
const ids = await baseAlign.call({ createAccounts: async () => createdAccounts }, { entropySource, groupIndex });
|
|
62
|
-
return ids;
|
|
63
|
-
});
|
|
64
49
|
mocks.init.mockImplementation((accountIds) => {
|
|
65
50
|
accountIds.forEach((id) => mocks.accounts.add(id));
|
|
66
51
|
});
|
|
@@ -97,4 +82,16 @@ export function mockCreateAccountsOnce(provider, created) {
|
|
|
97
82
|
return created;
|
|
98
83
|
});
|
|
99
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Helper to convert a group index range to an array of group indices, inclusive of the
|
|
87
|
+
* start and end indices.
|
|
88
|
+
*
|
|
89
|
+
* @param range - The range.
|
|
90
|
+
* @param range.from - The starting index of the range (inclusive).
|
|
91
|
+
* @param range.to - The ending index of the range (inclusive).
|
|
92
|
+
* @returns An array of group indices from `from` to `to`, inclusive.
|
|
93
|
+
*/
|
|
94
|
+
export function toGroupIndexRangeArray({ from = 0, to, }) {
|
|
95
|
+
return Array.from({ length: to - from + 1 }, (_, i) => from + i);
|
|
96
|
+
}
|
|
100
97
|
//# sourceMappingURL=providers.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.mjs","sourceRoot":"","sources":["../../src/tests/providers.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"providers.mjs","sourceRoot":"","sources":["../../src/tests/providers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,8BAA8B;AAM/E,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,+BAAqB;AAsB1E,MAAM,UAAU,uBAAuB,CACrC,WAA6B,EAAE;IAE/B,OAAO;QACL,YAAY,EA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C,KAAK,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA6B,EAC7B,OAAyB;IAEzB,QAAQ,CAAC,cAAc,CAAC,sBAAsB,CAAC,KAAK,IAAI,EAAE;QACxD,8DAA8D;QAC9D,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;gBACxD,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QACD,iEAAiE;QACjE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACrC,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;YACrB,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC5B,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,IAAI,GAAG,CAAC,EACR,EAAE,GACc;IAChB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { BtcScope, EthScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport type {\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\n\nimport { AccountProviderWrapper, EvmAccountProvider } from '../providers';\nimport { GroupIndexRange } from '../utils';\n\nexport type MockAccountProvider = {\n mockAccounts: KeyringAccount[];\n accounts: Set<KeyringAccount['id']>;\n capabilities: KeyringCapabilities;\n constructor: jest.Mock;\n alignAccounts: jest.Mock;\n init: jest.Mock;\n resyncAccounts: jest.Mock;\n getAccount: jest.Mock;\n getAccounts: jest.Mock;\n createAccounts: jest.Mock;\n discoverAccounts: jest.Mock;\n isAccountCompatible: jest.Mock;\n getName: jest.Mock;\n isEnabled: boolean;\n isDisabled: jest.Mock;\n setEnabled: jest.Mock;\n};\n\nexport function makeMockAccountProvider(\n accounts: KeyringAccount[] = [],\n): MockAccountProvider {\n return {\n mockAccounts: accounts,\n accounts: new Set(),\n capabilities: {\n scopes: [\n SolScope.Devnet,\n SolScope.Testnet,\n BtcScope.Testnet,\n TrxScope.Shasta,\n EthScope.Eoa,\n ],\n bip44: { deriveIndex: true },\n },\n constructor: jest.fn(),\n alignAccounts: jest.fn(),\n init: jest.fn(),\n resyncAccounts: jest.fn(),\n getAccount: jest.fn(),\n getAccounts: jest.fn(),\n createAccounts: jest.fn(),\n discoverAccounts: jest.fn(),\n isAccountCompatible: jest.fn(),\n getName: jest.fn(),\n isDisabled: jest.fn(),\n setEnabled: jest.fn(),\n isEnabled: true,\n };\n}\n\nexport function setupBip44AccountProvider({\n name = 'Mocked Provider',\n accounts,\n mocks = makeMockAccountProvider(),\n index,\n}: {\n name?: string;\n mocks?: MockAccountProvider;\n accounts: KeyringAccount[];\n filter?: (account: KeyringAccount) => boolean;\n index?: number;\n}): MockAccountProvider {\n // You can mock this and all other mocks will re-use that list\n // of accounts.\n mocks.mockAccounts = accounts;\n mocks.accounts = new Set(accounts.map((account) => account.id));\n // Toggle enabled state only\n mocks.setEnabled.mockImplementation((enabled: boolean) => {\n mocks.isEnabled = enabled;\n });\n mocks.isDisabled.mockImplementation(() => !mocks.isEnabled);\n\n const getAccounts = (): KeyringAccount[] =>\n mocks.mockAccounts.filter((account) =>\n [...mocks.accounts].includes(account.id),\n );\n\n mocks.getName.mockImplementation(() => name);\n\n mocks.getAccounts.mockImplementation(getAccounts);\n mocks.getAccount.mockImplementation(\n (id: Bip44Account<KeyringAccount>['id']) =>\n // Assuming this never fails.\n getAccounts().find((account) => account.id === id),\n );\n mocks.createAccounts.mockResolvedValue([]);\n mocks.init.mockImplementation(\n (accountIds: Bip44Account<KeyringAccount>['id'][]) => {\n accountIds.forEach((id) => mocks.accounts.add(id));\n },\n );\n\n if (index === 0) {\n // Make the first provider to always be an `EvmAccountProvider`, since we\n // check for this pre-condition in some methods.\n Object.setPrototypeOf(mocks, EvmAccountProvider.prototype);\n }\n\n if (index !== 0) {\n Object.setPrototypeOf(mocks, AccountProviderWrapper.prototype);\n }\n\n return mocks;\n}\n\n/**\n * Helper to mock a single createAccounts call while updating the provider's\n * internal state so subsequent getAccount/getAccounts can resolve the accounts.\n *\n * @param provider - The mock provider whose createAccounts call to mock.\n * @param created - The accounts to be returned and persisted in the mock state.\n */\nexport function mockCreateAccountsOnce(\n provider: MockAccountProvider,\n created: KeyringAccount[],\n): void {\n provider.createAccounts.mockImplementationOnce(async () => {\n // Add newly created accounts to the provider's internal store\n for (const acc of created) {\n if (!provider.mockAccounts.some((a) => a.id === acc.id)) {\n provider.mockAccounts.push(acc);\n }\n }\n // Merge IDs into the visible list used by getAccounts/getAccount\n const ids = created.map((a) => a.id);\n for (const id of ids) {\n provider.accounts.add(id);\n }\n\n return created;\n });\n}\n\n/**\n * Helper to convert a group index range to an array of group indices, inclusive of the\n * start and end indices.\n *\n * @param range - The range.\n * @param range.from - The starting index of the range (inclusive).\n * @param range.to - The ending index of the range (inclusive).\n * @returns An array of group indices from `from` to `to`, inclusive.\n */\nexport function toGroupIndexRangeArray({\n from = 0,\n to,\n}: GroupIndexRange): number[] {\n return Array.from({ length: to - from + 1 }, (_, i) => from + i);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/tests/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * A utility type that makes all properties of a type optional, recursively.\n */\nexport type DeepPartial<Type> = Type extends string\n ? Type\n : {\n [Property in keyof Type]?: Type[Property] extends (infer Value)[]\n ? DeepPartial<Value>[]\n : Type[Property] extends readonly (infer Value)[]\n ? readonly DeepPartial<Value>[]\n : Type[Property] extends object\n ? DeepPartial<Type[Property]>\n : Type[Property];\n };\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility type that makes all properties of a type optional, recursively.
|
|
3
|
+
*/
|
|
4
|
+
export type DeepPartial<Type> = Type extends string ? Type : {
|
|
5
|
+
[Property in keyof Type]?: Type[Property] extends (infer Value)[] ? DeepPartial<Value>[] : Type[Property] extends readonly (infer Value)[] ? readonly DeepPartial<Value>[] : Type[Property] extends object ? DeepPartial<Type[Property]> : Type[Property];
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/tests/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,IAAI,IAAI,SAAS,MAAM,GAC/C,IAAI,GACJ;KACG,QAAQ,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,GAC7D,WAAW,CAAC,KAAK,CAAC,EAAE,GACpB,IAAI,CAAC,QAAQ,CAAC,SAAS,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,GAC7C,SAAS,WAAW,CAAC,KAAK,CAAC,EAAE,GAC7B,IAAI,CAAC,QAAQ,CAAC,SAAS,MAAM,GAC3B,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAC3B,IAAI,CAAC,QAAQ,CAAC;CACvB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility type that makes all properties of a type optional, recursively.
|
|
3
|
+
*/
|
|
4
|
+
export type DeepPartial<Type> = Type extends string ? Type : {
|
|
5
|
+
[Property in keyof Type]?: Type[Property] extends (infer Value)[] ? DeepPartial<Value>[] : Type[Property] extends readonly (infer Value)[] ? readonly DeepPartial<Value>[] : Type[Property] extends object ? DeepPartial<Type[Property]> : Type[Property];
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/tests/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,IAAI,IAAI,SAAS,MAAM,GAC/C,IAAI,GACJ;KACG,QAAQ,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,GAC7D,WAAW,CAAC,KAAK,CAAC,EAAE,GACpB,IAAI,CAAC,QAAQ,CAAC,SAAS,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,GAC7C,SAAS,WAAW,CAAC,KAAK,CAAC,EAAE,GAC7B,IAAI,CAAC,QAAQ,CAAC,SAAS,MAAM,GAC3B,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAC3B,IAAI,CAAC,QAAQ,CAAC;CACvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/tests/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * A utility type that makes all properties of a type optional, recursively.\n */\nexport type DeepPartial<Type> = Type extends string\n ? Type\n : {\n [Property in keyof Type]?: Type[Property] extends (infer Value)[]\n ? DeepPartial<Value>[]\n : Type[Property] extends readonly (infer Value)[]\n ? readonly DeepPartial<Value>[]\n : Type[Property] extends object\n ? DeepPartial<Type[Property]>\n : Type[Property];\n };\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Bip44Account,\n MultichainAccountGroup,\n MultichainAccountWalletId,\n MultichainAccountWalletStatus,\n} from '@metamask/account-api';\nimport type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetAccountsAction,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { KeyringAccount } from '@metamask/keyring-api';\nimport type {\n KeyringControllerAddNewKeyringAction,\n KeyringControllerCreateNewVaultAndKeychainAction,\n KeyringControllerCreateNewVaultAndRestoreAction,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerGetStateAction,\n KeyringControllerRemoveAccountAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerWithKeyringAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type {\n HandleSnapRequest as SnapControllerHandleSnapRequestAction,\n SnapControllerGetStateAction,\n SnapStateChange as SnapControllerStateChangeEvent,\n} from '@metamask/snaps-controllers';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Bip44Account,\n MultichainAccountGroup,\n MultichainAccountWalletId,\n MultichainAccountWalletStatus,\n} from '@metamask/account-api';\nimport type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetAccountsAction,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { KeyringAccount } from '@metamask/keyring-api';\nimport type {\n KeyringControllerAddNewKeyringAction,\n KeyringControllerCreateNewVaultAndKeychainAction,\n KeyringControllerCreateNewVaultAndRestoreAction,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerGetStateAction,\n KeyringControllerRemoveAccountAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerWithKeyringAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type {\n HandleSnapRequest as SnapControllerHandleSnapRequestAction,\n SnapControllerGetStateAction,\n SnapStateChange as SnapControllerStateChangeEvent,\n} from '@metamask/snaps-controllers';\n\nimport type { serviceName } from './MultichainAccountService';\nimport type { MultichainAccountServiceMethodActions } from './MultichainAccountService-method-action-types';\n\n/**\n * All actions that {@link MultichainAccountService} registers so that other\n * modules can call them.\n */\nexport type MultichainAccountServiceActions =\n MultichainAccountServiceMethodActions;\n\nexport type MultichainAccountServiceMultichainAccountGroupCreatedEvent = {\n type: `${typeof serviceName}:multichainAccountGroupCreated`;\n payload: [MultichainAccountGroup<Bip44Account<KeyringAccount>>];\n};\n\nexport type MultichainAccountServiceMultichainAccountGroupUpdatedEvent = {\n type: `${typeof serviceName}:multichainAccountGroupUpdated`;\n payload: [MultichainAccountGroup<Bip44Account<KeyringAccount>>];\n};\n\nexport type MultichainAccountServiceWalletStatusChangeEvent = {\n type: `${typeof serviceName}:walletStatusChange`;\n payload: [MultichainAccountWalletId, MultichainAccountWalletStatus];\n};\n\n/**\n * All events that {@link MultichainAccountService} publishes so that other modules\n * can subscribe to them.\n */\nexport type MultichainAccountServiceEvents =\n | MultichainAccountServiceMultichainAccountGroupCreatedEvent\n | MultichainAccountServiceMultichainAccountGroupUpdatedEvent\n | MultichainAccountServiceWalletStatusChangeEvent;\n\n/**\n * All actions registered by other modules that {@link MultichainAccountService}\n * calls.\n */\ntype AllowedActions =\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerGetAccountsAction\n | AccountsControllerGetAccountAction\n | AccountsControllerGetAccountByAddressAction\n | SnapControllerGetStateAction\n | SnapControllerHandleSnapRequestAction\n | KeyringControllerWithKeyringAction\n | KeyringControllerGetStateAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerAddNewKeyringAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | KeyringControllerCreateNewVaultAndKeychainAction\n | KeyringControllerCreateNewVaultAndRestoreAction\n | KeyringControllerRemoveAccountAction;\n\n/**\n * All events published by other modules that {@link MultichainAccountService}\n * subscribes to.\n */\ntype AllowedEvents =\n | SnapControllerStateChangeEvent\n | KeyringControllerStateChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent;\n\n/**\n * The messenger restricted to actions and events that\n * {@link MultichainAccountService} needs to access.\n */\nexport type MultichainAccountServiceMessenger = Messenger<\n 'MultichainAccountService',\n MultichainAccountServiceActions | AllowedActions,\n MultichainAccountServiceEvents | AllowedEvents\n>;\n\n/**\n * Config for the Snap platform watcher (SnapPlatformWatcher).\n */\nexport type SnapPlatformWatcherConfig = {\n /**\n * How long to wait for the Snap keyring to appear before rejecting (ms).\n */\n timeoutMs?: number;\n};\n\nexport type MultichainAccountServiceConfig = {\n trace?: TraceCallback;\n snapPlatformWatcher?: SnapPlatformWatcherConfig;\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -6,64 +6,13 @@ import type { KeyringControllerAddNewKeyringAction, KeyringControllerCreateNewVa
|
|
|
6
6
|
import type { Messenger } from "@metamask/messenger";
|
|
7
7
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
8
8
|
import type { HandleSnapRequest as SnapControllerHandleSnapRequestAction, SnapControllerGetStateAction, SnapStateChange as SnapControllerStateChangeEvent } from "@metamask/snaps-controllers";
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
type: `${typeof serviceName}:getMultichainAccountGroup`;
|
|
12
|
-
handler: MultichainAccountService['getMultichainAccountGroup'];
|
|
13
|
-
};
|
|
14
|
-
export type MultichainAccountServiceGetMultichainAccountGroupsAction = {
|
|
15
|
-
type: `${typeof serviceName}:getMultichainAccountGroups`;
|
|
16
|
-
handler: MultichainAccountService['getMultichainAccountGroups'];
|
|
17
|
-
};
|
|
18
|
-
export type MultichainAccountServiceGetMultichainAccountWalletAction = {
|
|
19
|
-
type: `${typeof serviceName}:getMultichainAccountWallet`;
|
|
20
|
-
handler: MultichainAccountService['getMultichainAccountWallet'];
|
|
21
|
-
};
|
|
22
|
-
export type MultichainAccountServiceGetMultichainAccountWalletsAction = {
|
|
23
|
-
type: `${typeof serviceName}:getMultichainAccountWallets`;
|
|
24
|
-
handler: MultichainAccountService['getMultichainAccountWallets'];
|
|
25
|
-
};
|
|
26
|
-
export type MultichainAccountServiceCreateNextMultichainAccountGroupAction = {
|
|
27
|
-
type: `${typeof serviceName}:createNextMultichainAccountGroup`;
|
|
28
|
-
handler: MultichainAccountService['createNextMultichainAccountGroup'];
|
|
29
|
-
};
|
|
30
|
-
export type MultichainAccountServiceCreateMultichainAccountGroupAction = {
|
|
31
|
-
type: `${typeof serviceName}:createMultichainAccountGroup`;
|
|
32
|
-
handler: MultichainAccountService['createMultichainAccountGroup'];
|
|
33
|
-
};
|
|
34
|
-
export type MultichainAccountServiceSetBasicFunctionalityAction = {
|
|
35
|
-
type: `${typeof serviceName}:setBasicFunctionality`;
|
|
36
|
-
handler: MultichainAccountService['setBasicFunctionality'];
|
|
37
|
-
};
|
|
38
|
-
export type MultichainAccountServiceAlignWalletAction = {
|
|
39
|
-
type: `${typeof serviceName}:alignWallet`;
|
|
40
|
-
handler: MultichainAccountService['alignWallet'];
|
|
41
|
-
};
|
|
42
|
-
export type MultichainAccountServiceAlignWalletsAction = {
|
|
43
|
-
type: `${typeof serviceName}:alignWallets`;
|
|
44
|
-
handler: MultichainAccountService['alignWallets'];
|
|
45
|
-
};
|
|
46
|
-
export type MultichainAccountServiceCreateMultichainAccountWalletAction = {
|
|
47
|
-
type: `${typeof serviceName}:createMultichainAccountWallet`;
|
|
48
|
-
handler: MultichainAccountService['createMultichainAccountWallet'];
|
|
49
|
-
};
|
|
50
|
-
export type MultichainAccountServiceResyncAccountsAction = {
|
|
51
|
-
type: `${typeof serviceName}:resyncAccounts`;
|
|
52
|
-
handler: MultichainAccountService['resyncAccounts'];
|
|
53
|
-
};
|
|
54
|
-
export type MultichainAccountServiceRemoveMultichainAccountWalletAction = {
|
|
55
|
-
type: `${typeof serviceName}:removeMultichainAccountWallet`;
|
|
56
|
-
handler: MultichainAccountService['removeMultichainAccountWallet'];
|
|
57
|
-
};
|
|
58
|
-
export type MultichainAccountServiceEnsureCanUseSnapPlatformAction = {
|
|
59
|
-
type: `${typeof serviceName}:ensureCanUseSnapPlatform`;
|
|
60
|
-
handler: MultichainAccountService['ensureCanUseSnapPlatform'];
|
|
61
|
-
};
|
|
9
|
+
import type { serviceName } from "./MultichainAccountService.cjs";
|
|
10
|
+
import type { MultichainAccountServiceMethodActions } from "./MultichainAccountService-method-action-types.cjs";
|
|
62
11
|
/**
|
|
63
12
|
* All actions that {@link MultichainAccountService} registers so that other
|
|
64
13
|
* modules can call them.
|
|
65
14
|
*/
|
|
66
|
-
export type MultichainAccountServiceActions =
|
|
15
|
+
export type MultichainAccountServiceActions = MultichainAccountServiceMethodActions;
|
|
67
16
|
export type MultichainAccountServiceMultichainAccountGroupCreatedEvent = {
|
|
68
17
|
type: `${typeof serviceName}:multichainAccountGroupCreated`;
|
|
69
18
|
payload: [MultichainAccountGroup<Bip44Account<KeyringAccount>>];
|
|
@@ -96,8 +45,18 @@ type AllowedEvents = SnapControllerStateChangeEvent | KeyringControllerStateChan
|
|
|
96
45
|
* {@link MultichainAccountService} needs to access.
|
|
97
46
|
*/
|
|
98
47
|
export type MultichainAccountServiceMessenger = Messenger<'MultichainAccountService', MultichainAccountServiceActions | AllowedActions, MultichainAccountServiceEvents | AllowedEvents>;
|
|
48
|
+
/**
|
|
49
|
+
* Config for the Snap platform watcher (SnapPlatformWatcher).
|
|
50
|
+
*/
|
|
51
|
+
export type SnapPlatformWatcherConfig = {
|
|
52
|
+
/**
|
|
53
|
+
* How long to wait for the Snap keyring to appear before rejecting (ms).
|
|
54
|
+
*/
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
};
|
|
99
57
|
export type MultichainAccountServiceConfig = {
|
|
100
58
|
trace?: TraceCallback;
|
|
59
|
+
snapPlatformWatcher?: SnapPlatformWatcherConfig;
|
|
101
60
|
};
|
|
102
61
|
export {};
|
|
103
62
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,yBAAyB,EACzB,6BAA6B,EAC9B,8BAA8B;AAC/B,OAAO,KAAK,EACV,mCAAmC,EACnC,qCAAqC,EACrC,kCAAkC,EAClC,2CAA2C,EAC3C,mCAAmC,EACnC,8CAA8C,EAC/C,sCAAsC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAC5D,OAAO,KAAK,EACV,oCAAoC,EACpC,gDAAgD,EAChD,+CAA+C,EAC/C,wCAAwC,EACxC,+BAA+B,EAC/B,oCAAoC,EACpC,iCAAiC,EACjC,kCAAkC,EACnC,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,mDAAmD,EACn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messenger } from "@metamask/messenger";
|
|
7
7
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
8
8
|
import type { HandleSnapRequest as SnapControllerHandleSnapRequestAction, SnapControllerGetStateAction, SnapStateChange as SnapControllerStateChangeEvent } from "@metamask/snaps-controllers";
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
type: `${typeof serviceName}:getMultichainAccountGroup`;
|
|
12
|
-
handler: MultichainAccountService['getMultichainAccountGroup'];
|
|
13
|
-
};
|
|
14
|
-
export type MultichainAccountServiceGetMultichainAccountGroupsAction = {
|
|
15
|
-
type: `${typeof serviceName}:getMultichainAccountGroups`;
|
|
16
|
-
handler: MultichainAccountService['getMultichainAccountGroups'];
|
|
17
|
-
};
|
|
18
|
-
export type MultichainAccountServiceGetMultichainAccountWalletAction = {
|
|
19
|
-
type: `${typeof serviceName}:getMultichainAccountWallet`;
|
|
20
|
-
handler: MultichainAccountService['getMultichainAccountWallet'];
|
|
21
|
-
};
|
|
22
|
-
export type MultichainAccountServiceGetMultichainAccountWalletsAction = {
|
|
23
|
-
type: `${typeof serviceName}:getMultichainAccountWallets`;
|
|
24
|
-
handler: MultichainAccountService['getMultichainAccountWallets'];
|
|
25
|
-
};
|
|
26
|
-
export type MultichainAccountServiceCreateNextMultichainAccountGroupAction = {
|
|
27
|
-
type: `${typeof serviceName}:createNextMultichainAccountGroup`;
|
|
28
|
-
handler: MultichainAccountService['createNextMultichainAccountGroup'];
|
|
29
|
-
};
|
|
30
|
-
export type MultichainAccountServiceCreateMultichainAccountGroupAction = {
|
|
31
|
-
type: `${typeof serviceName}:createMultichainAccountGroup`;
|
|
32
|
-
handler: MultichainAccountService['createMultichainAccountGroup'];
|
|
33
|
-
};
|
|
34
|
-
export type MultichainAccountServiceSetBasicFunctionalityAction = {
|
|
35
|
-
type: `${typeof serviceName}:setBasicFunctionality`;
|
|
36
|
-
handler: MultichainAccountService['setBasicFunctionality'];
|
|
37
|
-
};
|
|
38
|
-
export type MultichainAccountServiceAlignWalletAction = {
|
|
39
|
-
type: `${typeof serviceName}:alignWallet`;
|
|
40
|
-
handler: MultichainAccountService['alignWallet'];
|
|
41
|
-
};
|
|
42
|
-
export type MultichainAccountServiceAlignWalletsAction = {
|
|
43
|
-
type: `${typeof serviceName}:alignWallets`;
|
|
44
|
-
handler: MultichainAccountService['alignWallets'];
|
|
45
|
-
};
|
|
46
|
-
export type MultichainAccountServiceCreateMultichainAccountWalletAction = {
|
|
47
|
-
type: `${typeof serviceName}:createMultichainAccountWallet`;
|
|
48
|
-
handler: MultichainAccountService['createMultichainAccountWallet'];
|
|
49
|
-
};
|
|
50
|
-
export type MultichainAccountServiceResyncAccountsAction = {
|
|
51
|
-
type: `${typeof serviceName}:resyncAccounts`;
|
|
52
|
-
handler: MultichainAccountService['resyncAccounts'];
|
|
53
|
-
};
|
|
54
|
-
export type MultichainAccountServiceRemoveMultichainAccountWalletAction = {
|
|
55
|
-
type: `${typeof serviceName}:removeMultichainAccountWallet`;
|
|
56
|
-
handler: MultichainAccountService['removeMultichainAccountWallet'];
|
|
57
|
-
};
|
|
58
|
-
export type MultichainAccountServiceEnsureCanUseSnapPlatformAction = {
|
|
59
|
-
type: `${typeof serviceName}:ensureCanUseSnapPlatform`;
|
|
60
|
-
handler: MultichainAccountService['ensureCanUseSnapPlatform'];
|
|
61
|
-
};
|
|
9
|
+
import type { serviceName } from "./MultichainAccountService.mjs";
|
|
10
|
+
import type { MultichainAccountServiceMethodActions } from "./MultichainAccountService-method-action-types.mjs";
|
|
62
11
|
/**
|
|
63
12
|
* All actions that {@link MultichainAccountService} registers so that other
|
|
64
13
|
* modules can call them.
|
|
65
14
|
*/
|
|
66
|
-
export type MultichainAccountServiceActions =
|
|
15
|
+
export type MultichainAccountServiceActions = MultichainAccountServiceMethodActions;
|
|
67
16
|
export type MultichainAccountServiceMultichainAccountGroupCreatedEvent = {
|
|
68
17
|
type: `${typeof serviceName}:multichainAccountGroupCreated`;
|
|
69
18
|
payload: [MultichainAccountGroup<Bip44Account<KeyringAccount>>];
|
|
@@ -96,8 +45,18 @@ type AllowedEvents = SnapControllerStateChangeEvent | KeyringControllerStateChan
|
|
|
96
45
|
* {@link MultichainAccountService} needs to access.
|
|
97
46
|
*/
|
|
98
47
|
export type MultichainAccountServiceMessenger = Messenger<'MultichainAccountService', MultichainAccountServiceActions | AllowedActions, MultichainAccountServiceEvents | AllowedEvents>;
|
|
48
|
+
/**
|
|
49
|
+
* Config for the Snap platform watcher (SnapPlatformWatcher).
|
|
50
|
+
*/
|
|
51
|
+
export type SnapPlatformWatcherConfig = {
|
|
52
|
+
/**
|
|
53
|
+
* How long to wait for the Snap keyring to appear before rejecting (ms).
|
|
54
|
+
*/
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
};
|
|
99
57
|
export type MultichainAccountServiceConfig = {
|
|
100
58
|
trace?: TraceCallback;
|
|
59
|
+
snapPlatformWatcher?: SnapPlatformWatcherConfig;
|
|
101
60
|
};
|
|
102
61
|
export {};
|
|
103
62
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,yBAAyB,EACzB,6BAA6B,EAC9B,8BAA8B;AAC/B,OAAO,KAAK,EACV,mCAAmC,EACnC,qCAAqC,EACrC,kCAAkC,EAClC,2CAA2C,EAC3C,mCAAmC,EACnC,8CAA8C,EAC/C,sCAAsC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAC5D,OAAO,KAAK,EACV,oCAAoC,EACpC,gDAAgD,EAChD,+CAA+C,EAC/C,wCAAwC,EACxC,+BAA+B,EAC/B,oCAAoC,EACpC,iCAAiC,EACj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/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Bip44Account,\n MultichainAccountGroup,\n MultichainAccountWalletId,\n MultichainAccountWalletStatus,\n} from '@metamask/account-api';\nimport type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetAccountsAction,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { KeyringAccount } from '@metamask/keyring-api';\nimport type {\n KeyringControllerAddNewKeyringAction,\n KeyringControllerCreateNewVaultAndKeychainAction,\n KeyringControllerCreateNewVaultAndRestoreAction,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerGetStateAction,\n KeyringControllerRemoveAccountAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerWithKeyringAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type {\n HandleSnapRequest as SnapControllerHandleSnapRequestAction,\n SnapControllerGetStateAction,\n SnapStateChange as SnapControllerStateChangeEvent,\n} from '@metamask/snaps-controllers';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Bip44Account,\n MultichainAccountGroup,\n MultichainAccountWalletId,\n MultichainAccountWalletStatus,\n} from '@metamask/account-api';\nimport type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetAccountsAction,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { KeyringAccount } from '@metamask/keyring-api';\nimport type {\n KeyringControllerAddNewKeyringAction,\n KeyringControllerCreateNewVaultAndKeychainAction,\n KeyringControllerCreateNewVaultAndRestoreAction,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerGetStateAction,\n KeyringControllerRemoveAccountAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerWithKeyringAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type {\n HandleSnapRequest as SnapControllerHandleSnapRequestAction,\n SnapControllerGetStateAction,\n SnapStateChange as SnapControllerStateChangeEvent,\n} from '@metamask/snaps-controllers';\n\nimport type { serviceName } from './MultichainAccountService';\nimport type { MultichainAccountServiceMethodActions } from './MultichainAccountService-method-action-types';\n\n/**\n * All actions that {@link MultichainAccountService} registers so that other\n * modules can call them.\n */\nexport type MultichainAccountServiceActions =\n MultichainAccountServiceMethodActions;\n\nexport type MultichainAccountServiceMultichainAccountGroupCreatedEvent = {\n type: `${typeof serviceName}:multichainAccountGroupCreated`;\n payload: [MultichainAccountGroup<Bip44Account<KeyringAccount>>];\n};\n\nexport type MultichainAccountServiceMultichainAccountGroupUpdatedEvent = {\n type: `${typeof serviceName}:multichainAccountGroupUpdated`;\n payload: [MultichainAccountGroup<Bip44Account<KeyringAccount>>];\n};\n\nexport type MultichainAccountServiceWalletStatusChangeEvent = {\n type: `${typeof serviceName}:walletStatusChange`;\n payload: [MultichainAccountWalletId, MultichainAccountWalletStatus];\n};\n\n/**\n * All events that {@link MultichainAccountService} publishes so that other modules\n * can subscribe to them.\n */\nexport type MultichainAccountServiceEvents =\n | MultichainAccountServiceMultichainAccountGroupCreatedEvent\n | MultichainAccountServiceMultichainAccountGroupUpdatedEvent\n | MultichainAccountServiceWalletStatusChangeEvent;\n\n/**\n * All actions registered by other modules that {@link MultichainAccountService}\n * calls.\n */\ntype AllowedActions =\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerGetAccountsAction\n | AccountsControllerGetAccountAction\n | AccountsControllerGetAccountByAddressAction\n | SnapControllerGetStateAction\n | SnapControllerHandleSnapRequestAction\n | KeyringControllerWithKeyringAction\n | KeyringControllerGetStateAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerAddNewKeyringAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | KeyringControllerCreateNewVaultAndKeychainAction\n | KeyringControllerCreateNewVaultAndRestoreAction\n | KeyringControllerRemoveAccountAction;\n\n/**\n * All events published by other modules that {@link MultichainAccountService}\n * subscribes to.\n */\ntype AllowedEvents =\n | SnapControllerStateChangeEvent\n | KeyringControllerStateChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent;\n\n/**\n * The messenger restricted to actions and events that\n * {@link MultichainAccountService} needs to access.\n */\nexport type MultichainAccountServiceMessenger = Messenger<\n 'MultichainAccountService',\n MultichainAccountServiceActions | AllowedActions,\n MultichainAccountServiceEvents | AllowedEvents\n>;\n\n/**\n * Config for the Snap platform watcher (SnapPlatformWatcher).\n */\nexport type SnapPlatformWatcherConfig = {\n /**\n * How long to wait for the Snap keyring to appear before rejecting (ms).\n */\n timeoutMs?: number;\n};\n\nexport type MultichainAccountServiceConfig = {\n trace?: TraceCallback;\n snapPlatformWatcher?: SnapPlatformWatcherConfig;\n};\n"]}
|
package/dist/utils.cjs
CHANGED
|
@@ -1,22 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSentryError = void 0;
|
|
3
|
+
exports.toErrorMessage = exports.createSentryError = exports.assertGroupIndexIsValid = exports.assertGroupIndexRangeIsValid = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Asserts that a range is valid.
|
|
6
|
+
*
|
|
7
|
+
* @param range - The range to assert.
|
|
8
|
+
* @param range.from - The starting index of the range (inclusive).
|
|
9
|
+
* @param range.to - The ending index of the range (inclusive).
|
|
10
|
+
*/
|
|
11
|
+
function assertGroupIndexRangeIsValid({ from = 0, to, }) {
|
|
12
|
+
if (from < 0) {
|
|
13
|
+
throw new Error(`Bad range, from (${from}) must be >= 0`);
|
|
14
|
+
}
|
|
15
|
+
if (to < 0) {
|
|
16
|
+
throw new Error(`Bad range, to (${to}) must be >= 0`);
|
|
17
|
+
}
|
|
18
|
+
if (to < from) {
|
|
19
|
+
throw new Error(`Bad range, to (${to}) must be >= from (${from})`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.assertGroupIndexRangeIsValid = assertGroupIndexRangeIsValid;
|
|
23
|
+
/**
|
|
24
|
+
* Asserts that a group index is valid given the next available group index.
|
|
25
|
+
*
|
|
26
|
+
* @param groupIndex - The group index to assert.
|
|
27
|
+
* @param nextGroupIndex - The next available group index.
|
|
28
|
+
*/
|
|
29
|
+
function assertGroupIndexIsValid(groupIndex, nextGroupIndex) {
|
|
30
|
+
if (groupIndex > nextGroupIndex) {
|
|
31
|
+
throw new Error(`Bad group index, groupIndex (${groupIndex}) cannot be higher than the next available one (<= ${nextGroupIndex})`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.assertGroupIndexIsValid = assertGroupIndexIsValid;
|
|
4
35
|
/**
|
|
5
36
|
* Creates a Sentry error from an error message, an inner error and a context.
|
|
6
37
|
*
|
|
7
38
|
* NOTE: Sentry defaults to a depth of 3 when extracting non-native attributes.
|
|
8
39
|
* As such, the context depth shouldn't be too deep.
|
|
9
40
|
*
|
|
10
|
-
* @param
|
|
41
|
+
* @param message - The error message to create a Sentry error from.
|
|
11
42
|
* @param innerError - The inner error to create a Sentry error from.
|
|
12
43
|
* @param context - The context to add to the Sentry error.
|
|
13
44
|
* @returns A Sentry error.
|
|
14
45
|
*/
|
|
15
|
-
const createSentryError = (
|
|
16
|
-
const error = new Error(
|
|
46
|
+
const createSentryError = (message, innerError, context) => {
|
|
47
|
+
const error = new Error(message);
|
|
17
48
|
error.cause = innerError;
|
|
18
|
-
|
|
49
|
+
if (context) {
|
|
50
|
+
error.context = context;
|
|
51
|
+
}
|
|
19
52
|
return error;
|
|
20
53
|
};
|
|
21
54
|
exports.createSentryError = createSentryError;
|
|
55
|
+
/**
|
|
56
|
+
* Converts an unknown error value to a string message.
|
|
57
|
+
*
|
|
58
|
+
* @param error - The error to convert.
|
|
59
|
+
* @returns The error message if the error is an `Error` instance, otherwise
|
|
60
|
+
* the string representation of the value.
|
|
61
|
+
*/
|
|
62
|
+
function toErrorMessage(error) {
|
|
63
|
+
return error instanceof Error ? error.message : String(error);
|
|
64
|
+
}
|
|
65
|
+
exports.toErrorMessage = toErrorMessage;
|
|
22
66
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAQA;;;;;;GAMG;AACH,SAAgB,4BAA4B,CAAC,EAC3C,IAAI,GAAG,CAAC,EACR,EAAE,GACc;IAChB,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,gBAAgB,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kBAAkB,EAAE,sBAAsB,IAAI,GAAG,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAfD,oEAeC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,UAAkB,EAClB,cAAsB;IAEtB,IAAI,UAAU,GAAG,cAAc,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,gCAAgC,UAAU,sDAAsD,cAAc,GAAG,CAClH,CAAC;IACJ,CAAC;AACH,CAAC;AATD,0DASC;AAED;;;;;;;;;;GAUG;AACI,MAAM,iBAAiB,GAAG,CAC/B,OAAe,EACf,UAAiB,EACjB,OAAiC,EAC1B,EAAE;IACT,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAG9B,CAAC;IACF,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC;IACzB,IAAI,OAAO,EAAE,CAAC;QACZ,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IAC1B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B;AAEF;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAFD,wCAEC","sourcesContent":["/**\n * Range-based multichain account creations type.\n */\nexport type GroupIndexRange = {\n from?: number;\n to: number;\n};\n\n/**\n * Asserts that a range is valid.\n *\n * @param range - The range to assert.\n * @param range.from - The starting index of the range (inclusive).\n * @param range.to - The ending index of the range (inclusive).\n */\nexport function assertGroupIndexRangeIsValid({\n from = 0,\n to,\n}: GroupIndexRange): void {\n if (from < 0) {\n throw new Error(`Bad range, from (${from}) must be >= 0`);\n }\n\n if (to < 0) {\n throw new Error(`Bad range, to (${to}) must be >= 0`);\n }\n\n if (to < from) {\n throw new Error(`Bad range, to (${to}) must be >= from (${from})`);\n }\n}\n\n/**\n * Asserts that a group index is valid given the next available group index.\n *\n * @param groupIndex - The group index to assert.\n * @param nextGroupIndex - The next available group index.\n */\nexport function assertGroupIndexIsValid(\n groupIndex: number,\n nextGroupIndex: number,\n): void {\n if (groupIndex > nextGroupIndex) {\n throw new Error(\n `Bad group index, groupIndex (${groupIndex}) cannot be higher than the next available one (<= ${nextGroupIndex})`,\n );\n }\n}\n\n/**\n * Creates a Sentry error from an error message, an inner error and a context.\n *\n * NOTE: Sentry defaults to a depth of 3 when extracting non-native attributes.\n * As such, the context depth shouldn't be too deep.\n *\n * @param message - The error message to create a Sentry error from.\n * @param innerError - The inner error to create a Sentry error from.\n * @param context - The context to add to the Sentry error.\n * @returns A Sentry error.\n */\nexport const createSentryError = (\n message: string,\n innerError: Error,\n context?: Record<string, unknown>,\n): Error => {\n const error = new Error(message) as Error & {\n cause: Error;\n context: typeof context;\n };\n error.cause = innerError;\n if (context) {\n error.context = context;\n }\n return error;\n};\n\n/**\n * Converts an unknown error value to a string message.\n *\n * @param error - The error to convert.\n * @returns The error message if the error is an `Error` instance, otherwise\n * the string representation of the value.\n */\nexport function toErrorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"]}
|