@metamask/multichain-account-service 12.0.0 → 13.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 (50) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/analytics/traces.cjs +0 -1
  3. package/dist/analytics/traces.cjs.map +1 -1
  4. package/dist/analytics/traces.d.cts +0 -1
  5. package/dist/analytics/traces.d.cts.map +1 -1
  6. package/dist/analytics/traces.d.mts +0 -1
  7. package/dist/analytics/traces.d.mts.map +1 -1
  8. package/dist/analytics/traces.mjs +0 -1
  9. package/dist/analytics/traces.mjs.map +1 -1
  10. package/dist/providers/BtcAccountProvider.cjs +0 -11
  11. package/dist/providers/BtcAccountProvider.cjs.map +1 -1
  12. package/dist/providers/BtcAccountProvider.d.cts +1 -6
  13. package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
  14. package/dist/providers/BtcAccountProvider.d.mts +1 -6
  15. package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
  16. package/dist/providers/BtcAccountProvider.mjs +0 -11
  17. package/dist/providers/BtcAccountProvider.mjs.map +1 -1
  18. package/dist/providers/SnapAccountProvider.cjs +17 -76
  19. package/dist/providers/SnapAccountProvider.cjs.map +1 -1
  20. package/dist/providers/SnapAccountProvider.d.cts +13 -19
  21. package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
  22. package/dist/providers/SnapAccountProvider.d.mts +13 -19
  23. package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
  24. package/dist/providers/SnapAccountProvider.mjs +17 -76
  25. package/dist/providers/SnapAccountProvider.mjs.map +1 -1
  26. package/dist/providers/SolAccountProvider.cjs +0 -9
  27. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  28. package/dist/providers/SolAccountProvider.d.cts +1 -5
  29. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  30. package/dist/providers/SolAccountProvider.d.mts +1 -5
  31. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  32. package/dist/providers/SolAccountProvider.mjs +0 -9
  33. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  34. package/dist/providers/TrxAccountProvider.cjs +0 -11
  35. package/dist/providers/TrxAccountProvider.cjs.map +1 -1
  36. package/dist/providers/TrxAccountProvider.d.cts +1 -6
  37. package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
  38. package/dist/providers/TrxAccountProvider.d.mts +1 -6
  39. package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
  40. package/dist/providers/TrxAccountProvider.mjs +0 -11
  41. package/dist/providers/TrxAccountProvider.mjs.map +1 -1
  42. package/dist/providers/XlmAccountProvider.cjs +0 -11
  43. package/dist/providers/XlmAccountProvider.cjs.map +1 -1
  44. package/dist/providers/XlmAccountProvider.d.cts +1 -6
  45. package/dist/providers/XlmAccountProvider.d.cts.map +1 -1
  46. package/dist/providers/XlmAccountProvider.d.mts +1 -6
  47. package/dist/providers/XlmAccountProvider.d.mts.map +1 -1
  48. package/dist/providers/XlmAccountProvider.mjs +0 -11
  49. package/dist/providers/XlmAccountProvider.mjs.map +1 -1
  50. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [13.0.0]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/accounts-controller` from `^39.0.4` to `^39.0.5` ([#9470](https://github.com/MetaMask/core/pull/9470))
15
+
16
+ ### Removed
17
+
18
+ - **BREAKING:** Removed use of v1 `createAccount` entirely ([#9460](https://github.com/MetaMask/core/pull/9460))
19
+ - All BIP-44 Snaps are expected to implement `createAccounts` (v1 or v2).
20
+ - The old v1 `createAccount` flow had some undesired side-effetcs sometimes (e.g auto-selecting a non-EVM account after being created, which is not compatible with our new group model).
21
+
10
22
  ## [12.0.0]
11
23
 
12
24
  ### Added
@@ -571,7 +583,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
571
583
  - Add `MultichainAccountService` ([#6141](https://github.com/MetaMask/core/pull/6141), [#6165](https://github.com/MetaMask/core/pull/6165))
572
584
  - This service manages multichain accounts/wallets.
573
585
 
574
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@12.0.0...HEAD
586
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@13.0.0...HEAD
587
+ [13.0.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@12.0.0...@metamask/multichain-account-service@13.0.0
575
588
  [12.0.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@11.1.0...@metamask/multichain-account-service@12.0.0
576
589
  [11.1.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@11.0.0...@metamask/multichain-account-service@11.1.0
577
590
  [11.0.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@10.0.3...@metamask/multichain-account-service@11.0.0
@@ -60,7 +60,6 @@ var TraceName;
60
60
  (function (TraceName) {
61
61
  TraceName["SnapDiscoverAccounts"] = "Snap Discover Accounts";
62
62
  TraceName["EvmDiscoverAccounts"] = "EVM Discover Accounts";
63
- TraceName["ProviderCreateAccountV1"] = "Provider Create Account (v1)";
64
63
  TraceName["ProviderCreateAccounts"] = "Provider Create Accounts (v2 - batched)";
65
64
  TraceName["WalletAlignment"] = "Wallet Alignment";
66
65
  TraceName["WalletCreateMultichainAccountGroup"] = "Wallet Create Multichain Account Group";
@@ -1 +1 @@
1
- {"version":3,"file":"traces.cjs","sourceRoot":"","sources":["../../src/analytics/traces.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;GASG;AACI,MAAM,aAAa,GAAkB,KAAK,EAC/C,QAAsB,EACtB,EAA2C,EACtB,EAAE;IACvB,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,SAAuB,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB;AAEF;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,SAAiC;IAEjC,wFAAwF;IACxF,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnB,GAAG,IAAI;QACP,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI;KAC3B,CAAC,EACF,EAAE,CACH,CAAC;AACJ,CAAC;AAXD,oDAWC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAC1C,OAA6B;IAE7B,IAAI,OAAO,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;QAC1C,OAAO;YACL,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,0BAA0B,EAAE,CAAC;QACvD,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;YACxB,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE;SACrB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAdD,oEAcC;AAED;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,4DAA+C,CAAA;IAC/C,0DAA6C,CAAA;IAC7C,qEAAwD,CAAA;IACxD,+EAAkE,CAAA;IAClE,iDAAoC,CAAA;IACpC,0FAA6E,CAAA;IAC7E,4FAA+E,CAAA;AACjF,CAAC,EARW,SAAS,yBAAT,SAAS,QAQpB","sourcesContent":["import type {\n TraceCallback,\n TraceContext,\n TraceRequest,\n} from '@metamask/controller-utils';\nimport { CreateAccountOptions } from '@metamask/keyring-api';\n\n// Explicit import to avoid circular dependency between `analytics` and `providers`.\nimport type { Bip44AccountProvider } from '../providers/BaseBip44AccountProvider';\n\n/**\n * Fallback function for tracing.\n * This function is used when no specific trace function is provided.\n * It executes the provided function in a trace context if available.\n *\n * @param _request - The trace request containing additional data and context.\n * @param fn - The function to execute within the trace context.\n * @returns A promise that resolves to the result of the executed function.\n * If no function is provided, it resolves to undefined.\n */\nexport const traceFallback: TraceCallback = async <ReturnType>(\n _request: TraceRequest,\n fn?: (context?: TraceContext) => ReturnType,\n): Promise<ReturnType> => {\n if (!fn) {\n return undefined as ReturnType;\n }\n return await Promise.resolve(fn());\n};\n\n/**\n * Compute trace data for a list of providers.\n *\n * @param providers Providers to be included in the trace data.\n * @returns An object mapping provider names to true, indicating their presence in the trace.\n */\nexport function toProviderDataTraces(\n providers: Bip44AccountProvider[],\n): Record<string, boolean> {\n // We cannot use complex objects within traces, so we just map provider names with true.\n return providers.reduce(\n (data, provider) => ({\n ...data,\n [provider.getName()]: true,\n }),\n {},\n );\n}\n\n/**\n * Compute trace data for `createAccounts` options.\n *\n * @param options The `createAccounts` options.\n * @returns An object containing options data depending on its type.\n */\nexport function toCreateAccountsV2DataTraces(\n options: CreateAccountOptions,\n): Record<string, string | number | boolean> {\n if (options.type === 'bip44:derive-index') {\n return {\n groupIndex: options.groupIndex,\n };\n } else if (options.type === 'bip44:derive-index-range') {\n return {\n from: options.range.from,\n to: options.range.to,\n };\n }\n return {};\n}\n\n/**\n * Trace names.\n */\nexport enum TraceName {\n SnapDiscoverAccounts = 'Snap Discover Accounts',\n EvmDiscoverAccounts = 'EVM Discover Accounts',\n ProviderCreateAccountV1 = 'Provider Create Account (v1)',\n ProviderCreateAccounts = 'Provider Create Accounts (v2 - batched)',\n WalletAlignment = 'Wallet Alignment',\n WalletCreateMultichainAccountGroup = 'Wallet Create Multichain Account Group',\n WalletCreateMultichainAccountGroups = 'Wallet Create Multichain Account Groups',\n}\n"]}
1
+ {"version":3,"file":"traces.cjs","sourceRoot":"","sources":["../../src/analytics/traces.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;GASG;AACI,MAAM,aAAa,GAAkB,KAAK,EAC/C,QAAsB,EACtB,EAA2C,EACtB,EAAE;IACvB,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,SAAuB,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB;AAEF;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,SAAiC;IAEjC,wFAAwF;IACxF,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnB,GAAG,IAAI;QACP,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI;KAC3B,CAAC,EACF,EAAE,CACH,CAAC;AACJ,CAAC;AAXD,oDAWC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAC1C,OAA6B;IAE7B,IAAI,OAAO,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;QAC1C,OAAO;YACL,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,0BAA0B,EAAE,CAAC;QACvD,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;YACxB,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE;SACrB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAdD,oEAcC;AAED;;GAEG;AACH,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4DAA+C,CAAA;IAC/C,0DAA6C,CAAA;IAC7C,+EAAkE,CAAA;IAClE,iDAAoC,CAAA;IACpC,0FAA6E,CAAA;IAC7E,4FAA+E,CAAA;AACjF,CAAC,EAPW,SAAS,yBAAT,SAAS,QAOpB","sourcesContent":["import type {\n TraceCallback,\n TraceContext,\n TraceRequest,\n} from '@metamask/controller-utils';\nimport { CreateAccountOptions } from '@metamask/keyring-api';\n\n// Explicit import to avoid circular dependency between `analytics` and `providers`.\nimport type { Bip44AccountProvider } from '../providers/BaseBip44AccountProvider';\n\n/**\n * Fallback function for tracing.\n * This function is used when no specific trace function is provided.\n * It executes the provided function in a trace context if available.\n *\n * @param _request - The trace request containing additional data and context.\n * @param fn - The function to execute within the trace context.\n * @returns A promise that resolves to the result of the executed function.\n * If no function is provided, it resolves to undefined.\n */\nexport const traceFallback: TraceCallback = async <ReturnType>(\n _request: TraceRequest,\n fn?: (context?: TraceContext) => ReturnType,\n): Promise<ReturnType> => {\n if (!fn) {\n return undefined as ReturnType;\n }\n return await Promise.resolve(fn());\n};\n\n/**\n * Compute trace data for a list of providers.\n *\n * @param providers Providers to be included in the trace data.\n * @returns An object mapping provider names to true, indicating their presence in the trace.\n */\nexport function toProviderDataTraces(\n providers: Bip44AccountProvider[],\n): Record<string, boolean> {\n // We cannot use complex objects within traces, so we just map provider names with true.\n return providers.reduce(\n (data, provider) => ({\n ...data,\n [provider.getName()]: true,\n }),\n {},\n );\n}\n\n/**\n * Compute trace data for `createAccounts` options.\n *\n * @param options The `createAccounts` options.\n * @returns An object containing options data depending on its type.\n */\nexport function toCreateAccountsV2DataTraces(\n options: CreateAccountOptions,\n): Record<string, string | number | boolean> {\n if (options.type === 'bip44:derive-index') {\n return {\n groupIndex: options.groupIndex,\n };\n } else if (options.type === 'bip44:derive-index-range') {\n return {\n from: options.range.from,\n to: options.range.to,\n };\n }\n return {};\n}\n\n/**\n * Trace names.\n */\nexport enum TraceName {\n SnapDiscoverAccounts = 'Snap Discover Accounts',\n EvmDiscoverAccounts = 'EVM Discover Accounts',\n ProviderCreateAccounts = 'Provider Create Accounts (v2 - batched)',\n WalletAlignment = 'Wallet Alignment',\n WalletCreateMultichainAccountGroup = 'Wallet Create Multichain Account Group',\n WalletCreateMultichainAccountGroups = 'Wallet Create Multichain Account Groups',\n}\n"]}
@@ -32,7 +32,6 @@ export declare function toCreateAccountsV2DataTraces(options: CreateAccountOptio
32
32
  export declare enum TraceName {
33
33
  SnapDiscoverAccounts = "Snap Discover Accounts",
34
34
  EvmDiscoverAccounts = "EVM Discover Accounts",
35
- ProviderCreateAccountV1 = "Provider Create Account (v1)",
36
35
  ProviderCreateAccounts = "Provider Create Accounts (v2 - batched)",
37
36
  WalletAlignment = "Wallet Alignment",
38
37
  WalletCreateMultichainAccountGroup = "Wallet Create Multichain Account Group",
@@ -1 +1 @@
1
- {"version":3,"file":"traces.d.cts","sourceRoot":"","sources":["../../src/analytics/traces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAGd,mCAAmC;AACpC,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAG7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,kDAA8C;AAElF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,aAQ3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,oBAAoB,EAAE,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAY3C;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,oBAAoB,2BAA2B;IAC/C,mBAAmB,0BAA0B;IAC7C,uBAAuB,iCAAiC;IACxD,sBAAsB,4CAA4C;IAClE,eAAe,qBAAqB;IACpC,kCAAkC,2CAA2C;IAC7E,mCAAmC,4CAA4C;CAChF"}
1
+ {"version":3,"file":"traces.d.cts","sourceRoot":"","sources":["../../src/analytics/traces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAGd,mCAAmC;AACpC,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAG7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,kDAA8C;AAElF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,aAQ3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,oBAAoB,EAAE,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAY3C;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,oBAAoB,2BAA2B;IAC/C,mBAAmB,0BAA0B;IAC7C,sBAAsB,4CAA4C;IAClE,eAAe,qBAAqB;IACpC,kCAAkC,2CAA2C;IAC7E,mCAAmC,4CAA4C;CAChF"}
@@ -32,7 +32,6 @@ export declare function toCreateAccountsV2DataTraces(options: CreateAccountOptio
32
32
  export declare enum TraceName {
33
33
  SnapDiscoverAccounts = "Snap Discover Accounts",
34
34
  EvmDiscoverAccounts = "EVM Discover Accounts",
35
- ProviderCreateAccountV1 = "Provider Create Account (v1)",
36
35
  ProviderCreateAccounts = "Provider Create Accounts (v2 - batched)",
37
36
  WalletAlignment = "Wallet Alignment",
38
37
  WalletCreateMultichainAccountGroup = "Wallet Create Multichain Account Group",
@@ -1 +1 @@
1
- {"version":3,"file":"traces.d.mts","sourceRoot":"","sources":["../../src/analytics/traces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAGd,mCAAmC;AACpC,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAG7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,kDAA8C;AAElF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,aAQ3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,oBAAoB,EAAE,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAY3C;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,oBAAoB,2BAA2B;IAC/C,mBAAmB,0BAA0B;IAC7C,uBAAuB,iCAAiC;IACxD,sBAAsB,4CAA4C;IAClE,eAAe,qBAAqB;IACpC,kCAAkC,2CAA2C;IAC7E,mCAAmC,4CAA4C;CAChF"}
1
+ {"version":3,"file":"traces.d.mts","sourceRoot":"","sources":["../../src/analytics/traces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAGd,mCAAmC;AACpC,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAG7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,kDAA8C;AAElF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,aAQ3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,oBAAoB,EAAE,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAY3C;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,oBAAoB,2BAA2B;IAC/C,mBAAmB,0BAA0B;IAC7C,sBAAsB,4CAA4C;IAClE,eAAe,qBAAqB;IACpC,kCAAkC,2CAA2C;IAC7E,mCAAmC,4CAA4C;CAChF"}
@@ -54,7 +54,6 @@ export var TraceName;
54
54
  (function (TraceName) {
55
55
  TraceName["SnapDiscoverAccounts"] = "Snap Discover Accounts";
56
56
  TraceName["EvmDiscoverAccounts"] = "EVM Discover Accounts";
57
- TraceName["ProviderCreateAccountV1"] = "Provider Create Account (v1)";
58
57
  TraceName["ProviderCreateAccounts"] = "Provider Create Accounts (v2 - batched)";
59
58
  TraceName["WalletAlignment"] = "Wallet Alignment";
60
59
  TraceName["WalletCreateMultichainAccountGroup"] = "Wallet Create Multichain Account Group";
@@ -1 +1 @@
1
- {"version":3,"file":"traces.mjs","sourceRoot":"","sources":["../../src/analytics/traces.ts"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB,KAAK,EAC/C,QAAsB,EACtB,EAA2C,EACtB,EAAE;IACvB,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,SAAuB,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAiC;IAEjC,wFAAwF;IACxF,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnB,GAAG,IAAI;QACP,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI;KAC3B,CAAC,EACF,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,OAA6B;IAE7B,IAAI,OAAO,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;QAC1C,OAAO;YACL,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,0BAA0B,EAAE,CAAC;QACvD,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;YACxB,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE;SACrB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,4DAA+C,CAAA;IAC/C,0DAA6C,CAAA;IAC7C,qEAAwD,CAAA;IACxD,+EAAkE,CAAA;IAClE,iDAAoC,CAAA;IACpC,0FAA6E,CAAA;IAC7E,4FAA+E,CAAA;AACjF,CAAC,EARW,SAAS,KAAT,SAAS,QAQpB","sourcesContent":["import type {\n TraceCallback,\n TraceContext,\n TraceRequest,\n} from '@metamask/controller-utils';\nimport { CreateAccountOptions } from '@metamask/keyring-api';\n\n// Explicit import to avoid circular dependency between `analytics` and `providers`.\nimport type { Bip44AccountProvider } from '../providers/BaseBip44AccountProvider';\n\n/**\n * Fallback function for tracing.\n * This function is used when no specific trace function is provided.\n * It executes the provided function in a trace context if available.\n *\n * @param _request - The trace request containing additional data and context.\n * @param fn - The function to execute within the trace context.\n * @returns A promise that resolves to the result of the executed function.\n * If no function is provided, it resolves to undefined.\n */\nexport const traceFallback: TraceCallback = async <ReturnType>(\n _request: TraceRequest,\n fn?: (context?: TraceContext) => ReturnType,\n): Promise<ReturnType> => {\n if (!fn) {\n return undefined as ReturnType;\n }\n return await Promise.resolve(fn());\n};\n\n/**\n * Compute trace data for a list of providers.\n *\n * @param providers Providers to be included in the trace data.\n * @returns An object mapping provider names to true, indicating their presence in the trace.\n */\nexport function toProviderDataTraces(\n providers: Bip44AccountProvider[],\n): Record<string, boolean> {\n // We cannot use complex objects within traces, so we just map provider names with true.\n return providers.reduce(\n (data, provider) => ({\n ...data,\n [provider.getName()]: true,\n }),\n {},\n );\n}\n\n/**\n * Compute trace data for `createAccounts` options.\n *\n * @param options The `createAccounts` options.\n * @returns An object containing options data depending on its type.\n */\nexport function toCreateAccountsV2DataTraces(\n options: CreateAccountOptions,\n): Record<string, string | number | boolean> {\n if (options.type === 'bip44:derive-index') {\n return {\n groupIndex: options.groupIndex,\n };\n } else if (options.type === 'bip44:derive-index-range') {\n return {\n from: options.range.from,\n to: options.range.to,\n };\n }\n return {};\n}\n\n/**\n * Trace names.\n */\nexport enum TraceName {\n SnapDiscoverAccounts = 'Snap Discover Accounts',\n EvmDiscoverAccounts = 'EVM Discover Accounts',\n ProviderCreateAccountV1 = 'Provider Create Account (v1)',\n ProviderCreateAccounts = 'Provider Create Accounts (v2 - batched)',\n WalletAlignment = 'Wallet Alignment',\n WalletCreateMultichainAccountGroup = 'Wallet Create Multichain Account Group',\n WalletCreateMultichainAccountGroups = 'Wallet Create Multichain Account Groups',\n}\n"]}
1
+ {"version":3,"file":"traces.mjs","sourceRoot":"","sources":["../../src/analytics/traces.ts"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB,KAAK,EAC/C,QAAsB,EACtB,EAA2C,EACtB,EAAE;IACvB,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,SAAuB,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAiC;IAEjC,wFAAwF;IACxF,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnB,GAAG,IAAI;QACP,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI;KAC3B,CAAC,EACF,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,OAA6B;IAE7B,IAAI,OAAO,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;QAC1C,OAAO;YACL,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,0BAA0B,EAAE,CAAC;QACvD,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;YACxB,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE;SACrB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4DAA+C,CAAA;IAC/C,0DAA6C,CAAA;IAC7C,+EAAkE,CAAA;IAClE,iDAAoC,CAAA;IACpC,0FAA6E,CAAA;IAC7E,4FAA+E,CAAA;AACjF,CAAC,EAPW,SAAS,KAAT,SAAS,QAOpB","sourcesContent":["import type {\n TraceCallback,\n TraceContext,\n TraceRequest,\n} from '@metamask/controller-utils';\nimport { CreateAccountOptions } from '@metamask/keyring-api';\n\n// Explicit import to avoid circular dependency between `analytics` and `providers`.\nimport type { Bip44AccountProvider } from '../providers/BaseBip44AccountProvider';\n\n/**\n * Fallback function for tracing.\n * This function is used when no specific trace function is provided.\n * It executes the provided function in a trace context if available.\n *\n * @param _request - The trace request containing additional data and context.\n * @param fn - The function to execute within the trace context.\n * @returns A promise that resolves to the result of the executed function.\n * If no function is provided, it resolves to undefined.\n */\nexport const traceFallback: TraceCallback = async <ReturnType>(\n _request: TraceRequest,\n fn?: (context?: TraceContext) => ReturnType,\n): Promise<ReturnType> => {\n if (!fn) {\n return undefined as ReturnType;\n }\n return await Promise.resolve(fn());\n};\n\n/**\n * Compute trace data for a list of providers.\n *\n * @param providers Providers to be included in the trace data.\n * @returns An object mapping provider names to true, indicating their presence in the trace.\n */\nexport function toProviderDataTraces(\n providers: Bip44AccountProvider[],\n): Record<string, boolean> {\n // We cannot use complex objects within traces, so we just map provider names with true.\n return providers.reduce(\n (data, provider) => ({\n ...data,\n [provider.getName()]: true,\n }),\n {},\n );\n}\n\n/**\n * Compute trace data for `createAccounts` options.\n *\n * @param options The `createAccounts` options.\n * @returns An object containing options data depending on its type.\n */\nexport function toCreateAccountsV2DataTraces(\n options: CreateAccountOptions,\n): Record<string, string | number | boolean> {\n if (options.type === 'bip44:derive-index') {\n return {\n groupIndex: options.groupIndex,\n };\n } else if (options.type === 'bip44:derive-index-range') {\n return {\n from: options.range.from,\n to: options.range.to,\n };\n }\n return {};\n}\n\n/**\n * Trace names.\n */\nexport enum TraceName {\n SnapDiscoverAccounts = 'Snap Discover Accounts',\n EvmDiscoverAccounts = 'EVM Discover Accounts',\n ProviderCreateAccounts = 'Provider Create Accounts (v2 - batched)',\n WalletAlignment = 'Wallet Alignment',\n WalletCreateMultichainAccountGroup = 'Wallet Create Multichain Account Group',\n WalletCreateMultichainAccountGroups = 'Wallet Create Multichain Account Groups',\n}\n"]}
@@ -34,17 +34,6 @@ class BtcAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
34
34
  return (account.type === keyring_api_1.BtcAccountType.P2wpkh &&
35
35
  Object.values(keyring_api_1.BtcAccountType).includes(account.type));
36
36
  }
37
- createAccountV1(keyring, { entropySource, groupIndex, }) {
38
- if (!keyring.v1) {
39
- throw new Error(`Snap "${BtcAccountProvider.BTC_SNAP_ID}" is v2-only and does not support v1 account creation`);
40
- }
41
- return keyring.v1.createAccount({
42
- entropySource,
43
- index: groupIndex,
44
- addressType: keyring_api_1.BtcAccountType.P2wpkh,
45
- scope: keyring_api_1.BtcScope.Mainnet,
46
- });
47
- }
48
37
  }
49
38
  exports.BtcAccountProvider = BtcAccountProvider;
50
39
  BtcAccountProvider.NAME = exports.BTC_ACCOUNT_PROVIDER_NAME;
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;AAGA,uDAAiE;AAKjE,sDAA6C;AAE7C,mEAA4D;AAQ/C,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;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,yCAAmB;IASzD,YACE,SAA4C,EAC5C,SAAmC,2CAAmC,EACtE,QAAuB,yBAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QATlE,2EAA2E;QAC3E,wEAAwE;QACrD,sBAAiB,GAAkB,CAAC,sBAAQ,CAAC,OAAO,CAAC,CAAC;IAQzE,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;IAEkB,eAAe,CAChC,OAA8B,EAC9B,EACE,aAAa,EACb,UAAU,GAC6C;QAEzD,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,SAAS,kBAAkB,CAAC,WAAW,uDAAuD,CAC/F,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC,EAAE,CAAC,aAAa,CAAC;YAC9B,aAAa;YACb,KAAK,EAAE,UAAU;YACjB,WAAW,EAAE,4BAAc,CAAC,MAAM;YAClC,KAAK,EAAE,sBAAQ,CAAC,OAAO;SACxB,CAAC,CAAC;IACL,CAAC;;AA9CH,gDA+CC;AA9CQ,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { 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';\nimport type { CaipChainId } from '@metamask/utils';\n\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\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 resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n // TODO: Remove once the Snap is fully v2 — discovery is then driven by the\n // Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n protected readonly v1DiscoveryScopes: CaipChainId[] = [BtcScope.Mainnet];\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n protected override createAccountV1(\n keyring: RestrictedSnapKeyring,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Promise<KeyringAccount> {\n if (!keyring.v1) {\n throw new Error(\n `Snap \"${BtcAccountProvider.BTC_SNAP_ID}\" is v2-only and does not support v1 account creation`,\n );\n }\n return keyring.v1.createAccount({\n entropySource,\n index: groupIndex,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"BtcAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;AAEA,uDAAiE;AAKjE,sDAA6C;AAE7C,mEAA4D;AAK/C,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;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,yCAAmB;IASzD,YACE,SAA4C,EAC5C,SAAmC,2CAAmC,EACtE,QAAuB,yBAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QATlE,2EAA2E;QAC3E,wEAAwE;QACrD,sBAAiB,GAAkB,CAAC,sBAAQ,CAAC,OAAO,CAAC,CAAC;IAQzE,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;;AA1BH,gDA2BC;AA1BQ,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport { BtcAccountType, BtcScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { CaipChainId } from '@metamask/utils';\n\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type { SnapAccountProviderConfig } from './SnapAccountProvider';\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 resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n // TODO: Remove once the Snap is fully v2 — discovery is then driven by the\n // Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n protected readonly v1DiscoveryScopes: CaipChainId[] = [BtcScope.Mainnet];\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"]}
@@ -1,12 +1,11 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
2
  import type { TraceCallback } from "@metamask/controller-utils";
3
- import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
4
3
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
4
  import type { SnapId } from "@metamask/snaps-sdk";
6
5
  import type { CaipChainId } from "@metamask/utils";
7
6
  import type { MultichainAccountServiceMessenger } from "../types.cjs";
8
7
  import { SnapAccountProvider } from "./SnapAccountProvider.cjs";
9
- import type { RestrictedSnapKeyring, SnapAccountProviderConfig } from "./SnapAccountProvider.cjs";
8
+ import type { SnapAccountProviderConfig } from "./SnapAccountProvider.cjs";
10
9
  export type BtcAccountProviderConfig = SnapAccountProviderConfig;
11
10
  export declare const BTC_ACCOUNT_PROVIDER_NAME = "Bitcoin";
12
11
  export declare const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig;
@@ -17,9 +16,5 @@ export declare class BtcAccountProvider extends SnapAccountProvider {
17
16
  constructor(messenger: MultichainAccountServiceMessenger, config?: BtcAccountProviderConfig, trace?: TraceCallback);
18
17
  getName(): string;
19
18
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
20
- protected createAccountV1(keyring: RestrictedSnapKeyring, { entropySource, groupIndex, }: {
21
- entropySource: EntropySourceId;
22
- groupIndex: number;
23
- }): Promise<KeyringAccount>;
24
19
  }
25
20
  //# sourceMappingURL=BtcAccountProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AAAA,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;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAGnD,OAAO,KAAK,EAAE,iCAA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8B;AAEvE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,eAAO,MAAM,mCAAmC,EAAE,wBAcjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAAiD;IAInE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,WAAW,EAAE,CAAsB;gBAGvE,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;CAMrE"}
@@ -1,12 +1,11 @@
1
1
  import type { Bip44Account } from "@metamask/account-api";
2
2
  import type { TraceCallback } from "@metamask/controller-utils";
3
- import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
4
3
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
4
  import type { SnapId } from "@metamask/snaps-sdk";
6
5
  import type { CaipChainId } from "@metamask/utils";
7
6
  import type { MultichainAccountServiceMessenger } from "../types.mjs";
8
7
  import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
9
- import type { RestrictedSnapKeyring, SnapAccountProviderConfig } from "./SnapAccountProvider.mjs";
8
+ import type { SnapAccountProviderConfig } from "./SnapAccountProvider.mjs";
10
9
  export type BtcAccountProviderConfig = SnapAccountProviderConfig;
11
10
  export declare const BTC_ACCOUNT_PROVIDER_NAME = "Bitcoin";
12
11
  export declare const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig;
@@ -17,9 +16,5 @@ export declare class BtcAccountProvider extends SnapAccountProvider {
17
16
  constructor(messenger: MultichainAccountServiceMessenger, config?: BtcAccountProviderConfig, trace?: TraceCallback);
18
17
  getName(): string;
19
18
  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
20
- protected createAccountV1(keyring: RestrictedSnapKeyring, { entropySource, groupIndex, }: {
21
- entropySource: EntropySourceId;
22
- groupIndex: number;
23
- }): Promise<KeyringAccount>;
24
19
  }
25
20
  //# sourceMappingURL=BtcAccountProvider.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AAAA,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;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAGnD,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAClE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EACV,qBAAqB,EACrB,yBAAyB,EAC1B,kCAA8B;AAE/B,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,eAAO,MAAM,mCAAmC,EAAE,wBAcjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAAiD;IAInE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,WAAW,EAAE,CAAsB;gBAGvE,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;CAa3B"}
1
+ {"version":3,"file":"BtcAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAGnD,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAClE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EAAE,yBAAyB,EAAE,kCAA8B;AAEvE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,eAAO,MAAM,mCAAmC,EAAE,wBAcjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAAiD;IAInE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,WAAW,EAAE,CAAsB;gBAGvE,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;CAMrE"}
@@ -31,17 +31,6 @@ export class BtcAccountProvider extends SnapAccountProvider {
31
31
  return (account.type === BtcAccountType.P2wpkh &&
32
32
  Object.values(BtcAccountType).includes(account.type));
33
33
  }
34
- createAccountV1(keyring, { entropySource, groupIndex, }) {
35
- if (!keyring.v1) {
36
- throw new Error(`Snap "${BtcAccountProvider.BTC_SNAP_ID}" is v2-only and does not support v1 account creation`);
37
- }
38
- return keyring.v1.createAccount({
39
- entropySource,
40
- index: groupIndex,
41
- addressType: BtcAccountType.P2wpkh,
42
- scope: BtcScope.Mainnet,
43
- });
44
- }
45
34
  }
46
35
  BtcAccountProvider.NAME = BTC_ACCOUNT_PROVIDER_NAME;
47
36
  BtcAccountProvider.BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap';
@@ -1 +1 @@
1
- {"version":3,"file":"BtcAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,8BAA8B;AAKjE,OAAO,EAAE,aAAa,EAAE,+BAAqB;AAE7C,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAQ5D,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;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IASzD,YACE,SAA4C,EAC5C,SAAmC,mCAAmC,EACtE,QAAuB,aAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QATlE,2EAA2E;QAC3E,wEAAwE;QACrD,sBAAiB,GAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAQzE,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,MAAM;YACtC,MAAM,CAAC,MAAM,CAAS,cAAc,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAC7D,CAAC;IACJ,CAAC;IAEkB,eAAe,CAChC,OAA8B,EAC9B,EACE,aAAa,EACb,UAAU,GAC6C;QAEzD,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,SAAS,kBAAkB,CAAC,WAAW,uDAAuD,CAC/F,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC,EAAE,CAAC,aAAa,CAAC;YAC9B,aAAa;YACb,KAAK,EAAE,UAAU;YACjB,WAAW,EAAE,cAAc,CAAC,MAAM;YAClC,KAAK,EAAE,QAAQ,CAAC,OAAO;SACxB,CAAC,CAAC;IACL,CAAC;;AA7CM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type { 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';\nimport type { CaipChainId } from '@metamask/utils';\n\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\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 resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n // TODO: Remove once the Snap is fully v2 — discovery is then driven by the\n // Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n protected readonly v1DiscoveryScopes: CaipChainId[] = [BtcScope.Mainnet];\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n protected override createAccountV1(\n keyring: RestrictedSnapKeyring,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Promise<KeyringAccount> {\n if (!keyring.v1) {\n throw new Error(\n `Snap \"${BtcAccountProvider.BTC_SNAP_ID}\" is v2-only and does not support v1 account creation`,\n );\n }\n return keyring.v1.createAccount({\n entropySource,\n index: groupIndex,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"BtcAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,8BAA8B;AAKjE,OAAO,EAAE,aAAa,EAAE,+BAAqB;AAE7C,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAK5D,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;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IASzD,YACE,SAA4C,EAC5C,SAAmC,mCAAmC,EACtE,QAAuB,aAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QATlE,2EAA2E;QAC3E,wEAAwE;QACrD,sBAAiB,GAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAQzE,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,MAAM;YACtC,MAAM,CAAC,MAAM,CAAS,cAAc,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAC7D,CAAC;IACJ,CAAC;;AAzBM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport { BtcAccountType, BtcScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { CaipChainId } from '@metamask/utils';\n\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type { SnapAccountProviderConfig } from './SnapAccountProvider';\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 resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n // TODO: Remove once the Snap is fully v2 — discovery is then driven by the\n // Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n protected readonly v1DiscoveryScopes: CaipChainId[] = [BtcScope.Mainnet];\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"]}
@@ -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_sender, _SnapAccountProvider_queue, _SnapAccountProvider_trace, _SnapAccountProvider_getRestrictedSnapKeyring, _SnapAccountProvider_createSender, _SnapAccountProvider_resolveClient, _SnapAccountProvider_withSnapKeyring;
13
+ var _SnapAccountProvider_instances, _SnapAccountProvider_client, _SnapAccountProvider_sender, _SnapAccountProvider_queue, _SnapAccountProvider_trace, _SnapAccountProvider_createSender, _SnapAccountProvider_resolveClient, _SnapAccountProvider_withSnapKeyring;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.isSnapAccountProvider = exports.SnapAccountProvider = void 0;
16
16
  const account_api_1 = require("@metamask/account-api");
@@ -64,6 +64,10 @@ class SnapAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountPro
64
64
  /**
65
65
  * Ensures that the Snap is ready to be used.
66
66
  *
67
+ * Once this resolves, a Snap keyring for {@link snapId} is guaranteed to
68
+ * exist in the `KeyringController`, so subsequent {@link #withSnapKeyring}
69
+ * calls will not fail with "No keyring matches the selector".
70
+ *
67
71
  * @returns A promise that resolves when the Snap is ready.
68
72
  * @throws An error if the Snap could not become ready.
69
73
  */
@@ -166,10 +170,11 @@ class SnapAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountPro
166
170
  async withSnap(operation) {
167
171
  await this.ensureReady();
168
172
  const client = await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_resolveClient).call(this);
169
- return await operation({
170
- client,
171
- keyring: await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_getRestrictedSnapKeyring).call(this),
172
- });
173
+ const keyring = {
174
+ createAccounts: (options) => __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, ({ keyring: snapKeyring }) => snapKeyring.createAccounts(options)),
175
+ deleteAccount: (id) => __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, ({ keyring: snapKeyring }) => snapKeyring.deleteAccount(id)),
176
+ };
177
+ return await operation({ client, keyring });
173
178
  }
174
179
  toBip44Account(account, _options) {
175
180
  (0, account_api_1.assertIsBip44Account)(account);
@@ -177,58 +182,17 @@ class SnapAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountPro
177
182
  }
178
183
  async createBip44Accounts(keyring, options) {
179
184
  return this.withMaxConcurrency(async () => {
180
- let groupIndexOffset = 0;
181
- let snapAccounts = [];
182
- // v2 Snaps expose `createAccounts` but no singular `createAccount`, so
183
- // they must always go through the batched flow. v1 Snaps only have the
184
- // singular `createAccount`.
185
- const batched = this.isV2();
186
185
  const { entropySource } = options;
187
- const createAccountV1 = async (groupIndex) => await (0, utils_1.withTimeout)(() => this.trace({
188
- name: analytics_1.TraceName.ProviderCreateAccountV1,
189
- data: {
190
- provider: this.getName(),
191
- groupIndex,
192
- },
193
- }, () => this.createAccountV1(keyring, { entropySource, groupIndex })), this.config.createAccounts.timeoutMs);
194
- const createAccountsV2 = async (optionsV2) => await (0, utils_1.withTimeout)(() => this.trace({
186
+ const snapAccounts = await (0, utils_1.withTimeout)(() => this.trace({
195
187
  name: analytics_1.TraceName.ProviderCreateAccounts,
196
188
  data: {
197
189
  provider: this.getName(),
198
- ...(0, analytics_1.toCreateAccountsV2DataTraces)(optionsV2),
190
+ ...(0, analytics_1.toCreateAccountsV2DataTraces)(options),
199
191
  },
200
- }, () => keyring.createAccounts(optionsV2)), this.config.createAccounts.timeoutMs);
201
- if (options.type === `${keyring_api_1.AccountCreationType.Bip44DeriveIndexRange}`) {
202
- if (batched) {
203
- // Batch account creations.
204
- snapAccounts = await createAccountsV2(options);
205
- }
206
- else {
207
- const { range } = options;
208
- // Create accounts one by one.
209
- for (let groupIndex = range.from; groupIndex <= range.to; groupIndex++) {
210
- const snapAccount = await createAccountV1(groupIndex);
211
- snapAccounts.push(snapAccount);
212
- }
213
- }
214
- // Group indices are sequential, so we just need the starting index.
215
- groupIndexOffset = options.range.from;
216
- }
217
- else {
218
- if (batched) {
219
- // Create account using new v2-like flow (no async flow + no Snap keyring events).
220
- snapAccounts = await createAccountsV2(options);
221
- }
222
- else {
223
- const { groupIndex } = options;
224
- // Create account using the existing v1 flow.
225
- const snapAccount = await createAccountV1(groupIndex);
226
- snapAccounts = [snapAccount];
227
- }
228
- // For single account, there will only be 1 account, so we can use the
229
- // provided group index directly.
230
- groupIndexOffset = options.groupIndex;
231
- }
192
+ }, () => keyring.createAccounts(options)), this.config.createAccounts.timeoutMs);
193
+ const groupIndexOffset = options.type === `${keyring_api_1.AccountCreationType.Bip44DeriveIndexRange}`
194
+ ? options.range.from
195
+ : options.groupIndex;
232
196
  return snapAccounts.map((snapAccount, index) => {
233
197
  const groupIndex = groupIndexOffset + index;
234
198
  const account = this.toBip44Account(snapAccount, {
@@ -324,30 +288,7 @@ class SnapAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountPro
324
288
  }
325
289
  }
326
290
  exports.SnapAccountProvider = SnapAccountProvider;
327
- _SnapAccountProvider_client = new WeakMap(), _SnapAccountProvider_sender = new WeakMap(), _SnapAccountProvider_queue = new WeakMap(), _SnapAccountProvider_trace = new WeakMap(), _SnapAccountProvider_instances = new WeakSet(), _SnapAccountProvider_getRestrictedSnapKeyring = async function _SnapAccountProvider_getRestrictedSnapKeyring() {
328
- // NOTE: We're not supposed to make the keyring instance escape `withKeyringV2` but
329
- // we have to use the `SnapKeyringV2` instance to be able to create Solana account
330
- // without triggering UI confirmation.
331
- // Also, creating account that way won't invalidate the Snap keyring state. The
332
- // account will get created and persisted properly with the Snap account creation
333
- // flow "asynchronously" (with `notify:accountCreated`).
334
- const createAccount = await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, async ({ keyring }) => {
335
- if (keyring.v1) {
336
- return keyring.v1.createAccount.bind(keyring.v1);
337
- }
338
- // This method does not exist in v2.
339
- return undefined;
340
- });
341
- return {
342
- // V1 interface is only present for v1 Snaps, otherwise it's `undefined`.
343
- v1: createAccount ? { createAccount } : undefined,
344
- // Every v2 operations must be done through the `#withSnapKeyring` transaction:
345
- createAccounts: async (options) => await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, async ({ keyring }) => await keyring.createAccounts(options)),
346
- deleteAccount: async (id) => await __classPrivateFieldGet(this, _SnapAccountProvider_instances, "m", _SnapAccountProvider_withSnapKeyring).call(this, async ({ keyring }) => {
347
- await keyring.deleteAccount(id);
348
- }),
349
- };
350
- }, _SnapAccountProvider_createSender = function _SnapAccountProvider_createSender(snapId) {
291
+ _SnapAccountProvider_client = new WeakMap(), _SnapAccountProvider_sender = new WeakMap(), _SnapAccountProvider_queue = new WeakMap(), _SnapAccountProvider_trace = new WeakMap(), _SnapAccountProvider_instances = new WeakSet(), _SnapAccountProvider_createSender = function _SnapAccountProvider_createSender(snapId) {
351
292
  return {
352
293
  send: async (request) => {
353
294
  const response = await this.messenger.call('SnapController:handleRequest', {
@@ -1 +1 @@
1
- {"version":3,"file":"SnapAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA6D;AAK7D,sDAGuC;AACvC,uDAG+B;AAa/B,uDAAoD;AAEpD,6CAAwC;AAExC,sDAIsB;AACtB,0CAAwC;AACxC,0CAAiE;AAEjE,6EAAsE;AACtE,+DAA8D;AAE9D,uCAAiD;AA4CjD,MAAsB,mBAAoB,SAAQ,mDAAwB;IAiCxE,YACE,MAAc,EACd,SAA4C,EAC5C,MAAiC;IACjC,0BAA0B;IAC1B,QAAuB,yBAAa;QAEpC,KAAK,CAAC,SAAS,CAAC,CAAC;;QAnCnB;;;;WAIG;QACH,iBAAY,GAAwB,uBAAkB,CAAC;QAEvD;;;WAGG;QACH,8CAA4B;QAEnB,8CAAgB;QAEhB,6CAAmB;QAEnB,6CAAsB;QAoB7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,uBAAA,IAAI,+BAAW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C;AACJ,CAAC;AAqQI,MAAM,qBAAqB,GAAG,CACnC,QAAiB,EACgB,EAAE;IACnC,OAAO,QAAQ,YAAY,mBAAmB,CAAC;AACjD,CAAC,CAAC;AAJW,QAAA,qBAAqB,yBAIhC","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback, TraceRequest } from '@metamask/controller-utils';\nimport type { SnapKeyringV1 } from '@metamask/eth-snap-keyring';\nimport type { SnapKeyring as SnapKeyringV2 } from '@metamask/eth-snap-keyring/v2';\nimport {\n EMPTY_CAPABILITIES,\n isSnapKeyring,\n} from '@metamask/eth-snap-keyring/v2';\nimport {\n AccountCreationType,\n assertCreateAccountOptionIsSupported,\n} from '@metamask/keyring-api';\nimport type {\n CreateAccountBip44DeriveIndexOptions,\n CreateAccountBip44DeriveIndexRangeOptions,\n CreateAccountBip44DiscoverOptions,\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport type { KeyringMetadata } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Json, JsonRpcRequest, SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { CaipChainId } from '@metamask/utils';\nimport { Semaphore } from 'async-mutex';\n\nimport {\n toCreateAccountsV2DataTraces,\n traceFallback,\n TraceName,\n} from '../analytics';\nimport { reportError } from '../errors';\nimport { projectLogger as log, WARNING_PREFIX } from '../logger';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\nimport { createSnapKeyringClient } from './SnapKeyringClient';\nimport type { Sender, SnapKeyringClient } from './SnapKeyringClient';\nimport { withRetry, withTimeout } from './utils';\n\nexport type RestrictedSnapKeyring = {\n /**\n * V1 interface, present only when the Snap does not declare v2 capabilities.\n * `undefined` for v2-only Snaps.\n *\n * Use this to make v1 calls explicit:\n * if (!keyring.v1) { throw new Error('Snap is v2-only'); }\n * keyring.v1.createAccount(options);\n */\n v1?: { createAccount: SnapKeyringV1['createAccount'] };\n createAccounts: SnapKeyringV2['createAccounts'];\n deleteAccount: SnapKeyringV2['deleteAccount'];\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 /**\n * Timeout for account creation operations.\n *\n * NOTE: Batching (and thus whether a single call may create multiple\n * accounts) is driven by the Snap's declared capabilities, not this config.\n * The value might have to be adapted when the Snap supports batching.\n */\n timeoutMs: number;\n };\n resyncAccounts?: {\n /**\n * Whether to automatically remove extra Snap accounts when the Snap has\n * more accounts than MetaMask. If `false`, a warning is logged instead.\n * Defaults to `true`.\n */\n autoRemoveExtraSnapAccounts?: boolean;\n };\n};\n\nexport abstract class SnapAccountProvider extends BaseBip44AccountProvider {\n readonly snapId: SnapId;\n\n protected readonly config: SnapAccountProviderConfig;\n\n /**\n * The Snap's keyring capabilities, sourced from `SnapAccountService` (which\n * reads them from the Snap's manifest). Populated the first time the client\n * is resolved; defaults to an empty capability set until then.\n */\n capabilities: KeyringCapabilities = EMPTY_CAPABILITIES;\n\n /**\n * Version-agnostic keyring client, resolved lazily once the Snap is ready and\n * its capabilities are known — see {@link SnapAccountProvider.withSnap}.\n */\n #client?: SnapKeyringClient;\n\n readonly #sender: Sender;\n\n readonly #queue?: Semaphore;\n\n readonly #trace: TraceCallback;\n\n /**\n * Scopes passed to the v1 `discoverAccounts` client method. Only used on the\n * v1 discovery path.\n *\n * TODO: Remove once all Snaps are fully v2 — discovery is then driven by the\n * Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n */\n protected abstract readonly v1DiscoveryScopes: CaipChainId[];\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.#sender = this.#createSender(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 is ready to be used.\n *\n * @returns A promise that resolves when the Snap is ready.\n * @throws An error if the Snap could not become ready.\n */\n async ensureReady(): Promise<void> {\n return this.messenger.call('SnapAccountService:ensureReady', this.snapId);\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 `withKeyringV2` but\n // we have to use the `SnapKeyringV2` 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(async ({ keyring }) => {\n if (keyring.v1) {\n return keyring.v1.createAccount.bind(keyring.v1);\n }\n\n // This method does not exist in v2.\n return undefined;\n });\n\n return {\n // V1 interface is only present for v1 Snaps, otherwise it's `undefined`.\n v1: createAccount ? { createAccount } : undefined,\n // Every v2 operations must be done through the `#withSnapKeyring` transaction:\n createAccounts: async (options) =>\n await this.#withSnapKeyring(\n async ({ keyring }) => await keyring.createAccounts(options),\n ),\n deleteAccount: async (id: string) =>\n await this.#withSnapKeyring(async ({ keyring }) => {\n await keyring.deleteAccount(id);\n }),\n };\n }\n\n #createSender(snapId: string): Sender {\n return {\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 /**\n * Whether the Snap supports the v2 keyring protocol, inferred from its\n * declared capabilities (a v2-capable Snap declares BIP-44 capabilities).\n *\n * @returns `true` if the Snap is v2-capable.\n */\n protected isV2(): boolean {\n return Boolean(this.capabilities.bip44);\n }\n\n /**\n * Resolves the version-agnostic keyring client, fetching the Snap's\n * capabilities from `SnapAccountService` on first use and caching both the\n * capabilities and the resulting client.\n *\n * Callers must ensure the Snap is ready (via\n * {@link SnapAccountProvider.ensureReady}) beforehand so that the\n * capabilities are reliably populated — {@link SnapAccountProvider.withSnap}\n * guarantees this ordering.\n *\n * @returns The resolved {@link SnapKeyringClient}.\n */\n async #resolveClient(): Promise<SnapKeyringClient> {\n if (!this.#client) {\n this.capabilities = await this.messenger.call(\n 'SnapAccountService:getCapabilities',\n this.snapId,\n );\n this.#client = createSnapKeyringClient(this.#sender, this.isV2());\n }\n return this.#client;\n }\n\n async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n await this.withSnap(async ({ client, keyring }) => {\n const localSnapAccounts = accounts.filter(\n (account) => account.metadata.snap?.id === this.snapId,\n );\n const snapAccounts = new Set(\n (await client.getAccounts()).map((account) => account.id),\n );\n\n // NOTE: This should never happen, but if it does, we recover by deleting the\n // extra accounts from the Snap to bring it back in sync with MetaMask.\n if (localSnapAccounts.length < snapAccounts.size) {\n const autoRemoveExtraSnapAccounts =\n this.config.resyncAccounts?.autoRemoveExtraSnapAccounts ?? true;\n\n if (autoRemoveExtraSnapAccounts) {\n // Build a set of local account IDs for quick lookup\n const localAccountIds = new Set(\n localSnapAccounts.map((account) => account.id),\n );\n\n // Find and delete accounts that exist in Snap but not in MetaMask\n await Promise.all(\n [...snapAccounts].map(async (snapAccountId) => {\n try {\n if (!localAccountIds.has(snapAccountId)) {\n // This account exists in the Snap but not in MetaMask, delete it from\n // the Snap.\n await client.deleteAccount(snapAccountId);\n // Update the local Set so subsequent checks use the correct size\n snapAccounts.delete(snapAccountId);\n }\n } catch (error) {\n reportError(\n this.messenger,\n `Unable to delete de-synced Snap account: ${this.snapId}`,\n error,\n {\n provider: this.getName(),\n snapAccountId,\n },\n );\n }\n }),\n );\n } else {\n const message = `Snap \"${this.snapId}\" has de-synced accounts, Snap has more accounts than MetaMask! (${localSnapAccounts.length} < ${snapAccounts.size})`;\n log(`${WARNING_PREFIX} ${message}`);\n console.warn(message);\n return;\n }\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 // 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.deleteAccount(account.id);\n // The Snap has no account in its state for this one, we re-create it.\n await this.createAccounts({\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n }\n } catch (error) {\n reportError(this.messenger, 'Unable to re-sync accounts', error, {\n provider: this.getName(),\n groupIndex,\n });\n }\n }),\n );\n }\n });\n }\n\n async #withSnapKeyring<CallbackResult = void>(\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SnapKeyringV2;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n return this.withKeyringV2<SnapKeyringV2, CallbackResult>(\n {\n filter: (keyring) =>\n isSnapKeyring(keyring) && keyring.snapId === this.snapId,\n },\n (args) => operation(args),\n );\n }\n\n protected async withSnap<CallbackResult = void>(\n operation: (snap: {\n client: SnapKeyringClient;\n keyring: RestrictedSnapKeyring;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n await this.ensureReady();\n const client = await this.#resolveClient();\n\n return await operation({\n client,\n keyring: await this.#getRestrictedSnapKeyring(),\n });\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n\n protected abstract createAccountV1(\n keyring: RestrictedSnapKeyring,\n options: { entropySource: EntropySourceId; groupIndex: number },\n ): Promise<KeyringAccount>;\n\n protected toBip44Account(\n account: KeyringAccount,\n _options: { entropySource: EntropySourceId; groupIndex: number },\n ): Bip44Account<KeyringAccount> {\n assertIsBip44Account(account);\n return account;\n }\n\n protected async createBip44Accounts(\n keyring: RestrictedSnapKeyring,\n options:\n | CreateAccountBip44DeriveIndexOptions\n | CreateAccountBip44DeriveIndexRangeOptions\n | CreateAccountBip44DiscoverOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n let groupIndexOffset = 0;\n let snapAccounts: KeyringAccount[] = [];\n\n // v2 Snaps expose `createAccounts` but no singular `createAccount`, so\n // they must always go through the batched flow. v1 Snaps only have the\n // singular `createAccount`.\n const batched = this.isV2();\n const { entropySource } = options;\n\n const createAccountV1 = async (\n groupIndex: number,\n ): Promise<KeyringAccount> =>\n await withTimeout(\n () =>\n this.trace(\n {\n name: TraceName.ProviderCreateAccountV1,\n data: {\n provider: this.getName(),\n groupIndex,\n },\n },\n () =>\n this.createAccountV1(keyring, { entropySource, groupIndex }),\n ),\n this.config.createAccounts.timeoutMs,\n );\n const createAccountsV2 = async (\n optionsV2:\n | CreateAccountBip44DeriveIndexOptions\n | CreateAccountBip44DeriveIndexRangeOptions\n | CreateAccountBip44DiscoverOptions,\n ): Promise<KeyringAccount[]> =>\n await withTimeout(\n () =>\n this.trace(\n {\n name: TraceName.ProviderCreateAccounts,\n data: {\n provider: this.getName(),\n ...toCreateAccountsV2DataTraces(optionsV2),\n },\n },\n () => keyring.createAccounts(optionsV2),\n ),\n this.config.createAccounts.timeoutMs,\n );\n\n if (options.type === `${AccountCreationType.Bip44DeriveIndexRange}`) {\n if (batched) {\n // Batch account creations.\n snapAccounts = await createAccountsV2(options);\n } else {\n const { range } = options;\n\n // Create accounts one by one.\n for (\n let groupIndex = range.from;\n groupIndex <= range.to;\n groupIndex++\n ) {\n const snapAccount = await createAccountV1(groupIndex);\n\n snapAccounts.push(snapAccount);\n }\n }\n\n // Group indices are sequential, so we just need the starting index.\n groupIndexOffset = options.range.from;\n } else {\n if (batched) {\n // Create account using new v2-like flow (no async flow + no Snap keyring events).\n snapAccounts = await createAccountsV2(options);\n } else {\n const { groupIndex } = options;\n\n // Create account using the existing v1 flow.\n const snapAccount = await createAccountV1(groupIndex);\n\n snapAccounts = [snapAccount];\n }\n\n // For single account, there will only be 1 account, so we can use the\n // provided group index directly.\n groupIndexOffset = options.groupIndex;\n }\n\n return snapAccounts.map((snapAccount, index) => {\n const groupIndex = groupIndexOffset + index;\n const account = this.toBip44Account(snapAccount, {\n entropySource,\n groupIndex,\n });\n\n this.accounts.add(snapAccount.id);\n return account;\n });\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n assertCreateAccountOptionIsSupported(options, [\n `${AccountCreationType.Bip44DeriveIndex}`,\n `${AccountCreationType.Bip44DeriveIndexRange}`,\n ]);\n\n return this.withSnap(async ({ keyring }) =>\n this.createBip44Accounts(keyring, options),\n );\n }\n\n /**\n * Delete a snap account by id.\n *\n * Resolves the account's address from the tracked account, then forwards to\n * the legacy `SnapKeyring.removeAccount(address)`. The Snap keyring takes\n * care of notifying the snap to clean up its own state through the normal\n * account-removal flow (same path used by `resyncAccounts`).\n *\n * @param id - The id of the account to delete.\n */\n async deleteAccount(id: Bip44Account<KeyringAccount>['id']): Promise<void> {\n const account = this.getAccount(id);\n\n await this.#withSnapKeyring(async ({ keyring }) => {\n await keyring.deleteAccount(account.id);\n });\n\n this.accounts.delete(id);\n }\n\n /**\n * Discovers accounts for the given entropy source and group index.\n *\n * v2 Snaps drive discovery through `createAccounts({ bip44:discover })`: the\n * Snap checks for on-chain activity (using its own supported scopes) and\n * returns the created account(s), or nothing once discovery is exhausted.\n *\n * v1 Snaps use the client's `discoverAccounts` to detect activity on\n * {@link v1DiscoveryScopes}, then create the account for the group index.\n *\n * @param options - The discovery options.\n * @param options.entropySource - The entropy source to discover accounts for.\n * @param options.groupIndex - The group index to discover accounts for.\n * @returns The discovered (and created) accounts, or an empty array when\n * there is nothing to discover at this group index.\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 this.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 if (this.isV2()) {\n // The v2 client has no `discoverAccounts`, so discovery is only\n // possible when the Snap supports `bip44:discover`. Otherwise there\n // is no way to discover and we report nothing.\n if (!this.capabilities.bip44?.discover) {\n return [];\n }\n\n // v2: the Snap detects on-chain activity and creates the account in\n // a single `createAccounts({ bip44:discover })` call. An empty\n // result means discovery is exhausted at this group index.\n return this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44Discover,\n entropySource,\n groupIndex,\n });\n }\n\n // v1: detect activity via the client, then create the account for\n // this group index.\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n () =>\n client.discoverAccounts(\n this.v1DiscoveryScopes,\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 this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n ),\n );\n }\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":";;;;;;;;;;;;;;;AAAA,uDAA6D;AAI7D,sDAGuC;AACvC,uDAG+B;AAa/B,uDAAoD;AAEpD,6CAAwC;AAExC,sDAIsB;AACtB,0CAAwC;AACxC,0CAAiE;AAEjE,6EAAsE;AACtE,+DAA8D;AAE9D,uCAAiD;AAyCjD,MAAsB,mBAAoB,SAAQ,mDAAwB;IAiCxE,YACE,MAAc,EACd,SAA4C,EAC5C,MAAiC;IACjC,0BAA0B;IAC1B,QAAuB,yBAAa;QAEpC,KAAK,CAAC,SAAS,CAAC,CAAC;;QAnCnB;;;;WAIG;QACH,iBAAY,GAAwB,uBAAkB,CAAC;QAEvD;;;WAGG;QACH,8CAA4B;QAEnB,8CAAgB;QAEhB,6CAAmB;QAEnB,6CAAsB;QAoB7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,uBAAA,IAAI,+BAAW,uBAAA,IAAI,yEAAc,MAAlB,IAAI,EAAe,MAAM,CAAC,MAAA,CAAC;QAE1C,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,CAA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AC;AACJ,CAAC;AAqMI,MAAM,qBAAqB,GAAG,CACnC,QAAiB,EACgB,EAAE;IACnC,OAAO,QAAQ,YAAY,mBAAmB,CAAC;AACjD,CAAC,CAAC;AAJW,QAAA,qBAAqB,yBAIhC","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback, TraceRequest } from '@metamask/controller-utils';\nimport type { SnapKeyring as SnapKeyringV2 } from '@metamask/eth-snap-keyring/v2';\nimport {\n EMPTY_CAPABILITIES,\n isSnapKeyring,\n} from '@metamask/eth-snap-keyring/v2';\nimport {\n AccountCreationType,\n assertCreateAccountOptionIsSupported,\n} from '@metamask/keyring-api';\nimport type {\n CreateAccountBip44DeriveIndexOptions,\n CreateAccountBip44DeriveIndexRangeOptions,\n CreateAccountBip44DiscoverOptions,\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport type { KeyringMetadata } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Json, JsonRpcRequest, SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { CaipChainId } from '@metamask/utils';\nimport { Semaphore } from 'async-mutex';\n\nimport {\n toCreateAccountsV2DataTraces,\n traceFallback,\n TraceName,\n} from '../analytics';\nimport { reportError } from '../errors';\nimport { projectLogger as log, WARNING_PREFIX } from '../logger';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\nimport { createSnapKeyringClient } from './SnapKeyringClient';\nimport type { Sender, SnapKeyringClient } from './SnapKeyringClient';\nimport { withRetry, withTimeout } from './utils';\n\n/**\n * A proxy to the Snap's keyring operations that routes every call through the\n * `KeyringController` mutex (via {@link SnapAccountProvider.#withSnapKeyring}).\n * Callers receive this object from {@link SnapAccountProvider.withSnap} and\n * never interact with the raw keyring or the mutex directly.\n */\nexport type SnapKeyringProxy = {\n createAccounts: SnapKeyringV2['createAccounts'];\n deleteAccount: SnapKeyringV2['deleteAccount'];\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 /**\n * Timeout for account creation operations.\n *\n * NOTE: Batching (and thus whether a single call may create multiple\n * accounts) is driven by the Snap's declared capabilities, not this config.\n * The value might have to be adapted when the Snap supports batching.\n */\n timeoutMs: number;\n };\n resyncAccounts?: {\n /**\n * Whether to automatically remove extra Snap accounts when the Snap has\n * more accounts than MetaMask. If `false`, a warning is logged instead.\n * Defaults to `true`.\n */\n autoRemoveExtraSnapAccounts?: boolean;\n };\n};\n\nexport abstract class SnapAccountProvider extends BaseBip44AccountProvider {\n readonly snapId: SnapId;\n\n protected readonly config: SnapAccountProviderConfig;\n\n /**\n * The Snap's keyring capabilities, sourced from `SnapAccountService` (which\n * reads them from the Snap's manifest). Populated the first time the client\n * is resolved; defaults to an empty capability set until then.\n */\n capabilities: KeyringCapabilities = EMPTY_CAPABILITIES;\n\n /**\n * Version-agnostic keyring client, resolved lazily once the Snap is ready and\n * its capabilities are known — see {@link SnapAccountProvider.withSnap}.\n */\n #client?: SnapKeyringClient;\n\n readonly #sender: Sender;\n\n readonly #queue?: Semaphore;\n\n readonly #trace: TraceCallback;\n\n /**\n * Scopes passed to the v1 `discoverAccounts` client method. Only used on the\n * v1 discovery path.\n *\n * TODO: Remove once all Snaps are fully v2 — discovery is then driven by the\n * Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n */\n protected abstract readonly v1DiscoveryScopes: CaipChainId[];\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.#sender = this.#createSender(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 is ready to be used.\n *\n * Once this resolves, a Snap keyring for {@link snapId} is guaranteed to\n * exist in the `KeyringController`, so subsequent {@link #withSnapKeyring}\n * calls will not fail with \"No keyring matches the selector\".\n *\n * @returns A promise that resolves when the Snap is ready.\n * @throws An error if the Snap could not become ready.\n */\n async ensureReady(): Promise<void> {\n return this.messenger.call('SnapAccountService:ensureReady', this.snapId);\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 #createSender(snapId: string): Sender {\n return {\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 /**\n * Whether the Snap supports the v2 keyring protocol, inferred from its\n * declared capabilities (a v2-capable Snap declares BIP-44 capabilities).\n *\n * @returns `true` if the Snap is v2-capable.\n */\n protected isV2(): boolean {\n return Boolean(this.capabilities.bip44);\n }\n\n /**\n * Resolves the version-agnostic keyring client, fetching the Snap's\n * capabilities from `SnapAccountService` on first use and caching both the\n * capabilities and the resulting client.\n *\n * Callers must ensure the Snap is ready (via\n * {@link SnapAccountProvider.ensureReady}) beforehand so that the\n * capabilities are reliably populated — {@link SnapAccountProvider.withSnap}\n * guarantees this ordering.\n *\n * @returns The resolved {@link SnapKeyringClient}.\n */\n async #resolveClient(): Promise<SnapKeyringClient> {\n if (!this.#client) {\n this.capabilities = await this.messenger.call(\n 'SnapAccountService:getCapabilities',\n this.snapId,\n );\n this.#client = createSnapKeyringClient(this.#sender, this.isV2());\n }\n return this.#client;\n }\n\n async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n await this.withSnap(async ({ client, keyring }) => {\n const localSnapAccounts = accounts.filter(\n (account) => account.metadata.snap?.id === this.snapId,\n );\n const snapAccounts = new Set(\n (await client.getAccounts()).map((account) => account.id),\n );\n\n // NOTE: This should never happen, but if it does, we recover by deleting the\n // extra accounts from the Snap to bring it back in sync with MetaMask.\n if (localSnapAccounts.length < snapAccounts.size) {\n const autoRemoveExtraSnapAccounts =\n this.config.resyncAccounts?.autoRemoveExtraSnapAccounts ?? true;\n\n if (autoRemoveExtraSnapAccounts) {\n // Build a set of local account IDs for quick lookup\n const localAccountIds = new Set(\n localSnapAccounts.map((account) => account.id),\n );\n\n // Find and delete accounts that exist in Snap but not in MetaMask\n await Promise.all(\n [...snapAccounts].map(async (snapAccountId) => {\n try {\n if (!localAccountIds.has(snapAccountId)) {\n // This account exists in the Snap but not in MetaMask, delete it from\n // the Snap.\n await client.deleteAccount(snapAccountId);\n // Update the local Set so subsequent checks use the correct size\n snapAccounts.delete(snapAccountId);\n }\n } catch (error) {\n reportError(\n this.messenger,\n `Unable to delete de-synced Snap account: ${this.snapId}`,\n error,\n {\n provider: this.getName(),\n snapAccountId,\n },\n );\n }\n }),\n );\n } else {\n const message = `Snap \"${this.snapId}\" has de-synced accounts, Snap has more accounts than MetaMask! (${localSnapAccounts.length} < ${snapAccounts.size})`;\n log(`${WARNING_PREFIX} ${message}`);\n console.warn(message);\n return;\n }\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 // 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.deleteAccount(account.id);\n // The Snap has no account in its state for this one, we re-create it.\n await this.createAccounts({\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n }\n } catch (error) {\n reportError(this.messenger, 'Unable to re-sync accounts', error, {\n provider: this.getName(),\n groupIndex,\n });\n }\n }),\n );\n }\n });\n }\n\n async #withSnapKeyring<CallbackResult = void>(\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SnapKeyringV2;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n return this.withKeyringV2<SnapKeyringV2, CallbackResult>(\n {\n filter: (keyring) =>\n isSnapKeyring(keyring) && keyring.snapId === this.snapId,\n },\n (args) => operation(args),\n );\n }\n\n protected async withSnap<CallbackResult = void>(\n operation: (snap: {\n client: SnapKeyringClient;\n keyring: SnapKeyringProxy;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n await this.ensureReady();\n const client = await this.#resolveClient();\n const keyring: SnapKeyringProxy = {\n createAccounts: (options) =>\n this.#withSnapKeyring(({ keyring: snapKeyring }) =>\n snapKeyring.createAccounts(options),\n ),\n deleteAccount: (id) =>\n this.#withSnapKeyring(({ keyring: snapKeyring }) =>\n snapKeyring.deleteAccount(id),\n ),\n };\n return await operation({ client, keyring });\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n\n protected toBip44Account(\n account: KeyringAccount,\n _options: { entropySource: EntropySourceId; groupIndex: number },\n ): Bip44Account<KeyringAccount> {\n assertIsBip44Account(account);\n return account;\n }\n\n protected async createBip44Accounts(\n keyring: SnapKeyringProxy,\n options:\n | CreateAccountBip44DeriveIndexOptions\n | CreateAccountBip44DeriveIndexRangeOptions\n | CreateAccountBip44DiscoverOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const { entropySource } = options;\n\n const snapAccounts = await withTimeout(\n () =>\n this.trace(\n {\n name: TraceName.ProviderCreateAccounts,\n data: {\n provider: this.getName(),\n ...toCreateAccountsV2DataTraces(options),\n },\n },\n () => keyring.createAccounts(options),\n ),\n this.config.createAccounts.timeoutMs,\n );\n\n const groupIndexOffset =\n options.type === `${AccountCreationType.Bip44DeriveIndexRange}`\n ? options.range.from\n : options.groupIndex;\n\n return snapAccounts.map((snapAccount, index) => {\n const groupIndex = groupIndexOffset + index;\n const account = this.toBip44Account(snapAccount, {\n entropySource,\n groupIndex,\n });\n\n this.accounts.add(snapAccount.id);\n return account;\n });\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n assertCreateAccountOptionIsSupported(options, [\n `${AccountCreationType.Bip44DeriveIndex}`,\n `${AccountCreationType.Bip44DeriveIndexRange}`,\n ]);\n\n return this.withSnap(async ({ keyring }) =>\n this.createBip44Accounts(keyring, options),\n );\n }\n\n /**\n * Delete a snap account by id.\n *\n * Resolves the account's address from the tracked account, then forwards to\n * the legacy `SnapKeyring.removeAccount(address)`. The Snap keyring takes\n * care of notifying the snap to clean up its own state through the normal\n * account-removal flow (same path used by `resyncAccounts`).\n *\n * @param id - The id of the account to delete.\n */\n async deleteAccount(id: Bip44Account<KeyringAccount>['id']): Promise<void> {\n const account = this.getAccount(id);\n\n await this.#withSnapKeyring(async ({ keyring }) => {\n await keyring.deleteAccount(account.id);\n });\n\n this.accounts.delete(id);\n }\n\n /**\n * Discovers accounts for the given entropy source and group index.\n *\n * v2 Snaps drive discovery through `createAccounts({ bip44:discover })`: the\n * Snap checks for on-chain activity (using its own supported scopes) and\n * returns the created account(s), or nothing once discovery is exhausted.\n *\n * v1 Snaps use the client's `discoverAccounts` to detect activity on\n * {@link v1DiscoveryScopes}, then create the account for the group index.\n *\n * @param options - The discovery options.\n * @param options.entropySource - The entropy source to discover accounts for.\n * @param options.groupIndex - The group index to discover accounts for.\n * @returns The discovered (and created) accounts, or an empty array when\n * there is nothing to discover at this group index.\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 this.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 if (this.isV2()) {\n // The v2 client has no `discoverAccounts`, so discovery is only\n // possible when the Snap supports `bip44:discover`. Otherwise there\n // is no way to discover and we report nothing.\n if (!this.capabilities.bip44?.discover) {\n return [];\n }\n\n // v2: the Snap detects on-chain activity and creates the account in\n // a single `createAccounts({ bip44:discover })` call. An empty\n // result means discovery is exhausted at this group index.\n return this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44Discover,\n entropySource,\n groupIndex,\n });\n }\n\n // v1: detect activity via the client, then create the account for\n // this group index.\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n () =>\n client.discoverAccounts(\n this.v1DiscoveryScopes,\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 this.createBip44Accounts(keyring, {\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n },\n ),\n );\n }\n}\n\nexport const isSnapAccountProvider = (\n provider: unknown,\n): provider is SnapAccountProvider => {\n return provider instanceof SnapAccountProvider;\n};\n"]}