@metamask-previews/multichain-account-service 4.1.0-preview-1d3aa020 → 4.1.0-preview-67bc4e39

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 (62) hide show
  1. package/CHANGELOG.md +0 -11
  2. package/dist/MultichainAccountService.cjs +2 -9
  3. package/dist/MultichainAccountService.cjs.map +1 -1
  4. package/dist/MultichainAccountService.d.cts +0 -1
  5. package/dist/MultichainAccountService.d.cts.map +1 -1
  6. package/dist/MultichainAccountService.d.mts +0 -1
  7. package/dist/MultichainAccountService.d.mts.map +1 -1
  8. package/dist/MultichainAccountService.mjs +2 -9
  9. package/dist/MultichainAccountService.mjs.map +1 -1
  10. package/dist/providers/BtcAccountProvider.cjs +32 -46
  11. package/dist/providers/BtcAccountProvider.cjs.map +1 -1
  12. package/dist/providers/BtcAccountProvider.d.cts +1 -2
  13. package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
  14. package/dist/providers/BtcAccountProvider.d.mts +1 -2
  15. package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
  16. package/dist/providers/BtcAccountProvider.mjs +32 -46
  17. package/dist/providers/BtcAccountProvider.mjs.map +1 -1
  18. package/dist/providers/SnapAccountProvider.cjs +54 -81
  19. package/dist/providers/SnapAccountProvider.cjs.map +1 -1
  20. package/dist/providers/SnapAccountProvider.d.cts +4 -16
  21. package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
  22. package/dist/providers/SnapAccountProvider.d.mts +4 -16
  23. package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
  24. package/dist/providers/SnapAccountProvider.mjs +54 -81
  25. package/dist/providers/SnapAccountProvider.mjs.map +1 -1
  26. package/dist/providers/SolAccountProvider.cjs +31 -36
  27. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  28. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  29. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  30. package/dist/providers/SolAccountProvider.mjs +31 -36
  31. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  32. package/dist/providers/TrxAccountProvider.cjs +29 -47
  33. package/dist/providers/TrxAccountProvider.cjs.map +1 -1
  34. package/dist/providers/TrxAccountProvider.d.cts +0 -1
  35. package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
  36. package/dist/providers/TrxAccountProvider.d.mts +0 -1
  37. package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
  38. package/dist/providers/TrxAccountProvider.mjs +29 -47
  39. package/dist/providers/TrxAccountProvider.mjs.map +1 -1
  40. package/dist/tests/messenger.cjs +1 -8
  41. package/dist/tests/messenger.cjs.map +1 -1
  42. package/dist/tests/messenger.d.cts +4 -9
  43. package/dist/tests/messenger.d.cts.map +1 -1
  44. package/dist/tests/messenger.d.mts +4 -9
  45. package/dist/tests/messenger.d.mts.map +1 -1
  46. package/dist/tests/messenger.mjs +1 -8
  47. package/dist/tests/messenger.mjs.map +1 -1
  48. package/dist/types.cjs.map +1 -1
  49. package/dist/types.d.cts +4 -8
  50. package/dist/types.d.cts.map +1 -1
  51. package/dist/types.d.mts +4 -8
  52. package/dist/types.d.mts.map +1 -1
  53. package/dist/types.mjs.map +1 -1
  54. package/package.json +2 -3
  55. package/dist/snaps/SnapPlatformWatcher.cjs +0 -60
  56. package/dist/snaps/SnapPlatformWatcher.cjs.map +0 -1
  57. package/dist/snaps/SnapPlatformWatcher.d.cts +0 -8
  58. package/dist/snaps/SnapPlatformWatcher.d.cts.map +0 -1
  59. package/dist/snaps/SnapPlatformWatcher.d.mts +0 -8
  60. package/dist/snaps/SnapPlatformWatcher.d.mts.map +0 -1
  61. package/dist/snaps/SnapPlatformWatcher.mjs +0 -57
  62. package/dist/snaps/SnapPlatformWatcher.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAA6D;AAI7D,uDAAiE;A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aAAa;YACb,KAAK;YACL,WAAW,EAAE,4BAAc,CAAC,MAAM;YAClC,KAAK,EAAE,sBAAQ,CAAC,OAAO;SACxB,CAAC,EACF,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CACrC,CAAC;QAEF,IAAA,kCAAoB,EAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AA9CM,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { BtcAccountType, BtcScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../constants/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n async #createAccounts({\n keyring,\n entropySource,\n groupIndex: index,\n }: {\n keyring: RestrictedSnapKeyring;\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const account = await withTimeout(\n keyring.createAccount({\n entropySource,\n index,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n return [account];\n });\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ keyring }) => {\n return this.#createAccounts({ keyring, entropySource, groupIndex });\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ client, keyring }) => {\n return await super.trace(\n {\n name: TraceName.SnapDiscoverAccounts,\n data: {\n provider: this.getName(),\n },\n },\n async () => {\n if (!this.config.discovery.enabled) {\n return [];\n }\n\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n const createdAccounts = await this.#createAccounts({\n keyring,\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"BtcAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;AAAA,uDAA6D;AAI7D,uDAAiE;AAIjE,mEAA4D;AAE5D,uCAAiD;AACjD,sDAA6C;AAC7C,oDAAgD;AAKnC,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEtC,QAAA,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE;QACd,SAAS,EAAE,IAAI;KAChB;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,yCAAmB;IAKzD,YACE,SAA4C,EAC5C,SAAmC,2CAAmC,EACtE,QAAuB,yBAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAClE,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,MAAM;YACtC,MAAM,CAAC,MAAM,CAAS,4BAAc,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAC7D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,EAAE,KAAK,GAIlB;QACC,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE;YACxC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;YAEnE,MAAM,OAAO,GAAG,MAAM,IA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,cAAc,CAAC;gBAChD,aAAa;gBACb,UAAU;aACX,CAAC,CAAC;YAEH,OAAO,eAAe,CAAC;QACzB,CAAC,CACF,CAAC;IACJ,CAAC;;AAnGH,gDAoGC;AAnGQ,uBAAI,GAAG,iCAAyB,CAAC;AAEjC,8BAAW,GAAG,mCAA6C,CAAC","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 { BtcAccountType, BtcScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type { SnapAccountProviderConfig } from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../constants/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex: index,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n\n const account = await withTimeout(\n createAccount({\n entropySource,\n index,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n return [account];\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\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 this.client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n const createdAccounts = await this.createAccounts({\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n },\n );\n }\n}\n"]}
@@ -10,13 +10,12 @@ export type BtcAccountProviderConfig = SnapAccountProviderConfig;
10
10
  export declare const BTC_ACCOUNT_PROVIDER_NAME = "Bitcoin";
11
11
  export declare const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig;
12
12
  export declare class BtcAccountProvider extends SnapAccountProvider {
13
- #private;
14
13
  static NAME: string;
15
14
  static BTC_SNAP_ID: SnapId;
16
15
  constructor(messenger: MultichainAccountServiceMessenger, config?: BtcAccountProviderConfig, trace?: TraceCallback);
17
16
  getName(): string;
18
17
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
19
- createAccounts({ entropySource, groupIndex, }: {
18
+ createAccounts({ entropySource, groupIndex: index, }: {
20
19
  entropySource: EntropySourceId;
21
20
  groupIndex: number;
22
21
  }): Promise<Bip44Account<KeyringAccount>[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EAEV,yBAAyB,EAC1B,kCAA8B;AAI/B,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,eAAO,MAAM,mCAAmC,EAAE,wBAWjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAAiD;gBAGjE,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;IAgC9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MA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UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAmBrC,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;CA6C5C"}
@@ -10,13 +10,12 @@ export type BtcAccountProviderConfig = SnapAccountProviderConfig;
10
10
  export declare const BTC_ACCOUNT_PROVIDER_NAME = "Bitcoin";
11
11
  export declare const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig;
12
12
  export declare class BtcAccountProvider extends SnapAccountProvider {
13
- #private;
14
13
  static NAME: string;
15
14
  static BTC_SNAP_ID: SnapId;
16
15
  constructor(messenger: MultichainAccountServiceMessenger, config?: BtcAccountProviderConfig, trace?: TraceCallback);
17
16
  getName(): string;
18
17
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
19
- createAccounts({ entropySource, groupIndex, }: {
18
+ createAccounts({ entropySource, groupIndex: index, }: {
20
19
  entropySource: EntropySourceId;
21
20
  groupIndex: number;
22
21
  }): Promise<Bip44Account<KeyringAccount>[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EAEV,yBAAyB,EAC1B,kCAA8B;AAI/B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IvE,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,eAAO,MAAM,mCAAmC,EAAE,wBAWjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAAiD;gBAGjE,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;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,EAAE,KAAK,GAClB,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAmBrC,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;CA6C5C"}
@@ -1,9 +1,3 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _BtcAccountProvider_instances, _BtcAccountProvider_createAccounts;
7
1
  import { assertIsBip44Account } from "@metamask/account-api";
8
2
  import { BtcAccountType, BtcScope } from "@metamask/keyring-api";
9
3
  import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
@@ -26,7 +20,6 @@ export const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
26
20
  export class BtcAccountProvider extends SnapAccountProvider {
27
21
  constructor(messenger, config = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = traceFallback) {
28
22
  super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);
29
- _BtcAccountProvider_instances.add(this);
30
23
  }
31
24
  getName() {
32
25
  return BtcAccountProvider.NAME;
@@ -35,52 +28,45 @@ export class BtcAccountProvider extends SnapAccountProvider {
35
28
  return (account.type === BtcAccountType.P2wpkh &&
36
29
  Object.values(BtcAccountType).includes(account.type));
37
30
  }
38
- async createAccounts({ entropySource, groupIndex, }) {
39
- return this.withSnap(async ({ keyring }) => {
40
- return __classPrivateFieldGet(this, _BtcAccountProvider_instances, "m", _BtcAccountProvider_createAccounts).call(this, { keyring, entropySource, groupIndex });
31
+ async createAccounts({ entropySource, groupIndex: index, }) {
32
+ return this.withMaxConcurrency(async () => {
33
+ const createAccount = await this.getRestrictedSnapAccountCreator();
34
+ const account = await withTimeout(createAccount({
35
+ entropySource,
36
+ index,
37
+ addressType: BtcAccountType.P2wpkh,
38
+ scope: BtcScope.Mainnet,
39
+ }), this.config.createAccounts.timeoutMs);
40
+ assertIsBip44Account(account);
41
+ return [account];
41
42
  });
42
43
  }
43
44
  async discoverAccounts({ entropySource, groupIndex, }) {
44
- return this.withSnap(async ({ client, keyring }) => {
45
- return await super.trace({
46
- name: TraceName.SnapDiscoverAccounts,
47
- data: {
48
- provider: this.getName(),
49
- },
50
- }, async () => {
51
- if (!this.config.discovery.enabled) {
52
- return [];
53
- }
54
- const discoveredAccounts = await withRetry(() => withTimeout(client.discoverAccounts([BtcScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
55
- maxAttempts: this.config.discovery.maxAttempts,
56
- backOffMs: this.config.discovery.backOffMs,
57
- });
58
- if (!Array.isArray(discoveredAccounts) ||
59
- discoveredAccounts.length === 0) {
60
- return [];
61
- }
62
- const createdAccounts = await __classPrivateFieldGet(this, _BtcAccountProvider_instances, "m", _BtcAccountProvider_createAccounts).call(this, {
63
- keyring,
64
- entropySource,
65
- groupIndex,
66
- });
67
- return createdAccounts;
45
+ return await super.trace({
46
+ name: TraceName.SnapDiscoverAccounts,
47
+ data: {
48
+ provider: this.getName(),
49
+ },
50
+ }, async () => {
51
+ if (!this.config.discovery.enabled) {
52
+ return [];
53
+ }
54
+ const discoveredAccounts = await withRetry(() => withTimeout(this.client.discoverAccounts([BtcScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
55
+ maxAttempts: this.config.discovery.maxAttempts,
56
+ backOffMs: this.config.discovery.backOffMs,
57
+ });
58
+ if (!Array.isArray(discoveredAccounts) ||
59
+ discoveredAccounts.length === 0) {
60
+ return [];
61
+ }
62
+ const createdAccounts = await this.createAccounts({
63
+ entropySource,
64
+ groupIndex,
68
65
  });
66
+ return createdAccounts;
69
67
  });
70
68
  }
71
69
  }
72
- _BtcAccountProvider_instances = new WeakSet(), _BtcAccountProvider_createAccounts = async function _BtcAccountProvider_createAccounts({ keyring, entropySource, groupIndex: index, }) {
73
- return this.withMaxConcurrency(async () => {
74
- const account = await withTimeout(keyring.createAccount({
75
- entropySource,
76
- index,
77
- addressType: BtcAccountType.P2wpkh,
78
- scope: BtcScope.Mainnet,
79
- }), this.config.createAccounts.timeoutMs);
80
- assertIsBip44Account(account);
81
- return [account];
82
- });
83
- };
84
70
  BtcAccountProvider.NAME = BTC_ACCOUNT_PROVIDER_NAME;
85
71
  BtcAccountProvider.BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap';
86
72
  //# sourceMappingURL=BtcAccountProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAI7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AAE,KAAK,GAKlB;IACC,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE;QACxC,MAAM,OAAO,GAAG,MAAM,WAAW,CAC/B,OAAO,CAAC,aAAa,CAAC;YACpB,aAAa;YACb,KAAK;YACL,WAAW,EAAE,cAAc,CAAC,MAAM;YAClC,KAAK,EAAE,QAAQ,CAAC,OAAO;SACxB,CAAC,EACF,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CACrC,CAAC;QAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AA9CM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { BtcAccountType, BtcScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../constants/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n async #createAccounts({\n keyring,\n entropySource,\n groupIndex: index,\n }: {\n keyring: RestrictedSnapKeyring;\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const account = await withTimeout(\n keyring.createAccount({\n entropySource,\n index,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n return [account];\n });\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ keyring }) => {\n return this.#createAccounts({ keyring, entropySource, groupIndex });\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ client, keyring }) => {\n return await super.trace(\n {\n name: TraceName.SnapDiscoverAccounts,\n data: {\n provider: this.getName(),\n },\n },\n async () => {\n if (!this.config.discovery.enabled) {\n return [];\n }\n\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n const createdAccounts = await this.#createAccounts({\n keyring,\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"BtcAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAI7D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,8BAA8B;AAIjE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AACjD,OAAO,EAAE,aAAa,EAAE,+BAAqB;AAC7C,OAAO,EAAE,SAAS,EAAE,gCAA4B;AAKhD,MAAM,CAAC,MAAM,yBAAyB,GAAG,SAAS,CAAC;AAEnD,MAAM,CAAC,MAAM,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE;QACd,SAAS,EAAE,IAAI;KAChB;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;CACF,CAAC;AAEF,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IAKzD,YACE,SAA4C,EAC5C,SAAmC,mCAAmC,EACtE,QAAuB,aAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAClE,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,MA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AI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW;gBAC9C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS;aAC3C,CACF,CAAC;YAEF,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;gBAClC,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAC/B,CAAC;gBACD,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;gBAChD,aAAa;gBACb,UAAU;aACX,CAAC,CAAC;YAEH,OAAO,eAAe,CAAC;QACzB,CAAC,CACF,CAAC;IACJ,CAAC;;AAlGM,uBAAI,GAAG,yBAAyB,CAAC;AAEjC,8BAAW,GAAG,mCAA6C,CAAC","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 { BtcAccountType, BtcScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type { SnapAccountProviderConfig } from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../constants/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex: index,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n\n const account = await withTimeout(\n createAccount({\n entropySource,\n index,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n return [account];\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\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 this.client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n const createdAccounts = await this.createAccounts({\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n },\n );\n }\n}\n"]}
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
12
  };
13
- var _SnapAccountProvider_instances, _SnapAccountProvider_client, _SnapAccountProvider_queue, _SnapAccountProvider_trace, _SnapAccountProvider_getRestrictedSnapKeyring, _SnapAccountProvider_getKeyringClientFromSnapId, _SnapAccountProvider_withSnapKeyring;
13
+ var _SnapAccountProvider_instances, _SnapAccountProvider_queue, _SnapAccountProvider_trace, _SnapAccountProvider_getKeyringClientFromSnapId, _SnapAccountProvider_withSnapKeyring;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.isSnapAccountProvider = exports.SnapAccountProvider = void 0;
16
16
  const keyring_controller_1 = require("@metamask/keyring-controller");
@@ -26,11 +26,10 @@ class SnapAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountPro
26
26
  trace = analytics_1.traceFallback) {
27
27
  super(messenger);
28
28
  _SnapAccountProvider_instances.add(this);
29
- _SnapAccountProvider_client.set(this, void 0);
30
29
  _SnapAccountProvider_queue.set(this, void 0);
31
30
  _SnapAccountProvider_trace.set(this, void 0);
32
31
  this.snapId = snapId;
33
- __classPrivateFieldSet(this, _SnapAccountProvider_client, __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_getKeyringClientFromSnapId).call(this, snapId), "f");
32
+ this.client = __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_getKeyringClientFromSnapId).call(this, snapId);
34
33
  const maxConcurrency = config.maxConcurrency ?? Infinity;
35
34
  this.config = {
36
35
  ...config,
@@ -46,15 +45,6 @@ class SnapAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountPro
46
45
  }
47
46
  __classPrivateFieldSet(this, _SnapAccountProvider_trace, trace, "f");
48
47
  }
49
- /**
50
- * Ensures that the Snap platform is ready to be used.
51
- *
52
- * @returns A promise that resolves when the platform is ready.
53
- * @throws An error if the platform is not ready (only effective once the platform has been ready at least once).
54
- */
55
- async ensureCanUseSnapPlatform() {
56
- return this.messenger.call('MultichainAccountService:ensureCanUseSnapPlatform');
57
- }
58
48
  /**
59
49
  * Wraps an async operation with concurrency limiting based on maxConcurrency config.
60
50
  * If maxConcurrency is Infinity (the default), the operation runs immediately without throttling.
@@ -72,82 +62,65 @@ class SnapAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountPro
72
62
  async trace(request, fn) {
73
63
  return __classPrivateFieldGet(this, _SnapAccountProvider_trace, "f").call(this, request, fn);
74
64
  }
65
+ async getRestrictedSnapAccountCreator() {
66
+ // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
67
+ // we have to use the `SnapKeyring` instance to be able to create Solana account
68
+ // without triggering UI confirmation.
69
+ // Also, creating account that way won't invalidate the Snap keyring state. The
70
+ // account will get created and persisted properly with the Snap account creation
71
+ // flow "asynchronously" (with `notify:accountCreated`).
72
+ const createAccount = await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, async ({ keyring }) => keyring.createAccount.bind(keyring));
73
+ return (options) => createAccount(this.snapId, options, {
74
+ displayAccountNameSuggestion: false,
75
+ displayConfirmation: false,
76
+ setSelectedAccount: false,
77
+ });
78
+ }
75
79
  async resyncAccounts(accounts) {
76
- await this.withSnap(async ({ keyring }) => {
77
- const localSnapAccounts = accounts.filter((account) => account.metadata.snap && account.metadata.snap.id === this.snapId);
78
- const snapAccounts = new Set((await __classPrivateFieldGet(this, _SnapAccountProvider_client, "f").listAccounts()).map((account) => account.id));
79
- // NOTE: This should never happen, but we want to report that kind of errors still
80
- // in case states are de-sync.
81
- if (localSnapAccounts.length < snapAccounts.size) {
82
- this.messenger.captureException?.(new Error(`Snap "${this.snapId}" has de-synced accounts, Snap has more accounts than MetaMask!`));
83
- // We don't recover from this case yet.
84
- return;
85
- }
86
- // We want this part to be fast, so we only check for sizes, but we might need
87
- // to make a real "diff" between the 2 states to not miss any de-sync.
88
- if (localSnapAccounts.length > snapAccounts.size) {
89
- // Accounts should never really be de-synced, so we want to log this to see how often this
90
- // happens, cause that means that something else is buggy elsewhere...
91
- this.messenger.captureException?.(new Error(`Snap "${this.snapId}" has de-synced accounts, we'll attempt to re-sync them...`));
92
- // We always use the MetaMask list as the main reference here.
93
- await Promise.all(localSnapAccounts.map(async (account) => {
94
- const { id: entropySource, groupIndex } = account.options.entropy;
95
- try {
96
- if (!snapAccounts.has(account.id)) {
97
- // We still need to remove the accounts from the Snap keyring since we're
98
- // about to create the same account again, which will use a new ID, but will
99
- // keep using the same address, and the Snap keyring does not allow this.
100
- await keyring.removeAccount(account.address);
101
- // The Snap has no account in its state for this one, we re-create it.
102
- await this.createAccounts({
103
- entropySource,
104
- groupIndex,
105
- });
106
- }
107
- }
108
- catch (error) {
109
- const sentryError = (0, utils_1.createSentryError)(`Unable to re-sync account: ${groupIndex}`, error, {
110
- provider: this.getName(),
80
+ const localSnapAccounts = accounts.filter((account) => account.metadata.snap && account.metadata.snap.id === this.snapId);
81
+ const snapAccounts = new Set((await this.client.listAccounts()).map((account) => account.id));
82
+ // NOTE: This should never happen, but we want to report that kind of errors still
83
+ // in case states are de-sync.
84
+ if (localSnapAccounts.length < snapAccounts.size) {
85
+ this.messenger.captureException?.(new Error(`Snap "${this.snapId}" has de-synced accounts, Snap has more accounts than MetaMask!`));
86
+ // We don't recover from this case yet.
87
+ return;
88
+ }
89
+ // We want this part to be fast, so we only check for sizes, but we might need
90
+ // to make a real "diff" between the 2 states to not miss any de-sync.
91
+ if (localSnapAccounts.length > snapAccounts.size) {
92
+ // Accounts should never really be de-synced, so we want to log this to see how often this
93
+ // happens, cause that means that something else is buggy elsewhere...
94
+ this.messenger.captureException?.(new Error(`Snap "${this.snapId}" has de-synced accounts, we'll attempt to re-sync them...`));
95
+ // We always use the MetaMask list as the main reference here.
96
+ await Promise.all(localSnapAccounts.map(async (account) => {
97
+ const { id: entropySource, groupIndex } = account.options.entropy;
98
+ try {
99
+ if (!snapAccounts.has(account.id)) {
100
+ // We still need to remove the accounts from the Snap keyring since we're
101
+ // about to create the same account again, which will use a new ID, but will
102
+ // keep using the same address, and the Snap keyring does not allow this.
103
+ await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, async ({ keyring }) => await keyring.removeAccount(account.address));
104
+ // The Snap has no account in its state for this one, we re-create it.
105
+ await this.createAccounts({
106
+ entropySource,
111
107
  groupIndex,
112
108
  });
113
- this.messenger.captureException?.(sentryError);
114
109
  }
115
- }));
116
- }
117
- });
118
- }
119
- async withSnap(operation) {
120
- await this.ensureCanUseSnapPlatform();
121
- return await operation({
122
- client: __classPrivateFieldGet(this, _SnapAccountProvider_client, "f"),
123
- keyring: await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_getRestrictedSnapKeyring).call(this),
124
- });
110
+ }
111
+ catch (error) {
112
+ const sentryError = (0, utils_1.createSentryError)(`Unable to re-sync account: ${groupIndex}`, error, {
113
+ provider: this.getName(),
114
+ groupIndex,
115
+ });
116
+ this.messenger.captureException?.(sentryError);
117
+ }
118
+ }));
119
+ }
125
120
  }
126
121
  }
127
122
  exports.SnapAccountProvider = SnapAccountProvider;
128
- _SnapAccountProvider_client = new WeakMap(), _SnapAccountProvider_queue = new WeakMap(), _SnapAccountProvider_trace = new WeakMap(), _SnapAccountProvider_instances = new WeakSet(), _SnapAccountProvider_getRestrictedSnapKeyring = async function _SnapAccountProvider_getRestrictedSnapKeyring() {
129
- // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
130
- // we have to use the `SnapKeyring` instance to be able to create Solana account
131
- // without triggering UI confirmation.
132
- // Also, creating account that way won't invalidate the Snap keyring state. The
133
- // account will get created and persisted properly with the Snap account creation
134
- // flow "asynchronously" (with `notify:accountCreated`).
135
- const createAccount = await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, async ({ keyring }) => keyring.createAccount.bind(keyring));
136
- return {
137
- createAccount: async (options) =>
138
- // We use the "unguarded" account creation here (see explanation above).
139
- await createAccount(this.snapId, options, {
140
- displayAccountNameSuggestion: false,
141
- displayConfirmation: false,
142
- setSelectedAccount: false,
143
- }),
144
- removeAccount: async (address) =>
145
- // Though, when removing account, we can use the normal flow.
146
- await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, async ({ keyring }) => {
147
- await keyring.removeAccount(address);
148
- }),
149
- };
150
- }, _SnapAccountProvider_getKeyringClientFromSnapId = function _SnapAccountProvider_getKeyringClientFromSnapId(snapId) {
123
+ _SnapAccountProvider_queue = new WeakMap(), _SnapAccountProvider_trace = new WeakMap(), _SnapAccountProvider_instances = new WeakSet(), _SnapAccountProvider_getKeyringClientFromSnapId = function _SnapAccountProvider_getKeyringClientFromSnapId(snapId) {
151
124
  return new keyring_snap_client_1.KeyringClient({
152
125
  send: async (request) => {
153
126
  const response = await this.messenger.call('SnapController:handleRequest', {
@@ -1 +1 @@
1
- {"version":3,"file":"SnapAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,qEAA4D;AAE5D,uEAA8D;AAE9D,uDAAoD;AACpD,6CAAwC;AAExC,6EAAsE;AACtE,sDAA6C;AAE7C,wCAA6C;AAoB7C,MAAsB,mBAAoB,SAAQ,mDAAwB;IAWxE,YACE,MAAc,EACd,SAA4C,EAC5C,MAAiC;IACjC,0BAA0B;IAC1B,QAAuB,yBAAa;QAEpC,KAAK,CAAC,SAAS,CAAC,CAAC;;QAbV,8CAAuB;QAEvB,6CAAmB;QAEnB,6CAAsB;QAW7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,uBAAA,IAAI,+BAAW,u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AAE,KAAK,EAAE,OAAe,EAAE,EAAE;QACvC,6DAA6D;QAC7D,MAAM,uBAAA,IAAI,4EAAiB,MAArB,IAAI,EAAkB,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YAChD,MAAM,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC,CAAC;KACL,CAAC;AACJ,CAAC,6GAE2B,MAAc;IACxC,OAAO,IAAI,mCAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAiB,EAAE;YACrD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACxC,8BAA8B,EAC9B;gBACE,MAAM,EAAE,MAAgB;gBACxB,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,yBAAW,CAAC,gBAAgB;gBACrC,OAAO;aACR,CACF,CAAC;YACF,OAAO,QAAgB,CAAC;QAC1B,CAAC;KACF,CAAC,CAAC;AACL,CAAC,yCAwED,KAAK,+CACH,SAM6B;IAE7B,OAAO,IAAI,CAAC,WAAW,CACrB,EAAE,IAAI,EAAE,iCAAY,CAAC,IAAI,EAAE,EAC3B,CAAC,IAAI,EAAE,EAAE;QACP,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC,CACF,CAAC;AACJ,CAAC;AA6BI,MAAM,qBAAqB,GAAG,CACnC,QAAiB,EACgB,EAAE;IACnC,OAAO,QAAQ,YAAY,mBAAmB,CAAC;AACjD,CAAC,CAAC;AAJW,QAAA,qBAAqB,yBAIhC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback, TraceRequest } from '@metamask/controller-utils';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type { KeyringMetadata } from '@metamask/keyring-controller';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { Json, JsonRpcRequest, SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport { Semaphore } from 'async-mutex';\n\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { createSentryError } from '../utils';\n\nexport type RestrictedSnapKeyring = {\n createAccount: (options: Record<string, Json>) => Promise<KeyringAccount>;\n removeAccount: (address: string) => Promise<void>;\n};\n\nexport type SnapAccountProviderConfig = {\n maxConcurrency?: number;\n discovery: {\n enabled?: boolean;\n maxAttempts: number;\n timeoutMs: number;\n backOffMs: number;\n };\n createAccounts: {\n timeoutMs: number;\n };\n};\n\nexport abstract class SnapAccountProvider extends BaseBip44AccountProvider {\n readonly snapId: SnapId;\n\n protected readonly config: SnapAccountProviderConfig;\n\n readonly #client: KeyringClient;\n\n readonly #queue?: Semaphore;\n\n readonly #trace: TraceCallback;\n\n constructor(\n snapId: SnapId,\n messenger: MultichainAccountServiceMessenger,\n config: SnapAccountProviderConfig,\n /* istanbul ignore next */\n trace: TraceCallback = traceFallback,\n ) {\n super(messenger);\n\n this.snapId = snapId;\n this.#client = this.#getKeyringClientFromSnapId(snapId);\n\n const maxConcurrency = config.maxConcurrency ?? Infinity;\n this.config = {\n ...config,\n discovery: {\n ...config.discovery,\n enabled: config.discovery.enabled ?? true,\n },\n maxConcurrency,\n };\n\n // Create semaphore only if concurrency is limited\n if (isFinite(maxConcurrency)) {\n this.#queue = new Semaphore(maxConcurrency);\n }\n\n this.#trace = trace;\n }\n\n /**\n * Ensures that the Snap platform is ready to be used.\n *\n * @returns A promise that resolves when the platform is ready.\n * @throws An error if the platform is not ready (only effective once the platform has been ready at least once).\n */\n async ensureCanUseSnapPlatform(): Promise<void> {\n return this.messenger.call(\n 'MultichainAccountService:ensureCanUseSnapPlatform',\n );\n }\n\n /**\n * Wraps an async operation with concurrency limiting based on maxConcurrency config.\n * If maxConcurrency is Infinity (the default), the operation runs immediately without throttling.\n * Otherwise, it's queued through the semaphore to respect the concurrency limit.\n *\n * @param operation - The async operation to execute.\n * @returns The result of the operation.\n */\n protected async withMaxConcurrency<Result>(\n operation: () => Promise<Result>,\n ): Promise<Result> {\n if (this.#queue) {\n return this.#queue.runExclusive(operation);\n }\n return operation();\n }\n\n protected async trace<ReturnType>(\n request: TraceRequest,\n fn: () => Promise<ReturnType>,\n ): Promise<ReturnType> {\n return this.#trace(request, fn);\n }\n\n async #getRestrictedSnapKeyring(): Promise<RestrictedSnapKeyring> {\n // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but\n // we have to use the `SnapKeyring` instance to be able to create Solana account\n // without triggering UI confirmation.\n // Also, creating account that way won't invalidate the Snap keyring state. The\n // account will get created and persisted properly with the Snap account creation\n // flow \"asynchronously\" (with `notify:accountCreated`).\n const createAccount = await this.#withSnapKeyring<\n SnapKeyring['createAccount']\n >(async ({ keyring }) => keyring.createAccount.bind(keyring));\n\n return {\n createAccount: async (options) =>\n // We use the \"unguarded\" account creation here (see explanation above).\n await createAccount(this.snapId, options, {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n }),\n removeAccount: async (address: string) =>\n // Though, when removing account, we can use the normal flow.\n await this.#withSnapKeyring(async ({ keyring }) => {\n await keyring.removeAccount(address);\n }),\n };\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest): Promise<Json> => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\n }\n\n async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n await this.withSnap(async ({ keyring }) => {\n const localSnapAccounts = accounts.filter(\n (account) =>\n account.metadata.snap && account.metadata.snap.id === this.snapId,\n );\n const snapAccounts = new Set(\n (await this.#client.listAccounts()).map((account) => account.id),\n );\n\n // NOTE: This should never happen, but we want to report that kind of errors still\n // in case states are de-sync.\n if (localSnapAccounts.length < snapAccounts.size) {\n this.messenger.captureException?.(\n new Error(\n `Snap \"${this.snapId}\" has de-synced accounts, Snap has more accounts than MetaMask!`,\n ),\n );\n\n // We don't recover from this case yet.\n return;\n }\n\n // We want this part to be fast, so we only check for sizes, but we might need\n // to make a real \"diff\" between the 2 states to not miss any de-sync.\n if (localSnapAccounts.length > snapAccounts.size) {\n // Accounts should never really be de-synced, so we want to log this to see how often this\n // happens, cause that means that something else is buggy elsewhere...\n this.messenger.captureException?.(\n new Error(\n `Snap \"${this.snapId}\" has de-synced accounts, we'll attempt to re-sync them...`,\n ),\n );\n\n // We always use the MetaMask list as the main reference here.\n await Promise.all(\n localSnapAccounts.map(async (account) => {\n const { id: entropySource, groupIndex } = account.options.entropy;\n\n try {\n if (!snapAccounts.has(account.id)) {\n // We still need to remove the accounts from the Snap keyring since we're\n // about to create the same account again, which will use a new ID, but will\n // keep using the same address, and the Snap keyring does not allow this.\n await keyring.removeAccount(account.address);\n // The Snap has no account in its state for this one, we re-create it.\n await this.createAccounts({\n entropySource,\n groupIndex,\n });\n }\n } catch (error) {\n const sentryError = createSentryError(\n `Unable to re-sync account: ${groupIndex}`,\n error as Error,\n {\n provider: this.getName(),\n groupIndex,\n },\n );\n this.messenger.captureException?.(sentryError);\n }\n }),\n );\n }\n });\n }\n\n async #withSnapKeyring<CallbackResult = void>(\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SnapKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n return this.withKeyring<SnapKeyring, CallbackResult>(\n { type: KeyringTypes.snap },\n (args) => {\n return operation(args);\n },\n );\n }\n\n protected async withSnap<CallbackResult = void>(\n operation: (snap: {\n client: KeyringClient;\n keyring: RestrictedSnapKeyring;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n await this.ensureCanUseSnapPlatform();\n\n return await operation({\n client: this.#client,\n keyring: await this.#getRestrictedSnapKeyring(),\n });\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n\n abstract createAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n\n abstract discoverAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n}\n\nexport const isSnapAccountProvider = (\n provider: unknown,\n): provider is SnapAccountProvider => {\n return provider instanceof SnapAccountProvider;\n};\n"]}
1
+ {"version":3,"file":"SnapAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,qEAA4D;AAE5D,uEAA8D;AAE9D,uDAAoD;AACpD,6CAAwC;AAExC,6EAAsE;AACtE,sDAA6C;AAE7C,wCAA6C;AAmB7C,MAAsB,mBAAoB,SAAQ,mDAAwB;IAWxE,YACE,MAAc,EACd,SAA4C,EAC5C,MAAiC;IACjC,0BAA0B;IAC1B,QAAuB,yBAAa;QAEpC,KAAK,CAAC,SAAS,CAAC,CAAC;;QAXV,6CAAmB;QAEnB,6CAAsB;QAW7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,uBAAA,IAAI,uFAA4B,MAAhC,IAAI,EAA6B,MAAM,CAAC,CAAC;QAEvD,MAAM,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,QAAQ,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,MAAM;YACT,SAAS,EAAE;gBACT,GAAG,MAAM,CAAC,SAAS;gBACnB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,IAAI,IAAI;aAC1C;YACD,cAAc;SACf,CAAC;QAEF,kDAAkD;QAClD,IAAI,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YAC7B,u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,CAAC,cAAc,CAAC;4BACxB,aAAa;4BACb,UAAU;yBACX,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,WAAW,GAAG,IAAA,yBAAiB,EACnC,8BAA8B,UAAU,EAAE,EAC1C,KAAc,EACd;wBACE,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE;wBACxB,UAAU;qBACX,CACF,CAAC;oBACF,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,WAAW,CAAC,CAAC;gBACjD,CAAC;YACH,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC;CA8BF;AAzMD,kDAyMC;mPArH6B,MAAc;IACxC,OAAO,IAAI,mCAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE;YACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACxC,8BAA8B,EAC9B;gBACE,MAAM,EAAE,MAAgB;gBACxB,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,yBAAW,CAAC,gBAAgB;gBACrC,OAAO;aACR,CACF,CAAC;YACF,OAAO,QAAgB,CAAC;QAC1B,CAAC;KACF,CAAC,CAAC;AACL,CAAC,yCA0ED,KAAK,+CACH,SAM6B;IAE7B,OAAO,IAAI,CAAC,WAAW,CACrB,EAAE,IAAI,EAAE,iCAAY,CAAC,IAAI,EAAE,EAC3B,CAAC,IAAI,EAAE,EAAE;QACP,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC,CACF,CAAC;AACJ,CAAC;AAeI,MAAM,qBAAqB,GAAG,CACnC,QAAiB,EACgB,EAAE;IACnC,OAAO,QAAQ,YAAY,mBAAmB,CAAC;AACjD,CAAC,CAAC;AAJW,QAAA,qBAAqB,yBAIhC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback, TraceRequest } from '@metamask/controller-utils';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type { KeyringMetadata } from '@metamask/keyring-controller';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { Json, JsonRpcRequest, SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport { Semaphore } from 'async-mutex';\n\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { createSentryError } from '../utils';\n\nexport type RestrictedSnapKeyringCreateAccount = (\n options: Record<string, Json>,\n) => Promise<KeyringAccount>;\n\nexport type SnapAccountProviderConfig = {\n maxConcurrency?: number;\n discovery: {\n enabled?: boolean;\n maxAttempts: number;\n timeoutMs: number;\n backOffMs: number;\n };\n createAccounts: {\n timeoutMs: number;\n };\n};\n\nexport abstract class SnapAccountProvider extends BaseBip44AccountProvider {\n readonly snapId: SnapId;\n\n protected readonly config: SnapAccountProviderConfig;\n\n protected readonly client: KeyringClient;\n\n readonly #queue?: Semaphore;\n\n readonly #trace: TraceCallback;\n\n constructor(\n snapId: SnapId,\n messenger: MultichainAccountServiceMessenger,\n config: SnapAccountProviderConfig,\n /* istanbul ignore next */\n trace: TraceCallback = traceFallback,\n ) {\n super(messenger);\n\n this.snapId = snapId;\n this.client = this.#getKeyringClientFromSnapId(snapId);\n\n const maxConcurrency = config.maxConcurrency ?? Infinity;\n this.config = {\n ...config,\n discovery: {\n ...config.discovery,\n enabled: config.discovery.enabled ?? true,\n },\n maxConcurrency,\n };\n\n // Create semaphore only if concurrency is limited\n if (isFinite(maxConcurrency)) {\n this.#queue = new Semaphore(maxConcurrency);\n }\n\n this.#trace = trace;\n }\n\n /**\n * Wraps an async operation with concurrency limiting based on maxConcurrency config.\n * If maxConcurrency is Infinity (the default), the operation runs immediately without throttling.\n * Otherwise, it's queued through the semaphore to respect the concurrency limit.\n *\n * @param operation - The async operation to execute.\n * @returns The result of the operation.\n */\n protected async withMaxConcurrency<T>(\n operation: () => Promise<T>,\n ): Promise<T> {\n if (this.#queue) {\n return this.#queue.runExclusive(operation);\n }\n return operation();\n }\n\n protected async trace<ReturnType>(\n request: TraceRequest,\n fn: () => Promise<ReturnType>,\n ): Promise<ReturnType> {\n return this.#trace(request, fn);\n }\n\n protected async getRestrictedSnapAccountCreator(): Promise<RestrictedSnapKeyringCreateAccount> {\n // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but\n // we have to use the `SnapKeyring` instance to be able to create Solana account\n // without triggering UI confirmation.\n // Also, creating account that way won't invalidate the Snap keyring state. The\n // account will get created and persisted properly with the Snap account creation\n // flow \"asynchronously\" (with `notify:accountCreated`).\n const createAccount = await this.#withSnapKeyring<\n SnapKeyring['createAccount']\n >(async ({ keyring }) => keyring.createAccount.bind(keyring));\n\n return (options) =>\n createAccount(this.snapId, options, {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n });\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\n }\n\n async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n const localSnapAccounts = accounts.filter(\n (account) =>\n account.metadata.snap && account.metadata.snap.id === this.snapId,\n );\n const snapAccounts = new Set(\n (await this.client.listAccounts()).map((account) => account.id),\n );\n\n // NOTE: This should never happen, but we want to report that kind of errors still\n // in case states are de-sync.\n if (localSnapAccounts.length < snapAccounts.size) {\n this.messenger.captureException?.(\n new Error(\n `Snap \"${this.snapId}\" has de-synced accounts, Snap has more accounts than MetaMask!`,\n ),\n );\n\n // We don't recover from this case yet.\n return;\n }\n\n // We want this part to be fast, so we only check for sizes, but we might need\n // to make a real \"diff\" between the 2 states to not miss any de-sync.\n if (localSnapAccounts.length > snapAccounts.size) {\n // Accounts should never really be de-synced, so we want to log this to see how often this\n // happens, cause that means that something else is buggy elsewhere...\n this.messenger.captureException?.(\n new Error(\n `Snap \"${this.snapId}\" has de-synced accounts, we'll attempt to re-sync them...`,\n ),\n );\n\n // We always use the MetaMask list as the main reference here.\n await Promise.all(\n localSnapAccounts.map(async (account) => {\n const { id: entropySource, groupIndex } = account.options.entropy;\n\n try {\n if (!snapAccounts.has(account.id)) {\n // We still need to remove the accounts from the Snap keyring since we're\n // about to create the same account again, which will use a new ID, but will\n // keep using the same address, and the Snap keyring does not allow this.\n await this.#withSnapKeyring(\n async ({ keyring }) =>\n await keyring.removeAccount(account.address),\n );\n\n // The Snap has no account in its state for this one, we re-create it.\n await this.createAccounts({\n entropySource,\n groupIndex,\n });\n }\n } catch (error) {\n const sentryError = createSentryError(\n `Unable to re-sync account: ${groupIndex}`,\n error as Error,\n {\n provider: this.getName(),\n groupIndex,\n },\n );\n this.messenger.captureException?.(sentryError);\n }\n }),\n );\n }\n }\n\n async #withSnapKeyring<CallbackResult = void>(\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SnapKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n return this.withKeyring<SnapKeyring, CallbackResult>(\n { type: KeyringTypes.snap },\n (args) => {\n return operation(args);\n },\n );\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n\n abstract createAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n\n abstract discoverAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n}\n\nexport const isSnapAccountProvider = (\n provider: unknown,\n): provider is SnapAccountProvider => {\n return provider instanceof SnapAccountProvider;\n};\n"]}
@@ -6,10 +6,7 @@ import { KeyringClient } from "@metamask/keyring-snap-client";
6
6
  import type { Json, SnapId } from "@metamask/snaps-sdk";
7
7
  import { BaseBip44AccountProvider } from "./BaseBip44AccountProvider.cjs";
8
8
  import type { MultichainAccountServiceMessenger } from "../types.cjs";
9
- export type RestrictedSnapKeyring = {
10
- createAccount: (options: Record<string, Json>) => Promise<KeyringAccount>;
11
- removeAccount: (address: string) => Promise<void>;
12
- };
9
+ export type RestrictedSnapKeyringCreateAccount = (options: Record<string, Json>) => Promise<KeyringAccount>;
13
10
  export type SnapAccountProviderConfig = {
14
11
  maxConcurrency?: number;
15
12
  discovery: {
@@ -26,14 +23,8 @@ export declare abstract class SnapAccountProvider extends BaseBip44AccountProvid
26
23
  #private;
27
24
  readonly snapId: SnapId;
28
25
  protected readonly config: SnapAccountProviderConfig;
26
+ protected readonly client: KeyringClient;
29
27
  constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger, config: SnapAccountProviderConfig, trace?: TraceCallback);
30
- /**
31
- * Ensures that the Snap platform is ready to be used.
32
- *
33
- * @returns A promise that resolves when the platform is ready.
34
- * @throws An error if the platform is not ready (only effective once the platform has been ready at least once).
35
- */
36
- ensureCanUseSnapPlatform(): Promise<void>;
37
28
  /**
38
29
  * Wraps an async operation with concurrency limiting based on maxConcurrency config.
39
30
  * If maxConcurrency is Infinity (the default), the operation runs immediately without throttling.
@@ -42,13 +33,10 @@ export declare abstract class SnapAccountProvider extends BaseBip44AccountProvid
42
33
  * @param operation - The async operation to execute.
43
34
  * @returns The result of the operation.
44
35
  */
45
- protected withMaxConcurrency<Result>(operation: () => Promise<Result>): Promise<Result>;
36
+ protected withMaxConcurrency<T>(operation: () => Promise<T>): Promise<T>;
46
37
  protected trace<ReturnType>(request: TraceRequest, fn: () => Promise<ReturnType>): Promise<ReturnType>;
38
+ protected getRestrictedSnapAccountCreator(): Promise<RestrictedSnapKeyringCreateAccount>;
47
39
  resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
48
- protected withSnap<CallbackResult = void>(operation: (snap: {
49
- client: KeyringClient;
50
- keyring: RestrictedSnapKeyring;
51
- }) => Promise<CallbackResult>): Promise<CallbackResult>;
52
40
  abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
53
41
  abstract createAccounts(options: {
54
42
  entropySource: EntropySourceId;
@@ -1 +1 @@
1
- {"version":3,"file":"SnapAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,mCAAmC;AAE9E,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAG7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,EAAE,4BAA4B;AAIxE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AAEtE,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAGlE,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1E,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE;QACT,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,cAAc,EAAE;QACd,SAAS,EAAE,MAAM,CAA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;gBAOvC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,iCAAiC,EAC5C,MAAM,EAAE,yBAAyB,EAEjC,KAAK,GAAE,aAA6B;IAyBtC;;;;;;;OAOG;cACa,kBAAkB,CAAC,CAAC,EAClC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC;cAOG,KAAK,CAAC,UAAU,EAC9B,OAAO,EAAE,YAAY,EACrB,EAAE,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,GAC5B,OAAO,CAAC,UAAU,CAAC;cAIN,+BAA+B,IAAI,OAAO,CAAC,kCAAkC,CAAC;IAoCxF,cAAc,CAClB,QAAQ,EAAE,YAAY,CAAC,eAAe,CAAC,EAAE,GACxC,OAAO,CAAC,IAAI,CAAC;IAuFhB,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAE7E,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE;QAC/B,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAE3C,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAC5C;AAED,eAAO,MAAM,qBAAqB,aACtB,OAAO,oCAGlB,CAAC"}
@@ -6,10 +6,7 @@ import { KeyringClient } from "@metamask/keyring-snap-client";
6
6
  import type { Json, SnapId } from "@metamask/snaps-sdk";
7
7
  import { BaseBip44AccountProvider } from "./BaseBip44AccountProvider.mjs";
8
8
  import type { MultichainAccountServiceMessenger } from "../types.mjs";
9
- export type RestrictedSnapKeyring = {
10
- createAccount: (options: Record<string, Json>) => Promise<KeyringAccount>;
11
- removeAccount: (address: string) => Promise<void>;
12
- };
9
+ export type RestrictedSnapKeyringCreateAccount = (options: Record<string, Json>) => Promise<KeyringAccount>;
13
10
  export type SnapAccountProviderConfig = {
14
11
  maxConcurrency?: number;
15
12
  discovery: {
@@ -26,14 +23,8 @@ export declare abstract class SnapAccountProvider extends BaseBip44AccountProvid
26
23
  #private;
27
24
  readonly snapId: SnapId;
28
25
  protected readonly config: SnapAccountProviderConfig;
26
+ protected readonly client: KeyringClient;
29
27
  constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger, config: SnapAccountProviderConfig, trace?: TraceCallback);
30
- /**
31
- * Ensures that the Snap platform is ready to be used.
32
- *
33
- * @returns A promise that resolves when the platform is ready.
34
- * @throws An error if the platform is not ready (only effective once the platform has been ready at least once).
35
- */
36
- ensureCanUseSnapPlatform(): Promise<void>;
37
28
  /**
38
29
  * Wraps an async operation with concurrency limiting based on maxConcurrency config.
39
30
  * If maxConcurrency is Infinity (the default), the operation runs immediately without throttling.
@@ -42,13 +33,10 @@ export declare abstract class SnapAccountProvider extends BaseBip44AccountProvid
42
33
  * @param operation - The async operation to execute.
43
34
  * @returns The result of the operation.
44
35
  */
45
- protected withMaxConcurrency<Result>(operation: () => Promise<Result>): Promise<Result>;
36
+ protected withMaxConcurrency<T>(operation: () => Promise<T>): Promise<T>;
46
37
  protected trace<ReturnType>(request: TraceRequest, fn: () => Promise<ReturnType>): Promise<ReturnType>;
38
+ protected getRestrictedSnapAccountCreator(): Promise<RestrictedSnapKeyringCreateAccount>;
47
39
  resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
48
- protected withSnap<CallbackResult = void>(operation: (snap: {
49
- client: KeyringClient;
50
- keyring: RestrictedSnapKeyring;
51
- }) => Promise<CallbackResult>): Promise<CallbackResult>;
52
40
  abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
53
41
  abstract createAccounts(options: {
54
42
  entropySource: EntropySourceId;
@@ -1 +1 @@
1
- {"version":3,"file":"Sn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