@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.
Files changed (210) hide show
  1. package/CHANGELOG.md +63 -1
  2. package/dist/MultichainAccountGroup.cjs +4 -69
  3. package/dist/MultichainAccountGroup.cjs.map +1 -1
  4. package/dist/MultichainAccountGroup.d.cts +0 -6
  5. package/dist/MultichainAccountGroup.d.cts.map +1 -1
  6. package/dist/MultichainAccountGroup.d.mts +0 -6
  7. package/dist/MultichainAccountGroup.d.mts.map +1 -1
  8. package/dist/MultichainAccountGroup.mjs +5 -70
  9. package/dist/MultichainAccountGroup.mjs.map +1 -1
  10. package/dist/MultichainAccountService-method-action-types.cjs +7 -0
  11. package/dist/MultichainAccountService-method-action-types.cjs.map +1 -0
  12. package/dist/MultichainAccountService-method-action-types.d.cts +177 -0
  13. package/dist/MultichainAccountService-method-action-types.d.cts.map +1 -0
  14. package/dist/MultichainAccountService-method-action-types.d.mts +177 -0
  15. package/dist/MultichainAccountService-method-action-types.d.mts.map +1 -0
  16. package/dist/MultichainAccountService-method-action-types.mjs +6 -0
  17. package/dist/MultichainAccountService-method-action-types.mjs.map +1 -0
  18. package/dist/MultichainAccountService.cjs +59 -28
  19. package/dist/MultichainAccountService.cjs.map +1 -1
  20. package/dist/MultichainAccountService.d.cts +24 -2
  21. package/dist/MultichainAccountService.d.cts.map +1 -1
  22. package/dist/MultichainAccountService.d.mts +24 -2
  23. package/dist/MultichainAccountService.d.mts.map +1 -1
  24. package/dist/MultichainAccountService.mjs +60 -29
  25. package/dist/MultichainAccountService.mjs.map +1 -1
  26. package/dist/MultichainAccountWallet.cjs +302 -164
  27. package/dist/MultichainAccountWallet.cjs.map +1 -1
  28. package/dist/MultichainAccountWallet.d.cts +27 -7
  29. package/dist/MultichainAccountWallet.d.cts.map +1 -1
  30. package/dist/MultichainAccountWallet.d.mts +27 -7
  31. package/dist/MultichainAccountWallet.d.mts.map +1 -1
  32. package/dist/MultichainAccountWallet.mjs +303 -165
  33. package/dist/MultichainAccountWallet.mjs.map +1 -1
  34. package/dist/analytics/perf.cjs +65 -0
  35. package/dist/analytics/perf.cjs.map +1 -0
  36. package/dist/analytics/perf.d.cts +34 -0
  37. package/dist/analytics/perf.d.cts.map +1 -0
  38. package/dist/analytics/perf.d.mts +34 -0
  39. package/dist/analytics/perf.d.mts.map +1 -0
  40. package/dist/analytics/perf.mjs +59 -0
  41. package/dist/analytics/perf.mjs.map +1 -0
  42. package/dist/analytics/timer.cjs +14 -0
  43. package/dist/analytics/timer.cjs.map +1 -0
  44. package/dist/analytics/timer.d.cts +8 -0
  45. package/dist/analytics/timer.d.cts.map +1 -0
  46. package/dist/analytics/timer.d.mts +8 -0
  47. package/dist/analytics/timer.d.mts.map +1 -0
  48. package/dist/analytics/timer.mjs +10 -0
  49. package/dist/analytics/timer.mjs.map +1 -0
  50. package/dist/analytics/traces.cjs +49 -1
  51. package/dist/analytics/traces.cjs.map +1 -1
  52. package/dist/analytics/traces.d.cts +28 -0
  53. package/dist/analytics/traces.d.cts.map +1 -1
  54. package/dist/analytics/traces.d.mts +28 -0
  55. package/dist/analytics/traces.d.mts.map +1 -1
  56. package/dist/analytics/traces.mjs +46 -0
  57. package/dist/analytics/traces.mjs.map +1 -1
  58. package/dist/errors.cjs +32 -0
  59. package/dist/errors.cjs.map +1 -0
  60. package/dist/errors.d.cts +16 -0
  61. package/dist/errors.d.cts.map +1 -0
  62. package/dist/errors.d.mts +16 -0
  63. package/dist/errors.d.mts.map +1 -0
  64. package/dist/errors.mjs +28 -0
  65. package/dist/errors.mjs.map +1 -0
  66. package/dist/index.cjs.map +1 -1
  67. package/dist/index.d.cts +2 -1
  68. package/dist/index.d.cts.map +1 -1
  69. package/dist/index.d.mts +2 -1
  70. package/dist/index.d.mts.map +1 -1
  71. package/dist/index.mjs.map +1 -1
  72. package/dist/logger.cjs +14 -1
  73. package/dist/logger.cjs.map +1 -1
  74. package/dist/logger.d.cts +8 -0
  75. package/dist/logger.d.cts.map +1 -1
  76. package/dist/logger.d.mts +8 -0
  77. package/dist/logger.d.mts.map +1 -1
  78. package/dist/logger.mjs +12 -0
  79. package/dist/logger.mjs.map +1 -1
  80. package/dist/providers/AccountProviderWrapper.cjs +5 -6
  81. package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
  82. package/dist/providers/AccountProviderWrapper.d.cts +5 -4
  83. package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
  84. package/dist/providers/AccountProviderWrapper.d.mts +5 -4
  85. package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
  86. package/dist/providers/AccountProviderWrapper.mjs +5 -6
  87. package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
  88. package/dist/providers/BaseBip44AccountProvider.cjs +0 -10
  89. package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
  90. package/dist/providers/BaseBip44AccountProvider.d.cts +1 -17
  91. package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
  92. package/dist/providers/BaseBip44AccountProvider.d.mts +1 -17
  93. package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
  94. package/dist/providers/BaseBip44AccountProvider.mjs +0 -10
  95. package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
  96. package/dist/providers/BtcAccountProvider.cjs +15 -33
  97. package/dist/providers/BtcAccountProvider.cjs.map +1 -1
  98. package/dist/providers/BtcAccountProvider.d.cts +6 -4
  99. package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
  100. package/dist/providers/BtcAccountProvider.d.mts +6 -4
  101. package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
  102. package/dist/providers/BtcAccountProvider.mjs +16 -34
  103. package/dist/providers/BtcAccountProvider.mjs.map +1 -1
  104. package/dist/providers/EvmAccountProvider.cjs +44 -3
  105. package/dist/providers/EvmAccountProvider.cjs.map +1 -1
  106. package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
  107. package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
  108. package/dist/providers/EvmAccountProvider.mjs +44 -3
  109. package/dist/providers/EvmAccountProvider.mjs.map +1 -1
  110. package/dist/providers/SnapAccountProvider.cjs +111 -21
  111. package/dist/providers/SnapAccountProvider.cjs.map +1 -1
  112. package/dist/providers/SnapAccountProvider.d.cts +33 -2
  113. package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
  114. package/dist/providers/SnapAccountProvider.d.mts +33 -2
  115. package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
  116. package/dist/providers/SnapAccountProvider.mjs +113 -23
  117. package/dist/providers/SnapAccountProvider.mjs.map +1 -1
  118. package/dist/providers/SolAccountProvider.cjs +31 -39
  119. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  120. package/dist/providers/SolAccountProvider.d.cts +10 -3
  121. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  122. package/dist/providers/SolAccountProvider.d.mts +10 -3
  123. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  124. package/dist/providers/SolAccountProvider.mjs +32 -40
  125. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  126. package/dist/providers/TrxAccountProvider.cjs +15 -37
  127. package/dist/providers/TrxAccountProvider.cjs.map +1 -1
  128. package/dist/providers/TrxAccountProvider.d.cts +6 -4
  129. package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
  130. package/dist/providers/TrxAccountProvider.d.mts +6 -4
  131. package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
  132. package/dist/providers/TrxAccountProvider.mjs +16 -38
  133. package/dist/providers/TrxAccountProvider.mjs.map +1 -1
  134. package/dist/providers/index.cjs +2 -1
  135. package/dist/providers/index.cjs.map +1 -1
  136. package/dist/providers/index.d.cts +1 -1
  137. package/dist/providers/index.d.cts.map +1 -1
  138. package/dist/providers/index.d.mts +1 -1
  139. package/dist/providers/index.d.mts.map +1 -1
  140. package/dist/providers/index.mjs +1 -1
  141. package/dist/providers/index.mjs.map +1 -1
  142. package/dist/providers/utils.cjs +15 -5
  143. package/dist/providers/utils.cjs.map +1 -1
  144. package/dist/providers/utils.d.cts +9 -2
  145. package/dist/providers/utils.d.cts.map +1 -1
  146. package/dist/providers/utils.d.mts +9 -2
  147. package/dist/providers/utils.d.mts.map +1 -1
  148. package/dist/providers/utils.mjs +13 -4
  149. package/dist/providers/utils.mjs.map +1 -1
  150. package/dist/snaps/SnapPlatformWatcher.cjs +72 -8
  151. package/dist/snaps/SnapPlatformWatcher.cjs.map +1 -1
  152. package/dist/snaps/SnapPlatformWatcher.d.cts +15 -1
  153. package/dist/snaps/SnapPlatformWatcher.d.cts.map +1 -1
  154. package/dist/snaps/SnapPlatformWatcher.d.mts +15 -1
  155. package/dist/snaps/SnapPlatformWatcher.d.mts.map +1 -1
  156. package/dist/snaps/SnapPlatformWatcher.mjs +72 -8
  157. package/dist/snaps/SnapPlatformWatcher.mjs.map +1 -1
  158. package/dist/tests/accounts.cjs +7 -1
  159. package/dist/tests/accounts.cjs.map +1 -1
  160. package/dist/tests/accounts.d.cts +9 -0
  161. package/dist/tests/accounts.d.cts.map +1 -1
  162. package/dist/tests/accounts.d.mts +9 -0
  163. package/dist/tests/accounts.d.mts.map +1 -1
  164. package/dist/tests/accounts.mjs +6 -0
  165. package/dist/tests/accounts.mjs.map +1 -1
  166. package/dist/tests/index.cjs.map +1 -1
  167. package/dist/tests/index.d.cts +1 -0
  168. package/dist/tests/index.d.cts.map +1 -1
  169. package/dist/tests/index.d.mts +1 -0
  170. package/dist/tests/index.d.mts.map +1 -1
  171. package/dist/tests/index.mjs.map +1 -1
  172. package/dist/tests/providers.cjs +14 -16
  173. package/dist/tests/providers.cjs.map +1 -1
  174. package/dist/tests/providers.d.cts +11 -0
  175. package/dist/tests/providers.d.cts.map +1 -1
  176. package/dist/tests/providers.d.mts +11 -0
  177. package/dist/tests/providers.d.mts.map +1 -1
  178. package/dist/tests/providers.mjs +14 -17
  179. package/dist/tests/providers.mjs.map +1 -1
  180. package/dist/tests/types.cjs +3 -0
  181. package/dist/tests/types.cjs.map +1 -0
  182. package/dist/tests/types.d.cts +7 -0
  183. package/dist/tests/types.d.cts.map +1 -0
  184. package/dist/tests/types.d.mts +7 -0
  185. package/dist/tests/types.d.mts.map +1 -0
  186. package/dist/tests/types.mjs +2 -0
  187. package/dist/tests/types.mjs.map +1 -0
  188. package/dist/types.cjs.map +1 -1
  189. package/dist/types.d.cts +13 -54
  190. package/dist/types.d.cts.map +1 -1
  191. package/dist/types.d.mts +13 -54
  192. package/dist/types.d.mts.map +1 -1
  193. package/dist/types.mjs.map +1 -1
  194. package/dist/utils.cjs +49 -5
  195. package/dist/utils.cjs.map +1 -1
  196. package/dist/utils.d.cts +32 -5
  197. package/dist/utils.d.cts.map +1 -1
  198. package/dist/utils.d.mts +32 -5
  199. package/dist/utils.d.mts.map +1 -1
  200. package/dist/utils.mjs +45 -4
  201. package/dist/utils.mjs.map +1 -1
  202. package/package.json +9 -7
  203. package/dist/constants/traces.cjs +0 -9
  204. package/dist/constants/traces.cjs.map +0 -1
  205. package/dist/constants/traces.d.cts +0 -5
  206. package/dist/constants/traces.d.cts.map +0 -1
  207. package/dist/constants/traces.d.mts +0 -5
  208. package/dist/constants/traces.d.mts.map +0 -1
  209. package/dist/constants/traces.mjs +0 -6
  210. package/dist/constants/traces.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"BaseBip44AccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAAuD;AAEvD,uDAA4D;AAe5D;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,IAAA,4BAAc,EAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAND,oDAMC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,QAA0B;IAE1B,QAAQ,CAAC,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;SACT,CAAC,CACL,CAAC;QAEF,OAAO,MAAwB,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAClB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;YACzC,IAAI,EAAE,iCAAmB,CAAC,gBAAgB;YAC1C,aAAa;YACb,UAAU;SACX,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACzD,OAAO,UAAU,CAAC;IACpB,CAAC;CAqBF;AAjID,4DAiIC;;IAlGG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { AccountProvider, Bip44Account } from '@metamask/account-api';\nimport { AccountCreationType } from '@metamask/keyring-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\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 type Bip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> = AccountProvider<Account> & {\n /**\n * Provider capabilities, including supported scopes and BIP-44 options.\n *\n * @returns The provider capabilities.\n */\n get capabilities(): KeyringCapabilities;\n /**\n * Get the name of the provider.\n *\n * @returns The name of the provider.\n */\n getName(): string;\n /**\n * Initialize the provider with the given accounts.\n *\n * @param accounts - The accounts to initialize the provider with.\n */\n init(accounts: Bip44Account<KeyringAccount>['id'][]): void;\n /**\n * Check if the account is compatible with the provider.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n /**\n * Align the accounts with the given entropy source and group index.\n *\n * @param options - The options for aligning the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @returns The already and newly aligned accounts IDs.\n */\n alignAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account['id'][]>;\n /**\n * Create accounts for the provider.\n *\n * @param options - The options for creating the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @param options.type - The type of account creation.\n * @returns The created accounts.\n */\n createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n */\n resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;\n};\n\nexport abstract class BaseBip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> implements Bip44AccountProvider\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n protected accounts: Set<Bip44Account<KeyringAccount>['id']> = new Set();\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Add accounts to the provider.\n *\n * Note: There's an implicit assumption that the accounts are BIP-44 compatible.\n *\n * @param accounts - The accounts to add.\n */\n init(accounts: Account['id'][]): void {\n for (const account of accounts) {\n this.accounts.add(account);\n }\n }\n\n /**\n * Get the accounts list for the provider.\n *\n * @returns The accounts list.\n */\n #getAccountIds(): Account['id'][] {\n return [...this.accounts];\n }\n\n /**\n * Get the accounts list for the provider from the AccountsController.\n *\n * @returns The accounts list.\n */\n getAccounts(): Account[] {\n const accountsIds = this.#getAccountIds();\n const internalAccounts = this.messenger.call(\n 'AccountsController:getAccounts',\n accountsIds,\n );\n // we cast here because we know that the accounts are BIP-44 compatible\n return internalAccounts as unknown as Account[];\n }\n\n /**\n * Get the account for the provider.\n *\n * @param id - The account ID.\n * @returns The account.\n * @throws If the account is not found.\n */\n getAccount(id: Account['id']): Account {\n const hasAccount = this.accounts.has(id);\n\n if (!hasAccount) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n // We need to upcast here since InternalAccounts are not always BIP-44 compatible\n // but we know that the account is BIP-44 compatible here so it is safe to do so\n return this.messenger.call(\n 'AccountsController:getAccount',\n id,\n ) as unknown as Account;\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 async alignAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account['id'][]> {\n const accounts = await this.createAccounts({\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n const accountIds = accounts.map((account) => account.id);\n return accountIds;\n }\n\n abstract get capabilities(): KeyringCapabilities;\n\n abstract getName(): string;\n\n abstract resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void>;\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n\n abstract discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account[]>;\n}\n"]}
1
+ {"version":3,"file":"BaseBip44AccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAAuD;AAgBvD;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,IAAA,4BAAc,EAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAND,oDAMC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,QAA0B;IAE1B,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACzC,CAAC;AAJD,wDAIC;AA+CD,MAAsB,wBAAwB;IAQ5C,YAAY,SAA4C;;QAF9C,aAAQ,GAA4C,IAAI,GAAG,EAAE,CAAC;QAGtE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,IAAI,CAAC,QAAyB;QAC5B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAWD;;;;OAIG;IACH,WAAW;QACT,MAAM,WAAW,GAAG,uBAAA,IAAI,oFAAe,MAAnB,IAAI,CAAiB,CAAC;QAC1C,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAC1C,gCAAgC,EAChC,WAAW,CACZ,CAAC;QACF,uEAAuE;QACvE,OAAO,gBAAwC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,EAAiB;QAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEzC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC;QAED,iFAAiF;QACjF,gFAAgF;QAChF,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CACxB,+BAA+B,EAC/B,EAAE,CACmB,CAAC;IAC1B,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;CAqBF;AAjHD,4DAiHC;;IAlFG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { AccountProvider, Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\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 type Bip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> = AccountProvider<Account> & {\n /**\n * Provider capabilities, including supported scopes and BIP-44 options.\n *\n * @returns The provider capabilities.\n */\n get capabilities(): KeyringCapabilities;\n /**\n * Get the name of the provider.\n *\n * @returns The name of the provider.\n */\n getName(): string;\n /**\n * Initialize the provider with the given accounts.\n *\n * @param accounts - The accounts to initialize the provider with.\n */\n init(accounts: Bip44Account<KeyringAccount>['id'][]): void;\n /**\n * Check if the account is compatible with the provider.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n /**\n * Create accounts for the provider.\n *\n * @param options - The options for creating the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @param options.type - The type of account creation.\n * @returns The created accounts.\n */\n createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n */\n resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;\n};\n\nexport abstract class BaseBip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> implements Bip44AccountProvider<Account>\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n protected accounts: Set<Bip44Account<KeyringAccount>['id']> = new Set();\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Add accounts to the provider.\n *\n * Note: There's an implicit assumption that the accounts are BIP-44 compatible.\n *\n * @param accounts - The accounts to add.\n */\n init(accounts: Account['id'][]): void {\n for (const account of accounts) {\n this.accounts.add(account);\n }\n }\n\n /**\n * Get the accounts list for the provider.\n *\n * @returns The accounts list.\n */\n #getAccountIds(): Account['id'][] {\n return [...this.accounts];\n }\n\n /**\n * Get the accounts list for the provider from the AccountsController.\n *\n * @returns The accounts list.\n */\n getAccounts(): Account[] {\n const accountsIds = this.#getAccountIds();\n const internalAccounts = this.messenger.call(\n 'AccountsController:getAccounts',\n accountsIds,\n );\n // we cast here because we know that the accounts are BIP-44 compatible\n return internalAccounts as unknown as Account[];\n }\n\n /**\n * Get the account for the provider.\n *\n * @param id - The account ID.\n * @returns The account.\n * @throws If the account is not found.\n */\n getAccount(id: Account['id']): Account {\n const hasAccount = this.accounts.has(id);\n\n if (!hasAccount) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n // We need to upcast here since InternalAccounts are not always BIP-44 compatible\n // but we know that the account is BIP-44 compatible here so it is safe to do so\n return this.messenger.call(\n 'AccountsController:getAccount',\n id,\n ) as unknown as Account;\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 get capabilities(): KeyringCapabilities;\n\n abstract getName(): string;\n\n abstract resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void>;\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n\n abstract discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account[]>;\n}\n"]}
@@ -40,18 +40,6 @@ export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> =
40
40
  * Check if the account is compatible with the provider.
41
41
  */
42
42
  isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;
43
- /**
44
- * Align the accounts with the given entropy source and group index.
45
- *
46
- * @param options - The options for aligning the accounts.
47
- * @param options.entropySource - The entropy source.
48
- * @param options.groupIndex - The group index.
49
- * @returns The already and newly aligned accounts IDs.
50
- */
51
- alignAccounts({ entropySource, groupIndex, }: {
52
- entropySource: EntropySourceId;
53
- groupIndex: number;
54
- }): Promise<Account['id'][]>;
55
43
  /**
56
44
  * Create accounts for the provider.
57
45
  *
@@ -71,7 +59,7 @@ export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> =
71
59
  */
72
60
  resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
73
61
  };
74
- export declare abstract class BaseBip44AccountProvider<Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>> implements Bip44AccountProvider {
62
+ export declare abstract class BaseBip44AccountProvider<Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>> implements Bip44AccountProvider<Account> {
75
63
  #private;
76
64
  protected readonly messenger: MultichainAccountServiceMessenger;
77
65
  protected accounts: Set<Bip44Account<KeyringAccount>['id']>;
@@ -102,10 +90,6 @@ export declare abstract class BaseBip44AccountProvider<Account extends Bip44Acco
102
90
  keyring: SelectedKeyring;
103
91
  metadata: KeyringMetadata;
104
92
  }) => Promise<CallbackResult>): Promise<CallbackResult>;
105
- alignAccounts({ entropySource, groupIndex, }: {
106
- entropySource: EntropySourceId;
107
- groupIndex: number;
108
- }): Promise<Account['id'][]>;
109
93
  abstract get capabilities(): KeyringCapabilities;
110
94
  abstract getName(): string;
111
95
  abstract resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"BaseBip44AccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,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,CAAC,GAC5B,OAAO,CAAC,cAAc,CAAC;IAc1B,QAAQ,KAAK,YAAY,IAAI,mBAAmB,CAAC;IAEjD,QAAQ,CAAC,OAAO,IAAI,MAAM;IAE1B,QAAQ,CAAC,cAAc,CACrB,QAAQ,EAAE,YAAY,CAAC,eAAe,CAAC,EAAE,GACxC,OAAO,CAAC,IAAI,CAAC;IAEhB,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO;IAE5E,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAE1E,QAAQ,CAAC,gBAAgB,CAAC,EACxB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CACvB"}
@@ -40,18 +40,6 @@ export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> =
40
40
  * Check if the account is compatible with the provider.
41
41
  */
42
42
  isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;
43
- /**
44
- * Align the accounts with the given entropy source and group index.
45
- *
46
- * @param options - The options for aligning the accounts.
47
- * @param options.entropySource - The entropy source.
48
- * @param options.groupIndex - The group index.
49
- * @returns The already and newly aligned accounts IDs.
50
- */
51
- alignAccounts({ entropySource, groupIndex, }: {
52
- entropySource: EntropySourceId;
53
- groupIndex: number;
54
- }): Promise<Account['id'][]>;
55
43
  /**
56
44
  * Create accounts for the provider.
57
45
  *
@@ -71,7 +59,7 @@ export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> =
71
59
  */
72
60
  resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
73
61
  };
74
- export declare abstract class BaseBip44AccountProvider<Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>> implements Bip44AccountProvider {
62
+ export declare abstract class BaseBip44AccountProvider<Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>> implements Bip44AccountProvider<Account> {
75
63
  #private;
76
64
  protected readonly messenger: MultichainAccountServiceMessenger;
77
65
  protected accounts: Set<Bip44Account<KeyringAccount>['id']>;
@@ -102,10 +90,6 @@ export declare abstract class BaseBip44AccountProvider<Account extends Bip44Acco
102
90
  keyring: SelectedKeyring;
103
91
  metadata: KeyringMetadata;
104
92
  }) => Promise<CallbackResult>): Promise<CallbackResult>;
105
- alignAccounts({ entropySource, groupIndex, }: {
106
- entropySource: EntropySourceId;
107
- groupIndex: number;
108
- }): Promise<Account['id'][]>;
109
93
  abstract get capabilities(): KeyringCapabilities;
110
94
  abstract getName(): string;
111
95
  abstract resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"BaseBip44AccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,8BAA8B;AAE3E,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAC/B,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAChB,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,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,MAAM,MAAM,oBAAoB,CAC9B,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,GAAG,YAAY,C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@ -5,7 +5,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
5
5
  };
6
6
  var _BaseBip44AccountProvider_instances, _BaseBip44AccountProvider_getAccountIds;
7
7
  import { isBip44Account } from "@metamask/account-api";
8
- import { AccountCreationType } from "@metamask/keyring-api";
9
8
  /**
10
9
  * Asserts a keyring account is BIP-44 compatible.
11
10
  *
@@ -78,15 +77,6 @@ export class BaseBip44AccountProvider {
78
77
  }));
79
78
  return result;
80
79
  }
81
- async alignAccounts({ entropySource, groupIndex, }) {
82
- const accounts = await this.createAccounts({
83
- type: AccountCreationType.Bip44DeriveIndex,
84
- entropySource,
85
- groupIndex,
86
- });
87
- const accountIds = accounts.map((account) => account.id);
88
- return accountIds;
89
- }
90
80
  }
91
81
  _BaseBip44AccountProvider_instances = new WeakSet(), _BaseBip44AccountProvider_getAccountIds = function _BaseBip44AccountProvider_getAccountIds() {
92
82
  return [...this.accounts];
@@ -1 +1 @@
1
- {"version":3,"file":"BaseBip44AccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAEvD,OAAO,EAAE,mBAAmB,EAAE,8BAA8B;AAe5D;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA0B;IAE1B,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACzC,CAAC;AA8DD,MAAM,OAAgB,wBAAwB;IAQ5C,YAAY,SAA4C;;QAF9C,aAAQ,GAA4C,IAAI,GAAG,EAAE,CAAC;QAGtE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CA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AC,gBAAgB;YAC1C,aAAa;YACb,UAAU;SACX,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACzD,OAAO,UAAU,CAAC;IACpB,CAAC;CAqBF;;IAlGG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { AccountProvider, Bip44Account } from '@metamask/account-api';\nimport { AccountCreationType } from '@metamask/keyring-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\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 type Bip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> = AccountProvider<Account> & {\n /**\n * Provider capabilities, including supported scopes and BIP-44 options.\n *\n * @returns The provider capabilities.\n */\n get capabilities(): KeyringCapabilities;\n /**\n * Get the name of the provider.\n *\n * @returns The name of the provider.\n */\n getName(): string;\n /**\n * Initialize the provider with the given accounts.\n *\n * @param accounts - The accounts to initialize the provider with.\n */\n init(accounts: Bip44Account<KeyringAccount>['id'][]): void;\n /**\n * Check if the account is compatible with the provider.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n /**\n * Align the accounts with the given entropy source and group index.\n *\n * @param options - The options for aligning the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @returns The already and newly aligned accounts IDs.\n */\n alignAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account['id'][]>;\n /**\n * Create accounts for the provider.\n *\n * @param options - The options for creating the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @param options.type - The type of account creation.\n * @returns The created accounts.\n */\n createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n */\n resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;\n};\n\nexport abstract class BaseBip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> implements Bip44AccountProvider\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n protected accounts: Set<Bip44Account<KeyringAccount>['id']> = new Set();\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Add accounts to the provider.\n *\n * Note: There's an implicit assumption that the accounts are BIP-44 compatible.\n *\n * @param accounts - The accounts to add.\n */\n init(accounts: Account['id'][]): void {\n for (const account of accounts) {\n this.accounts.add(account);\n }\n }\n\n /**\n * Get the accounts list for the provider.\n *\n * @returns The accounts list.\n */\n #getAccountIds(): Account['id'][] {\n return [...this.accounts];\n }\n\n /**\n * Get the accounts list for the provider from the AccountsController.\n *\n * @returns The accounts list.\n */\n getAccounts(): Account[] {\n const accountsIds = this.#getAccountIds();\n const internalAccounts = this.messenger.call(\n 'AccountsController:getAccounts',\n accountsIds,\n );\n // we cast here because we know that the accounts are BIP-44 compatible\n return internalAccounts as unknown as Account[];\n }\n\n /**\n * Get the account for the provider.\n *\n * @param id - The account ID.\n * @returns The account.\n * @throws If the account is not found.\n */\n getAccount(id: Account['id']): Account {\n const hasAccount = this.accounts.has(id);\n\n if (!hasAccount) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n // We need to upcast here since InternalAccounts are not always BIP-44 compatible\n // but we know that the account is BIP-44 compatible here so it is safe to do so\n return this.messenger.call(\n 'AccountsController:getAccount',\n id,\n ) as unknown as Account;\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 async alignAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account['id'][]> {\n const accounts = await this.createAccounts({\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n const accountIds = accounts.map((account) => account.id);\n return accountIds;\n }\n\n abstract get capabilities(): KeyringCapabilities;\n\n abstract getName(): string;\n\n abstract resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void>;\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n\n abstract discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account[]>;\n}\n"]}
1
+ {"version":3,"file":"BaseBip44AccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/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AAO,IAAI,CAAC,SAAS,CAAC,IAAI,CACxB,+BAA+B,EAC/B,EAAE,CACmB,CAAC;IAC1B,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;CAqBF;;IAlFG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { AccountProvider, Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\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 type Bip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> = AccountProvider<Account> & {\n /**\n * Provider capabilities, including supported scopes and BIP-44 options.\n *\n * @returns The provider capabilities.\n */\n get capabilities(): KeyringCapabilities;\n /**\n * Get the name of the provider.\n *\n * @returns The name of the provider.\n */\n getName(): string;\n /**\n * Initialize the provider with the given accounts.\n *\n * @param accounts - The accounts to initialize the provider with.\n */\n init(accounts: Bip44Account<KeyringAccount>['id'][]): void;\n /**\n * Check if the account is compatible with the provider.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n /**\n * Create accounts for the provider.\n *\n * @param options - The options for creating the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @param options.type - The type of account creation.\n * @returns The created accounts.\n */\n createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n */\n resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;\n};\n\nexport abstract class BaseBip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> implements Bip44AccountProvider<Account>\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n protected accounts: Set<Bip44Account<KeyringAccount>['id']> = new Set();\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Add accounts to the provider.\n *\n * Note: There's an implicit assumption that the accounts are BIP-44 compatible.\n *\n * @param accounts - The accounts to add.\n */\n init(accounts: Account['id'][]): void {\n for (const account of accounts) {\n this.accounts.add(account);\n }\n }\n\n /**\n * Get the accounts list for the provider.\n *\n * @returns The accounts list.\n */\n #getAccountIds(): Account['id'][] {\n return [...this.accounts];\n }\n\n /**\n * Get the accounts list for the provider from the AccountsController.\n *\n * @returns The accounts list.\n */\n getAccounts(): Account[] {\n const accountsIds = this.#getAccountIds();\n const internalAccounts = this.messenger.call(\n 'AccountsController:getAccounts',\n accountsIds,\n );\n // we cast here because we know that the accounts are BIP-44 compatible\n return internalAccounts as unknown as Account[];\n }\n\n /**\n * Get the account for the provider.\n *\n * @param id - The account ID.\n * @returns The account.\n * @throws If the account is not found.\n */\n getAccount(id: Account['id']): Account {\n const hasAccount = this.accounts.has(id);\n\n if (!hasAccount) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n // We need to upcast here since InternalAccounts are not always BIP-44 compatible\n // but we know that the account is BIP-44 compatible here so it is safe to do so\n return this.messenger.call(\n 'AccountsController:getAccount',\n id,\n ) as unknown as Account;\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 get capabilities(): KeyringCapabilities;\n\n abstract getName(): string;\n\n abstract resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void>;\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n\n abstract discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account[]>;\n}\n"]}
@@ -1,22 +1,16 @@
1
1
  "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var _BtcAccountProvider_instances, _BtcAccountProvider_createAccounts;
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
9
3
  exports.BtcAccountProvider = exports.BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG = exports.BTC_ACCOUNT_PROVIDER_NAME = void 0;
10
- const account_api_1 = require("@metamask/account-api");
11
4
  const keyring_api_1 = require("@metamask/keyring-api");
12
5
  const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
13
6
  const utils_1 = require("./utils.cjs");
14
7
  const analytics_1 = require("../analytics/index.cjs");
15
- const traces_1 = require("../constants/traces.cjs");
8
+ const traces_1 = require("../analytics/traces.cjs");
16
9
  exports.BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';
17
10
  exports.BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
18
11
  maxConcurrency: 3,
19
12
  createAccounts: {
13
+ batched: false, // For now, the Snap is not fully v2 compliant.
20
14
  timeoutMs: 3000,
21
15
  },
22
16
  discovery: {
@@ -25,15 +19,18 @@ exports.BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
25
19
  maxAttempts: 3,
26
20
  backOffMs: 1000,
27
21
  },
22
+ resyncAccounts: {
23
+ autoRemoveExtraSnapAccounts: true,
24
+ },
28
25
  };
29
26
  class BtcAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
30
27
  constructor(messenger, config = exports.BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = analytics_1.traceFallback) {
31
28
  super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);
32
- _BtcAccountProvider_instances.add(this);
33
29
  this.capabilities = {
34
30
  scopes: [keyring_api_1.BtcScope.Mainnet, keyring_api_1.BtcScope.Testnet],
35
31
  bip44: {
36
32
  deriveIndex: true,
33
+ deriveIndexRange: true,
37
34
  },
38
35
  };
39
36
  }
@@ -44,13 +41,12 @@ class BtcAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
44
41
  return (account.type === keyring_api_1.BtcAccountType.P2wpkh &&
45
42
  Object.values(keyring_api_1.BtcAccountType).includes(account.type));
46
43
  }
47
- async createAccounts(options) {
48
- (0, keyring_api_1.assertCreateAccountOptionIsSupported)(options, [
49
- `${keyring_api_1.AccountCreationType.Bip44DeriveIndex}`,
50
- ]);
51
- const { entropySource, groupIndex } = options;
52
- return this.withSnap(async ({ keyring }) => {
53
- return __classPrivateFieldGet(this, _BtcAccountProvider_instances, "m", _BtcAccountProvider_createAccounts).call(this, { keyring, entropySource, groupIndex });
44
+ createAccountV1(keyring, { entropySource, groupIndex, }) {
45
+ return keyring.createAccount({
46
+ entropySource,
47
+ index: groupIndex,
48
+ addressType: keyring_api_1.BtcAccountType.P2wpkh,
49
+ scope: keyring_api_1.BtcScope.Mainnet,
54
50
  });
55
51
  }
56
52
  async discoverAccounts({ entropySource, groupIndex, }) {
@@ -64,7 +60,7 @@ class BtcAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
64
60
  if (!this.config.discovery.enabled) {
65
61
  return [];
66
62
  }
67
- const discoveredAccounts = await (0, utils_1.withRetry)(() => (0, utils_1.withTimeout)(client.discoverAccounts([keyring_api_1.BtcScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
63
+ const discoveredAccounts = await (0, utils_1.withRetry)(() => (0, utils_1.withTimeout)(() => client.discoverAccounts([keyring_api_1.BtcScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
68
64
  maxAttempts: this.config.discovery.maxAttempts,
69
65
  backOffMs: this.config.discovery.backOffMs,
70
66
  });
@@ -72,30 +68,16 @@ class BtcAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
72
68
  discoveredAccounts.length === 0) {
73
69
  return [];
74
70
  }
75
- const createdAccounts = await __classPrivateFieldGet(this, _BtcAccountProvider_instances, "m", _BtcAccountProvider_createAccounts).call(this, {
76
- keyring,
71
+ return await this.createBip44Accounts(keyring, {
72
+ type: keyring_api_1.AccountCreationType.Bip44DeriveIndex,
77
73
  entropySource,
78
74
  groupIndex,
79
75
  });
80
- return createdAccounts;
81
76
  });
82
77
  });
83
78
  }
84
79
  }
85
80
  exports.BtcAccountProvider = BtcAccountProvider;
86
- _BtcAccountProvider_instances = new WeakSet(), _BtcAccountProvider_createAccounts = async function _BtcAccountProvider_createAccounts({ keyring, entropySource, groupIndex: index, }) {
87
- return this.withMaxConcurrency(async () => {
88
- const account = await (0, utils_1.withTimeout)(keyring.createAccount({
89
- entropySource,
90
- index,
91
- addressType: keyring_api_1.BtcAccountType.P2wpkh,
92
- scope: keyring_api_1.BtcScope.Mainnet,
93
- }), this.config.createAccounts.timeoutMs);
94
- (0, account_api_1.assertIsBip44Account)(account);
95
- this.accounts.add(account.id);
96
- return [account];
97
- });
98
- };
99
81
  BtcAccountProvider.NAME = exports.BTC_ACCOUNT_PROVIDER_NAME;
100
82
  BtcAccountProvider.BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap';
101
83
  //# sourceMappingURL=BtcAccountProvider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAA6D;AAS7D,uDAK+B;AAI/B,mEAA4D;AAK5D,uCAAiD;AACjD,sDAA6C;AAC7C,oDAAgD;AAKnC,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEtC,QAAA,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE;QACd,SAAS,EAAE,IAAI;KAChB;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,yCAAmB;IAYzD,YACE,SAA4C,EAC5C,SAAmC,2CAAmC,EACtE,QAAuB,yBAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,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O,CAAC,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAtDM,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n assertCreateAccountOptionIsSupported,\n BtcAccountType,\n BtcScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../constants/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [BtcScope.Mainnet, BtcScope.Testnet],\n bip44: {\n deriveIndex: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n async #createAccounts({\n keyring,\n entropySource,\n groupIndex: index,\n }: {\n keyring: RestrictedSnapKeyring;\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const account = await withTimeout(\n keyring.createAccount({\n entropySource,\n index,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n this.accounts.add(account.id);\n return [account];\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n assertCreateAccountOptionIsSupported(options, [\n `${AccountCreationType.Bip44DeriveIndex}`,\n ]);\n\n const { entropySource, groupIndex } = options;\n\n return this.withSnap(async ({ keyring }) => {\n return this.#createAccounts({ keyring, entropySource, groupIndex });\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ client, keyring }) => {\n return await super.trace(\n {\n name: TraceName.SnapDiscoverAccounts,\n data: {\n provider: this.getName(),\n },\n },\n async () => {\n if (!this.config.discovery.enabled) {\n return [];\n }\n\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n const createdAccounts = await this.#createAccounts({\n keyring,\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"BtcAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;AAOA,uDAI+B;AAI/B,mEAA4D;AAK5D,uCAAiD;AACjD,sDAA6C;AAC7C,oDAAgD;AAKnC,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEtC,QAAA,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE;QACd,OAAO,EAAE,KAAK,EAAE,+CAA+C;QAC/D,SAAS,EAAE,IAAI;KAChB;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,yCAAmB;IAazD,YACE,SAA4C,EAC5C,SAAmC,2CAAmC,EACtE,QAAuB,yBAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAbzD,iBAAY,GAAwB;YAC3C,MAAM,EAAE,CAAC,sBAAQ,CAAC,OAAO,EAAE,sBAAQ,CAAC,OAAO,CAAC;YAC5C,KAAK,EAAE;gBACL,WAAW,EAAE,IAAI;gBACjB,gBAAgB,EAAE,IAAI;aACvB;SACF,CAAC;IAQF,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO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;gBAEF,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;oBAClC,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAC/B,CAAC;oBACD,OAAO,EAAE,CAAC;gBACZ,CAAC;gBAED,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE;oBAC7C,IAAI,EAAE,iCAAmB,CAAC,gBAAgB;oBAC1C,aAAa;oBACb,UAAU;iBACX,CAAC,CAAC;YACL,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;AAnGH,gDAoGC;AAnGQ,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type {\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n BtcAccountType,\n BtcScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../analytics/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n batched: false, // For now, the Snap is not fully v2 compliant.\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [BtcScope.Mainnet, BtcScope.Testnet],\n bip44: {\n deriveIndex: true,\n deriveIndexRange: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n protected override createAccountV1(\n keyring: RestrictedSnapKeyring,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Promise<KeyringAccount> {\n return keyring.createAccount({\n entropySource,\n index: groupIndex,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ client, keyring }) => {\n return await super.trace(\n {\n name: TraceName.SnapDiscoverAccounts,\n data: {\n provider: this.getName(),\n },\n },\n async () => {\n if (!this.config.discovery.enabled) {\n return [];\n }\n\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n () =>\n client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n return await this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n );\n });\n }\n}\n"]}
@@ -1,23 +1,25 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
2
  import type { TraceCallback } from "@metamask/controller-utils";
3
- import type { CreateAccountOptions, EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
3
+ import type { EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
4
4
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
5
  import type { SnapId } from "@metamask/snaps-sdk";
6
6
  import { SnapAccountProvider } from "./SnapAccountProvider.cjs";
7
- import type { SnapAccountProviderConfig } from "./SnapAccountProvider.cjs";
7
+ import type { RestrictedSnapKeyring, SnapAccountProviderConfig } from "./SnapAccountProvider.cjs";
8
8
  import type { MultichainAccountServiceMessenger } from "../types.cjs";
9
9
  export type BtcAccountProviderConfig = SnapAccountProviderConfig;
10
10
  export declare const BTC_ACCOUNT_PROVIDER_NAME = "Bitcoin";
11
11
  export declare const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig;
12
12
  export declare class BtcAccountProvider extends SnapAccountProvider {
13
- #private;
14
13
  static NAME: string;
15
14
  static BTC_SNAP_ID: SnapId;
16
15
  readonly capabilities: KeyringCapabilities;
17
16
  constructor(messenger: MultichainAccountServiceMessenger, config?: BtcAccountProviderConfig, trace?: TraceCallback);
18
17
  getName(): string;
19
18
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
20
- createAccounts(options: CreateAccountOptions): Promise<Bip44Account<KeyringAccount>[]>;
19
+ protected createAccountV1(keyring: RestrictedSnapKeyring, { entropySource, groupIndex, }: {
20
+ entropySource: EntropySourceId;
21
+ groupIndex: number;
22
+ }): Promise<KeyringAccount>;
21
23
  discoverAccounts({ entropySource, groupIndex, }: {
22
24
  entropySource: EntropySourceId;
23
25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C/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CA+C5C"}
@@ -1,23 +1,25 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
2
  import type { TraceCallback } from "@metamask/controller-utils";
3
- import type { CreateAccountOptions, EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
3
+ import type { EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
4
4
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
5
  import type { SnapId } from "@metamask/snaps-sdk";
6
6
  import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
7
- import type { SnapAccountProviderConfig } from "./SnapAccountProvider.mjs";
7
+ import type { RestrictedSnapKeyring, SnapAccountProviderConfig } from "./SnapAccountProvider.mjs";
8
8
  import type { MultichainAccountServiceMessenger } from "../types.mjs";
9
9
  export type BtcAccountProviderConfig = SnapAccountProviderConfig;
10
10
  export declare const BTC_ACCOUNT_PROVIDER_NAME = "Bitcoin";
11
11
  export declare const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig;
12
12
  export declare class BtcAccountProvider extends SnapAccountProvider {
13
- #private;
14
13
  static NAME: string;
15
14
  static BTC_SNAP_ID: SnapId;
16
15
  readonly capabilities: KeyringCapabilities;
17
16
  constructor(messenger: MultichainAccountServiceMessenger, config?: BtcAccountProviderConfig, trace?: TraceCallback);
18
17
  getName(): string;
19
18
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
20
- createAccounts(options: CreateAccountOptions): Promise<Bip44Account<KeyringAccount>[]>;
19
+ protected createAccountV1(keyring: RestrictedSnapKeyring, { entropySource, groupIndex, }: {
20
+ entropySource: EntropySourceId;
21
+ groupIndex: number;
22
+ }): Promise<KeyringAccount>;
21
23
  discoverAccounts({ entropySource, groupIndex, }: {
22
24
  entropySource: EntropySourceId;
23
25
  groupIndex: number;
@@ -1 +1 @@
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;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CA+C5C"}
@@ -1,19 +1,13 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _BtcAccountProvider_instances, _BtcAccountProvider_createAccounts;
7
- import { assertIsBip44Account } from "@metamask/account-api";
8
- import { AccountCreationType, assertCreateAccountOptionIsSupported, BtcAccountType, BtcScope } from "@metamask/keyring-api";
1
+ import { AccountCreationType, BtcAccountType, BtcScope } from "@metamask/keyring-api";
9
2
  import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
10
3
  import { withRetry, withTimeout } from "./utils.mjs";
11
4
  import { traceFallback } from "../analytics/index.mjs";
12
- import { TraceName } from "../constants/traces.mjs";
5
+ import { TraceName } from "../analytics/traces.mjs";
13
6
  export const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';
14
7
  export const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
15
8
  maxConcurrency: 3,
16
9
  createAccounts: {
10
+ batched: false, // For now, the Snap is not fully v2 compliant.
17
11
  timeoutMs: 3000,
18
12
  },
19
13
  discovery: {
@@ -22,15 +16,18 @@ export const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
22
16
  maxAttempts: 3,
23
17
  backOffMs: 1000,
24
18
  },
19
+ resyncAccounts: {
20
+ autoRemoveExtraSnapAccounts: true,
21
+ },
25
22
  };
26
23
  export class BtcAccountProvider extends SnapAccountProvider {
27
24
  constructor(messenger, config = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = traceFallback) {
28
25
  super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);
29
- _BtcAccountProvider_instances.add(this);
30
26
  this.capabilities = {
31
27
  scopes: [BtcScope.Mainnet, BtcScope.Testnet],
32
28
  bip44: {
33
29
  deriveIndex: true,
30
+ deriveIndexRange: true,
34
31
  },
35
32
  };
36
33
  }
@@ -41,13 +38,12 @@ export class BtcAccountProvider extends SnapAccountProvider {
41
38
  return (account.type === BtcAccountType.P2wpkh &&
42
39
  Object.values(BtcAccountType).includes(account.type));
43
40
  }
44
- async createAccounts(options) {
45
- assertCreateAccountOptionIsSupported(options, [
46
- `${AccountCreationType.Bip44DeriveIndex}`,
47
- ]);
48
- const { entropySource, groupIndex } = options;
49
- return this.withSnap(async ({ keyring }) => {
50
- return __classPrivateFieldGet(this, _BtcAccountProvider_instances, "m", _BtcAccountProvider_createAccounts).call(this, { keyring, entropySource, groupIndex });
41
+ createAccountV1(keyring, { entropySource, groupIndex, }) {
42
+ return keyring.createAccount({
43
+ entropySource,
44
+ index: groupIndex,
45
+ addressType: BtcAccountType.P2wpkh,
46
+ scope: BtcScope.Mainnet,
51
47
  });
52
48
  }
53
49
  async discoverAccounts({ entropySource, groupIndex, }) {
@@ -61,7 +57,7 @@ export class BtcAccountProvider extends SnapAccountProvider {
61
57
  if (!this.config.discovery.enabled) {
62
58
  return [];
63
59
  }
64
- const discoveredAccounts = await withRetry(() => withTimeout(client.discoverAccounts([BtcScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
60
+ const discoveredAccounts = await withRetry(() => withTimeout(() => client.discoverAccounts([BtcScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
65
61
  maxAttempts: this.config.discovery.maxAttempts,
66
62
  backOffMs: this.config.discovery.backOffMs,
67
63
  });
@@ -69,29 +65,15 @@ export class BtcAccountProvider extends SnapAccountProvider {
69
65
  discoveredAccounts.length === 0) {
70
66
  return [];
71
67
  }
72
- const createdAccounts = await __classPrivateFieldGet(this, _BtcAccountProvider_instances, "m", _BtcAccountProvider_createAccounts).call(this, {
73
- keyring,
68
+ return await this.createBip44Accounts(keyring, {
69
+ type: AccountCreationType.Bip44DeriveIndex,
74
70
  entropySource,
75
71
  groupIndex,
76
72
  });
77
- return createdAccounts;
78
73
  });
79
74
  });
80
75
  }
81
76
  }
82
- _BtcAccountProvider_instances = new WeakSet(), _BtcAccountProvider_createAccounts = async function _BtcAccountProvider_createAccounts({ keyring, entropySource, groupIndex: index, }) {
83
- return this.withMaxConcurrency(async () => {
84
- const account = await withTimeout(keyring.createAccount({
85
- entropySource,
86
- index,
87
- addressType: BtcAccountType.P2wpkh,
88
- scope: BtcScope.Mainnet,
89
- }), this.config.createAccounts.timeoutMs);
90
- assertIsBip44Account(account);
91
- this.accounts.add(account.id);
92
- return [account];
93
- });
94
- };
95
77
  BtcAccountProvider.NAME = BTC_ACCOUNT_PROVIDER_NAME;
96
78
  BtcAccountProvider.BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap';
97
79
  //# sourceMappingURL=BtcAccountProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAS7D,OAAO,EACL,mBAAmB,EACnB,oCAAoC,EACpC,cAAc,EACd,QAAQ,EACT,8BAA8B;AAI/B,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAK5D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AACjD,OAAO,EAAE,aAAa,EAAE,+BAAqB;AAC7C,OAAO,EAAE,SAAS,EAAE,gCAA4B;AAKhD,MAAM,CAAC,MAAM,yBAAyB,GAAG,SAAS,CAAC;AAEnD,MAAM,CAAC,MAAM,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE;QACd,SAAS,EAAE,IAAI;KAChB;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAA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;YACb,KAAK;YACL,WAAW,EAAE,cAAc,CAAC,MAAM;YAClC,KAAK,EAAE,QAAQ,CAAC,OAAO;SACxB,CAAC,EACF,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CACrC,CAAC;QAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAtDM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n assertCreateAccountOptionIsSupported,\n BtcAccountType,\n BtcScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../constants/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [BtcScope.Mainnet, BtcScope.Testnet],\n bip44: {\n deriveIndex: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n async #createAccounts({\n keyring,\n entropySource,\n groupIndex: index,\n }: {\n keyring: RestrictedSnapKeyring;\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const account = await withTimeout(\n keyring.createAccount({\n entropySource,\n index,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n this.accounts.add(account.id);\n return [account];\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n assertCreateAccountOptionIsSupported(options, [\n `${AccountCreationType.Bip44DeriveIndex}`,\n ]);\n\n const { entropySource, groupIndex } = options;\n\n return this.withSnap(async ({ keyring }) => {\n return this.#createAccounts({ keyring, entropySource, groupIndex });\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ client, keyring }) => {\n return await super.trace(\n {\n name: TraceName.SnapDiscoverAccounts,\n data: {\n provider: this.getName(),\n },\n },\n async () => {\n if (!this.config.discovery.enabled) {\n return [];\n }\n\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n const createdAccounts = await this.#createAccounts({\n keyring,\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"BtcAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACT,8BAA8B;AAI/B,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAK5D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AACjD,OAAO,EAAE,aAAa,EAAE,+BAAqB;AAC7C,OAAO,EAAE,SAAS,EAAE,gCAA4B;AAKhD,MAAM,CAAC,MAAM,yBAAyB,GAAG,SAAS,CAAC;AAEnD,MAAM,CAAC,MAAM,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE;QACd,OAAO,EAAE,KAAK,EAAE,+CAA+C;QAC/D,SAAS,EAAE,IAAI;KAChB;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IAazD,YACE,SAA4C,EAC5C,SAAmC,mCAAmC,EACtE,QAAuB,aAAa;QAEpC,KAAK,CAAC,k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SAAS,CACxC,GAAG,EAAE,CACH,WAAW,CACT,GAAG,EAAE,CACH,MAAM,CAAC,gBAAgB,CACrB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAClB,aAAa,EACb,UAAU,CACX,EACH,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAChC,EACH;oBACE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW;oBAC9C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS;iBAC3C,CACF,CAAC;gBAEF,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;oBAClC,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAC/B,CAAC;oBACD,OAAO,EAAE,CAAC;gBACZ,CAAC;gBAED,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE;oBAC7C,IAAI,EAAE,mBAAmB,CAAC,gBAAgB;oBAC1C,aAAa;oBACb,UAAU;iBACX,CAAC,CAAC;YACL,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;AAlGM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type {\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n BtcAccountType,\n BtcScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../analytics/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n batched: false, // For now, the Snap is not fully v2 compliant.\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [BtcScope.Mainnet, BtcScope.Testnet],\n bip44: {\n deriveIndex: true,\n deriveIndexRange: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n protected override createAccountV1(\n keyring: RestrictedSnapKeyring,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Promise<KeyringAccount> {\n return keyring.createAccount({\n entropySource,\n index: groupIndex,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ client, keyring }) => {\n return await super.trace(\n {\n name: TraceName.SnapDiscoverAccounts,\n data: {\n provider: this.getName(),\n },\n },\n async () => {\n if (!this.config.discovery.enabled) {\n return [];\n }\n\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n () =>\n client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n return await this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n );\n });\n }\n}\n"]}