@metamask-previews/multichain-account-service 0.9.0-preview-463efec → 0.9.0-preview-7e5cb81

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 (58) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/MultichainAccountService.cjs +4 -3
  3. package/dist/MultichainAccountService.cjs.map +1 -1
  4. package/dist/MultichainAccountService.d.cts +10 -3
  5. package/dist/MultichainAccountService.d.cts.map +1 -1
  6. package/dist/MultichainAccountService.d.mts +10 -3
  7. package/dist/MultichainAccountService.d.mts.map +1 -1
  8. package/dist/MultichainAccountService.mjs +4 -3
  9. package/dist/MultichainAccountService.mjs.map +1 -1
  10. package/dist/index.cjs +2 -1
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +1 -1
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +1 -1
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +1 -1
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/providers/EvmAccountProvider.cjs +28 -60
  19. package/dist/providers/EvmAccountProvider.cjs.map +1 -1
  20. package/dist/providers/EvmAccountProvider.d.cts +11 -0
  21. package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
  22. package/dist/providers/EvmAccountProvider.d.mts +11 -0
  23. package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
  24. package/dist/providers/EvmAccountProvider.mjs +27 -59
  25. package/dist/providers/EvmAccountProvider.mjs.map +1 -1
  26. package/dist/providers/SolAccountProvider.cjs +20 -6
  27. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  28. package/dist/providers/SolAccountProvider.d.cts +10 -1
  29. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  30. package/dist/providers/SolAccountProvider.d.mts +10 -1
  31. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  32. package/dist/providers/SolAccountProvider.mjs +19 -5
  33. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  34. package/dist/providers/index.cjs +4 -0
  35. package/dist/providers/index.cjs.map +1 -1
  36. package/dist/providers/index.d.cts +1 -0
  37. package/dist/providers/index.d.cts.map +1 -1
  38. package/dist/providers/index.d.mts +1 -0
  39. package/dist/providers/index.d.mts.map +1 -1
  40. package/dist/providers/index.mjs +2 -0
  41. package/dist/providers/index.mjs.map +1 -1
  42. package/dist/providers/utils.cjs +66 -0
  43. package/dist/providers/utils.cjs.map +1 -0
  44. package/dist/providers/utils.d.cts +27 -0
  45. package/dist/providers/utils.d.cts.map +1 -0
  46. package/dist/providers/utils.d.mts +27 -0
  47. package/dist/providers/utils.d.mts.map +1 -0
  48. package/dist/providers/utils.mjs +60 -0
  49. package/dist/providers/utils.mjs.map +1 -0
  50. package/dist/tests/providers.cjs +1 -0
  51. package/dist/tests/providers.cjs.map +1 -1
  52. package/dist/tests/providers.d.cts +1 -0
  53. package/dist/tests/providers.d.cts.map +1 -1
  54. package/dist/tests/providers.d.mts +1 -0
  55. package/dist/tests/providers.d.mts.map +1 -1
  56. package/dist/tests/providers.mjs +1 -0
  57. package/dist/tests/providers.mjs.map +1 -1
  58. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"EvmAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAEA,uDAAuD;AACvD,qEAA4D;AAQ5D,6EAIoC;AAEpC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAEnC;;;;;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,mDAAwB;IAAhE;;;IA8NA,CAAC;IA7NC,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ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AAM,KAAK,GAAG,OAAO,CAAC;YACtB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC,CAAC;SACd;KACF;IACD,MAAM,SAAS,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,KAAK,0CACH,OAAmB,EACnB,YAAoB,GAAG;IAEvB,IAAI,KAAK,CAAC;IACV,IAAI;QACF,OAAO,MAAM,OAAO,CAAC,IAAI,CAAI;YAC3B,OAAO;YACP,IAAI,OAAO,CAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;gBAClC,KAAK,GAAG,UAAU,CAChB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;KACJ;YAAS;QACR,IAAI,KAAK,EAAE;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;SACrB;KACF;AACH,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } 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 { Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n assertAreBip44Accounts,\n assertIsBip44Account,\n BaseBip44AccountProvider,\n} from './BaseBip44AccountProvider';\n\nconst ETH_MAINNET_CHAIN_ID = '0x1';\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 BaseBip44AccountProvider {\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 getName(): string {\n return 'EVM';\n }\n\n /**\n * Get the EVM provider.\n *\n * @returns The EVM provider.\n */\n getEvmProvider(): Provider {\n const networkClientId = this.messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n ETH_MAINNET_CHAIN_ID,\n );\n const { provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return provider;\n }\n\n async #createAccount({\n entropySource,\n groupIndex,\n throwOnGap = false,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n throwOnGap?: boolean;\n }): Promise<[Hex, boolean]> {\n const result = await this.withKeyring<EthKeyring, [Hex, boolean]>(\n { id: entropySource },\n async ({ keyring }) => {\n const existing = await keyring.getAccounts();\n if (groupIndex < existing.length) {\n return [existing[groupIndex], false];\n }\n\n // If the throwOnGap flag is set, we throw an error to prevent index gaps.\n if (throwOnGap && groupIndex !== existing.length) {\n throw new Error('Trying to create too many accounts');\n }\n\n const [added] = await keyring.addAccounts(1);\n return [added, true];\n },\n );\n\n return result;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const [address] = await this.#createAccount({\n entropySource,\n groupIndex,\n throwOnGap: true,\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\n const accountsArray = [account];\n assertAreBip44Accounts(accountsArray);\n\n return accountsArray;\n }\n\n async #getTransactionCount(\n provider: Provider,\n address: Hex,\n ): Promise<number> {\n const countHex = await this.#withRetry<Hex>(() =>\n this.#withTimeout(\n provider.request({\n method: 'eth_getTransactionCount',\n params: [address, 'latest'],\n }),\n ),\n );\n\n return parseInt(countHex, 16);\n }\n\n /**\n * Discover and create accounts for the EVM provider.\n *\n * @param opts - The options for the discovery and creation of accounts.\n * @param opts.entropySource - The entropy source to use for the discovery and creation of accounts.\n * @param opts.groupIndex - The index of the group to create the accounts for.\n * @returns The accounts for the EVM provider.\n */\n async discoverAccounts(opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const provider = this.getEvmProvider();\n const { entropySource, groupIndex } = opts;\n\n const [address, didCreate] = await this.#createAccount({\n entropySource,\n groupIndex,\n });\n\n // We don't want to remove the account if it's the first one.\n const shouldCleanup = didCreate && groupIndex !== 0;\n try {\n const count = await this.#getTransactionCount(provider, address);\n\n if (count === 0 && shouldCleanup) {\n await this.withKeyring<EthKeyring>(\n { id: entropySource },\n async ({ keyring }) => {\n keyring.removeAccount?.(address);\n },\n );\n return [];\n }\n } catch (error) {\n // If the RPC request fails and we just created this account for discovery,\n // remove it to avoid leaving a dangling account.\n if (shouldCleanup) {\n await this.withKeyring<EthKeyring>(\n { id: entropySource },\n async ({ keyring }) => {\n keyring.removeAccount?.(address);\n },\n );\n }\n throw error;\n }\n\n const account = this.messenger.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n assertInternalAccountExists(account);\n assertIsBip44Account(account);\n return [account];\n }\n\n /**\n * Execute a function with exponential backoff on transient failures.\n *\n * @param fnToExecute - The function to execute.\n * @param options - The options for the retry.\n * @param options.maxAttempts - The maximum number of attempts.\n * @param options.backOffMs - The backoff in milliseconds.\n * @throws An error if the transaction count cannot be retrieved.\n * @returns The result of the function.\n */\n async #withRetry<T>(\n fnToExecute: () => Promise<T>,\n {\n maxAttempts = 3,\n backOffMs = 500,\n }: { maxAttempts?: number; backOffMs?: number } = {},\n ): Promise<T> {\n let lastError;\n let backOff = backOffMs;\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await fnToExecute();\n } catch (error) {\n lastError = error;\n if (attempt >= maxAttempts) {\n break;\n }\n const delay = backOff;\n await new Promise((resolve) => setTimeout(resolve, delay));\n backOff *= 2;\n }\n }\n throw lastError;\n }\n\n /**\n * Execute a promise with a timeout.\n *\n * @param promise - The promise to execute.\n * @param timeoutMs - The timeout in milliseconds.\n * @returns The result of the promise.\n */\n async #withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number = 500,\n ): Promise<T> {\n let timer;\n try {\n return await Promise.race<T>([\n promise,\n new Promise<T>((_resolve, reject) => {\n timer = setTimeout(\n () => reject(new Error('RPC request timed out')),\n timeoutMs,\n );\n }),\n ]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"EvmAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,uDAAuD;AACvD,qEAA4D;AAS5D,6EAIoC;AACpC,uCAAiD;AAEjD,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAEnC;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,OAAoC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;AACH,CAAC;AAUY,QAAA,yBAAyB,GAAG,KAAc,CAAC;AAExD,MAAa,kBAAmB,SAAQ,mDAAwB;IAK9D,YACE,SAA4C,EAC5C,SAAmC;QACjC,SAAS,EAAE;YACT,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,GAAG;SACf;KACF;QAED,KAAK,CAAC,SAAS,CAAC,CAAC;;QAZV,6CAAkC;QAazC,uBAAA,IAAI,8BAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,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,OAAO;QACL,OAAO,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AE,KAAK,CAAC,CAAC;SACtC;QAED,0EAA0E;QAC1E,IAAI,UAAU,IAAI,UAAU,KAAK,QAAQ,CAAC,MAAM,EAAE;YAChD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QAED,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7C,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,4CA6BD,KAAK,kDACH,QAAkB,EAClB,OAAY;IAEZ,MAAM,QAAQ,GAAG,MAAM,IAAA,iBAAS,EAC9B,GAAG,EAAE,CACH,IAAA,mBAAW,EACT,QAAQ,CAAC,OAAO,CAAC;QACf,MAAM,EAAE,yBAAyB;QACjC,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;KAC5B,CAAC,EACF,uBAAA,IAAI,kCAAQ,CAAC,SAAS,CAAC,SAAS,CACjC,EACH;QACE,WAAW,EAAE,uBAAA,IAAI,kCAAQ,CAAC,SAAS,CAAC,WAAW;QAC/C,SAAS,EAAE,uBAAA,IAAI,kCAAQ,CAAC,SAAS,CAAC,SAAS;KAC5C,CACF,CAAC;IAEF,OAAO,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC;AA3HM,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } 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 { Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport {\n assertAreBip44Accounts,\n assertIsBip44Account,\n BaseBip44AccountProvider,\n} from './BaseBip44AccountProvider';\nimport { withRetry, withTimeout } from './utils';\n\nconst ETH_MAINNET_CHAIN_ID = '0x1';\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 type EvmAccountProviderConfig = {\n discovery: {\n maxAttempts: number;\n timeoutMs: number;\n backOffMs: number;\n };\n};\n\nexport const EVM_ACCOUNT_PROVIDER_NAME = 'EVM' as const;\n\nexport class EvmAccountProvider extends BaseBip44AccountProvider {\n static NAME = EVM_ACCOUNT_PROVIDER_NAME;\n\n readonly #config: EvmAccountProviderConfig;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: EvmAccountProviderConfig = {\n discovery: {\n maxAttempts: 3,\n timeoutMs: 500,\n backOffMs: 500,\n },\n },\n ) {\n super(messenger);\n this.#config = config;\n }\n\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 getName(): string {\n return EvmAccountProvider.NAME;\n }\n\n /**\n * Get the EVM provider.\n *\n * @returns The EVM provider.\n */\n getEvmProvider(): Provider {\n const networkClientId = this.messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n ETH_MAINNET_CHAIN_ID,\n );\n const { provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return provider;\n }\n\n async #createAccount({\n entropySource,\n groupIndex,\n throwOnGap = false,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n throwOnGap?: boolean;\n }): Promise<[Hex, boolean]> {\n const result = await this.withKeyring<EthKeyring, [Hex, boolean]>(\n { id: entropySource },\n async ({ keyring }) => {\n const existing = await keyring.getAccounts();\n if (groupIndex < existing.length) {\n return [existing[groupIndex], false];\n }\n\n // If the throwOnGap flag is set, we throw an error to prevent index gaps.\n if (throwOnGap && groupIndex !== existing.length) {\n throw new Error('Trying to create too many accounts');\n }\n\n const [added] = await keyring.addAccounts(1);\n return [added, true];\n },\n );\n\n return result;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const [address] = await this.#createAccount({\n entropySource,\n groupIndex,\n throwOnGap: true,\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\n const accountsArray = [account];\n assertAreBip44Accounts(accountsArray);\n\n return accountsArray;\n }\n\n async #getTransactionCount(\n provider: Provider,\n address: Hex,\n ): Promise<number> {\n const countHex = await withRetry<Hex>(\n () =>\n withTimeout(\n provider.request({\n method: 'eth_getTransactionCount',\n params: [address, 'latest'],\n }),\n this.#config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.#config.discovery.maxAttempts,\n backOffMs: this.#config.discovery.backOffMs,\n },\n );\n\n return parseInt(countHex, 16);\n }\n\n /**\n * Discover and create accounts for the EVM provider.\n *\n * @param opts - The options for the discovery and creation of accounts.\n * @param opts.entropySource - The entropy source to use for the discovery and creation of accounts.\n * @param opts.groupIndex - The index of the group to create the accounts for.\n * @returns The accounts for the EVM provider.\n */\n async discoverAccounts(opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const provider = this.getEvmProvider();\n const { entropySource, groupIndex } = opts;\n\n const [address, didCreate] = await this.#createAccount({\n entropySource,\n groupIndex,\n });\n\n // We don't want to remove the account if it's the first one.\n const shouldCleanup = didCreate && groupIndex !== 0;\n try {\n const count = await this.#getTransactionCount(provider, address);\n\n if (count === 0 && shouldCleanup) {\n await this.withKeyring<EthKeyring>(\n { id: entropySource },\n async ({ keyring }) => {\n keyring.removeAccount?.(address);\n },\n );\n return [];\n }\n } catch (error) {\n // If the RPC request fails and we just created this account for discovery,\n // remove it to avoid leaving a dangling account.\n if (shouldCleanup) {\n await this.withKeyring<EthKeyring>(\n { id: entropySource },\n async ({ keyring }) => {\n keyring.removeAccount?.(address);\n },\n );\n }\n throw error;\n }\n\n const account = this.messenger.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n assertInternalAccountExists(account);\n assertIsBip44Account(account);\n return [account];\n }\n}\n"]}
@@ -2,9 +2,20 @@ import type { Bip44Account } from "@metamask/account-api";
2
2
  import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
3
3
  import type { InternalAccount } from "@metamask/keyring-internal-api";
4
4
  import type { Provider } from "@metamask/network-controller";
5
+ import type { MultichainAccountServiceMessenger } from "src/types";
5
6
  import { BaseBip44AccountProvider } from "./BaseBip44AccountProvider.cjs";
7
+ export type EvmAccountProviderConfig = {
8
+ discovery: {
9
+ maxAttempts: number;
10
+ timeoutMs: number;
11
+ backOffMs: number;
12
+ };
13
+ };
14
+ export declare const EVM_ACCOUNT_PROVIDER_NAME: "EVM";
6
15
  export declare class EvmAccountProvider extends BaseBip44AccountProvider {
7
16
  #private;
17
+ static NAME: "EVM";
18
+ constructor(messenger: MultichainAccountServiceMessenger, config?: EvmAccountProviderConfig);
8
19
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
9
20
  getName(): string;
10
21
  /**
@@ -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,cAAc,EAAE,8BAA8B;AAG7E,OAAO,KAAK,EAEV,eAAe,EAChB,uCAAuC;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAG7D,OAAO,EAGL,wBAAwB,EACzB,uCAAmC;AAkBpC,qBAAa,kBAAmB,SAAQ,wBAAwB;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E,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAOpE,OAAO,IAAI,MAAM;IAIjB;;;;OAIG;IACH,cAAc,IAAI,QAAQ;IA0CpB,cAAc,CAAC,EACnB,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;IA2C3C;;;;;;;OAOG;IACG,gBAAgB,CAAC,IAAI,EAAE;QAC3B,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CA6C5C"}
@@ -2,9 +2,20 @@ import type { Bip44Account } from "@metamask/account-api";
2
2
  import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
3
3
  import type { InternalAccount } from "@metamask/keyring-internal-api";
4
4
  import type { Provider } from "@metamask/network-controller";
5
+ import type { MultichainAccountServiceMessenger } from "src/types";
5
6
  import { BaseBip44AccountProvider } from "./BaseBip44AccountProvider.mjs";
7
+ export type EvmAccountProviderConfig = {
8
+ discovery: {
9
+ maxAttempts: number;
10
+ timeoutMs: number;
11
+ backOffMs: number;
12
+ };
13
+ };
14
+ export declare const EVM_ACCOUNT_PROVIDER_NAME: "EVM";
6
15
  export declare class EvmAccountProvider extends BaseBip44AccountProvider {
7
16
  #private;
17
+ static NAME: "EVM";
18
+ constructor(messenger: MultichainAccountServiceMessenger, config?: EvmAccountProviderConfig);
8
19
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
9
20
  getName(): string;
10
21
  /**
@@ -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,cA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,eAAO,MAAM,yBAAyB,OAAiB,CAAC;AAExD,qBAAa,kBAAmB,SAAQ,wBAAwB;;IAC9D,MAAM,CAAC,IAAI,QAA6B;gBAKtC,SAAS,EAAE,iCAAiC,EAC5C,MAAM,GAAE,wBAMP;IAMH,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAOpE,OAAO,IAAI,MAAM;IAIjB;;;;OAIG;IACH,cAAc,IAAI,QAAQ;IA0CpB,cAAc,CAAC,EACnB,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;IA2C3C;;;;;;;OAOG;IACG,gBAAgB,CAAC,IAAI,EAAE;QAC3B,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CA6C5C"}
@@ -1,12 +1,19 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
1
7
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
8
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
11
  };
6
- var _EvmAccountProvider_instances, _EvmAccountProvider_createAccount, _EvmAccountProvider_getTransactionCount, _EvmAccountProvider_withRetry, _EvmAccountProvider_withTimeout;
12
+ var _EvmAccountProvider_instances, _EvmAccountProvider_config, _EvmAccountProvider_createAccount, _EvmAccountProvider_getTransactionCount;
7
13
  import { EthAccountType } from "@metamask/keyring-api";
8
14
  import { KeyringTypes } from "@metamask/keyring-controller";
9
15
  import { assertAreBip44Accounts, assertIsBip44Account, BaseBip44AccountProvider } from "./BaseBip44AccountProvider.mjs";
16
+ import { withRetry, withTimeout } from "./utils.mjs";
10
17
  const ETH_MAINNET_CHAIN_ID = '0x1';
11
18
  /**
12
19
  * Asserts an internal account exists.
@@ -19,17 +26,26 @@ function assertInternalAccountExists(account) {
19
26
  throw new Error('Internal account does not exist');
20
27
  }
21
28
  }
29
+ export const EVM_ACCOUNT_PROVIDER_NAME = 'EVM';
22
30
  export class EvmAccountProvider extends BaseBip44AccountProvider {
23
- constructor() {
24
- super(...arguments);
31
+ constructor(messenger, config = {
32
+ discovery: {
33
+ maxAttempts: 3,
34
+ timeoutMs: 500,
35
+ backOffMs: 500,
36
+ },
37
+ }) {
38
+ super(messenger);
25
39
  _EvmAccountProvider_instances.add(this);
40
+ _EvmAccountProvider_config.set(this, void 0);
41
+ __classPrivateFieldSet(this, _EvmAccountProvider_config, config, "f");
26
42
  }
27
43
  isAccountCompatible(account) {
28
44
  return (account.type === EthAccountType.Eoa &&
29
45
  account.metadata.keyring.type === KeyringTypes.hd);
30
46
  }
31
47
  getName() {
32
- return 'EVM';
48
+ return EvmAccountProvider.NAME;
33
49
  }
34
50
  /**
35
51
  * Get the EVM provider.
@@ -96,7 +112,7 @@ export class EvmAccountProvider extends BaseBip44AccountProvider {
96
112
  return [account];
97
113
  }
98
114
  }
99
- _EvmAccountProvider_instances = new WeakSet(), _EvmAccountProvider_createAccount = async function _EvmAccountProvider_createAccount({ entropySource, groupIndex, throwOnGap = false, }) {
115
+ _EvmAccountProvider_config = new WeakMap(), _EvmAccountProvider_instances = new WeakSet(), _EvmAccountProvider_createAccount = async function _EvmAccountProvider_createAccount({ entropySource, groupIndex, throwOnGap = false, }) {
100
116
  const result = await this.withKeyring({ id: entropySource }, async ({ keyring }) => {
101
117
  const existing = await keyring.getAccounts();
102
118
  if (groupIndex < existing.length) {
@@ -111,62 +127,14 @@ _EvmAccountProvider_instances = new WeakSet(), _EvmAccountProvider_createAccount
111
127
  });
112
128
  return result;
113
129
  }, _EvmAccountProvider_getTransactionCount = async function _EvmAccountProvider_getTransactionCount(provider, address) {
114
- const countHex = await __classPrivateFieldGet(this, _EvmAccountProvider_instances, "m", _EvmAccountProvider_withRetry).call(this, () => __classPrivateFieldGet(this, _EvmAccountProvider_instances, "m", _EvmAccountProvider_withTimeout).call(this, provider.request({
130
+ const countHex = await withRetry(() => withTimeout(provider.request({
115
131
  method: 'eth_getTransactionCount',
116
132
  params: [address, 'latest'],
117
- })));
133
+ }), __classPrivateFieldGet(this, _EvmAccountProvider_config, "f").discovery.timeoutMs), {
134
+ maxAttempts: __classPrivateFieldGet(this, _EvmAccountProvider_config, "f").discovery.maxAttempts,
135
+ backOffMs: __classPrivateFieldGet(this, _EvmAccountProvider_config, "f").discovery.backOffMs,
136
+ });
118
137
  return parseInt(countHex, 16);
119
- }, _EvmAccountProvider_withRetry =
120
- /**
121
- * Execute a function with exponential backoff on transient failures.
122
- *
123
- * @param fnToExecute - The function to execute.
124
- * @param options - The options for the retry.
125
- * @param options.maxAttempts - The maximum number of attempts.
126
- * @param options.backOffMs - The backoff in milliseconds.
127
- * @throws An error if the transaction count cannot be retrieved.
128
- * @returns The result of the function.
129
- */
130
- async function _EvmAccountProvider_withRetry(fnToExecute, { maxAttempts = 3, backOffMs = 500, } = {}) {
131
- let lastError;
132
- let backOff = backOffMs;
133
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
134
- try {
135
- return await fnToExecute();
136
- }
137
- catch (error) {
138
- lastError = error;
139
- if (attempt >= maxAttempts) {
140
- break;
141
- }
142
- const delay = backOff;
143
- await new Promise((resolve) => setTimeout(resolve, delay));
144
- backOff *= 2;
145
- }
146
- }
147
- throw lastError;
148
- }, _EvmAccountProvider_withTimeout =
149
- /**
150
- * Execute a promise with a timeout.
151
- *
152
- * @param promise - The promise to execute.
153
- * @param timeoutMs - The timeout in milliseconds.
154
- * @returns The result of the promise.
155
- */
156
- async function _EvmAccountProvider_withTimeout(promise, timeoutMs = 500) {
157
- let timer;
158
- try {
159
- return await Promise.race([
160
- promise,
161
- new Promise((_resolve, reject) => {
162
- timer = setTimeout(() => reject(new Error('RPC request timed out')), timeoutMs);
163
- }),
164
- ]);
165
- }
166
- finally {
167
- if (timer) {
168
- clearTimeout(timer);
169
- }
170
- }
171
138
  };
139
+ EvmAccountProvider.NAME = EVM_ACCOUNT_PROVIDER_NAME;
172
140
  //# 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;AAQ5D,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACzB,uCAAmC;AAEpC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAEnC;;;;;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,wBAAwB;IAAhE;;;IA8NA,CAAC;IA7NC,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,CA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OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC,CAAC;SACd;KACF;IACD,MAAM,SAAS,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,KAAK,0CACH,OAAmB,EACnB,YAAoB,GAAG;IAEvB,IAAI,KAAK,CAAC;IACV,IAAI;QACF,OAAO,MAAM,OAAO,CAAC,IAAI,CAAI;YAC3B,OAAO;YACP,IAAI,OAAO,CAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;gBAClC,KAAK,GAAG,UAAU,CAChB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;KACJ;YAAS;QACR,IAAI,KAAK,EAAE;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;SACrB;KACF;AACH,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } 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 { Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n assertAreBip44Accounts,\n assertIsBip44Account,\n BaseBip44AccountProvider,\n} from './BaseBip44AccountProvider';\n\nconst ETH_MAINNET_CHAIN_ID = '0x1';\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 BaseBip44AccountProvider {\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 getName(): string {\n return 'EVM';\n }\n\n /**\n * Get the EVM provider.\n *\n * @returns The EVM provider.\n */\n getEvmProvider(): Provider {\n const networkClientId = this.messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n ETH_MAINNET_CHAIN_ID,\n );\n const { provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return provider;\n }\n\n async #createAccount({\n entropySource,\n groupIndex,\n throwOnGap = false,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n throwOnGap?: boolean;\n }): Promise<[Hex, boolean]> {\n const result = await this.withKeyring<EthKeyring, [Hex, boolean]>(\n { id: entropySource },\n async ({ keyring }) => {\n const existing = await keyring.getAccounts();\n if (groupIndex < existing.length) {\n return [existing[groupIndex], false];\n }\n\n // If the throwOnGap flag is set, we throw an error to prevent index gaps.\n if (throwOnGap && groupIndex !== existing.length) {\n throw new Error('Trying to create too many accounts');\n }\n\n const [added] = await keyring.addAccounts(1);\n return [added, true];\n },\n );\n\n return result;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const [address] = await this.#createAccount({\n entropySource,\n groupIndex,\n throwOnGap: true,\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\n const accountsArray = [account];\n assertAreBip44Accounts(accountsArray);\n\n return accountsArray;\n }\n\n async #getTransactionCount(\n provider: Provider,\n address: Hex,\n ): Promise<number> {\n const countHex = await this.#withRetry<Hex>(() =>\n this.#withTimeout(\n provider.request({\n method: 'eth_getTransactionCount',\n params: [address, 'latest'],\n }),\n ),\n );\n\n return parseInt(countHex, 16);\n }\n\n /**\n * Discover and create accounts for the EVM provider.\n *\n * @param opts - The options for the discovery and creation of accounts.\n * @param opts.entropySource - The entropy source to use for the discovery and creation of accounts.\n * @param opts.groupIndex - The index of the group to create the accounts for.\n * @returns The accounts for the EVM provider.\n */\n async discoverAccounts(opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const provider = this.getEvmProvider();\n const { entropySource, groupIndex } = opts;\n\n const [address, didCreate] = await this.#createAccount({\n entropySource,\n groupIndex,\n });\n\n // We don't want to remove the account if it's the first one.\n const shouldCleanup = didCreate && groupIndex !== 0;\n try {\n const count = await this.#getTransactionCount(provider, address);\n\n if (count === 0 && shouldCleanup) {\n await this.withKeyring<EthKeyring>(\n { id: entropySource },\n async ({ keyring }) => {\n keyring.removeAccount?.(address);\n },\n );\n return [];\n }\n } catch (error) {\n // If the RPC request fails and we just created this account for discovery,\n // remove it to avoid leaving a dangling account.\n if (shouldCleanup) {\n await this.withKeyring<EthKeyring>(\n { id: entropySource },\n async ({ keyring }) => {\n keyring.removeAccount?.(address);\n },\n );\n }\n throw error;\n }\n\n const account = this.messenger.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n assertInternalAccountExists(account);\n assertIsBip44Account(account);\n return [account];\n }\n\n /**\n * Execute a function with exponential backoff on transient failures.\n *\n * @param fnToExecute - The function to execute.\n * @param options - The options for the retry.\n * @param options.maxAttempts - The maximum number of attempts.\n * @param options.backOffMs - The backoff in milliseconds.\n * @throws An error if the transaction count cannot be retrieved.\n * @returns The result of the function.\n */\n async #withRetry<T>(\n fnToExecute: () => Promise<T>,\n {\n maxAttempts = 3,\n backOffMs = 500,\n }: { maxAttempts?: number; backOffMs?: number } = {},\n ): Promise<T> {\n let lastError;\n let backOff = backOffMs;\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await fnToExecute();\n } catch (error) {\n lastError = error;\n if (attempt >= maxAttempts) {\n break;\n }\n const delay = backOff;\n await new Promise((resolve) => setTimeout(resolve, delay));\n backOff *= 2;\n }\n }\n throw lastError;\n }\n\n /**\n * Execute a promise with a timeout.\n *\n * @param promise - The promise to execute.\n * @param timeoutMs - The timeout in milliseconds.\n * @returns The result of the promise.\n */\n async #withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number = 500,\n ): Promise<T> {\n let timer;\n try {\n return await Promise.race<T>([\n promise,\n new Promise<T>((_resolve, reject) => {\n timer = setTimeout(\n () => reject(new Error('RPC request timed out')),\n timeoutMs,\n );\n }),\n ]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n }\n}\n"]}
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;AAS5D,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACzB,uCAAmC;AACpC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AAEjD,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAEnC;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,OAAoC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;AACH,CAAC;AAUD,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAc,CAAC;AAExD,MAAM,OAAO,kBAAmB,SAAQ,wBAAwB;IAK9D,YACE,SAA4C,EAC5C,SAAmC;QACjC,SAAS,EAAE;YACT,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,GAAG;SACf;KACF;QAED,KAAK,CAAC,SAAS,CAAC,CAAC;;QAZV,6CAAkC;QAazC,uBAAA,IAAI,8BAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,EAA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,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC;SACtC;QAED,0EAA0E;QAC1E,IAAI,UAAU,IAAI,UAAU,KAAK,QAAQ,CAAC,MAAM,EAAE;YAChD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QAED,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7C,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,4CA6BD,KAAK,kDACH,QAAkB,EAClB,OAAY;IAEZ,MAAM,QAAQ,GAAG,MAAM,SAAS,CAC9B,GAAG,EAAE,CACH,WAAW,CACT,QAAQ,CAAC,OAAO,CAAC;QACf,MAAM,EAAE,yBAAyB;QACjC,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;KAC5B,CAAC,EACF,uBAAA,IAAI,kCAAQ,CAAC,SAAS,CAAC,SAAS,CACjC,EACH;QACE,WAAW,EAAE,uBAAA,IAAI,kCAAQ,CAAC,SAAS,CAAC,WAAW;QAC/C,SAAS,EAAE,uBAAA,IAAI,kCAAQ,CAAC,SAAS,CAAC,SAAS;KAC5C,CACF,CAAC;IAEF,OAAO,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC;AA3HM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } 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 { Provider } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport {\n assertAreBip44Accounts,\n assertIsBip44Account,\n BaseBip44AccountProvider,\n} from './BaseBip44AccountProvider';\nimport { withRetry, withTimeout } from './utils';\n\nconst ETH_MAINNET_CHAIN_ID = '0x1';\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 type EvmAccountProviderConfig = {\n discovery: {\n maxAttempts: number;\n timeoutMs: number;\n backOffMs: number;\n };\n};\n\nexport const EVM_ACCOUNT_PROVIDER_NAME = 'EVM' as const;\n\nexport class EvmAccountProvider extends BaseBip44AccountProvider {\n static NAME = EVM_ACCOUNT_PROVIDER_NAME;\n\n readonly #config: EvmAccountProviderConfig;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: EvmAccountProviderConfig = {\n discovery: {\n maxAttempts: 3,\n timeoutMs: 500,\n backOffMs: 500,\n },\n },\n ) {\n super(messenger);\n this.#config = config;\n }\n\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 getName(): string {\n return EvmAccountProvider.NAME;\n }\n\n /**\n * Get the EVM provider.\n *\n * @returns The EVM provider.\n */\n getEvmProvider(): Provider {\n const networkClientId = this.messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n ETH_MAINNET_CHAIN_ID,\n );\n const { provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return provider;\n }\n\n async #createAccount({\n entropySource,\n groupIndex,\n throwOnGap = false,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n throwOnGap?: boolean;\n }): Promise<[Hex, boolean]> {\n const result = await this.withKeyring<EthKeyring, [Hex, boolean]>(\n { id: entropySource },\n async ({ keyring }) => {\n const existing = await keyring.getAccounts();\n if (groupIndex < existing.length) {\n return [existing[groupIndex], false];\n }\n\n // If the throwOnGap flag is set, we throw an error to prevent index gaps.\n if (throwOnGap && groupIndex !== existing.length) {\n throw new Error('Trying to create too many accounts');\n }\n\n const [added] = await keyring.addAccounts(1);\n return [added, true];\n },\n );\n\n return result;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const [address] = await this.#createAccount({\n entropySource,\n groupIndex,\n throwOnGap: true,\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\n const accountsArray = [account];\n assertAreBip44Accounts(accountsArray);\n\n return accountsArray;\n }\n\n async #getTransactionCount(\n provider: Provider,\n address: Hex,\n ): Promise<number> {\n const countHex = await withRetry<Hex>(\n () =>\n withTimeout(\n provider.request({\n method: 'eth_getTransactionCount',\n params: [address, 'latest'],\n }),\n this.#config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.#config.discovery.maxAttempts,\n backOffMs: this.#config.discovery.backOffMs,\n },\n );\n\n return parseInt(countHex, 16);\n }\n\n /**\n * Discover and create accounts for the EVM provider.\n *\n * @param opts - The options for the discovery and creation of accounts.\n * @param opts.entropySource - The entropy source to use for the discovery and creation of accounts.\n * @param opts.groupIndex - The index of the group to create the accounts for.\n * @returns The accounts for the EVM provider.\n */\n async discoverAccounts(opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const provider = this.getEvmProvider();\n const { entropySource, groupIndex } = opts;\n\n const [address, didCreate] = await this.#createAccount({\n entropySource,\n groupIndex,\n });\n\n // We don't want to remove the account if it's the first one.\n const shouldCleanup = didCreate && groupIndex !== 0;\n try {\n const count = await this.#getTransactionCount(provider, address);\n\n if (count === 0 && shouldCleanup) {\n await this.withKeyring<EthKeyring>(\n { id: entropySource },\n async ({ keyring }) => {\n keyring.removeAccount?.(address);\n },\n );\n return [];\n }\n } catch (error) {\n // If the RPC request fails and we just created this account for discovery,\n // remove it to avoid leaving a dangling account.\n if (shouldCleanup) {\n await this.withKeyring<EthKeyring>(\n { id: entropySource },\n async ({ keyring }) => {\n keyring.removeAccount?.(address);\n },\n );\n }\n throw error;\n }\n\n const account = this.messenger.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n assertInternalAccountExists(account);\n assertIsBip44Account(account);\n return [account];\n }\n}\n"]}
@@ -10,9 +10,9 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
12
  };
13
- var _SolAccountProvider_instances, _SolAccountProvider_client, _SolAccountProvider_getKeyringClientFromSnapId, _SolAccountProvider_createAccount;
13
+ var _SolAccountProvider_instances, _SolAccountProvider_client, _SolAccountProvider_config, _SolAccountProvider_getKeyringClientFromSnapId, _SolAccountProvider_createAccount;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.SolAccountProvider = void 0;
15
+ exports.SolAccountProvider = exports.SOL_ACCOUNT_PROVIDER_NAME = void 0;
16
16
  const account_api_1 = require("@metamask/account-api");
17
17
  const keyring_api_1 = require("@metamask/keyring-api");
18
18
  const keyring_api_2 = require("@metamask/keyring-api");
@@ -20,15 +20,25 @@ const keyring_controller_1 = require("@metamask/keyring-controller");
20
20
  const keyring_snap_client_1 = require("@metamask/keyring-snap-client");
21
21
  const snaps_utils_1 = require("@metamask/snaps-utils");
22
22
  const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
23
+ const utils_1 = require("./utils.cjs");
24
+ exports.SOL_ACCOUNT_PROVIDER_NAME = 'Solana';
23
25
  class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
24
- constructor(messenger) {
26
+ constructor(messenger, config = {
27
+ discovery: {
28
+ timeoutMs: 2000,
29
+ maxAttempts: 3,
30
+ backOffMs: 1000,
31
+ },
32
+ }) {
25
33
  super(SolAccountProvider.SOLANA_SNAP_ID, messenger);
26
34
  _SolAccountProvider_instances.add(this);
27
35
  _SolAccountProvider_client.set(this, void 0);
36
+ _SolAccountProvider_config.set(this, void 0);
28
37
  __classPrivateFieldSet(this, _SolAccountProvider_client, __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_getKeyringClientFromSnapId).call(this, SolAccountProvider.SOLANA_SNAP_ID), "f");
38
+ __classPrivateFieldSet(this, _SolAccountProvider_config, config, "f");
29
39
  }
30
40
  getName() {
31
- return 'Solana';
41
+ return SolAccountProvider.NAME;
32
42
  }
33
43
  isAccountCompatible(account) {
34
44
  return (account.type === keyring_api_2.SolAccountType.DataAccount &&
@@ -44,7 +54,10 @@ class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
44
54
  return [account];
45
55
  }
46
56
  async discoverAccounts({ entropySource, groupIndex, }) {
47
- const discoveredAccounts = await __classPrivateFieldGet(this, _SolAccountProvider_client, "f").discoverAccounts([keyring_api_1.SolScope.Mainnet], entropySource, groupIndex);
57
+ const discoveredAccounts = await (0, utils_1.withRetry)(() => (0, utils_1.withTimeout)(__classPrivateFieldGet(this, _SolAccountProvider_client, "f").discoverAccounts([keyring_api_1.SolScope.Mainnet], entropySource, groupIndex), __classPrivateFieldGet(this, _SolAccountProvider_config, "f").discovery.timeoutMs), {
58
+ maxAttempts: __classPrivateFieldGet(this, _SolAccountProvider_config, "f").discovery.maxAttempts,
59
+ backOffMs: __classPrivateFieldGet(this, _SolAccountProvider_config, "f").discovery.backOffMs,
60
+ });
48
61
  if (!discoveredAccounts.length) {
49
62
  return [];
50
63
  }
@@ -57,7 +70,7 @@ class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
57
70
  }
58
71
  }
59
72
  exports.SolAccountProvider = SolAccountProvider;
60
- _SolAccountProvider_client = new WeakMap(), _SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getKeyringClientFromSnapId = function _SolAccountProvider_getKeyringClientFromSnapId(snapId) {
73
+ _SolAccountProvider_client = new WeakMap(), _SolAccountProvider_config = new WeakMap(), _SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getKeyringClientFromSnapId = function _SolAccountProvider_getKeyringClientFromSnapId(snapId) {
61
74
  return new keyring_snap_client_1.KeyringClient({
62
75
  send: async (request) => {
63
76
  const response = await this.messenger.call('SnapController:handleRequest', {
@@ -82,5 +95,6 @@ _SolAccountProvider_client = new WeakMap(), _SolAccountProvider_instances = new
82
95
  (0, account_api_1.assertIsBip44Account)(account);
83
96
  return account;
84
97
  };
98
+ SolAccountProvider.NAME = exports.SOL_ACCOUNT_PROVIDER_NAME;
85
99
  SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
86
100
  //# sourceMappingURL=SolAccountProvider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAAgF;AAEhF,uDAAiD;AACjD,uDAG+B;AAC/B,qEAA4D;AAE5D,uEAA8D;AAE9D,uDAAoD;AAIpD,mEAA4D;AAE5D,MAAa,kBAAmB,SAAQ,yCAAmB;IAKzD,YAAY,SAA4C;QACtD,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;;QAH7C,6CAAuB;QAI9B,uBAAA,IAAI,8BAAW,uBAAA,IAAI,qFAA4B,MAAhC,IAAI,EACjB,kBAAkB,CAAC,cAAc,CAClC,MAAA,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,QAAQ,CAAC;IAClB,CAAC;IAmBD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IA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ACF,CAAC,CAAC;AACL,CAAC,sCASD,KAAK,4CAAgB,EACnB,aAAa,EACb,UAAU,EACV,cAAc,GAKf;IACC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;IACnE,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,CAAC;IAEvE,6DAA6D;IAC7D,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;QACxB,IAAI,EAAE,6CAA+B,CAAC,QAAQ;QAC9C,EAAE,EAAE,aAAa;QACjB,UAAU;QACV,cAAc;KACf,CAAC;IAEF,IAAA,kCAAoB,EAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA7DM,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account, type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { SolScope } 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 { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n readonly #client: KeyringClient;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n this.#client = this.#getKeyringClientFromSnapId(\n SolAccountProvider.SOLANA_SNAP_ID,\n );\n }\n\n getName(): string {\n return 'Solana';\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\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 #createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n derivationPath: string;\n }): Promise<Bip44Account<KeyringAccount>> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n const account = await createAccount({ entropySource, derivationPath });\n\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n return account;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n });\n return [account];\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const discoveredAccounts = await this.#client.discoverAccounts(\n [SolScope.Mainnet],\n entropySource,\n groupIndex,\n );\n\n if (!discoveredAccounts.length) {\n return [];\n }\n\n const createdAccounts = await Promise.all(\n discoveredAccounts.map((d) =>\n this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath: d.derivationPath,\n }),\n ),\n );\n\n return createdAccounts;\n }\n}\n"]}
1
+ {"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":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G,MAAM,aAAa,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,CAAC;IAEvE,6DAA6D;IAC7D,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;QACxB,IAAI,EAAE,6CAA+B,CAAC,QAAQ;QAC9C,EAAE,EAAE,aAAa;QACjB,UAAU;QACV,cAAc;KACf,CAAC;IAEF,IAAA,kCAAoB,EAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA3EM,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account, type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { SolScope } 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 { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\n\nexport type SolAccountProviderConfig = {\n discovery: {\n maxAttempts: number;\n timeoutMs: number;\n backOffMs: number;\n };\n};\n\nexport const SOL_ACCOUNT_PROVIDER_NAME = 'Solana' as const;\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static NAME = SOL_ACCOUNT_PROVIDER_NAME;\n\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n readonly #client: KeyringClient;\n\n readonly #config: SolAccountProviderConfig;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: SolAccountProviderConfig = {\n discovery: {\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n },\n ) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n this.#client = this.#getKeyringClientFromSnapId(\n SolAccountProvider.SOLANA_SNAP_ID,\n );\n this.#config = config;\n }\n\n getName(): string {\n return SolAccountProvider.NAME;\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\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 #createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n derivationPath: string;\n }): Promise<Bip44Account<KeyringAccount>> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n const account = await createAccount({ entropySource, derivationPath });\n\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n return account;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n });\n return [account];\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n this.#client.discoverAccounts(\n [SolScope.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 (!discoveredAccounts.length) {\n return [];\n }\n\n const createdAccounts = await Promise.all(\n discoveredAccounts.map((d) =>\n this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath: d.derivationPath,\n }),\n ),\n );\n\n return createdAccounts;\n }\n}\n"]}
@@ -4,10 +4,19 @@ import type { InternalAccount } from "@metamask/keyring-internal-api";
4
4
  import type { SnapId } from "@metamask/snaps-sdk";
5
5
  import type { MultichainAccountServiceMessenger } from "src/types";
6
6
  import { SnapAccountProvider } from "./SnapAccountProvider.cjs";
7
+ export type SolAccountProviderConfig = {
8
+ discovery: {
9
+ maxAttempts: number;
10
+ timeoutMs: number;
11
+ backOffMs: number;
12
+ };
13
+ };
14
+ export declare const SOL_ACCOUNT_PROVIDER_NAME: "Solana";
7
15
  export declare class SolAccountProvider extends SnapAccountProvider {
8
16
  #private;
17
+ static NAME: "Solana";
9
18
  static SOLANA_SNAP_ID: SnapId;
10
- constructor(messenger: MultichainAccountServiceMessenger);
19
+ constructor(messenger: MultichainAccountServiceMessenger, config?: SolAccountProviderConfig);
11
20
  getName(): string;
12
21
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
13
22
  createAccounts({ entropySource, groupIndex, }: {
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,8BAA8B;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAO7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAGlD,OAAO,KAAK,EAAE,iCAAiC,EAAE,kBAAkB;AAEnE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ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C,EAC5C,MAAM,GAAE,wBAMP;IASH,OAAO,IAAI,MAAM;IAqBjB,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IA+B9D,cAAc,CAAC,EACnB,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;IAUrC,gBAAgB,CAAC,EACrB,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;CAiC5C"}
@@ -4,10 +4,19 @@ import type { InternalAccount } from "@metamask/keyring-internal-api";
4
4
  import type { SnapId } from "@metamask/snaps-sdk";
5
5
  import type { MultichainAccountServiceMessenger } from "src/types";
6
6
  import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
7
+ export type SolAccountProviderConfig = {
8
+ discovery: {
9
+ maxAttempts: number;
10
+ timeoutMs: number;
11
+ backOffMs: number;
12
+ };
13
+ };
14
+ export declare const SOL_ACCOUNT_PROVIDER_NAME: "Solana";
7
15
  export declare class SolAccountProvider extends SnapAccountProvider {
8
16
  #private;
17
+ static NAME: "Solana";
9
18
  static SOLANA_SNAP_ID: SnapId;
10
- constructor(messenger: MultichainAccountServiceMessenger);
19
+ constructor(messenger: MultichainAccountServiceMessenger, config?: SolAccountProviderConfig);
11
20
  getName(): string;
12
21
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
13
22
  createAccounts({ entropySource, groupIndex, }: {
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,8BAA8B;AAChF,OAAO,KAAK,EAAE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AS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,yBAAyB,UAAoB,CAAC;AAE3D,qBAAa,kBAAmB,SAAQ,mBAAmB;;IACzD,MAAM,CAAC,IAAI,WAA6B;IAExC,MAAM,CAAC,cAAc,SAAgD;gBAOnE,SAAS,EAAE,iCAAiC,EAC5C,MAAM,GAAE,wBAMP;IASH,OAAO,IAAI,MAAM;IAqBjB,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IA+B9D,cAAc,CAAC,EACnB,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;IAUrC,gBAAgB,CAAC,EACrB,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;CAiC5C"}
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _SolAccountProvider_instances, _SolAccountProvider_client, _SolAccountProvider_getKeyringClientFromSnapId, _SolAccountProvider_createAccount;
12
+ var _SolAccountProvider_instances, _SolAccountProvider_client, _SolAccountProvider_config, _SolAccountProvider_getKeyringClientFromSnapId, _SolAccountProvider_createAccount;
13
13
  import { assertIsBip44Account } from "@metamask/account-api";
14
14
  import { SolScope } from "@metamask/keyring-api";
15
15
  import { KeyringAccountEntropyTypeOption, SolAccountType } from "@metamask/keyring-api";
@@ -17,15 +17,25 @@ import { KeyringTypes } from "@metamask/keyring-controller";
17
17
  import { KeyringClient } from "@metamask/keyring-snap-client";
18
18
  import { HandlerType } from "@metamask/snaps-utils";
19
19
  import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
20
+ import { withRetry, withTimeout } from "./utils.mjs";
21
+ export const SOL_ACCOUNT_PROVIDER_NAME = 'Solana';
20
22
  export class SolAccountProvider extends SnapAccountProvider {
21
- constructor(messenger) {
23
+ constructor(messenger, config = {
24
+ discovery: {
25
+ timeoutMs: 2000,
26
+ maxAttempts: 3,
27
+ backOffMs: 1000,
28
+ },
29
+ }) {
22
30
  super(SolAccountProvider.SOLANA_SNAP_ID, messenger);
23
31
  _SolAccountProvider_instances.add(this);
24
32
  _SolAccountProvider_client.set(this, void 0);
33
+ _SolAccountProvider_config.set(this, void 0);
25
34
  __classPrivateFieldSet(this, _SolAccountProvider_client, __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_getKeyringClientFromSnapId).call(this, SolAccountProvider.SOLANA_SNAP_ID), "f");
35
+ __classPrivateFieldSet(this, _SolAccountProvider_config, config, "f");
26
36
  }
27
37
  getName() {
28
- return 'Solana';
38
+ return SolAccountProvider.NAME;
29
39
  }
30
40
  isAccountCompatible(account) {
31
41
  return (account.type === SolAccountType.DataAccount &&
@@ -41,7 +51,10 @@ export class SolAccountProvider extends SnapAccountProvider {
41
51
  return [account];
42
52
  }
43
53
  async discoverAccounts({ entropySource, groupIndex, }) {
44
- const discoveredAccounts = await __classPrivateFieldGet(this, _SolAccountProvider_client, "f").discoverAccounts([SolScope.Mainnet], entropySource, groupIndex);
54
+ const discoveredAccounts = await withRetry(() => withTimeout(__classPrivateFieldGet(this, _SolAccountProvider_client, "f").discoverAccounts([SolScope.Mainnet], entropySource, groupIndex), __classPrivateFieldGet(this, _SolAccountProvider_config, "f").discovery.timeoutMs), {
55
+ maxAttempts: __classPrivateFieldGet(this, _SolAccountProvider_config, "f").discovery.maxAttempts,
56
+ backOffMs: __classPrivateFieldGet(this, _SolAccountProvider_config, "f").discovery.backOffMs,
57
+ });
45
58
  if (!discoveredAccounts.length) {
46
59
  return [];
47
60
  }
@@ -53,7 +66,7 @@ export class SolAccountProvider extends SnapAccountProvider {
53
66
  return createdAccounts;
54
67
  }
55
68
  }
56
- _SolAccountProvider_client = new WeakMap(), _SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getKeyringClientFromSnapId = function _SolAccountProvider_getKeyringClientFromSnapId(snapId) {
69
+ _SolAccountProvider_client = new WeakMap(), _SolAccountProvider_config = new WeakMap(), _SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getKeyringClientFromSnapId = function _SolAccountProvider_getKeyringClientFromSnapId(snapId) {
57
70
  return new KeyringClient({
58
71
  send: async (request) => {
59
72
  const response = await this.messenger.call('SnapController:handleRequest', {
@@ -78,5 +91,6 @@ _SolAccountProvider_client = new WeakMap(), _SolAccountProvider_instances = new
78
91
  assertIsBip44Account(account);
79
92
  return account;
80
93
  };
94
+ SolAccountProvider.NAME = SOL_ACCOUNT_PROVIDER_NAME;
81
95
  SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
82
96
  //# sourceMappingURL=SolAccountProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAqB,8BAA8B;AAEhF,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAE9D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAIpD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;I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CAAC;QAEF,OAAO,eAAe,CAAC;IACzB,CAAC;;oMA5F2B,MAAc;IACxC,OAAO,IAAI,aAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE;YACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACxC,8BAA8B,EAC9B;gBACE,MAAM,EAAE,MAAgB;gBACxB,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,WAAW,CAAC,gBAAgB;gBACrC,OAAO;aACR,CACF,CAAC;YACF,OAAO,QAAgB,CAAC;QAC1B,CAAC;KACF,CAAC,CAAC;AACL,CAAC,sCASD,KAAK,4CAAgB,EACnB,aAAa,EACb,UAAU,EACV,cAAc,GAKf;IACC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;IACnE,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,CAAC;IAEvE,6DAA6D;IAC7D,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;QACxB,IAAI,EAAE,+BAA+B,CAAC,QAAQ;QAC9C,EAAE,EAAE,aAAa;QACjB,UAAU;QACV,cAAc;KACf,CAAC;IAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA7DM,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account, type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { SolScope } 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 { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n readonly #client: KeyringClient;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n this.#client = this.#getKeyringClientFromSnapId(\n SolAccountProvider.SOLANA_SNAP_ID,\n );\n }\n\n getName(): string {\n return 'Solana';\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\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 #createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n derivationPath: string;\n }): Promise<Bip44Account<KeyringAccount>> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n const account = await createAccount({ entropySource, derivationPath });\n\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n return account;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n });\n return [account];\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const discoveredAccounts = await this.#client.discoverAccounts(\n [SolScope.Mainnet],\n entropySource,\n groupIndex,\n );\n\n if (!discoveredAccounts.length) {\n return [];\n }\n\n const createdAccounts = await Promise.all(\n discoveredAccounts.map((d) =>\n this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath: d.derivationPath,\n }),\n ),\n );\n\n return createdAccounts;\n }\n}\n"]}
1
+ {"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAqB,8BAA8B;AAEhF,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAE9D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAIpD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AAUjD,MAAM,CAAC,MAAM,yBAAyB,GAAG,QAAiB,CAAC;AAE3D,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IASzD,YACE,SAA4C,EAC5C,SAAmC;QACjC,SAAS,EAAE;YACT,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,IAAI;SAChB;KACF;QAED,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;;QAd7C,6CAAuB;QAEvB,6CAAkC;QAazC,uBAAA,IAAI,8BAAW,uBAAA,IAAI,qFAA4B,MAAhC,IAAI,EACjB,kBAAkB,CAAC,cAAc,CAClC,MAAA,CAAC;QACF,uBAAA,IAAI,8BAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,OA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,cAAc;SACjC,CAAC,CACH,CACF,CAAC;QAEF,OAAO,eAAe,CAAC;IACzB,CAAC;;gPAtG2B,MAAc;IACxC,OAAO,IAAI,aAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE;YACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACxC,8BAA8B,EAC9B;gBACE,MAAM,EAAE,MAAgB;gBACxB,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,WAAW,CAAC,gBAAgB;gBACrC,OAAO;aACR,CACF,CAAC;YACF,OAAO,QAAgB,CAAC;QAC1B,CAAC;KACF,CAAC,CAAC;AACL,CAAC,sCASD,KAAK,4CAAgB,EACnB,aAAa,EACb,UAAU,EACV,cAAc,GAKf;IACC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;IACnE,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,CAAC;IAEvE,6DAA6D;IAC7D,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;QACxB,IAAI,EAAE,+BAA+B,CAAC,QAAQ;QAC9C,EAAE,EAAE,aAAa;QACjB,UAAU;QACV,cAAc;KACf,CAAC;IAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA3EM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account, type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { SolScope } 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 { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\n\nexport type SolAccountProviderConfig = {\n discovery: {\n maxAttempts: number;\n timeoutMs: number;\n backOffMs: number;\n };\n};\n\nexport const SOL_ACCOUNT_PROVIDER_NAME = 'Solana' as const;\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static NAME = SOL_ACCOUNT_PROVIDER_NAME;\n\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n readonly #client: KeyringClient;\n\n readonly #config: SolAccountProviderConfig;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: SolAccountProviderConfig = {\n discovery: {\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n },\n ) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n this.#client = this.#getKeyringClientFromSnapId(\n SolAccountProvider.SOLANA_SNAP_ID,\n );\n this.#config = config;\n }\n\n getName(): string {\n return SolAccountProvider.NAME;\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\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 #createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n derivationPath: string;\n }): Promise<Bip44Account<KeyringAccount>> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n const account = await createAccount({ entropySource, derivationPath });\n\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n return account;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n });\n return [account];\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n this.#client.discoverAccounts(\n [SolScope.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 (!discoveredAccounts.length) {\n return [];\n }\n\n const createdAccounts = await Promise.all(\n discoveredAccounts.map((d) =>\n this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath: d.derivationPath,\n }),\n ),\n );\n\n return createdAccounts;\n }\n}\n"]}
@@ -14,9 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.TimeoutError = void 0;
17
18
  __exportStar(require("./BaseBip44AccountProvider.cjs"), exports);
18
19
  __exportStar(require("./SnapAccountProvider.cjs"), exports);
19
20
  __exportStar(require("./AccountProviderWrapper.cjs"), exports);
21
+ // Errors that can bubble up outside of provider calls.
22
+ var utils_1 = require("./utils.cjs");
23
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return utils_1.TimeoutError; } });
20
24
  // Concrete providers:
21
25
  __exportStar(require("./SolAccountProvider.cjs"), exports);
22
26
  __exportStar(require("./EvmAccountProvider.cjs"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA2C;AAC3C,4DAAsC;AACtC,+DAAyC;AAEzC,sBAAsB;AACtB,2DAAqC;AACrC,2DAAqC","sourcesContent":["export * from './BaseBip44AccountProvider';\nexport * from './SnapAccountProvider';\nexport * from './AccountProviderWrapper';\n\n// Concrete providers:\nexport * from './SolAccountProvider';\nexport * from './EvmAccountProvider';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iEAA2C;AAC3C,4DAAsC;AACtC,+DAAyC;AAEzC,uDAAuD;AACvD,qCAAuC;AAA9B,qGAAA,YAAY,OAAA;AAErB,sBAAsB;AACtB,2DAAqC;AACrC,2DAAqC","sourcesContent":["export * from './BaseBip44AccountProvider';\nexport * from './SnapAccountProvider';\nexport * from './AccountProviderWrapper';\n\n// Errors that can bubble up outside of provider calls.\nexport { TimeoutError } from './utils';\n\n// Concrete providers:\nexport * from './SolAccountProvider';\nexport * from './EvmAccountProvider';\n"]}
@@ -1,6 +1,7 @@
1
1
  export * from "./BaseBip44AccountProvider.cjs";
2
2
  export * from "./SnapAccountProvider.cjs";
3
3
  export * from "./AccountProviderWrapper.cjs";
4
+ export { TimeoutError } from "./utils.cjs";
4
5
  export * from "./SolAccountProvider.cjs";
5
6
  export * from "./EvmAccountProvider.cjs";
6
7
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,0CAAsC;AACtC,6CAAyC;AAGzC,yCAAqC;AACrC,yCAAqC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,0CAAsC;AACtC,6CAAyC;AAGzC,OAAO,EAAE,YAAY,EAAE,oBAAgB;AAGvC,yCAAqC;AACrC,yCAAqC"}
@@ -1,6 +1,7 @@
1
1
  export * from "./BaseBip44AccountProvider.mjs";
2
2
  export * from "./SnapAccountProvider.mjs";
3
3
  export * from "./AccountProviderWrapper.mjs";
4
+ export { TimeoutError } from "./utils.mjs";
4
5
  export * from "./SolAccountProvider.mjs";
5
6
  export * from "./EvmAccountProvider.mjs";
6
7
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,0CAAsC;AACtC,6CAAyC;AAGzC,yCAAqC;AACrC,yCAAqC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,0CAAsC;AACtC,6CAAyC;AAGzC,OAAO,EAAE,YAAY,EAAE,oBAAgB;AAGvC,yCAAqC;AACrC,yCAAqC"}