@metamask-previews/multichain-account-service 0.3.0-preview-5e0fb2b → 0.3.0-preview-8755e953

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 (86) hide show
  1. package/CHANGELOG.md +1 -6
  2. package/dist/MultichainAccountGroup.cjs.map +1 -1
  3. package/dist/MultichainAccountGroup.d.cts +3 -3
  4. package/dist/MultichainAccountGroup.d.cts.map +1 -1
  5. package/dist/MultichainAccountGroup.d.mts +3 -3
  6. package/dist/MultichainAccountGroup.d.mts.map +1 -1
  7. package/dist/MultichainAccountGroup.mjs.map +1 -1
  8. package/dist/MultichainAccountService.cjs +1 -16
  9. package/dist/MultichainAccountService.cjs.map +1 -1
  10. package/dist/MultichainAccountService.d.cts +8 -21
  11. package/dist/MultichainAccountService.d.cts.map +1 -1
  12. package/dist/MultichainAccountService.d.mts +8 -21
  13. package/dist/MultichainAccountService.d.mts.map +1 -1
  14. package/dist/MultichainAccountService.mjs +1 -16
  15. package/dist/MultichainAccountService.mjs.map +1 -1
  16. package/dist/MultichainAccountWallet.cjs +13 -115
  17. package/dist/MultichainAccountWallet.cjs.map +1 -1
  18. package/dist/MultichainAccountWallet.d.cts +1 -22
  19. package/dist/MultichainAccountWallet.d.cts.map +1 -1
  20. package/dist/MultichainAccountWallet.d.mts +1 -22
  21. package/dist/MultichainAccountWallet.d.mts.map +1 -1
  22. package/dist/MultichainAccountWallet.mjs +13 -115
  23. package/dist/MultichainAccountWallet.mjs.map +1 -1
  24. package/dist/index.cjs +1 -5
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +0 -1
  27. package/dist/index.d.cts.map +1 -1
  28. package/dist/index.d.mts +0 -1
  29. package/dist/index.d.mts.map +1 -1
  30. package/dist/index.mjs +0 -1
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/providers/BaseAccountProvider.cjs +1 -30
  33. package/dist/providers/BaseAccountProvider.cjs.map +1 -1
  34. package/dist/providers/BaseAccountProvider.d.cts +5 -32
  35. package/dist/providers/BaseAccountProvider.d.cts.map +1 -1
  36. package/dist/providers/BaseAccountProvider.d.mts +5 -32
  37. package/dist/providers/BaseAccountProvider.d.mts.map +1 -1
  38. package/dist/providers/BaseAccountProvider.mjs +0 -27
  39. package/dist/providers/BaseAccountProvider.mjs.map +1 -1
  40. package/dist/providers/EvmAccountProvider.cjs +0 -35
  41. package/dist/providers/EvmAccountProvider.cjs.map +1 -1
  42. package/dist/providers/EvmAccountProvider.d.cts +0 -66
  43. package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
  44. package/dist/providers/EvmAccountProvider.d.mts +0 -66
  45. package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
  46. package/dist/providers/EvmAccountProvider.mjs +1 -36
  47. package/dist/providers/EvmAccountProvider.mjs.map +1 -1
  48. package/dist/providers/SolAccountProvider.cjs +1 -31
  49. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  50. package/dist/providers/SolAccountProvider.d.cts +3 -14
  51. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  52. package/dist/providers/SolAccountProvider.d.mts +3 -14
  53. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  54. package/dist/providers/SolAccountProvider.mjs +3 -33
  55. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  56. package/dist/tests/accounts.cjs +0 -9
  57. package/dist/tests/accounts.cjs.map +1 -1
  58. package/dist/tests/accounts.d.cts +55 -27
  59. package/dist/tests/accounts.d.cts.map +1 -1
  60. package/dist/tests/accounts.d.mts +55 -27
  61. package/dist/tests/accounts.d.mts.map +1 -1
  62. package/dist/tests/accounts.mjs +0 -9
  63. package/dist/tests/accounts.mjs.map +1 -1
  64. package/dist/types.cjs.map +1 -1
  65. package/dist/types.d.cts +1 -5
  66. package/dist/types.d.cts.map +1 -1
  67. package/dist/types.d.mts +1 -5
  68. package/dist/types.d.mts.map +1 -1
  69. package/dist/types.mjs.map +1 -1
  70. package/package.json +4 -6
  71. package/dist/providers/SnapAccountProvider.cjs +0 -29
  72. package/dist/providers/SnapAccountProvider.cjs.map +0 -1
  73. package/dist/providers/SnapAccountProvider.d.cts +0 -22
  74. package/dist/providers/SnapAccountProvider.d.cts.map +0 -1
  75. package/dist/providers/SnapAccountProvider.d.mts +0 -22
  76. package/dist/providers/SnapAccountProvider.d.mts.map +0 -1
  77. package/dist/providers/SnapAccountProvider.mjs +0 -25
  78. package/dist/providers/SnapAccountProvider.mjs.map +0 -1
  79. package/dist/providers/index.cjs +0 -22
  80. package/dist/providers/index.cjs.map +0 -1
  81. package/dist/providers/index.d.cts +0 -5
  82. package/dist/providers/index.d.cts.map +0 -1
  83. package/dist/providers/index.d.mts +0 -5
  84. package/dist/providers/index.d.mts.map +0 -1
  85. package/dist/providers/index.mjs +0 -6
  86. package/dist/providers/index.mjs.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  export type { MultichainAccountServiceActions, MultichainAccountServiceEvents, MultichainAccountServiceMessenger, MultichainAccountServiceGetMultichainAccountGroupAction, MultichainAccountServiceGetMultichainAccountWalletAction, MultichainAccountServiceGetMultichainAccountWalletsAction, MultichainAccountServiceGetMultichainAccountGroupsAction, } from "./types.mjs";
2
- export { assertIsBip44Account, BaseAccountProvider, SnapAccountProvider, } from "./providers/index.mjs";
3
2
  export { MultichainAccountWallet } from "./MultichainAccountWallet.mjs";
4
3
  export { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
5
4
  export { MultichainAccountService } from "./MultichainAccountService.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,uDAAuD,EACvD,wDAAwD,EACxD,yDAAyD,EACzD,wDAAwD,GACzD,oBAAgB;AACjB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,8BAAoB;AACrB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,uDAAuD,EACvD,wDAAwD,EACxD,yDAAyD,EACzD,wDAAwD,GACzD,oBAAgB;AACjB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- export { assertIsBip44Account, BaseAccountProvider, SnapAccountProvider } from "./providers/index.mjs";
2
1
  export { MultichainAccountWallet } from "./MultichainAccountWallet.mjs";
3
2
  export { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
4
3
  export { MultichainAccountService } from "./MultichainAccountService.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACpB,8BAAoB;AACrB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC","sourcesContent":["export type {\n MultichainAccountServiceActions,\n MultichainAccountServiceEvents,\n MultichainAccountServiceMessenger,\n MultichainAccountServiceGetMultichainAccountGroupAction,\n MultichainAccountServiceGetMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountWalletsAction,\n MultichainAccountServiceGetMultichainAccountGroupsAction,\n} from './types';\nexport {\n assertIsBip44Account,\n BaseAccountProvider,\n SnapAccountProvider,\n} from './providers';\nexport { MultichainAccountWallet } from './MultichainAccountWallet';\nexport { MultichainAccountGroup } from './MultichainAccountGroup';\nexport { MultichainAccountService } from './MultichainAccountService';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC","sourcesContent":["export type {\n MultichainAccountServiceActions,\n MultichainAccountServiceEvents,\n MultichainAccountServiceMessenger,\n MultichainAccountServiceGetMultichainAccountGroupAction,\n MultichainAccountServiceGetMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountWalletsAction,\n MultichainAccountServiceGetMultichainAccountGroupsAction,\n} from './types';\nexport { MultichainAccountWallet } from './MultichainAccountWallet';\nexport { MultichainAccountGroup } from './MultichainAccountGroup';\nexport { MultichainAccountService } from './MultichainAccountService';\n"]}
@@ -6,30 +6,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  };
7
7
  var _BaseAccountProvider_instances, _BaseAccountProvider_getAccounts;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.BaseAccountProvider = exports.assertAreBip44Accounts = exports.assertIsBip44Account = void 0;
9
+ exports.BaseAccountProvider = void 0;
10
10
  const account_api_1 = require("@metamask/account-api");
11
- /**
12
- * Asserts a keyring account is BIP-44 compatible.
13
- *
14
- * @param account - Keyring account to check.
15
- * @throws If the keyring account is not compatible.
16
- */
17
- function assertIsBip44Account(account) {
18
- if (!(0, account_api_1.isBip44Account)(account)) {
19
- throw new Error('Created account is not BIP-44 compatible');
20
- }
21
- }
22
- exports.assertIsBip44Account = assertIsBip44Account;
23
- /**
24
- * Asserts that a list of keyring accounts are all BIP-44 compatible.
25
- *
26
- * @param accounts - Keyring accounts to check.
27
- * @throws If any of the keyring account is not compatible.
28
- */
29
- function assertAreBip44Accounts(accounts) {
30
- accounts.forEach(assertIsBip44Account);
31
- }
32
- exports.assertAreBip44Accounts = assertAreBip44Accounts;
33
11
  class BaseAccountProvider {
34
12
  constructor(messenger) {
35
13
  _BaseAccountProvider_instances.add(this);
@@ -46,13 +24,6 @@ class BaseAccountProvider {
46
24
  }
47
25
  return found;
48
26
  }
49
- async withKeyring(selector, operation) {
50
- const result = await this.messenger.call('KeyringController:withKeyring', selector, ({ keyring, metadata }) => operation({
51
- keyring: keyring,
52
- metadata,
53
- }));
54
- return result;
55
- }
56
27
  }
57
28
  exports.BaseAccountProvider = BaseAccountProvider;
58
29
  _BaseAccountProvider_instances = new WeakSet(), _BaseAccountProvider_getAccounts = function _BaseAccountProvider_getAccounts(filter = () => true) {
@@ -1 +1 @@
1
- {"version":3,"file":"BaseAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BaseAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAI+B;AAS/B;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,IAAA,4BAAc,EAAC,OAAO,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC7D;AACH,CAAC;AAND,oDAMC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,QAA0B;IAE1B,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACzC,CAAC;AAJD,wDAIC;AAED,MAAsB,mBAAmB;IAKvC,YAAY,SAA4C;;QACtD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAyBD,WAAW;QACT,OAAO,uBAAA,IAAI,wEAAa,MAAjB,IAAI,CAAe,CAAC;IAC7B,CAAC;IAED,UAAU,CACR,EAAsC;QAEtC,wDAAwD;QACxD,MAAM,CAAC,KAAK,CAAC,GAAG,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;SAClD;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAES,KAAK,CAAC,WAAW,CACzB,QAAyB,EACzB,SAM6B;QAE7B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACtC,+BAA+B,EAC/B,QAAQ,EACR,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CACxB,SAAS,CAAC;YACR,OAAO,EAAE,OAA0B;YACnC,QAAQ;SACT,CAAC,CACL,CAAC;QAEF,OAAO,MAAwB,CAAC;IAClC,CAAC;CAmBF;AAzFD,kDAyFC;6HA/EG,SAA+C,GAAG,EAAE,CAAC,IAAI;IAEzD,MAAM,QAAQ,GAAmC,EAAE,CAAC;IAEpD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI;IACvC,2EAA2E;IAC3E,yEAAyE;IACzE,kDAAkD;IAClD,2CAA2C,CAC5C,EAAE;QACD,IACE,IAAA,4BAAc,EAAC,OAAO,CAAC;YACvB,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC;YACjC,MAAM,CAAC,OAAO,CAAC,EACf;YACA,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxB;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n isBip44Account,\n type AccountProvider,\n type Bip44Account,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n} from '@metamask/keyring-controller';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\n\n/**\n * Asserts a keyring account is BIP-44 compatible.\n *\n * @param account - Keyring account to check.\n * @throws If the keyring account is not compatible.\n */\nexport function assertIsBip44Account(\n account: KeyringAccount,\n): asserts account is Bip44Account<KeyringAccount> {\n if (!isBip44Account(account)) {\n throw new Error('Created account is not BIP-44 compatible');\n }\n}\n\n/**\n * Asserts that a list of keyring accounts are all BIP-44 compatible.\n *\n * @param accounts - Keyring accounts to check.\n * @throws If any of the keyring account is not compatible.\n */\nexport function assertAreBip44Accounts(\n accounts: KeyringAccount[],\n): asserts accounts is Bip44Account<KeyringAccount>[] {\n accounts.forEach(assertIsBip44Account);\n}\n\nexport abstract class BaseAccountProvider\n implements AccountProvider<Bip44Account<KeyringAccount>>\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n #getAccounts(\n filter: (account: KeyringAccount) => boolean = () => true,\n ): Bip44Account<KeyringAccount>[] {\n const accounts: Bip44Account<KeyringAccount>[] = [];\n\n for (const account of this.messenger.call(\n // NOTE: Even though the name is misleading, this only fetches all internal\n // accounts, including EVM and non-EVM. We might wanna change this action\n // name once we fully support multichain accounts.\n 'AccountsController:listMultichainAccounts',\n )) {\n if (\n isBip44Account(account) &&\n this.isAccountCompatible(account) &&\n filter(account)\n ) {\n accounts.push(account);\n }\n }\n\n return accounts;\n }\n\n getAccounts(): Bip44Account<KeyringAccount>[] {\n return this.#getAccounts();\n }\n\n getAccount(\n id: Bip44Account<KeyringAccount>['id'],\n ): Bip44Account<KeyringAccount> {\n // TODO: Maybe just use a proper find for faster lookup?\n const [found] = this.#getAccounts((account) => account.id === id);\n\n if (!found) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n return found;\n }\n\n protected async withKeyring<SelectedKeyring, CallbackResult = void>(\n selector: KeyringSelector,\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SelectedKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n const result = await this.messenger.call(\n 'KeyringController:withKeyring',\n selector,\n ({ keyring, metadata }) =>\n operation({\n keyring: keyring as SelectedKeyring,\n metadata,\n }),\n );\n\n return result as CallbackResult;\n }\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n\n abstract discoverAndCreateAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n}\n"]}
1
+ {"version":3,"file":"BaseAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BaseAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAI+B;AAK/B,MAAsB,mBAAmB;IAKvC,YAAY,SAA4C;;QACtD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAyBD,WAAW;QACT,OAAO,uBAAA,IAAI,wEAAa,MAAjB,IAAI,CAAe,CAAC;IAC7B,CAAC;IAED,UAAU,CAAC,EAAyB;QAClC,wDAAwD;QACxD,MAAM,CAAC,KAAK,CAAC,GAAG,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;SAClD;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CAGF;AAhDD,kDAgDC;6HAtCG,SAAgD,GAAG,EAAE,CAAC,IAAI;IAE1D,MAAM,QAAQ,GAAoC,EAAE,CAAC;IAErD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI;IACvC,2EAA2E;IAC3E,yEAAyE;IACzE,kDAAkD;IAClD,2CAA2C,CAC5C,EAAE;QACD,IACE,IAAA,4BAAc,EAAC,OAAO,CAAC;YACvB,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC;YACjC,MAAM,CAAC,OAAO,CAAC,EACf;YACA,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxB;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n isBip44Account,\n type AccountProvider,\n type Bip44Account,\n} from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport abstract class BaseAccountProvider\n implements AccountProvider<Bip44Account<InternalAccount>>\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n #getAccounts(\n filter: (account: InternalAccount) => boolean = () => true,\n ): Bip44Account<InternalAccount>[] {\n const accounts: Bip44Account<InternalAccount>[] = [];\n\n for (const account of this.messenger.call(\n // NOTE: Even though the name is misleading, this only fetches all internal\n // accounts, including EVM and non-EVM. We might wanna change this action\n // name once we fully support multichain accounts.\n 'AccountsController:listMultichainAccounts',\n )) {\n if (\n isBip44Account(account) &&\n this.isAccountCompatible(account) &&\n filter(account)\n ) {\n accounts.push(account);\n }\n }\n\n return accounts;\n }\n\n getAccounts(): Bip44Account<InternalAccount>[] {\n return this.#getAccounts();\n }\n\n getAccount(id: InternalAccount['id']): Bip44Account<InternalAccount> {\n // TODO: Maybe just use a proper find for faster lookup?\n const [found] = this.#getAccounts((account) => account.id === id);\n\n if (!found) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n return found;\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n}\n"]}
@@ -1,39 +1,12 @@
1
1
  import { type AccountProvider, type Bip44Account } from "@metamask/account-api";
2
- import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
3
- import type { KeyringMetadata, KeyringSelector } from "@metamask/keyring-controller";
2
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
4
3
  import type { MultichainAccountServiceMessenger } from "../types.cjs";
5
- /**
6
- * Asserts a keyring account is BIP-44 compatible.
7
- *
8
- * @param account - Keyring account to check.
9
- * @throws If the keyring account is not compatible.
10
- */
11
- export declare function assertIsBip44Account(account: KeyringAccount): asserts account is Bip44Account<KeyringAccount>;
12
- /**
13
- * Asserts that a list of keyring accounts are all BIP-44 compatible.
14
- *
15
- * @param accounts - Keyring accounts to check.
16
- * @throws If any of the keyring account is not compatible.
17
- */
18
- export declare function assertAreBip44Accounts(accounts: KeyringAccount[]): asserts accounts is Bip44Account<KeyringAccount>[];
19
- export declare abstract class BaseAccountProvider implements AccountProvider<Bip44Account<KeyringAccount>> {
4
+ export declare abstract class BaseAccountProvider implements AccountProvider<Bip44Account<InternalAccount>> {
20
5
  #private;
21
6
  protected readonly messenger: MultichainAccountServiceMessenger;
22
7
  constructor(messenger: MultichainAccountServiceMessenger);
23
- getAccounts(): Bip44Account<KeyringAccount>[];
24
- getAccount(id: Bip44Account<KeyringAccount>['id']): Bip44Account<KeyringAccount>;
25
- protected withKeyring<SelectedKeyring, CallbackResult = void>(selector: KeyringSelector, operation: ({ keyring, metadata, }: {
26
- keyring: SelectedKeyring;
27
- metadata: KeyringMetadata;
28
- }) => Promise<CallbackResult>): Promise<CallbackResult>;
29
- abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;
30
- abstract createAccounts({ entropySource, groupIndex, }: {
31
- entropySource: EntropySourceId;
32
- groupIndex: number;
33
- }): Promise<Bip44Account<KeyringAccount>[]>;
34
- abstract discoverAndCreateAccounts({ entropySource, groupIndex, }: {
35
- entropySource: EntropySourceId;
36
- groupIndex: number;
37
- }): Promise<Bip44Account<KeyringAccount>[]>;
8
+ getAccounts(): Bip44Account<InternalAccount>[];
9
+ getAccount(id: InternalAccount['id']): Bip44Account<InternalAccount>;
10
+ abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
38
11
  }
39
12
  //# sourceMappingURL=BaseAccountProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BaseAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAC7E,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAChB,qCAAqC;AAEtC,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,cAAc,CAAC,CAIjD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,cAAc,EAAE,GACzB,OAAO,CAAC,QAAQ,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE,CAEpD;AAED,8BAAsB,mBACpB,YAAW,eAAe,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;;IAExD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,iCAAiC,CAAC;gBAEpD,SAAS,EAAE,iCAAiC;IA2BxD,WAAW,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE;IAI7C,UAAU,CACR,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GACrC,YAAY,CAAC,cAAc,CAAC;cAWf,WAAW,CAAC,eAAe,EAAE,cAAc,GAAG,IAAI,EAChE,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,CAAC,EACV,OAAO,EACP,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,eAAe,CAAC;QACzB,QAAQ,EAAE,eAAe,CAAC;KAC3B,KAAK,OAAO,CAAC,cAAc,CAAC,GAC5B,OAAO,CAAC,cAAc,CAAC;IAc1B,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO;IAE5E,QAAQ,CAAC,cAAc,CAAC,EACtB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAE3C,QAAQ,CAAC,yBAAyB,CAAC,EACjC,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAC5C"}
1
+ {"version":3,"file":"BaseAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BaseAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE,8BAAsB,mBACpB,YAAW,eAAe,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;;IAEzD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,iCAAiC,CAAC;gBAEpD,SAAS,EAAE,iCAAiC;IA2BxD,WAAW,IAAI,YAAY,CAAC,eAAe,CAAC,EAAE;IAI9C,UAAU,CAAC,EAAE,EAAE,eAAe,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,eAAe,CAAC;IAWpE,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;CAC9E"}
@@ -1,39 +1,12 @@
1
1
  import { type AccountProvider, type Bip44Account } from "@metamask/account-api";
2
- import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
3
- import type { KeyringMetadata, KeyringSelector } from "@metamask/keyring-controller";
2
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
4
3
  import type { MultichainAccountServiceMessenger } from "../types.mjs";
5
- /**
6
- * Asserts a keyring account is BIP-44 compatible.
7
- *
8
- * @param account - Keyring account to check.
9
- * @throws If the keyring account is not compatible.
10
- */
11
- export declare function assertIsBip44Account(account: KeyringAccount): asserts account is Bip44Account<KeyringAccount>;
12
- /**
13
- * Asserts that a list of keyring accounts are all BIP-44 compatible.
14
- *
15
- * @param accounts - Keyring accounts to check.
16
- * @throws If any of the keyring account is not compatible.
17
- */
18
- export declare function assertAreBip44Accounts(accounts: KeyringAccount[]): asserts accounts is Bip44Account<KeyringAccount>[];
19
- export declare abstract class BaseAccountProvider implements AccountProvider<Bip44Account<KeyringAccount>> {
4
+ export declare abstract class BaseAccountProvider implements AccountProvider<Bip44Account<InternalAccount>> {
20
5
  #private;
21
6
  protected readonly messenger: MultichainAccountServiceMessenger;
22
7
  constructor(messenger: MultichainAccountServiceMessenger);
23
- getAccounts(): Bip44Account<KeyringAccount>[];
24
- getAccount(id: Bip44Account<KeyringAccount>['id']): Bip44Account<KeyringAccount>;
25
- protected withKeyring<SelectedKeyring, CallbackResult = void>(selector: KeyringSelector, operation: ({ keyring, metadata, }: {
26
- keyring: SelectedKeyring;
27
- metadata: KeyringMetadata;
28
- }) => Promise<CallbackResult>): Promise<CallbackResult>;
29
- abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;
30
- abstract createAccounts({ entropySource, groupIndex, }: {
31
- entropySource: EntropySourceId;
32
- groupIndex: number;
33
- }): Promise<Bip44Account<KeyringAccount>[]>;
34
- abstract discoverAndCreateAccounts({ entropySource, groupIndex, }: {
35
- entropySource: EntropySourceId;
36
- groupIndex: number;
37
- }): Promise<Bip44Account<KeyringAccount>[]>;
8
+ getAccounts(): Bip44Account<InternalAccount>[];
9
+ getAccount(id: InternalAccount['id']): Bip44Account<InternalAccount>;
10
+ abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
38
11
  }
39
12
  //# sourceMappingURL=BaseAccountProvider.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BaseAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAC7E,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAChB,qCAAqC;AAEtC,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,cAAc,CAAC,CAIjD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,cAAc,EAAE,GACzB,OAAO,CAAC,QAAQ,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE,CAEpD;AAED,8BAAsB,mBACpB,YAAW,eAAe,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;;IAExD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,iCAAiC,CAAC;gBAEpD,SAAS,EAAE,iCAAiC;IA2BxD,WAAW,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE;IAI7C,UAAU,CACR,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GACrC,YAAY,CAAC,cAAc,CAAC;cAWf,WAAW,CAAC,eAAe,EAAE,cAAc,GAAG,IAAI,EAChE,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,CAAC,EACV,OAAO,EACP,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,eAAe,CAAC;QACzB,QAAQ,EAAE,eAAe,CAAC;KAC3B,KAAK,OAAO,CAAC,cAAc,CAAC,GAC5B,OAAO,CAAC,cAAc,CAAC;IAc1B,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO;IAE5E,QAAQ,CAAC,cAAc,CAAC,EACtB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAE3C,QAAQ,CAAC,yBAAyB,CAAC,EACjC,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAC5C"}
1
+ {"version":3,"file":"BaseAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BaseAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE,8BAAsB,mBACpB,YAAW,eAAe,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;;IAEzD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,iCAAiC,CAAC;gBAEpD,SAAS,EAAE,iCAAiC;IA2BxD,WAAW,IAAI,YAAY,CAAC,eAAe,CAAC,EAAE;IAI9C,UAAU,CAAC,EAAE,EAAE,eAAe,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,eAAe,CAAC;IAWpE,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;CAC9E"}
@@ -5,26 +5,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
5
5
  };
6
6
  var _BaseAccountProvider_instances, _BaseAccountProvider_getAccounts;
7
7
  import { isBip44Account } from "@metamask/account-api";
8
- /**
9
- * Asserts a keyring account is BIP-44 compatible.
10
- *
11
- * @param account - Keyring account to check.
12
- * @throws If the keyring account is not compatible.
13
- */
14
- export function assertIsBip44Account(account) {
15
- if (!isBip44Account(account)) {
16
- throw new Error('Created account is not BIP-44 compatible');
17
- }
18
- }
19
- /**
20
- * Asserts that a list of keyring accounts are all BIP-44 compatible.
21
- *
22
- * @param accounts - Keyring accounts to check.
23
- * @throws If any of the keyring account is not compatible.
24
- */
25
- export function assertAreBip44Accounts(accounts) {
26
- accounts.forEach(assertIsBip44Account);
27
- }
28
8
  export class BaseAccountProvider {
29
9
  constructor(messenger) {
30
10
  _BaseAccountProvider_instances.add(this);
@@ -41,13 +21,6 @@ export class BaseAccountProvider {
41
21
  }
42
22
  return found;
43
23
  }
44
- async withKeyring(selector, operation) {
45
- const result = await this.messenger.call('KeyringController:withKeyring', selector, ({ keyring, metadata }) => operation({
46
- keyring: keyring,
47
- metadata,
48
- }));
49
- return result;
50
- }
51
24
  }
52
25
  _BaseAccountProvider_instances = new WeakSet(), _BaseAccountProvider_getAccounts = function _BaseAccountProvider_getAccounts(filter = () => true) {
53
26
  const accounts = [];
@@ -1 +1 @@
1
- {"version":3,"file":"BaseAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BaseAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,cAAc,EAGf,8BAA8B;AAS/B;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC7D;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA0B;IAE1B,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,OAAgB,mBAAmB;IAKvC,YAAY,SAA4C;;QACtD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAyBD,WAAW;QACT,OAAO,uBAAA,IAAI,wEAAa,MAAjB,IAAI,CAAe,CAAC;IAC7B,CAAC;IAED,UAAU,CACR,EAAsC;QAEtC,wDAAwD;QACxD,MAAM,CAAC,KAAK,CAAC,GAAG,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;SAClD;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAES,KAAK,CAAC,WAAW,CACzB,QAAyB,EACzB,SAM6B;QAE7B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACtC,+BAA+B,EAC/B,QAAQ,EACR,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CACxB,SAAS,CAAC;YACR,OAAO,EAAE,OAA0B;YACnC,QAAQ;SACT,CAAC,CACL,CAAC;QAEF,OAAO,MAAwB,CAAC;IAClC,CAAC;CAmBF;6HA/EG,SAA+C,GAAG,EAAE,CAAC,IAAI;IAEzD,MAAM,QAAQ,GAAmC,EAAE,CAAC;IAEpD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI;IACvC,2EAA2E;IAC3E,yEAAyE;IACzE,kDAAkD;IAClD,2CAA2C,CAC5C,EAAE;QACD,IACE,cAAc,CAAC,OAAO,CAAC;YACvB,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC;YACjC,MAAM,CAAC,OAAO,CAAC,EACf;YACA,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxB;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n isBip44Account,\n type AccountProvider,\n type Bip44Account,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n} from '@metamask/keyring-controller';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\n\n/**\n * Asserts a keyring account is BIP-44 compatible.\n *\n * @param account - Keyring account to check.\n * @throws If the keyring account is not compatible.\n */\nexport function assertIsBip44Account(\n account: KeyringAccount,\n): asserts account is Bip44Account<KeyringAccount> {\n if (!isBip44Account(account)) {\n throw new Error('Created account is not BIP-44 compatible');\n }\n}\n\n/**\n * Asserts that a list of keyring accounts are all BIP-44 compatible.\n *\n * @param accounts - Keyring accounts to check.\n * @throws If any of the keyring account is not compatible.\n */\nexport function assertAreBip44Accounts(\n accounts: KeyringAccount[],\n): asserts accounts is Bip44Account<KeyringAccount>[] {\n accounts.forEach(assertIsBip44Account);\n}\n\nexport abstract class BaseAccountProvider\n implements AccountProvider<Bip44Account<KeyringAccount>>\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n #getAccounts(\n filter: (account: KeyringAccount) => boolean = () => true,\n ): Bip44Account<KeyringAccount>[] {\n const accounts: Bip44Account<KeyringAccount>[] = [];\n\n for (const account of this.messenger.call(\n // NOTE: Even though the name is misleading, this only fetches all internal\n // accounts, including EVM and non-EVM. We might wanna change this action\n // name once we fully support multichain accounts.\n 'AccountsController:listMultichainAccounts',\n )) {\n if (\n isBip44Account(account) &&\n this.isAccountCompatible(account) &&\n filter(account)\n ) {\n accounts.push(account);\n }\n }\n\n return accounts;\n }\n\n getAccounts(): Bip44Account<KeyringAccount>[] {\n return this.#getAccounts();\n }\n\n getAccount(\n id: Bip44Account<KeyringAccount>['id'],\n ): Bip44Account<KeyringAccount> {\n // TODO: Maybe just use a proper find for faster lookup?\n const [found] = this.#getAccounts((account) => account.id === id);\n\n if (!found) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n return found;\n }\n\n protected async withKeyring<SelectedKeyring, CallbackResult = void>(\n selector: KeyringSelector,\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SelectedKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n const result = await this.messenger.call(\n 'KeyringController:withKeyring',\n selector,\n ({ keyring, metadata }) =>\n operation({\n keyring: keyring as SelectedKeyring,\n metadata,\n }),\n );\n\n return result as CallbackResult;\n }\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n\n abstract discoverAndCreateAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n}\n"]}
1
+ {"version":3,"file":"BaseAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BaseAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,cAAc,EAGf,8BAA8B;AAK/B,MAAM,OAAgB,mBAAmB;IAKvC,YAAY,SAA4C;;QACtD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAyBD,WAAW;QACT,OAAO,uBAAA,IAAI,wEAAa,MAAjB,IAAI,CAAe,CAAC;IAC7B,CAAC;IAED,UAAU,CAAC,EAAyB;QAClC,wDAAwD;QACxD,MAAM,CAAC,KAAK,CAAC,GAAG,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;SAClD;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CAGF;6HAtCG,SAAgD,GAAG,EAAE,CAAC,IAAI;IAE1D,MAAM,QAAQ,GAAoC,EAAE,CAAC;IAErD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI;IACvC,2EAA2E;IAC3E,yEAAyE;IACzE,kDAAkD;IAClD,2CAA2C,CAC5C,EAAE;QACD,IACE,cAAc,CAAC,OAAO,CAAC;YACvB,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC;YACjC,MAAM,CAAC,OAAO,CAAC,EACf;YACA,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxB;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n isBip44Account,\n type AccountProvider,\n type Bip44Account,\n} from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport abstract class BaseAccountProvider\n implements AccountProvider<Bip44Account<InternalAccount>>\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n #getAccounts(\n filter: (account: InternalAccount) => boolean = () => true,\n ): Bip44Account<InternalAccount>[] {\n const accounts: Bip44Account<InternalAccount>[] = [];\n\n for (const account of this.messenger.call(\n // NOTE: Even though the name is misleading, this only fetches all internal\n // accounts, including EVM and non-EVM. We might wanna change this action\n // name once we fully support multichain accounts.\n 'AccountsController:listMultichainAccounts',\n )) {\n if (\n isBip44Account(account) &&\n this.isAccountCompatible(account) &&\n filter(account)\n ) {\n accounts.push(account);\n }\n }\n\n return accounts;\n }\n\n getAccounts(): Bip44Account<InternalAccount>[] {\n return this.#getAccounts();\n }\n\n getAccount(id: InternalAccount['id']): Bip44Account<InternalAccount> {\n // TODO: Maybe just use a proper find for faster lookup?\n const [found] = this.#getAccounts((account) => account.id === id);\n\n if (!found) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n return found;\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n}\n"]}
@@ -4,46 +4,11 @@ exports.EvmAccountProvider = void 0;
4
4
  const keyring_api_1 = require("@metamask/keyring-api");
5
5
  const keyring_controller_1 = require("@metamask/keyring-controller");
6
6
  const BaseAccountProvider_1 = require("./BaseAccountProvider.cjs");
7
- /**
8
- * Asserts an internal account exists.
9
- *
10
- * @param account - The internal account to check.
11
- * @throws An error if the internal account does not exist.
12
- */
13
- function assertInternalAccountExists(account) {
14
- if (!account) {
15
- throw new Error('Internal account does not exist');
16
- }
17
- }
18
7
  class EvmAccountProvider extends BaseAccountProvider_1.BaseAccountProvider {
19
8
  isAccountCompatible(account) {
20
9
  return (account.type === keyring_api_1.EthAccountType.Eoa &&
21
10
  account.metadata.keyring.type === keyring_controller_1.KeyringTypes.hd);
22
11
  }
23
- async createAccounts({ entropySource, groupIndex, }) {
24
- const [address] = await this.withKeyring({ id: entropySource }, async ({ keyring }) => {
25
- const accounts = await keyring.getAccounts();
26
- if (groupIndex < accounts.length) {
27
- // Nothing new to create, we just re-use the existing accounts here,
28
- return [accounts[groupIndex]];
29
- }
30
- // For now, we don't allow for gap, so if we need to create a new
31
- // account, this has to be the next one.
32
- if (groupIndex !== accounts.length) {
33
- throw new Error('Trying to create too many accounts');
34
- }
35
- // Create next account (and returns their addresses).
36
- return await keyring.addAccounts(1);
37
- });
38
- const account = this.messenger.call('AccountsController:getAccountByAddress', address);
39
- // We MUST have the associated internal account.
40
- assertInternalAccountExists(account);
41
- (0, BaseAccountProvider_1.assertIsBip44Account)(account);
42
- return [account];
43
- }
44
- async discoverAndCreateAccounts(_) {
45
- return []; // TODO: Implement account discovery.
46
- }
47
12
  }
48
13
  exports.EvmAccountProvider = EvmAccountProvider;
49
14
  //# sourceMappingURL=EvmAccountProvider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"EvmAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":";;;AAEA,uDAAuD;AACvD,qEAA4D;AAO5D,mEAG+B;AAE/B;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,OAAoC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;AACH,CAAC;AAED,MAAa,kBAAmB,SAAQ,yCAAmB;IACzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,EAAa,CAC9D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI,CAAC,WAAW,CACtC,EAAE,EAAE,EAAE,aAAa,EAAE,EACrB,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YACpB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;YAC7C,IAAI,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE;gBAChC,oEAAoE;gBACpE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;aAC/B;YAED,iEAAiE;YACjE,wCAAwC;YACxC,IAAI,UAAU,KAAK,QAAQ,CAAC,MAAM,EAAE;gBAClC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;aACvD;YAED,qDAAqD;YACrD,OAAO,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC,CACF,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACjC,wCAAwC,EACxC,OAAO,CACR,CAAC;QAEF,gDAAgD;QAChD,2BAA2B,CAAC,OAAO,CAAC,CAAC;QACrC,IAAA,0CAAoB,EAAC,OAAO,CAAC,CAAC;QAE9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;CACF;AArDD,gDAqDC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n EthKeyring,\n InternalAccount,\n} from '@metamask/keyring-internal-api';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n assertIsBip44Account,\n BaseAccountProvider,\n} from './BaseAccountProvider';\n\n/**\n * Asserts an internal account exists.\n *\n * @param account - The internal account to check.\n * @throws An error if the internal account does not exist.\n */\nfunction assertInternalAccountExists(\n account: InternalAccount | undefined,\n): asserts account is InternalAccount {\n if (!account) {\n throw new Error('Internal account does not exist');\n }\n}\n\nexport class EvmAccountProvider extends BaseAccountProvider {\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === EthAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.hd as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n const [address] = await this.withKeyring<EthKeyring, Hex[]>(\n { id: entropySource },\n async ({ keyring }) => {\n const accounts = await keyring.getAccounts();\n if (groupIndex < accounts.length) {\n // Nothing new to create, we just re-use the existing accounts here,\n return [accounts[groupIndex]];\n }\n\n // For now, we don't allow for gap, so if we need to create a new\n // account, this has to be the next one.\n if (groupIndex !== accounts.length) {\n throw new Error('Trying to create too many accounts');\n }\n\n // Create next account (and returns their addresses).\n return await keyring.addAccounts(1);\n },\n );\n\n const account = this.messenger.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n\n // We MUST have the associated internal account.\n assertInternalAccountExists(account);\n assertIsBip44Account(account);\n\n return [account];\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
1
+ {"version":3,"file":"EvmAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":";;;AACA,uDAAuD;AACvD,qEAA4D;AAG5D,mEAA4D;AAE5D,MAAa,kBAAmB,SAAQ,yCAAmB;IACzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,EAAa,CAC9D,CAAC;IACJ,CAAC;CACF;AAPD,gDAOC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { BaseAccountProvider } from './BaseAccountProvider';\n\nexport class EvmAccountProvider extends BaseAccountProvider {\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === EthAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.hd as string)\n );\n }\n}\n"]}
@@ -1,73 +1,7 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
- import type { EntropySourceId } from "@metamask/keyring-api";
3
2
  import type { InternalAccount } from "@metamask/keyring-internal-api";
4
3
  import { BaseAccountProvider } from "./BaseAccountProvider.cjs";
5
4
  export declare class EvmAccountProvider extends BaseAccountProvider {
6
5
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
7
- createAccounts({ entropySource, groupIndex, }: {
8
- entropySource: EntropySourceId;
9
- groupIndex: number;
10
- }): Promise<({
11
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account";
12
- id: string;
13
- options: Record<string, import("@metamask/utils").Json> & {
14
- entropy?: {
15
- type: "mnemonic";
16
- id: string;
17
- derivationPath: string;
18
- groupIndex: number;
19
- } | {
20
- type: "private-key";
21
- } | undefined;
22
- exportable?: boolean | undefined;
23
- };
24
- metadata: {
25
- name: string;
26
- importTime: number;
27
- keyring: {
28
- type: string;
29
- };
30
- nameLastUpdatedAt?: number | undefined;
31
- snap?: {
32
- name: string;
33
- id: string;
34
- enabled: boolean;
35
- } | undefined;
36
- lastSelected?: number | undefined;
37
- };
38
- address: string;
39
- scopes: `${string}:${string}`[];
40
- methods: string[];
41
- } & {
42
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "any:account";
43
- id: string;
44
- options: Record<string, import("@metamask/utils").Json> & {
45
- entropy?: {
46
- type: "mnemonic";
47
- id: string;
48
- derivationPath: string;
49
- groupIndex: number;
50
- } | {
51
- type: "private-key";
52
- } | undefined;
53
- exportable?: boolean | undefined;
54
- };
55
- address: string;
56
- scopes: `${string}:${string}`[];
57
- methods: string[];
58
- } & {
59
- options: {
60
- entropy: {
61
- type: "mnemonic";
62
- id: string;
63
- derivationPath: string;
64
- groupIndex: number;
65
- };
66
- };
67
- })[]>;
68
- discoverAndCreateAccounts(_: {
69
- entropySource: EntropySourceId;
70
- groupIndex: number;
71
- }): Promise<never[]>;
72
6
  }
73
7
  //# sourceMappingURL=EvmAccountProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EvmAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAG7D,OAAO,KAAK,EAEV,eAAe,EAChB,uCAAuC;AAGxC,OAAO,EAEL,mBAAmB,EACpB,kCAA8B;AAgB/B,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiCK,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
1
+ {"version":3,"file":"EvmAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;CAMrE"}
@@ -1,73 +1,7 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
- import type { EntropySourceId } from "@metamask/keyring-api";
3
2
  import type { InternalAccount } from "@metamask/keyring-internal-api";
4
3
  import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
5
4
  export declare class EvmAccountProvider extends BaseAccountProvider {
6
5
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
7
- createAccounts({ entropySource, groupIndex, }: {
8
- entropySource: EntropySourceId;
9
- groupIndex: number;
10
- }): Promise<({
11
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account";
12
- id: string;
13
- options: Record<string, import("@metamask/utils").Json> & {
14
- entropy?: {
15
- type: "mnemonic";
16
- id: string;
17
- derivationPath: string;
18
- groupIndex: number;
19
- } | {
20
- type: "private-key";
21
- } | undefined;
22
- exportable?: boolean | undefined;
23
- };
24
- metadata: {
25
- name: string;
26
- importTime: number;
27
- keyring: {
28
- type: string;
29
- };
30
- nameLastUpdatedAt?: number | undefined;
31
- snap?: {
32
- name: string;
33
- id: string;
34
- enabled: boolean;
35
- } | undefined;
36
- lastSelected?: number | undefined;
37
- };
38
- address: string;
39
- scopes: `${string}:${string}`[];
40
- methods: string[];
41
- } & {
42
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "any:account";
43
- id: string;
44
- options: Record<string, import("@metamask/utils").Json> & {
45
- entropy?: {
46
- type: "mnemonic";
47
- id: string;
48
- derivationPath: string;
49
- groupIndex: number;
50
- } | {
51
- type: "private-key";
52
- } | undefined;
53
- exportable?: boolean | undefined;
54
- };
55
- address: string;
56
- scopes: `${string}:${string}`[];
57
- methods: string[];
58
- } & {
59
- options: {
60
- entropy: {
61
- type: "mnemonic";
62
- id: string;
63
- derivationPath: string;
64
- groupIndex: number;
65
- };
66
- };
67
- })[]>;
68
- discoverAndCreateAccounts(_: {
69
- entropySource: EntropySourceId;
70
- groupIndex: number;
71
- }): Promise<never[]>;
72
6
  }
73
7
  //# sourceMappingURL=EvmAccountProvider.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EvmAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAG7D,OAAO,KAAK,EAEV,eAAe,EAChB,uCAAuC;AAGxC,OAAO,EAEL,mBAAmB,EACpB,kCAA8B;AAgB/B,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiCK,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
1
+ {"version":3,"file":"EvmAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;CAMrE"}
@@ -1,45 +1,10 @@
1
1
  import { EthAccountType } from "@metamask/keyring-api";
2
2
  import { KeyringTypes } from "@metamask/keyring-controller";
3
- import { assertIsBip44Account, BaseAccountProvider } from "./BaseAccountProvider.mjs";
4
- /**
5
- * Asserts an internal account exists.
6
- *
7
- * @param account - The internal account to check.
8
- * @throws An error if the internal account does not exist.
9
- */
10
- function assertInternalAccountExists(account) {
11
- if (!account) {
12
- throw new Error('Internal account does not exist');
13
- }
14
- }
3
+ import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
15
4
  export class EvmAccountProvider extends BaseAccountProvider {
16
5
  isAccountCompatible(account) {
17
6
  return (account.type === EthAccountType.Eoa &&
18
7
  account.metadata.keyring.type === KeyringTypes.hd);
19
8
  }
20
- async createAccounts({ entropySource, groupIndex, }) {
21
- const [address] = await this.withKeyring({ id: entropySource }, async ({ keyring }) => {
22
- const accounts = await keyring.getAccounts();
23
- if (groupIndex < accounts.length) {
24
- // Nothing new to create, we just re-use the existing accounts here,
25
- return [accounts[groupIndex]];
26
- }
27
- // For now, we don't allow for gap, so if we need to create a new
28
- // account, this has to be the next one.
29
- if (groupIndex !== accounts.length) {
30
- throw new Error('Trying to create too many accounts');
31
- }
32
- // Create next account (and returns their addresses).
33
- return await keyring.addAccounts(1);
34
- });
35
- const account = this.messenger.call('AccountsController:getAccountByAddress', address);
36
- // We MUST have the associated internal account.
37
- assertInternalAccountExists(account);
38
- assertIsBip44Account(account);
39
- return [account];
40
- }
41
- async discoverAndCreateAccounts(_) {
42
- return []; // TODO: Implement account discovery.
43
- }
44
9
  }
45
10
  //# sourceMappingURL=EvmAccountProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"EvmAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAO5D,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACpB,kCAA8B;AAE/B;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,OAAoC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;AACH,CAAC;AAED,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,EAAa,CAC9D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI,CAAC,WAAW,CACtC,EAAE,EAAE,EAAE,aAAa,EAAE,EACrB,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YACpB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;YAC7C,IAAI,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE;gBAChC,oEAAoE;gBACpE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;aAC/B;YAED,iEAAiE;YACjE,wCAAwC;YACxC,IAAI,UAAU,KAAK,QAAQ,CAAC,MAAM,EAAE;gBAClC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;aACvD;YAED,qDAAqD;YACrD,OAAO,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC,CACF,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACjC,wCAAwC,EACxC,OAAO,CACR,CAAC;QAEF,gDAAgD;QAChD,2BAA2B,CAAC,OAAO,CAAC,CAAC;QACrC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;CACF","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n EthKeyring,\n InternalAccount,\n} from '@metamask/keyring-internal-api';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n assertIsBip44Account,\n BaseAccountProvider,\n} from './BaseAccountProvider';\n\n/**\n * Asserts an internal account exists.\n *\n * @param account - The internal account to check.\n * @throws An error if the internal account does not exist.\n */\nfunction assertInternalAccountExists(\n account: InternalAccount | undefined,\n): asserts account is InternalAccount {\n if (!account) {\n throw new Error('Internal account does not exist');\n }\n}\n\nexport class EvmAccountProvider extends BaseAccountProvider {\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === EthAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.hd as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n const [address] = await this.withKeyring<EthKeyring, Hex[]>(\n { id: entropySource },\n async ({ keyring }) => {\n const accounts = await keyring.getAccounts();\n if (groupIndex < accounts.length) {\n // Nothing new to create, we just re-use the existing accounts here,\n return [accounts[groupIndex]];\n }\n\n // For now, we don't allow for gap, so if we need to create a new\n // account, this has to be the next one.\n if (groupIndex !== accounts.length) {\n throw new Error('Trying to create too many accounts');\n }\n\n // Create next account (and returns their addresses).\n return await keyring.addAccounts(1);\n },\n );\n\n const account = this.messenger.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n\n // We MUST have the associated internal account.\n assertInternalAccountExists(account);\n assertIsBip44Account(account);\n\n return [account];\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
1
+ {"version":3,"file":"EvmAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,EAAa,CAC9D,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { BaseAccountProvider } from './BaseAccountProvider';\n\nexport class EvmAccountProvider extends BaseAccountProvider {\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === EthAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.hd as string)\n );\n }\n}\n"]}
@@ -4,41 +4,11 @@ exports.SolAccountProvider = void 0;
4
4
  const keyring_api_1 = require("@metamask/keyring-api");
5
5
  const keyring_controller_1 = require("@metamask/keyring-controller");
6
6
  const BaseAccountProvider_1 = require("./BaseAccountProvider.cjs");
7
- const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
8
- class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
9
- constructor(messenger) {
10
- super(SolAccountProvider.SOLANA_SNAP_ID, messenger);
11
- }
7
+ class SolAccountProvider extends BaseAccountProvider_1.BaseAccountProvider {
12
8
  isAccountCompatible(account) {
13
9
  return (account.type === keyring_api_1.SolAccountType.DataAccount &&
14
10
  account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap);
15
11
  }
16
- async createAccounts({ entropySource, groupIndex, }) {
17
- return this.withCreateAccount(async (createAccount) => {
18
- // Create account without any confirmation nor selecting it.
19
- // TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
20
- // type once ready.
21
- const derivationPath = `m/44'/501'/${groupIndex}'/0'`;
22
- const account = await createAccount({
23
- entropySource,
24
- derivationPath,
25
- });
26
- // Solana Snap does not use BIP-44 typed options for the moment
27
- // so we "inject" them (the `AccountsController` does a similar thing
28
- // for the moment).
29
- account.options.entropy = {
30
- type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
31
- id: entropySource,
32
- groupIndex,
33
- derivationPath,
34
- };
35
- (0, BaseAccountProvider_1.assertIsBip44Account)(account);
36
- return [account];
37
- });
38
- }
39
- async discoverAndCreateAccounts(_) {
40
- return []; // TODO: Implement account discovery.
41
- }
42
12
  }
43
13
  exports.SolAccountProvider = SolAccountProvider;
44
14
  SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;AAEA,uDAG+B;AAC/B,qEAA4D;AAK5D,mEAA6D;AAC7D,mEAA4D;AAE5D,MAAa,kBAAmB,SAAQ,yCAAmB;IAGzD,YAAY,SAA4C;QACtD,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;YACpD,4DAA4D;YAC5D,uFAAuF;YACvF,mBAAmB;YACnB,MAAM,cAAc,GAAG,cAAc,UAAU,MAAM,CAAC;YACtD,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;gBAClC,aAAa;gBACb,cAAc;aACf,CAAC,CAAC;YAEH,+DAA+D;YAC/D,qEAAqE;YACrE,mBAAmB;YACnB,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;gBACxB,IAAI,EAAE,6CAA+B,CAAC,QAAQ;gBAC9C,EAAE,EAAE,aAAa;gBACjB,UAAU;gBACV,cAAc;aACf,CAAC;YAEF,IAAA,0CAAoB,EAAC,OAAO,CAAC,CAAC;YAE9B,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AApDH,gDAqDC;AApDQ,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { assertIsBip44Account } from './BaseAccountProvider';\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withCreateAccount(async (createAccount) => {\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount({\n entropySource,\n derivationPath,\n });\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n\n return [account];\n });\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
1
+ {"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;AACA,uDAAuD;AACvD,qEAA4D;AAI5D,mEAA4D;AAE5D,MAAa,kBAAmB,SAAQ,yCAAmB;IAGzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;;AARH,gDASC;AARQ,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { SolAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { BaseAccountProvider } from './BaseAccountProvider';\n\nexport class SolAccountProvider extends BaseAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n}\n"]}