@metamask/multichain-account-service 8.0.0 → 9.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 (126) hide show
  1. package/CHANGELOG.md +45 -12
  2. package/dist/MultichainAccountGroup.cjs.map +1 -1
  3. package/dist/MultichainAccountGroup.d.cts.map +1 -1
  4. package/dist/MultichainAccountGroup.d.mts.map +1 -1
  5. package/dist/MultichainAccountGroup.mjs.map +1 -1
  6. package/dist/MultichainAccountService-method-action-types.cjs.map +1 -1
  7. package/dist/MultichainAccountService-method-action-types.d.cts +9 -1
  8. package/dist/MultichainAccountService-method-action-types.d.cts.map +1 -1
  9. package/dist/MultichainAccountService-method-action-types.d.mts +9 -1
  10. package/dist/MultichainAccountService-method-action-types.d.mts.map +1 -1
  11. package/dist/MultichainAccountService-method-action-types.mjs.map +1 -1
  12. package/dist/MultichainAccountService.cjs +1 -0
  13. package/dist/MultichainAccountService.cjs.map +1 -1
  14. package/dist/MultichainAccountService.d.cts.map +1 -1
  15. package/dist/MultichainAccountService.d.mts.map +1 -1
  16. package/dist/MultichainAccountService.mjs +1 -0
  17. package/dist/MultichainAccountService.mjs.map +1 -1
  18. package/dist/MultichainAccountWallet.cjs.map +1 -1
  19. package/dist/MultichainAccountWallet.d.cts.map +1 -1
  20. package/dist/MultichainAccountWallet.d.mts.map +1 -1
  21. package/dist/MultichainAccountWallet.mjs.map +1 -1
  22. package/dist/analytics/perf.cjs +1 -1
  23. package/dist/analytics/perf.cjs.map +1 -1
  24. package/dist/analytics/perf.mjs +1 -1
  25. package/dist/analytics/perf.mjs.map +1 -1
  26. package/dist/errors.cjs +1 -1
  27. package/dist/errors.cjs.map +1 -1
  28. package/dist/errors.d.cts.map +1 -1
  29. package/dist/errors.d.mts.map +1 -1
  30. package/dist/errors.mjs +2 -2
  31. package/dist/errors.mjs.map +1 -1
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +1 -1
  34. package/dist/index.d.cts.map +1 -1
  35. package/dist/index.d.mts +1 -1
  36. package/dist/index.d.mts.map +1 -1
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
  39. package/dist/providers/AccountProviderWrapper.d.cts +3 -2
  40. package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
  41. package/dist/providers/AccountProviderWrapper.d.mts +3 -2
  42. package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
  43. package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
  44. package/dist/providers/BaseBip44AccountProvider.cjs +29 -0
  45. package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
  46. package/dist/providers/BaseBip44AccountProvider.d.cts +29 -2
  47. package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
  48. package/dist/providers/BaseBip44AccountProvider.d.mts +29 -2
  49. package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
  50. package/dist/providers/BaseBip44AccountProvider.mjs +29 -0
  51. package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
  52. package/dist/providers/BtcAccountProvider.cjs +2 -2
  53. package/dist/providers/BtcAccountProvider.cjs.map +1 -1
  54. package/dist/providers/BtcAccountProvider.d.cts +3 -2
  55. package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
  56. package/dist/providers/BtcAccountProvider.d.mts +3 -2
  57. package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
  58. package/dist/providers/BtcAccountProvider.mjs +2 -2
  59. package/dist/providers/BtcAccountProvider.mjs.map +1 -1
  60. package/dist/providers/EvmAccountProvider.cjs +63 -46
  61. package/dist/providers/EvmAccountProvider.cjs.map +1 -1
  62. package/dist/providers/EvmAccountProvider.d.cts +3 -2
  63. package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
  64. package/dist/providers/EvmAccountProvider.d.mts +3 -2
  65. package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
  66. package/dist/providers/EvmAccountProvider.mjs +63 -46
  67. package/dist/providers/EvmAccountProvider.mjs.map +1 -1
  68. package/dist/providers/SnapAccountProvider.cjs +2 -2
  69. package/dist/providers/SnapAccountProvider.cjs.map +1 -1
  70. package/dist/providers/SnapAccountProvider.d.cts +1 -1
  71. package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
  72. package/dist/providers/SnapAccountProvider.d.mts +1 -1
  73. package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
  74. package/dist/providers/SnapAccountProvider.mjs +2 -2
  75. package/dist/providers/SnapAccountProvider.mjs.map +1 -1
  76. package/dist/providers/SolAccountProvider.cjs +2 -2
  77. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  78. package/dist/providers/SolAccountProvider.d.cts +3 -2
  79. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  80. package/dist/providers/SolAccountProvider.d.mts +3 -2
  81. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  82. package/dist/providers/SolAccountProvider.mjs +2 -2
  83. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  84. package/dist/providers/TrxAccountProvider.cjs +2 -2
  85. package/dist/providers/TrxAccountProvider.cjs.map +1 -1
  86. package/dist/providers/TrxAccountProvider.d.cts +3 -2
  87. package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
  88. package/dist/providers/TrxAccountProvider.d.mts +3 -2
  89. package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
  90. package/dist/providers/TrxAccountProvider.mjs +2 -2
  91. package/dist/providers/TrxAccountProvider.mjs.map +1 -1
  92. package/dist/providers/utils.cjs +13 -1
  93. package/dist/providers/utils.cjs.map +1 -1
  94. package/dist/providers/utils.d.cts +7 -0
  95. package/dist/providers/utils.d.cts.map +1 -1
  96. package/dist/providers/utils.d.mts +7 -0
  97. package/dist/providers/utils.d.mts.map +1 -1
  98. package/dist/providers/utils.mjs +11 -0
  99. package/dist/providers/utils.mjs.map +1 -1
  100. package/dist/tests/accounts.cjs +4 -6
  101. package/dist/tests/accounts.cjs.map +1 -1
  102. package/dist/tests/accounts.d.cts +8 -21
  103. package/dist/tests/accounts.d.cts.map +1 -1
  104. package/dist/tests/accounts.d.mts +8 -21
  105. package/dist/tests/accounts.d.mts.map +1 -1
  106. package/dist/tests/accounts.mjs +4 -6
  107. package/dist/tests/accounts.mjs.map +1 -1
  108. package/dist/tests/messenger.cjs +1 -0
  109. package/dist/tests/messenger.cjs.map +1 -1
  110. package/dist/tests/messenger.d.cts.map +1 -1
  111. package/dist/tests/messenger.d.mts.map +1 -1
  112. package/dist/tests/messenger.mjs +1 -0
  113. package/dist/tests/messenger.mjs.map +1 -1
  114. package/dist/tests/providers.cjs.map +1 -1
  115. package/dist/tests/providers.d.cts +2 -1
  116. package/dist/tests/providers.d.cts.map +1 -1
  117. package/dist/tests/providers.d.mts +2 -1
  118. package/dist/tests/providers.d.mts.map +1 -1
  119. package/dist/tests/providers.mjs.map +1 -1
  120. package/dist/types.cjs.map +1 -1
  121. package/dist/types.d.cts +4 -4
  122. package/dist/types.d.cts.map +1 -1
  123. package/dist/types.d.mts +4 -4
  124. package/dist/types.d.mts.map +1 -1
  125. package/dist/types.mjs.map +1 -1
  126. package/package.json +32 -31
@@ -1 +1 @@
1
- {"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAQ7D,OAAO,EACL,mBAAmB,EACnB,+BAA+B,EAC/B,cAAc,EACd,QAAQ,EACT,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,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,QAAQ,CAAC;AAElD,MAAM,CAAC,MAAM,m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C9F,6FAA6F;gBAC7F,uCAAuC;gBACvC,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;;sIAzFkB,UAAkB;IACnC,OAAO,cAAc,UAAU,MAAM,CAAC;AACxC,CAAC;AAjCM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport 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 KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\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 SolAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const SOL_ACCOUNT_PROVIDER_NAME = 'Solana';\n\nexport const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG: SnapAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n batched: false, // For now, the Snap is not fully v2 compliant.\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\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 capabilities: KeyringCapabilities = {\n scopes: [SolScope.Mainnet, SolScope.Devnet, SolScope.Testnet],\n bip44: {\n deriveIndex: true,\n deriveIndexRange: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: SolAccountProviderConfig = SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return SolAccountProvider.NAME;\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 #getDerivationPath(groupIndex: number): string {\n return `m/44'/501'/${groupIndex}'/0'`;\n }\n\n protected override async createAccountV1(\n keyring: RestrictedSnapKeyring,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Promise<KeyringAccount> {\n return keyring.createAccount({\n entropySource,\n derivationPath: this.#getDerivationPath(groupIndex),\n });\n }\n\n protected override toBip44Account(\n account: KeyringAccount,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Bip44Account<KeyringAccount> {\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath: this.#getDerivationPath(groupIndex),\n };\n\n assertIsBip44Account(account);\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 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 [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 // NOTE: We know the Solana Snap only return 1 account per group index during discovery. Also,\n // we do not use the returned `derivationPath` on purpose. Instead we just create the account\n // for this group index and that's all.\n return await this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAI7D,OAAO,EACL,mBAAmB,EACnB,+BAA+B,EAC/B,cAAc,EACd,QAAQ,EACT,8BAA8B;AAE/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,OAAO,EAAE,aAAa,EAAE,+BAAqB;AAC7C,OAAO,EAAE,SAAS,EAAE,gCAA4B;AAEhD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAK5D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AAIjD,MAAM,CAAC,MAAM,yBAAyB,GAAG,QAAQ,CAAC;AAElD,MAAM,CAAC,MAAM,mCAAmC,GAA8B;IAC5E,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,OAAO,EAAE,KAAK,EAAE,+CAA+C;QAC/D,SAAS,EAAE,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AC;;sIAzFkB,UAAkB;IACnC,OAAO,cAAc,UAAU,MAAM,CAAC;AACxC,CAAC;AAjCM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolScope,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../analytics/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\n\nexport type SolAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const SOL_ACCOUNT_PROVIDER_NAME = 'Solana';\n\nexport const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG: SnapAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n batched: false, // For now, the Snap is not fully v2 compliant.\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\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 capabilities: KeyringCapabilities = {\n scopes: [SolScope.Mainnet, SolScope.Devnet, SolScope.Testnet],\n bip44: {\n deriveIndex: true,\n deriveIndexRange: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: SolAccountProviderConfig = SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return SolAccountProvider.NAME;\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 #getDerivationPath(groupIndex: number): string {\n return `m/44'/501'/${groupIndex}'/0'`;\n }\n\n protected override async createAccountV1(\n keyring: RestrictedSnapKeyring,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Promise<KeyringAccount> {\n return keyring.createAccount({\n entropySource,\n derivationPath: this.#getDerivationPath(groupIndex),\n });\n }\n\n protected override toBip44Account(\n account: KeyringAccount,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Bip44Account<KeyringAccount> {\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath: this.#getDerivationPath(groupIndex),\n };\n\n assertIsBip44Account(account);\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 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 [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 // NOTE: We know the Solana Snap only return 1 account per group index during discovery. Also,\n // we do not use the returned `derivationPath` on purpose. Instead we just create the account\n // for this group index and that's all.\n return await this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n );\n });\n }\n}\n"]}
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TrxAccountProvider = exports.TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG = exports.TRX_ACCOUNT_PROVIDER_NAME = void 0;
4
4
  const keyring_api_1 = require("@metamask/keyring-api");
5
5
  const keyring_controller_1 = require("@metamask/keyring-controller");
6
- const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
7
- const utils_1 = require("./utils.cjs");
8
6
  const analytics_1 = require("../analytics/index.cjs");
9
7
  const traces_1 = require("../analytics/traces.cjs");
8
+ const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
9
+ const utils_1 = require("./utils.cjs");
10
10
  exports.TRX_ACCOUNT_PROVIDER_NAME = 'Tron';
11
11
  exports.TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
12
12
  maxConcurrency: 3,
@@ -1 +1 @@
1
- {"version":3,"file":"TrxAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":";;;AAOA,uDAI+B;AAC/B,qEAA4D;AAI5D,mEAA4D;AAK5D,uCAAiD;AACjD,sDAA6C;AAC7C,oDAAgD;AAKnC,QAAA,yBAAyB,GAAG,MAAM,CAAC;AAEnC,QAAA,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;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S,CAAC,oBAAoB;gBACpC,IAAI,EAAE;oBACJ,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE;iBACzB;aACF,EACD,KAAK,IAAI,EAAE;gBACT,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;oBACnC,OAAO,EAAE,CAAC;gBACZ,CAAC;gBAED,MAAM,kBAAkB,GAAG,MAAM,IAAA,iBAAS,EACxC,GAAG,EAAE,CACH,IAAA,mBAAW,EACT,GAAG,EAAE,CACH,MAAM,CAAC,gBAAgB,CACrB,CAAC,sBAAQ,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,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;oBAC/B,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;;AAhGH,gDAiGC;AAhGQ,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,gCAA0C,AAA7C,CAA8C","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 TrxAccountType,\n TrxScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\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 TrxAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const TRX_ACCOUNT_PROVIDER_NAME = 'Tron';\n\nexport const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG: TrxAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n batched: false, // For now, the Snap is not fully v2 compliant.\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class TrxAccountProvider extends SnapAccountProvider {\n static NAME = TRX_ACCOUNT_PROVIDER_NAME;\n\n static TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [TrxScope.Mainnet, TrxScope.Shasta],\n bip44: {\n deriveIndex: true,\n deriveIndexRange: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: TrxAccountProviderConfig = TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(TrxAccountProvider.TRX_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return TrxAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === TrxAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\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: TrxAccountType.Eoa,\n scope: TrxScope.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 [TrxScope.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 return await this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"TrxAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":";;;AAGA,uDAI+B;AAE/B,qEAA4D;AAI5D,sDAA6C;AAC7C,oDAAgD;AAEhD,mEAA4D;AAK5D,uCAAiD;AAIpC,QAAA,yBAAyB,GAAG,MAAM,CAAC;AAEnC,QAAA,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,OAAO,EAAE,KAAK,EAAE,+CAA+C;QAC/D,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAa,kBAAm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,CAAC,OAAO,EAAE,CAAC;oBACnC,OAAO,EAAE,CAAC;gBACZ,CAAC;gBAED,MAAM,kBAAkB,GAAG,MAAM,IAAA,iBAAS,EACxC,GAAG,EAAE,CACH,IAAA,mBAAW,EACT,GAAG,EAAE,CACH,MAAM,CAAC,gBAAgB,CACrB,CAAC,sBAAQ,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,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;oBAC/B,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;;AAhGH,gDAiGC;AAhGQ,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,gCAA0C,AAA7C,CAA8C","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n TrxAccountType,\n TrxScope,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../analytics/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\n\nexport type TrxAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const TRX_ACCOUNT_PROVIDER_NAME = 'Tron';\n\nexport const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG: TrxAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n batched: false, // For now, the Snap is not fully v2 compliant.\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class TrxAccountProvider extends SnapAccountProvider {\n static NAME = TRX_ACCOUNT_PROVIDER_NAME;\n\n static TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [TrxScope.Mainnet, TrxScope.Shasta],\n bip44: {\n deriveIndex: true,\n deriveIndexRange: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: TrxAccountProviderConfig = TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(TrxAccountProvider.TRX_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return TrxAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === TrxAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\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: TrxAccountType.Eoa,\n scope: TrxScope.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 [TrxScope.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 return await this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n );\n });\n }\n}\n"]}
@@ -1,11 +1,12 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
2
  import type { TraceCallback } from "@metamask/controller-utils";
3
- import type { EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
3
+ import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
4
+ import type { KeyringCapabilities } from "@metamask/keyring-api/v2";
4
5
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
6
  import type { SnapId } from "@metamask/snaps-sdk";
7
+ import type { MultichainAccountServiceMessenger } from "../types.cjs";
6
8
  import { SnapAccountProvider } from "./SnapAccountProvider.cjs";
7
9
  import type { RestrictedSnapKeyring, SnapAccountProviderConfig } from "./SnapAccountProvider.cjs";
8
- import type { MultichainAccountServiceMessenger } from "../types.cjs";
9
10
  export type TrxAccountProviderConfig = SnapAccountProviderConfig;
10
11
  export declare const TRX_ACCOUNT_PROVIDER_NAME = "Tron";
11
12
  export declare const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG: TrxAccountProviderConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"TrxAccountProvider.d.cts","sourceRoot":"","sources":["../../src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E;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CA4C5C"}
@@ -1,11 +1,12 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
2
  import type { TraceCallback } from "@metamask/controller-utils";
3
- import type { EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
3
+ import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
4
+ import type { KeyringCapabilities } from "@metamask/keyring-api/v2";
4
5
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
6
  import type { SnapId } from "@metamask/snaps-sdk";
7
+ import type { MultichainAccountServiceMessenger } from "../types.mjs";
6
8
  import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
7
9
  import type { RestrictedSnapKeyring, SnapAccountProviderConfig } from "./SnapAccountProvider.mjs";
8
- import type { MultichainAccountServiceMessenger } from "../types.mjs";
9
10
  export type TrxAccountProviderConfig = SnapAccountProviderConfig;
10
11
  export declare const TRX_ACCOUNT_PROVIDER_NAME = "Tron";
11
12
  export declare const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG: TrxAccountProviderConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"TrxAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAO/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EACV,qBAAqB,EACrB,yBAAyB,EAC1B,kCAA8B;AAI/B,OAA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IlD,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAClE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EACV,qBAAqB,EACrB,yBAAyB,EAC1B,kCAA8B;AAG/B,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,SAAS,CAAC;AAEhD,eAAO,MAAM,mCAAmC,EAAE,wBAejD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAA8C;IAEhE,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAMxC;gBAGA,SAAS,EAAE,iCAAiC,EAC5C,MAAM,GAAE,wBAA8D,EACtE,KAAK,GAAE,aAA6B;IAKtC,OAAO,IAAI,MAAM;IAIjB,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;cAOjD,eAAe,CAChC,OAAO,EAAE,qBAAqB,EAC9B,EACE,aAAa,EACb,UAAU,GACX,EAAE;QAAE,aAAa,EAAE,eAAe,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GACxD,OAAO,CAAC,cAAc,CAAC;IASpB,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;CA4C5C"}
@@ -1,9 +1,9 @@
1
1
  import { AccountCreationType, TrxAccountType, TrxScope } from "@metamask/keyring-api";
2
2
  import { KeyringTypes } from "@metamask/keyring-controller";
3
- import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
4
- import { withRetry, withTimeout } from "./utils.mjs";
5
3
  import { traceFallback } from "../analytics/index.mjs";
6
4
  import { TraceName } from "../analytics/traces.mjs";
5
+ import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
6
+ import { withRetry, withTimeout } from "./utils.mjs";
7
7
  export const TRX_ACCOUNT_PROVIDER_NAME = 'Tron';
8
8
  export const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
9
9
  maxConcurrency: 3,
@@ -1 +1 @@
1
- {"version":3,"file":"TrxAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACT,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,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,MAAM,CAAC;AAEhD,MAAM,CAAC,MAAM,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,OAAO,EAAE,KAAK,EAAE,+CAA+C;QAC/D,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,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAbzD,iBAAY,GAAwB;YAC3C,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC;YAC3C,KAAK,EAAE;gB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;oBACE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW;oBAC9C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS;iBAC3C,CACF,CAAC;gBAEF,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;oBAC/B,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;;AA/FM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,gCAA0C,AAA7C,CAA8C","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 TrxAccountType,\n TrxScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\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 TrxAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const TRX_ACCOUNT_PROVIDER_NAME = 'Tron';\n\nexport const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG: TrxAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n batched: false, // For now, the Snap is not fully v2 compliant.\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class TrxAccountProvider extends SnapAccountProvider {\n static NAME = TRX_ACCOUNT_PROVIDER_NAME;\n\n static TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [TrxScope.Mainnet, TrxScope.Shasta],\n bip44: {\n deriveIndex: true,\n deriveIndexRange: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: TrxAccountProviderConfig = TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(TrxAccountProvider.TRX_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return TrxAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === TrxAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\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: TrxAccountType.Eoa,\n scope: TrxScope.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 [TrxScope.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 return await this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"TrxAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACT,8BAA8B;AAE/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,OAAO,EAAE,aAAa,EAAE,+BAAqB;AAC7C,OAAO,EAAE,SAAS,EAAE,gCAA4B;AAEhD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAK5D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AAIjD,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEhD,MAAM,CAAC,MAAM,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,OAAO,EAAE,KAAK,EAAE,+CAA+C;QAC/D,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,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAbzD,iBAAY,GAAwB;YAC3C,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC;YAC3C,KAAK,EA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C,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,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;oBAC/B,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;;AA/FM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,gCAA0C,AAA7C,CAA8C","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n TrxAccountType,\n TrxScope,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../analytics/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\n\nexport type TrxAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const TRX_ACCOUNT_PROVIDER_NAME = 'Tron';\n\nexport const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG: TrxAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n batched: false, // For now, the Snap is not fully v2 compliant.\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class TrxAccountProvider extends SnapAccountProvider {\n static NAME = TRX_ACCOUNT_PROVIDER_NAME;\n\n static TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [TrxScope.Mainnet, TrxScope.Shasta],\n bip44: {\n deriveIndex: true,\n deriveIndexRange: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: TrxAccountProviderConfig = TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(TrxAccountProvider.TRX_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return TrxAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === TrxAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\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: TrxAccountType.Eoa,\n scope: TrxScope.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 [TrxScope.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 return await this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n );\n });\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withTimeout = exports.withRetry = exports.isTimeoutError = exports.TimeoutError = void 0;
3
+ exports.withTimeout = exports.withRetry = exports.isKeyringControllerLockedError = exports.isTimeoutError = exports.TimeoutError = void 0;
4
+ const keyring_controller_1 = require("@metamask/keyring-controller");
4
5
  /** Timeout error. */
5
6
  class TimeoutError extends Error {
6
7
  constructor(message) {
@@ -19,6 +20,17 @@ function isTimeoutError(error) {
19
20
  return error instanceof TimeoutError;
20
21
  }
21
22
  exports.isTimeoutError = isTimeoutError;
23
+ /**
24
+ * Check if an error is a `KeyringControllerLockedError`.
25
+ *
26
+ * @param error - The error to check.
27
+ * @returns `true` if the error is a `KeyringControllerLockedError`, otherwise `false`.
28
+ */
29
+ function isKeyringControllerLockedError(error) {
30
+ return (error instanceof keyring_controller_1.KeyringControllerError &&
31
+ error.message === keyring_controller_1.KeyringControllerErrorMessage.ControllerLocked);
32
+ }
33
+ exports.isKeyringControllerLockedError = isKeyringControllerLockedError;
22
34
  /**
23
35
  * Execute a function with exponential backoff on transient failures.
24
36
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":";;;AAAA,qBAAqB;AACrB,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3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YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;AACH,CAAC;AApBD,kCAoBC","sourcesContent":["/** Timeout error. */\nexport class TimeoutError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * Check if an error is a `TimeoutError`.\n *\n * @param error - The error to check.\n * @returns `true` if the error is a `TimeoutError`, otherwise `false`.\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return error instanceof TimeoutError;\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 */\nexport async function 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 fn - A callback that returns the promise to execute.\n * @param timeoutMs - The timeout in milliseconds.\n * @returns The result of the promise.\n */\nexport async function withTimeout<T>(\n fn: () => Promise<T>,\n timeoutMs: number = 500,\n): Promise<T> {\n let timer;\n try {\n return await Promise.race<T>([\n fn(),\n new Promise<T>((_resolve, reject) => {\n timer = setTimeout(\n () => reject(new TimeoutError(`Timed out after: ${timeoutMs}ms`)),\n timeoutMs,\n );\n }),\n ]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":";;;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oB,EACpB,YAAoB,GAAG;IAEvB,IAAI,KAAK,CAAC;IACV,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAI;YAC3B,EAAE,EAAE;YACJ,IAAI,OAAO,CAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;gBAClC,KAAK,GAAG,UAAU,CAChB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,oBAAoB,SAAS,IAAI,CAAC,CAAC,EACjE,SAAS,CACV,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,IAAI,KAAK,EAAE,CAAC;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;AACH,CAAC;AApBD,kCAoBC","sourcesContent":["import {\n KeyringControllerError,\n KeyringControllerErrorMessage,\n} from '@metamask/keyring-controller';\n\n/** Timeout error. */\nexport class TimeoutError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * Check if an error is a `TimeoutError`.\n *\n * @param error - The error to check.\n * @returns `true` if the error is a `TimeoutError`, otherwise `false`.\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return error instanceof TimeoutError;\n}\n\n/**\n * Check if an error is a `KeyringControllerLockedError`.\n *\n * @param error - The error to check.\n * @returns `true` if the error is a `KeyringControllerLockedError`, otherwise `false`.\n */\nexport function isKeyringControllerLockedError(error: unknown): boolean {\n return (\n error instanceof KeyringControllerError &&\n error.message === KeyringControllerErrorMessage.ControllerLocked\n );\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 */\nexport async function 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 fn - A callback that returns the promise to execute.\n * @param timeoutMs - The timeout in milliseconds.\n * @returns The result of the promise.\n */\nexport async function withTimeout<T>(\n fn: () => Promise<T>,\n timeoutMs: number = 500,\n): Promise<T> {\n let timer;\n try {\n return await Promise.race<T>([\n fn(),\n new Promise<T>((_resolve, reject) => {\n timer = setTimeout(\n () => reject(new TimeoutError(`Timed out after: ${timeoutMs}ms`)),\n timeoutMs,\n );\n }),\n ]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n}\n"]}
@@ -9,6 +9,13 @@ export declare class TimeoutError extends Error {
9
9
  * @returns `true` if the error is a `TimeoutError`, otherwise `false`.
10
10
  */
11
11
  export declare function isTimeoutError(error: unknown): error is TimeoutError;
12
+ /**
13
+ * Check if an error is a `KeyringControllerLockedError`.
14
+ *
15
+ * @param error - The error to check.
16
+ * @returns `true` if the error is a `KeyringControllerLockedError`, otherwise `false`.
17
+ */
18
+ export declare function isKeyringControllerLockedError(error: unknown): boolean;
12
19
  /**
13
20
  * Execute a function with exponential backoff on transient failures.
14
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,WAAW,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC7B,EACE,WAAe,EACf,SAAe,GAChB,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,GAAE,MAAY,GACtB,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAKA,qBAAqB;AACrB,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKtE;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,WAAW,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC7B,EACE,WAAe,EACf,SAAe,GAChB,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,GAAE,MAAY,GACtB,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
@@ -9,6 +9,13 @@ export declare class TimeoutError extends Error {
9
9
  * @returns `true` if the error is a `TimeoutError`, otherwise `false`.
10
10
  */
11
11
  export declare function isTimeoutError(error: unknown): error is TimeoutError;
12
+ /**
13
+ * Check if an error is a `KeyringControllerLockedError`.
14
+ *
15
+ * @param error - The error to check.
16
+ * @returns `true` if the error is a `KeyringControllerLockedError`, otherwise `false`.
17
+ */
18
+ export declare function isKeyringControllerLockedError(error: unknown): boolean;
12
19
  /**
13
20
  * Execute a function with exponential backoff on transient failures.
14
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,WAAW,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC7B,EACE,WAAe,EACf,SAAe,GAChB,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,GAAE,MAAY,GACtB,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAKA,qBAAqB;AACrB,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKtE;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,WAAW,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC7B,EACE,WAAe,EACf,SAAe,GAChB,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,GAAE,MAAY,GACtB,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
@@ -1,3 +1,4 @@
1
+ import { KeyringControllerError, KeyringControllerErrorMessage } from "@metamask/keyring-controller";
1
2
  /** Timeout error. */
2
3
  export class TimeoutError extends Error {
3
4
  constructor(message) {
@@ -14,6 +15,16 @@ export class TimeoutError extends Error {
14
15
  export function isTimeoutError(error) {
15
16
  return error instanceof TimeoutError;
16
17
  }
18
+ /**
19
+ * Check if an error is a `KeyringControllerLockedError`.
20
+ *
21
+ * @param error - The error to check.
22
+ * @returns `true` if the error is a `KeyringControllerLockedError`, otherwise `false`.
23
+ */
24
+ export function isKeyringControllerLockedError(error) {
25
+ return (error instanceof KeyringControllerError &&
26
+ error.message === KeyringControllerErrorMessage.ControllerLocked);
27
+ }
17
28
  /**
18
29
  * Execute a function with exponential backoff on transient failures.
19
30
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,YAAY,CAAC;AACvC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IACH,CAAC;AACH,CAAC","sourcesContent":["/** Timeout error. */\nexport class TimeoutError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * Check if an error is a `TimeoutError`.\n *\n * @param error - The error to check.\n * @returns `true` if the error is a `TimeoutError`, otherwise `false`.\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return error instanceof TimeoutError;\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 */\nexport async function 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 fn - A callback that returns the promise to execute.\n * @param timeoutMs - The timeout in milliseconds.\n * @returns The result of the promise.\n */\nexport async function withTimeout<T>(\n fn: () => Promise<T>,\n timeoutMs: number = 500,\n): Promise<T> {\n let timer;\n try {\n return await Promise.race<T>([\n fn(),\n new Promise<T>((_resolve, reject) => {\n timer = setTimeout(\n () => reject(new TimeoutError(`Timed out after: ${timeoutMs}ms`)),\n timeoutMs,\n );\n }),\n ]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC9B,qCAAqC;AAE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AAI,KAAK,CAAC;IACV,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAI;YAC3B,EAAE,EAAE;YACJ,IAAI,OAAO,CAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;gBAClC,KAAK,GAAG,UAAU,CAChB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,oBAAoB,SAAS,IAAI,CAAC,CAAC,EACjE,SAAS,CACV,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,IAAI,KAAK,EAAE,CAAC;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import {\n KeyringControllerError,\n KeyringControllerErrorMessage,\n} from '@metamask/keyring-controller';\n\n/** Timeout error. */\nexport class TimeoutError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * Check if an error is a `TimeoutError`.\n *\n * @param error - The error to check.\n * @returns `true` if the error is a `TimeoutError`, otherwise `false`.\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return error instanceof TimeoutError;\n}\n\n/**\n * Check if an error is a `KeyringControllerLockedError`.\n *\n * @param error - The error to check.\n * @returns `true` if the error is a `KeyringControllerLockedError`, otherwise `false`.\n */\nexport function isKeyringControllerLockedError(error: unknown): boolean {\n return (\n error instanceof KeyringControllerError &&\n error.message === KeyringControllerErrorMessage.ControllerLocked\n );\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 */\nexport async function 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 fn - A callback that returns the promise to execute.\n * @param timeoutMs - The timeout in milliseconds.\n * @returns The result of the promise.\n */\nexport async function withTimeout<T>(\n fn: () => Promise<T>,\n timeoutMs: number = 500,\n): Promise<T> {\n let timer;\n try {\n return await Promise.race<T>([\n fn(),\n new Promise<T>((_resolve, reject) => {\n timer = setTimeout(\n () => reject(new TimeoutError(`Timed out after: ${timeoutMs}ms`)),\n timeoutMs,\n );\n }),\n ]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n}\n"]}
@@ -189,8 +189,6 @@ exports.MOCK_BTC_P2WPKH_ACCOUNT_1 = {
189
189
  },
190
190
  snap: {
191
191
  id: 'mock-btc-snap-id',
192
- enabled: true,
193
- name: 'Mock Bitcoin Snap',
194
192
  },
195
193
  },
196
194
  };
@@ -217,8 +215,6 @@ exports.MOCK_BTC_P2TR_ACCOUNT_1 = {
217
215
  },
218
216
  snap: {
219
217
  id: 'mock-btc-snap-id',
220
- enabled: true,
221
- name: 'Mock Bitcoin Snap',
222
218
  },
223
219
  },
224
220
  };
@@ -288,6 +284,10 @@ class MockAccountBuilder {
288
284
  __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").id = (0, uuid_1.v4)();
289
285
  return this;
290
286
  }
287
+ withAddress(address) {
288
+ __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").address = address;
289
+ return this;
290
+ }
291
291
  withAddressSuffix(suffix) {
292
292
  __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").address += suffix;
293
293
  return this;
@@ -307,9 +307,7 @@ class MockAccountBuilder {
307
307
  withSnapId(snapId) {
308
308
  if (isInternalAccount(__classPrivateFieldGet(this, _MockAccountBuilder_account, "f"))) {
309
309
  __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").metadata.snap = {
310
- enabled: true,
311
310
  id: snapId,
312
- name: `Name: ${snapId}`,
313
311
  };
314
312
  }
315
313
  return this;
@@ -1 +1 @@
1
- {"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uDAAuD;AAMvD,uDAc+B;AAC/B,qEAA4D;AAG5D,+BAAkC;AAErB,QAAA,eAAe,GAAG;IAC7B,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,IAAI;IACd,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;CACjB,CAAC;AAEX,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAS,CAAC,CAAC;AAEhC,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAC5C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAE5C,QAAA,aAAa,GACxB,sFAAsF,CAAC;AAE5E,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,iCAAY,CAAC,EAAE;IACrB,QAAQ,EAAE,EAAE,EAAE,EAAE,6BAAqB,EAAE,IAAI,EAAE,cAAc,EAAE;IAC7D,QAAQ,EAAE,CAAC,OAAO,CAAC;CACpB,CAAC;AAEW,Q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F;AAzDD,gDAyDC;;AAEY,QAAA,4BAA4B,GAAG,6BAAqB,CAAC;AAErD,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,yBAAiB,CAClB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,0BAAkB,CACnB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CACrE,iCAAyB,CAC1B;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,8BAA8B,GAAG,kBAAkB,CAAC,IAAI,CACnE,+BAAuB,CACxB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AAET,SAAgB,qBAAqB,CACnC,OAAuB;IAEvB,OAAO;QACL,GAAG,OAAO;QACV,QAAQ,EAAE;YACR,IAAI,EAAE,gBAAgB;YACtB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;YACtB,OAAO,EAAE;gBACP,IAAI,EAAE,mBAAmB;aAC1B;SACF;KACF,CAAC;AACJ,CAAC;AAbD,sDAaC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { isBip44Account } from '@metamask/account-api';\nimport type {\n DiscoveredAccount,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n BtcScope,\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolMethod,\n SolScope,\n TrxAccountType,\n TrxMethod,\n TrxScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { v4 as uuid } from 'uuid';\n\nexport const ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nconst SOL_METHODS = Object.values(SolMethod);\n\nexport const MOCK_SNAP_1 = {\n id: 'local:mock-snap-id-1',\n name: 'Mock Snap 1',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 1',\n },\n};\n\nexport const MOCK_SNAP_2 = {\n id: 'local:mock-snap-id-2',\n name: 'Mock Snap 2',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 2',\n },\n};\n\nexport const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1';\nexport const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2';\n\nexport const MOCK_MNEMONIC =\n 'abandon ability able about above absent absorb abstract absurd abuse access accident';\n\nexport const MOCK_HD_KEYRING_1 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' },\n accounts: ['0x123'],\n};\n\nexport const MOCK_HD_KEYRING_2 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' },\n accounts: ['0x456'],\n};\n\n/** Used when tests need ensureCanUseSnapPlatform to resolve (SnapPlatformWatcher waits for Snap keyring). */\nexport const MOCK_SNAP_KEYRING = {\n type: KeyringTypes.snap,\n metadata: { id: 'snap-keyring', name: 'Snap Keyring' },\n accounts: [],\n};\n\nexport const MOCK_HD_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-id-1',\n address: '0x123',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_1.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 1',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_HD_ACCOUNT_2: Bip44Account<InternalAccount> = {\n id: 'mock-id-2',\n address: '0x456',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 2',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_SOL_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: SOL_METHODS,\n type: SolAccountType.DataAccount,\n scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet],\n metadata: {\n name: 'Solana Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_TRX_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [TrxMethod.SignMessageV2, TrxMethod.VerifyMessageV2],\n type: TrxAccountType.Eoa,\n scopes: [TrxScope.Mainnet],\n metadata: {\n name: 'Tron Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SOL_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [SolScope.Mainnet],\n derivationPath: `m/44'/501'/0'/0'`,\n};\n\nexport const MOCK_TRX_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [TrxScope.Mainnet],\n derivationPath: `m/44'/195'/0'/0'`,\n};\n\nexport const MOCK_BTC_P2TR_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [BtcScope.Mainnet],\n derivationPath: `m/44'/0'/0'/0'`,\n};\n\nexport const MOCK_BTC_P2WPKH_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',\n type: BtcAccountType.P2wpkh,\n methods: Object.values(BtcMethod),\n address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Mainnet],\n metadata: {\n name: 'Bitcoin Native Segwit Account 1',\n importTime: 0,\n keyring: {\n type: KeyringTypes.snap,\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',\n type: BtcAccountType.P2tr,\n methods: Object.values(BtcMethod),\n address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Testnet],\n metadata: {\n name: 'Bitcoin Taproot Account 1',\n importTime: 0,\n keyring: {\n type: KeyringTypes.snap,\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_1 = MOCK_SOL_ACCOUNT_1;\n\nexport const MOCK_SNAP_ACCOUNT_2: InternalAccount = {\n id: 'mock-snap-id-2',\n address: '0x789',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Snap Acc 2',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_2,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_3 = MOCK_BTC_P2WPKH_ACCOUNT_1;\nexport const MOCK_SNAP_ACCOUNT_4 = MOCK_BTC_P2TR_ACCOUNT_1;\n\nexport const MOCK_HARDWARE_ACCOUNT_1: InternalAccount = {\n id: 'mock-hardware-id-1',\n address: '0xABC',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Hardware Acc 1',\n keyring: { type: KeyringTypes.ledger },\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport function isInternalAccount(\n account: KeyringAccount,\n): account is InternalAccount {\n // Meant to be used for testing, so we keep this simple.\n return Object.prototype.hasOwnProperty.call(account, 'metadata');\n}\n\nexport function asKeyringAccount<Account extends KeyringAccount>(\n account: Account,\n): KeyringAccount {\n const { id, type, address, scopes, options, methods } = account;\n\n return {\n id,\n type,\n address,\n scopes,\n options,\n methods,\n };\n}\n\nexport class MockAccountBuilder<Account extends KeyringAccount> {\n readonly #account: Account;\n\n constructor(account: Account) {\n // Make a deep-copy to avoid mutating the same ref.\n this.#account = JSON.parse(JSON.stringify(account));\n }\n\n static from<Account extends KeyringAccount>(\n account: Account,\n ): MockAccountBuilder<Account> {\n return new MockAccountBuilder(account);\n }\n\n withId(id: InternalAccount['id']) {\n this.#account.id = id;\n return this;\n }\n\n withUuid() {\n this.#account.id = uuid();\n return this;\n }\n\n withAddressSuffix(suffix: string) {\n this.#account.address += suffix;\n return this;\n }\n\n withEntropySource(entropySource: EntropySourceId) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.id = entropySource;\n }\n return this;\n }\n\n withGroupIndex(groupIndex: number) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.groupIndex = groupIndex;\n }\n return this;\n }\n\n withSnapId(snapId: SnapId) {\n if (isInternalAccount(this.#account)) {\n this.#account.metadata.snap = {\n enabled: true,\n id: snapId,\n name: `Name: ${snapId}`,\n };\n }\n return this;\n }\n\n get() {\n return this.#account;\n }\n}\n\nexport const MOCK_WALLET_1_ENTROPY_SOURCE = MOCK_ENTROPY_SOURCE_1;\n\nexport const MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(\n MOCK_HD_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(\n MOCK_SOL_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2WPKH_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2TR_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\n\nexport function mockAsInternalAccount(\n account: KeyringAccount,\n): InternalAccount {\n return {\n ...account,\n metadata: {\n name: 'Mocked Account',\n importTime: Date.now(),\n keyring: {\n type: 'mock-keyring-type',\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uDAAuD;AAMvD,uDAc+B;AAC/B,qEAA4D;AAG5D,+BAAkC;AAErB,QAAA,eAAe,GAAG;IAC7B,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,IAAI;IACd,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;CACjB,CAAC;AAEX,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAS,CAAC,CAAC;AAEhC,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAC5C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAE5C,QAAA,aAAa,GACxB,sFAAsF,CAAC;AAE5E,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,iCAAY,CAAC,EAAE;IACrB,QAAQ,EAAE,EAAE,EAAE,EAAE,6BAAqB,EAAE,IAAI,EAAE,cA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AAC;IACvB,CAAC;CACF;AA5DD,gDA4DC;;AAEY,QAAA,4BAA4B,GAAG,6BAAqB,CAAC;AAErD,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,yBAAiB,CAClB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,0BAAkB,CACnB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CACrE,iCAAyB,CAC1B;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,8BAA8B,GAAG,kBAAkB,CAAC,IAAI,CACnE,+BAAuB,CACxB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AAET,SAAgB,qBAAqB,CACnC,OAAuB;IAEvB,OAAO;QACL,GAAG,OAAO;QACV,QAAQ,EAAE;YACR,IAAI,EAAE,gBAAgB;YACtB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;YACtB,OAAO,EAAE;gBACP,IAAI,EAAE,mBAAmB;aAC1B;SACF;KACF,CAAC;AACJ,CAAC;AAbD,sDAaC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { isBip44Account } from '@metamask/account-api';\nimport type {\n DiscoveredAccount,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n BtcScope,\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolMethod,\n SolScope,\n TrxAccountType,\n TrxMethod,\n TrxScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { v4 as uuid } from 'uuid';\n\nexport const ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nconst SOL_METHODS = Object.values(SolMethod);\n\nexport const MOCK_SNAP_1 = {\n id: 'local:mock-snap-id-1',\n name: 'Mock Snap 1',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 1',\n },\n};\n\nexport const MOCK_SNAP_2 = {\n id: 'local:mock-snap-id-2',\n name: 'Mock Snap 2',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 2',\n },\n};\n\nexport const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1';\nexport const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2';\n\nexport const MOCK_MNEMONIC =\n 'abandon ability able about above absent absorb abstract absurd abuse access accident';\n\nexport const MOCK_HD_KEYRING_1 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' },\n accounts: ['0x123'],\n};\n\nexport const MOCK_HD_KEYRING_2 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' },\n accounts: ['0x456'],\n};\n\n/** Used when tests need ensureCanUseSnapPlatform to resolve (SnapPlatformWatcher waits for Snap keyring). */\nexport const MOCK_SNAP_KEYRING = {\n type: KeyringTypes.snap,\n metadata: { id: 'snap-keyring', name: 'Snap Keyring' },\n accounts: [],\n};\n\nexport const MOCK_HD_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-id-1',\n address: '0x123',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_1.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 1',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_HD_ACCOUNT_2: Bip44Account<InternalAccount> = {\n id: 'mock-id-2',\n address: '0x456',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 2',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_SOL_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: SOL_METHODS,\n type: SolAccountType.DataAccount,\n scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet],\n metadata: {\n name: 'Solana Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_TRX_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [TrxMethod.SignMessageV2, TrxMethod.VerifyMessageV2],\n type: TrxAccountType.Eoa,\n scopes: [TrxScope.Mainnet],\n metadata: {\n name: 'Tron Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SOL_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [SolScope.Mainnet],\n derivationPath: `m/44'/501'/0'/0'`,\n};\n\nexport const MOCK_TRX_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [TrxScope.Mainnet],\n derivationPath: `m/44'/195'/0'/0'`,\n};\n\nexport const MOCK_BTC_P2TR_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [BtcScope.Mainnet],\n derivationPath: `m/44'/0'/0'/0'`,\n};\n\nexport const MOCK_BTC_P2WPKH_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',\n type: BtcAccountType.P2wpkh,\n methods: Object.values(BtcMethod),\n address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Mainnet],\n metadata: {\n name: 'Bitcoin Native Segwit Account 1',\n importTime: 0,\n keyring: {\n type: KeyringTypes.snap,\n },\n snap: {\n id: 'mock-btc-snap-id',\n },\n },\n};\n\nexport const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',\n type: BtcAccountType.P2tr,\n methods: Object.values(BtcMethod),\n address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Testnet],\n metadata: {\n name: 'Bitcoin Taproot Account 1',\n importTime: 0,\n keyring: {\n type: KeyringTypes.snap,\n },\n snap: {\n id: 'mock-btc-snap-id',\n },\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_1 = MOCK_SOL_ACCOUNT_1;\n\nexport const MOCK_SNAP_ACCOUNT_2: InternalAccount = {\n id: 'mock-snap-id-2',\n address: '0x789',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Snap Acc 2',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_2,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_3 = MOCK_BTC_P2WPKH_ACCOUNT_1;\nexport const MOCK_SNAP_ACCOUNT_4 = MOCK_BTC_P2TR_ACCOUNT_1;\n\nexport const MOCK_HARDWARE_ACCOUNT_1: InternalAccount = {\n id: 'mock-hardware-id-1',\n address: '0xABC',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Hardware Acc 1',\n keyring: { type: KeyringTypes.ledger },\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport function isInternalAccount(\n account: KeyringAccount,\n): account is InternalAccount {\n // Meant to be used for testing, so we keep this simple.\n return Object.prototype.hasOwnProperty.call(account, 'metadata');\n}\n\nexport function asKeyringAccount<Account extends KeyringAccount>(\n account: Account,\n): KeyringAccount {\n const { id, type, address, scopes, options, methods } = account;\n\n return {\n id,\n type,\n address,\n scopes,\n options,\n methods,\n };\n}\n\nexport class MockAccountBuilder<Account extends KeyringAccount> {\n readonly #account: Account;\n\n constructor(account: Account) {\n // Make a deep-copy to avoid mutating the same ref.\n this.#account = JSON.parse(JSON.stringify(account));\n }\n\n static from<Account extends KeyringAccount>(\n account: Account,\n ): MockAccountBuilder<Account> {\n return new MockAccountBuilder(account);\n }\n\n withId(id: InternalAccount['id']) {\n this.#account.id = id;\n return this;\n }\n\n withUuid() {\n this.#account.id = uuid();\n return this;\n }\n\n withAddress(address: string): this {\n this.#account.address = address;\n return this;\n }\n\n withAddressSuffix(suffix: string) {\n this.#account.address += suffix;\n return this;\n }\n\n withEntropySource(entropySource: EntropySourceId) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.id = entropySource;\n }\n return this;\n }\n\n withGroupIndex(groupIndex: number) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.groupIndex = groupIndex;\n }\n return this;\n }\n\n withSnapId(snapId: SnapId) {\n if (isInternalAccount(this.#account)) {\n this.#account.metadata.snap = {\n id: snapId,\n };\n }\n return this;\n }\n\n get() {\n return this.#account;\n }\n}\n\nexport const MOCK_WALLET_1_ENTROPY_SOURCE = MOCK_ENTROPY_SOURCE_1;\n\nexport const MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(\n MOCK_HD_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(\n MOCK_SOL_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2WPKH_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2TR_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\n\nexport function mockAsInternalAccount(\n account: KeyringAccount,\n): InternalAccount {\n return {\n ...account,\n metadata: {\n name: 'Mocked Account',\n importTime: Date.now(),\n keyring: {\n type: 'mock-keyring-type',\n },\n },\n };\n}\n"]}
@@ -59,7 +59,7 @@ export declare const MOCK_BTC_P2TR_DISCOVERED_ACCOUNT_1: DiscoveredAccount;
59
59
  export declare const MOCK_BTC_P2WPKH_ACCOUNT_1: Bip44Account<InternalAccount>;
60
60
  export declare const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount>;
61
61
  export declare const MOCK_SNAP_ACCOUNT_1: Bip44Account<{
62
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
62
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account";
63
63
  id: string;
64
64
  options: Record<string, import("@metamask/snaps-sdk").Json> & {
65
65
  entropy?: {
@@ -81,9 +81,7 @@ export declare const MOCK_SNAP_ACCOUNT_1: Bip44Account<{
81
81
  type: string;
82
82
  };
83
83
  snap?: {
84
- name: string;
85
84
  id: string;
86
- enabled: boolean;
87
85
  } | undefined;
88
86
  nameLastUpdatedAt?: number | undefined;
89
87
  lastSelected?: number | undefined;
@@ -94,7 +92,7 @@ export declare const MOCK_SNAP_ACCOUNT_1: Bip44Account<{
94
92
  }>;
95
93
  export declare const MOCK_SNAP_ACCOUNT_2: InternalAccount;
96
94
  export declare const MOCK_SNAP_ACCOUNT_3: Bip44Account<{
97
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
95
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account";
98
96
  id: string;
99
97
  options: Record<string, import("@metamask/snaps-sdk").Json> & {
100
98
  entropy?: {
@@ -116,9 +114,7 @@ export declare const MOCK_SNAP_ACCOUNT_3: Bip44Account<{
116
114
  type: string;
117
115
  };
118
116
  snap?: {
119
- name: string;
120
117
  id: string;
121
- enabled: boolean;
122
118
  } | undefined;
123
119
  nameLastUpdatedAt?: number | undefined;
124
120
  lastSelected?: number | undefined;
@@ -128,7 +124,7 @@ export declare const MOCK_SNAP_ACCOUNT_3: Bip44Account<{
128
124
  methods: string[];
129
125
  }>;
130
126
  export declare const MOCK_SNAP_ACCOUNT_4: Bip44Account<{
131
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
127
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account";
132
128
  id: string;
133
129
  options: Record<string, import("@metamask/snaps-sdk").Json> & {
134
130
  entropy?: {
@@ -150,9 +146,7 @@ export declare const MOCK_SNAP_ACCOUNT_4: Bip44Account<{
150
146
  type: string;
151
147
  };
152
148
  snap?: {
153
- name: string;
154
149
  id: string;
155
- enabled: boolean;
156
150
  } | undefined;
157
151
  nameLastUpdatedAt?: number | undefined;
158
152
  lastSelected?: number | undefined;
@@ -170,6 +164,7 @@ export declare class MockAccountBuilder<Account extends KeyringAccount> {
170
164
  static from<Account extends KeyringAccount>(account: Account): MockAccountBuilder<Account>;
171
165
  withId(id: InternalAccount['id']): this;
172
166
  withUuid(): this;
167
+ withAddress(address: string): this;
173
168
  withAddressSuffix(suffix: string): this;
174
169
  withEntropySource(entropySource: EntropySourceId): this;
175
170
  withGroupIndex(groupIndex: number): this;
@@ -178,7 +173,7 @@ export declare class MockAccountBuilder<Account extends KeyringAccount> {
178
173
  }
179
174
  export declare const MOCK_WALLET_1_ENTROPY_SOURCE = "mock-keyring-id-1";
180
175
  export declare const MOCK_WALLET_1_EVM_ACCOUNT: Bip44Account<{
181
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
176
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account";
182
177
  id: string;
183
178
  options: Record<string, import("@metamask/snaps-sdk").Json> & {
184
179
  entropy?: {
@@ -200,9 +195,7 @@ export declare const MOCK_WALLET_1_EVM_ACCOUNT: Bip44Account<{
200
195
  type: string;
201
196
  };
202
197
  snap?: {
203
- name: string;
204
198
  id: string;
205
- enabled: boolean;
206
199
  } | undefined;
207
200
  nameLastUpdatedAt?: number | undefined;
208
201
  lastSelected?: number | undefined;
@@ -212,7 +205,7 @@ export declare const MOCK_WALLET_1_EVM_ACCOUNT: Bip44Account<{
212
205
  methods: string[];
213
206
  }>;
214
207
  export declare const MOCK_WALLET_1_SOL_ACCOUNT: Bip44Account<{
215
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
208
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account";
216
209
  id: string;
217
210
  options: Record<string, import("@metamask/snaps-sdk").Json> & {
218
211
  entropy?: {
@@ -234,9 +227,7 @@ export declare const MOCK_WALLET_1_SOL_ACCOUNT: Bip44Account<{
234
227
  type: string;
235
228
  };
236
229
  snap?: {
237
- name: string;
238
230
  id: string;
239
- enabled: boolean;
240
231
  } | undefined;
241
232
  nameLastUpdatedAt?: number | undefined;
242
233
  lastSelected?: number | undefined;
@@ -246,7 +237,7 @@ export declare const MOCK_WALLET_1_SOL_ACCOUNT: Bip44Account<{
246
237
  methods: string[];
247
238
  }>;
248
239
  export declare const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT: Bip44Account<{
249
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
240
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account";
250
241
  id: string;
251
242
  options: Record<string, import("@metamask/snaps-sdk").Json> & {
252
243
  entropy?: {
@@ -268,9 +259,7 @@ export declare const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT: Bip44Account<{
268
259
  type: string;
269
260
  };
270
261
  snap?: {
271
- name: string;
272
262
  id: string;
273
- enabled: boolean;
274
263
  } | undefined;
275
264
  nameLastUpdatedAt?: number | undefined;
276
265
  lastSelected?: number | undefined;
@@ -280,7 +269,7 @@ export declare const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT: Bip44Account<{
280
269
  methods: string[];
281
270
  }>;
282
271
  export declare const MOCK_WALLET_1_BTC_P2TR_ACCOUNT: Bip44Account<{
283
- type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
272
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account";
284
273
  id: string;
285
274
  options: Record<string, import("@metamask/snaps-sdk").Json> & {
286
275
  entropy?: {
@@ -302,9 +291,7 @@ export declare const MOCK_WALLET_1_BTC_P2TR_ACCOUNT: Bip44Account<{
302
291
  type: string;
303
292
  };
304
293
  snap?: {
305
- name: string;
306
294
  id: string;
307
- enabled: boolean;
308
295
  } | undefined;
309
296
  nameLastUpdatedAt?: number | undefined;
310
297
  lastSelected?: number | undefined;