@metamask/multichain-account-service 10.0.3 → 11.1.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 (110) hide show
  1. package/CHANGELOG.md +43 -2
  2. package/dist/MultichainAccountGroup.cjs +15 -0
  3. package/dist/MultichainAccountGroup.cjs.map +1 -1
  4. package/dist/MultichainAccountGroup.d.cts +10 -0
  5. package/dist/MultichainAccountGroup.d.cts.map +1 -1
  6. package/dist/MultichainAccountGroup.d.mts +10 -0
  7. package/dist/MultichainAccountGroup.d.mts.map +1 -1
  8. package/dist/MultichainAccountGroup.mjs +15 -0
  9. package/dist/MultichainAccountGroup.mjs.map +1 -1
  10. package/dist/MultichainAccountService-method-action-types.cjs.map +1 -1
  11. package/dist/MultichainAccountService-method-action-types.d.cts +10 -6
  12. package/dist/MultichainAccountService-method-action-types.d.cts.map +1 -1
  13. package/dist/MultichainAccountService-method-action-types.d.mts +10 -6
  14. package/dist/MultichainAccountService-method-action-types.d.mts.map +1 -1
  15. package/dist/MultichainAccountService-method-action-types.mjs.map +1 -1
  16. package/dist/MultichainAccountService.cjs +67 -8
  17. package/dist/MultichainAccountService.cjs.map +1 -1
  18. package/dist/MultichainAccountService.d.cts +31 -7
  19. package/dist/MultichainAccountService.d.cts.map +1 -1
  20. package/dist/MultichainAccountService.d.mts +31 -7
  21. package/dist/MultichainAccountService.d.mts.map +1 -1
  22. package/dist/MultichainAccountService.mjs +67 -8
  23. package/dist/MultichainAccountService.mjs.map +1 -1
  24. package/dist/MultichainAccountWallet.cjs +20 -0
  25. package/dist/MultichainAccountWallet.cjs.map +1 -1
  26. package/dist/MultichainAccountWallet.d.cts +10 -0
  27. package/dist/MultichainAccountWallet.d.cts.map +1 -1
  28. package/dist/MultichainAccountWallet.d.mts +10 -0
  29. package/dist/MultichainAccountWallet.d.mts.map +1 -1
  30. package/dist/MultichainAccountWallet.mjs +20 -0
  31. package/dist/MultichainAccountWallet.mjs.map +1 -1
  32. package/dist/index.cjs +3 -1
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +1 -1
  35. package/dist/index.d.cts.map +1 -1
  36. package/dist/index.d.mts +1 -1
  37. package/dist/index.d.mts.map +1 -1
  38. package/dist/index.mjs +1 -1
  39. package/dist/index.mjs.map +1 -1
  40. package/dist/providers/AccountProviderWrapper.cjs +43 -0
  41. package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
  42. package/dist/providers/AccountProviderWrapper.d.cts +37 -0
  43. package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
  44. package/dist/providers/AccountProviderWrapper.d.mts +37 -0
  45. package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
  46. package/dist/providers/AccountProviderWrapper.mjs +43 -0
  47. package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
  48. package/dist/providers/BaseBip44AccountProvider.cjs +3 -18
  49. package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
  50. package/dist/providers/BaseBip44AccountProvider.d.cts +36 -16
  51. package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
  52. package/dist/providers/BaseBip44AccountProvider.d.mts +36 -16
  53. package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
  54. package/dist/providers/BaseBip44AccountProvider.mjs +3 -18
  55. package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
  56. package/dist/providers/EvmAccountProvider.cjs +19 -0
  57. package/dist/providers/EvmAccountProvider.cjs.map +1 -1
  58. package/dist/providers/EvmAccountProvider.d.cts +12 -0
  59. package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
  60. package/dist/providers/EvmAccountProvider.d.mts +12 -0
  61. package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
  62. package/dist/providers/EvmAccountProvider.mjs +19 -0
  63. package/dist/providers/EvmAccountProvider.mjs.map +1 -1
  64. package/dist/providers/SnapAccountProvider.cjs +28 -11
  65. package/dist/providers/SnapAccountProvider.cjs.map +1 -1
  66. package/dist/providers/SnapAccountProvider.d.cts +16 -4
  67. package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
  68. package/dist/providers/SnapAccountProvider.d.mts +16 -4
  69. package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
  70. package/dist/providers/SnapAccountProvider.mjs +28 -11
  71. package/dist/providers/SnapAccountProvider.mjs.map +1 -1
  72. package/dist/providers/XlmAccountProvider.cjs +83 -0
  73. package/dist/providers/XlmAccountProvider.cjs.map +1 -0
  74. package/dist/providers/XlmAccountProvider.d.cts +29 -0
  75. package/dist/providers/XlmAccountProvider.d.cts.map +1 -0
  76. package/dist/providers/XlmAccountProvider.d.mts +29 -0
  77. package/dist/providers/XlmAccountProvider.d.mts.map +1 -0
  78. package/dist/providers/XlmAccountProvider.mjs +79 -0
  79. package/dist/providers/XlmAccountProvider.mjs.map +1 -0
  80. package/dist/providers/index.cjs +1 -0
  81. package/dist/providers/index.cjs.map +1 -1
  82. package/dist/providers/index.d.cts +1 -0
  83. package/dist/providers/index.d.cts.map +1 -1
  84. package/dist/providers/index.d.mts +1 -0
  85. package/dist/providers/index.d.mts.map +1 -1
  86. package/dist/providers/index.mjs +1 -0
  87. package/dist/providers/index.mjs.map +1 -1
  88. package/dist/tests/accounts.cjs +29 -1
  89. package/dist/tests/accounts.cjs.map +1 -1
  90. package/dist/tests/accounts.d.cts +2 -0
  91. package/dist/tests/accounts.d.cts.map +1 -1
  92. package/dist/tests/accounts.d.mts +2 -0
  93. package/dist/tests/accounts.d.mts.map +1 -1
  94. package/dist/tests/accounts.mjs +29 -1
  95. package/dist/tests/accounts.mjs.map +1 -1
  96. package/dist/tests/providers.cjs +5 -0
  97. package/dist/tests/providers.cjs.map +1 -1
  98. package/dist/tests/providers.d.cts +2 -0
  99. package/dist/tests/providers.d.cts.map +1 -1
  100. package/dist/tests/providers.d.mts +2 -0
  101. package/dist/tests/providers.d.mts.map +1 -1
  102. package/dist/tests/providers.mjs +6 -1
  103. package/dist/tests/providers.mjs.map +1 -1
  104. package/dist/utils.cjs.map +1 -1
  105. package/dist/utils.d.cts +14 -1
  106. package/dist/utils.d.cts.map +1 -1
  107. package/dist/utils.d.mts +14 -1
  108. package/dist/utils.d.mts.map +1 -1
  109. package/dist/utils.mjs.map +1 -1
  110. package/package.json +9 -9
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MultichainAccountService = exports.MultichainAccountGroup = exports.MultichainAccountWallet = exports.TrxAccountProvider = exports.TRX_ACCOUNT_PROVIDER_NAME = exports.BtcAccountProvider = exports.BTC_ACCOUNT_PROVIDER_NAME = exports.SolAccountProvider = exports.SOL_ACCOUNT_PROVIDER_NAME = exports.EvmAccountProvider = exports.EVM_ACCOUNT_PROVIDER_NAME = exports.TimeoutError = exports.SnapAccountProvider = exports.BaseBip44AccountProvider = exports.AccountProviderWrapper = void 0;
3
+ exports.MultichainAccountService = exports.MultichainAccountGroup = exports.MultichainAccountWallet = exports.XlmAccountProvider = exports.XLM_ACCOUNT_PROVIDER_NAME = exports.TrxAccountProvider = exports.TRX_ACCOUNT_PROVIDER_NAME = exports.BtcAccountProvider = exports.BTC_ACCOUNT_PROVIDER_NAME = exports.SolAccountProvider = exports.SOL_ACCOUNT_PROVIDER_NAME = exports.EvmAccountProvider = exports.EVM_ACCOUNT_PROVIDER_NAME = exports.TimeoutError = exports.SnapAccountProvider = exports.BaseBip44AccountProvider = exports.AccountProviderWrapper = void 0;
4
4
  var providers_1 = require("./providers/index.cjs");
5
5
  Object.defineProperty(exports, "AccountProviderWrapper", { enumerable: true, get: function () { return providers_1.AccountProviderWrapper; } });
6
6
  Object.defineProperty(exports, "BaseBip44AccountProvider", { enumerable: true, get: function () { return providers_1.BaseBip44AccountProvider; } });
@@ -14,6 +14,8 @@ Object.defineProperty(exports, "BTC_ACCOUNT_PROVIDER_NAME", { enumerable: true,
14
14
  Object.defineProperty(exports, "BtcAccountProvider", { enumerable: true, get: function () { return providers_1.BtcAccountProvider; } });
15
15
  Object.defineProperty(exports, "TRX_ACCOUNT_PROVIDER_NAME", { enumerable: true, get: function () { return providers_1.TRX_ACCOUNT_PROVIDER_NAME; } });
16
16
  Object.defineProperty(exports, "TrxAccountProvider", { enumerable: true, get: function () { return providers_1.TrxAccountProvider; } });
17
+ Object.defineProperty(exports, "XLM_ACCOUNT_PROVIDER_NAME", { enumerable: true, get: function () { return providers_1.XLM_ACCOUNT_PROVIDER_NAME; } });
18
+ Object.defineProperty(exports, "XlmAccountProvider", { enumerable: true, get: function () { return providers_1.XlmAccountProvider; } });
17
19
  var MultichainAccountWallet_1 = require("./MultichainAccountWallet.cjs");
18
20
  Object.defineProperty(exports, "MultichainAccountWallet", { enumerable: true, get: function () { return MultichainAccountWallet_1.MultichainAccountWallet; } });
19
21
  var MultichainAccountGroup_1 = require("./MultichainAccountGroup.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAwBA,mDAaqB;AAZnB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,gHAAA,mBAAmB,OAAA;AACnB,yGAAA,YAAY,OAAA;AACZ,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAEpB,yEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA","sourcesContent":["export type {\n MultichainAccountServiceActions,\n MultichainAccountServiceEvents,\n MultichainAccountServiceMessenger,\n MultichainAccountServiceMultichainAccountGroupCreatedEvent,\n MultichainAccountServiceMultichainAccountGroupUpdatedEvent,\n MultichainAccountServiceWalletStatusChangeEvent,\n} from './types';\nexport type {\n MultichainAccountServiceResyncAccountsAction,\n MultichainAccountServiceGetMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountWalletsAction,\n MultichainAccountServiceCreateMultichainAccountWalletAction,\n MultichainAccountServiceRemoveMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountGroupAction,\n MultichainAccountServiceGetMultichainAccountGroupsAction,\n MultichainAccountServiceCreateNextMultichainAccountGroupAction,\n MultichainAccountServiceCreateMultichainAccountGroupAction,\n MultichainAccountServiceCreateMultichainAccountGroupsAction,\n MultichainAccountServiceSetBasicFunctionalityAction,\n MultichainAccountServiceAlignWalletsAction,\n MultichainAccountServiceAlignWalletAction,\n MultichainAccountServiceInitAction,\n} from './MultichainAccountService-method-action-types';\nexport {\n AccountProviderWrapper,\n BaseBip44AccountProvider,\n SnapAccountProvider,\n TimeoutError,\n EVM_ACCOUNT_PROVIDER_NAME,\n EvmAccountProvider,\n SOL_ACCOUNT_PROVIDER_NAME,\n SolAccountProvider,\n BTC_ACCOUNT_PROVIDER_NAME,\n BtcAccountProvider,\n TRX_ACCOUNT_PROVIDER_NAME,\n TrxAccountProvider,\n} from './providers';\nexport { MultichainAccountWallet } from './MultichainAccountWallet';\nexport { MultichainAccountGroup } from './MultichainAccountGroup';\nexport { MultichainAccountService } from './MultichainAccountService';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAwBA,mDAeqB;AAdnB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,gHAAA,mBAAmB,OAAA;AACnB,yGAAA,YAAY,OAAA;AACZ,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,+GAAA,kBAAkB,OAAA;AAEpB,yEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA","sourcesContent":["export type {\n MultichainAccountServiceActions,\n MultichainAccountServiceEvents,\n MultichainAccountServiceMessenger,\n MultichainAccountServiceMultichainAccountGroupCreatedEvent,\n MultichainAccountServiceMultichainAccountGroupUpdatedEvent,\n MultichainAccountServiceWalletStatusChangeEvent,\n} from './types';\nexport type {\n MultichainAccountServiceResyncAccountsAction,\n MultichainAccountServiceGetMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountWalletsAction,\n MultichainAccountServiceCreateMultichainAccountWalletAction,\n MultichainAccountServiceRemoveMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountGroupAction,\n MultichainAccountServiceGetMultichainAccountGroupsAction,\n MultichainAccountServiceCreateNextMultichainAccountGroupAction,\n MultichainAccountServiceCreateMultichainAccountGroupAction,\n MultichainAccountServiceCreateMultichainAccountGroupsAction,\n MultichainAccountServiceSetBasicFunctionalityAction,\n MultichainAccountServiceAlignWalletsAction,\n MultichainAccountServiceAlignWalletAction,\n MultichainAccountServiceInitAction,\n} from './MultichainAccountService-method-action-types';\nexport {\n AccountProviderWrapper,\n BaseBip44AccountProvider,\n SnapAccountProvider,\n TimeoutError,\n EVM_ACCOUNT_PROVIDER_NAME,\n EvmAccountProvider,\n SOL_ACCOUNT_PROVIDER_NAME,\n SolAccountProvider,\n BTC_ACCOUNT_PROVIDER_NAME,\n BtcAccountProvider,\n TRX_ACCOUNT_PROVIDER_NAME,\n TrxAccountProvider,\n XLM_ACCOUNT_PROVIDER_NAME,\n XlmAccountProvider,\n} from './providers';\nexport { MultichainAccountWallet } from './MultichainAccountWallet';\nexport { MultichainAccountGroup } from './MultichainAccountGroup';\nexport { MultichainAccountService } from './MultichainAccountService';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type { MultichainAccountServiceActions, MultichainAccountServiceEvents, MultichainAccountServiceMessenger, MultichainAccountServiceMultichainAccountGroupCreatedEvent, MultichainAccountServiceMultichainAccountGroupUpdatedEvent, MultichainAccountServiceWalletStatusChangeEvent, } from "./types.cjs";
2
2
  export type { MultichainAccountServiceResyncAccountsAction, MultichainAccountServiceGetMultichainAccountWalletAction, MultichainAccountServiceGetMultichainAccountWalletsAction, MultichainAccountServiceCreateMultichainAccountWalletAction, MultichainAccountServiceRemoveMultichainAccountWalletAction, MultichainAccountServiceGetMultichainAccountGroupAction, MultichainAccountServiceGetMultichainAccountGroupsAction, MultichainAccountServiceCreateNextMultichainAccountGroupAction, MultichainAccountServiceCreateMultichainAccountGroupAction, MultichainAccountServiceCreateMultichainAccountGroupsAction, MultichainAccountServiceSetBasicFunctionalityAction, MultichainAccountServiceAlignWalletsAction, MultichainAccountServiceAlignWalletAction, MultichainAccountServiceInitAction, } from "./MultichainAccountService-method-action-types.cjs";
3
- export { AccountProviderWrapper, BaseBip44AccountProvider, SnapAccountProvider, TimeoutError, EVM_ACCOUNT_PROVIDER_NAME, EvmAccountProvider, SOL_ACCOUNT_PROVIDER_NAME, SolAccountProvider, BTC_ACCOUNT_PROVIDER_NAME, BtcAccountProvider, TRX_ACCOUNT_PROVIDER_NAME, TrxAccountProvider, } from "./providers/index.cjs";
3
+ export { AccountProviderWrapper, BaseBip44AccountProvider, SnapAccountProvider, TimeoutError, EVM_ACCOUNT_PROVIDER_NAME, EvmAccountProvider, SOL_ACCOUNT_PROVIDER_NAME, SolAccountProvider, BTC_ACCOUNT_PROVIDER_NAME, BtcAccountProvider, TRX_ACCOUNT_PROVIDER_NAME, TrxAccountProvider, XLM_ACCOUNT_PROVIDER_NAME, XlmAccountProvider, } from "./providers/index.cjs";
4
4
  export { MultichainAccountWallet } from "./MultichainAccountWallet.cjs";
5
5
  export { MultichainAccountGroup } from "./MultichainAccountGroup.cjs";
6
6
  export { MultichainAccountService } from "./MultichainAccountService.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,0DAA0D,EAC1D,0DAA0D,EAC1D,+CAA+C,GAChD,oBAAgB;AACjB,YAAY,EACV,4CAA4C,EAC5C,wDAAwD,EACxD,yDAAyD,EACzD,2DAA2D,EAC3D,2DAA2D,EAC3D,uDAAuD,EACvD,wDAAwD,EACxD,8DAA8D,EAC9D,0DAA0D,EAC1D,2DAA2D,EAC3D,mDAAmD,EACnD,0CAA0C,EAC1C,yCAAyC,EACzC,kCAAkC,GACnC,2DAAuD;AACxD,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,GACnB,8BAAoB;AACrB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,0DAA0D,EAC1D,0DAA0D,EAC1D,+CAA+C,GAChD,oBAAgB;AACjB,YAAY,EACV,4CAA4C,EAC5C,wDAAwD,EACxD,yDAAyD,EACzD,2DAA2D,EAC3D,2DAA2D,EAC3D,uDAAuD,EACvD,wDAAwD,EACxD,8DAA8D,EAC9D,0DAA0D,EAC1D,2DAA2D,EAC3D,mDAAmD,EACnD,0CAA0C,EAC1C,yCAAyC,EACzC,kCAAkC,GACnC,2DAAuD;AACxD,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,GACnB,8BAAoB;AACrB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC"}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type { MultichainAccountServiceActions, MultichainAccountServiceEvents, MultichainAccountServiceMessenger, MultichainAccountServiceMultichainAccountGroupCreatedEvent, MultichainAccountServiceMultichainAccountGroupUpdatedEvent, MultichainAccountServiceWalletStatusChangeEvent, } from "./types.mjs";
2
2
  export type { MultichainAccountServiceResyncAccountsAction, MultichainAccountServiceGetMultichainAccountWalletAction, MultichainAccountServiceGetMultichainAccountWalletsAction, MultichainAccountServiceCreateMultichainAccountWalletAction, MultichainAccountServiceRemoveMultichainAccountWalletAction, MultichainAccountServiceGetMultichainAccountGroupAction, MultichainAccountServiceGetMultichainAccountGroupsAction, MultichainAccountServiceCreateNextMultichainAccountGroupAction, MultichainAccountServiceCreateMultichainAccountGroupAction, MultichainAccountServiceCreateMultichainAccountGroupsAction, MultichainAccountServiceSetBasicFunctionalityAction, MultichainAccountServiceAlignWalletsAction, MultichainAccountServiceAlignWalletAction, MultichainAccountServiceInitAction, } from "./MultichainAccountService-method-action-types.mjs";
3
- export { AccountProviderWrapper, BaseBip44AccountProvider, SnapAccountProvider, TimeoutError, EVM_ACCOUNT_PROVIDER_NAME, EvmAccountProvider, SOL_ACCOUNT_PROVIDER_NAME, SolAccountProvider, BTC_ACCOUNT_PROVIDER_NAME, BtcAccountProvider, TRX_ACCOUNT_PROVIDER_NAME, TrxAccountProvider, } from "./providers/index.mjs";
3
+ export { AccountProviderWrapper, BaseBip44AccountProvider, SnapAccountProvider, TimeoutError, EVM_ACCOUNT_PROVIDER_NAME, EvmAccountProvider, SOL_ACCOUNT_PROVIDER_NAME, SolAccountProvider, BTC_ACCOUNT_PROVIDER_NAME, BtcAccountProvider, TRX_ACCOUNT_PROVIDER_NAME, TrxAccountProvider, XLM_ACCOUNT_PROVIDER_NAME, XlmAccountProvider, } from "./providers/index.mjs";
4
4
  export { MultichainAccountWallet } from "./MultichainAccountWallet.mjs";
5
5
  export { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
6
6
  export { MultichainAccountService } from "./MultichainAccountService.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,0DAA0D,EAC1D,0DAA0D,EAC1D,+CAA+C,GAChD,oBAAgB;AACjB,YAAY,EACV,4CAA4C,EAC5C,wDAAwD,EACxD,yDAAyD,EACzD,2DAA2D,EAC3D,2DAA2D,EAC3D,uDAAuD,EACvD,wDAAwD,EACxD,8DAA8D,EAC9D,0DAA0D,EAC1D,2DAA2D,EAC3D,mDAAmD,EACnD,0CAA0C,EAC1C,yCAAyC,EACzC,kCAAkC,GACnC,2DAAuD;AACxD,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,GACnB,8BAAoB;AACrB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,0DAA0D,EAC1D,0DAA0D,EAC1D,+CAA+C,GAChD,oBAAgB;AACjB,YAAY,EACV,4CAA4C,EAC5C,wDAAwD,EACxD,yDAAyD,EACzD,2DAA2D,EAC3D,2DAA2D,EAC3D,uDAAuD,EACvD,wDAAwD,EACxD,8DAA8D,EAC9D,0DAA0D,EAC1D,2DAA2D,EAC3D,mDAAmD,EACnD,0CAA0C,EAC1C,yCAAyC,EACzC,kCAAkC,GACnC,2DAAuD;AACxD,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,GACnB,8BAAoB;AACrB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { AccountProviderWrapper, BaseBip44AccountProvider, SnapAccountProvider, TimeoutError, EVM_ACCOUNT_PROVIDER_NAME, EvmAccountProvider, SOL_ACCOUNT_PROVIDER_NAME, SolAccountProvider, BTC_ACCOUNT_PROVIDER_NAME, BtcAccountProvider, TRX_ACCOUNT_PROVIDER_NAME, TrxAccountProvider } from "./providers/index.mjs";
1
+ export { AccountProviderWrapper, BaseBip44AccountProvider, SnapAccountProvider, TimeoutError, EVM_ACCOUNT_PROVIDER_NAME, EvmAccountProvider, SOL_ACCOUNT_PROVIDER_NAME, SolAccountProvider, BTC_ACCOUNT_PROVIDER_NAME, BtcAccountProvider, TRX_ACCOUNT_PROVIDER_NAME, TrxAccountProvider, XLM_ACCOUNT_PROVIDER_NAME, XlmAccountProvider } from "./providers/index.mjs";
2
2
  export { MultichainAccountWallet } from "./MultichainAccountWallet.mjs";
3
3
  export { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
4
4
  export { MultichainAccountService } from "./MultichainAccountService.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EACnB,8BAAoB;AACrB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC","sourcesContent":["export type {\n MultichainAccountServiceActions,\n MultichainAccountServiceEvents,\n MultichainAccountServiceMessenger,\n MultichainAccountServiceMultichainAccountGroupCreatedEvent,\n MultichainAccountServiceMultichainAccountGroupUpdatedEvent,\n MultichainAccountServiceWalletStatusChangeEvent,\n} from './types';\nexport type {\n MultichainAccountServiceResyncAccountsAction,\n MultichainAccountServiceGetMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountWalletsAction,\n MultichainAccountServiceCreateMultichainAccountWalletAction,\n MultichainAccountServiceRemoveMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountGroupAction,\n MultichainAccountServiceGetMultichainAccountGroupsAction,\n MultichainAccountServiceCreateNextMultichainAccountGroupAction,\n MultichainAccountServiceCreateMultichainAccountGroupAction,\n MultichainAccountServiceCreateMultichainAccountGroupsAction,\n MultichainAccountServiceSetBasicFunctionalityAction,\n MultichainAccountServiceAlignWalletsAction,\n MultichainAccountServiceAlignWalletAction,\n MultichainAccountServiceInitAction,\n} from './MultichainAccountService-method-action-types';\nexport {\n AccountProviderWrapper,\n BaseBip44AccountProvider,\n SnapAccountProvider,\n TimeoutError,\n EVM_ACCOUNT_PROVIDER_NAME,\n EvmAccountProvider,\n SOL_ACCOUNT_PROVIDER_NAME,\n SolAccountProvider,\n BTC_ACCOUNT_PROVIDER_NAME,\n BtcAccountProvider,\n TRX_ACCOUNT_PROVIDER_NAME,\n TrxAccountProvider,\n} from './providers';\nexport { MultichainAccountWallet } from './MultichainAccountWallet';\nexport { MultichainAccountGroup } from './MultichainAccountGroup';\nexport { MultichainAccountService } from './MultichainAccountService';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EACnB,8BAAoB;AACrB,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC","sourcesContent":["export type {\n MultichainAccountServiceActions,\n MultichainAccountServiceEvents,\n MultichainAccountServiceMessenger,\n MultichainAccountServiceMultichainAccountGroupCreatedEvent,\n MultichainAccountServiceMultichainAccountGroupUpdatedEvent,\n MultichainAccountServiceWalletStatusChangeEvent,\n} from './types';\nexport type {\n MultichainAccountServiceResyncAccountsAction,\n MultichainAccountServiceGetMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountWalletsAction,\n MultichainAccountServiceCreateMultichainAccountWalletAction,\n MultichainAccountServiceRemoveMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountGroupAction,\n MultichainAccountServiceGetMultichainAccountGroupsAction,\n MultichainAccountServiceCreateNextMultichainAccountGroupAction,\n MultichainAccountServiceCreateMultichainAccountGroupAction,\n MultichainAccountServiceCreateMultichainAccountGroupsAction,\n MultichainAccountServiceSetBasicFunctionalityAction,\n MultichainAccountServiceAlignWalletsAction,\n MultichainAccountServiceAlignWalletAction,\n MultichainAccountServiceInitAction,\n} from './MultichainAccountService-method-action-types';\nexport {\n AccountProviderWrapper,\n BaseBip44AccountProvider,\n SnapAccountProvider,\n TimeoutError,\n EVM_ACCOUNT_PROVIDER_NAME,\n EvmAccountProvider,\n SOL_ACCOUNT_PROVIDER_NAME,\n SolAccountProvider,\n BTC_ACCOUNT_PROVIDER_NAME,\n BtcAccountProvider,\n TRX_ACCOUNT_PROVIDER_NAME,\n TrxAccountProvider,\n XLM_ACCOUNT_PROVIDER_NAME,\n XlmAccountProvider,\n} from './providers';\nexport { MultichainAccountWallet } from './MultichainAccountWallet';\nexport { MultichainAccountGroup } from './MultichainAccountGroup';\nexport { MultichainAccountService } from './MultichainAccountService';\n"]}
@@ -27,6 +27,21 @@ class AccountProviderWrapper extends BaseBip44AccountProvider_1.BaseBip44Account
27
27
  init(accounts) {
28
28
  this.provider.init(accounts);
29
29
  }
30
+ /**
31
+ * Returns the underlying (unwrapped) provider.
32
+ *
33
+ * Most callers should go through the wrapper's public surface so that the
34
+ * `disabled` gating is respected. This escape hatch is reserved for
35
+ * cleanup flows (e.g. wallet removal) that must see the wrapped
36
+ * provider's accounts regardless of enabled state, so that snap-backed
37
+ * accounts created while the provider was enabled can still be deleted
38
+ * after it has been disabled.
39
+ *
40
+ * @returns The wrapped provider instance.
41
+ */
42
+ unwrap() {
43
+ return this.provider;
44
+ }
30
45
  /**
31
46
  * Set the enabled state for this provider.
32
47
  *
@@ -78,6 +93,22 @@ class AccountProviderWrapper extends BaseBip44AccountProvider_1.BaseBip44Account
78
93
  }
79
94
  return this.provider.getAccount(id);
80
95
  }
96
+ /**
97
+ * Returns true immediately when disabled (a disabled provider is considered
98
+ * aligned by definition). Delegates to the wrapped provider otherwise.
99
+ *
100
+ * @param context - The entropy source and group index to check.
101
+ * @param context.entropySource - The entropy source to check against.
102
+ * @param context.groupIndex - The group index to check against.
103
+ * @param accountIds - Account IDs pre-filtered by the caller.
104
+ * @returns Whether the provider is aligned for the given context.
105
+ */
106
+ isAligned(context, accountIds) {
107
+ if (!this.isEnabled) {
108
+ return true;
109
+ }
110
+ return this.provider.isAligned(context, accountIds);
111
+ }
81
112
  /**
82
113
  * Implement abstract method: Check if account is compatible.
83
114
  * Delegates directly to wrapped provider - no runtime checks needed!
@@ -100,6 +131,18 @@ class AccountProviderWrapper extends BaseBip44AccountProvider_1.BaseBip44Account
100
131
  }
101
132
  return this.provider.createAccounts(options);
102
133
  }
134
+ /**
135
+ * Forwards to the wrapped provider unconditionally, because deletion must run even
136
+ * when the wrapper is disabled, so that wallet-removal flows can clean up
137
+ * snap-backed accounts that were created while the provider was previously
138
+ * enabled.
139
+ *
140
+ * @param id - The id of the account to delete.
141
+ * @returns A promise that resolves when the account is deleted.
142
+ */
143
+ async deleteAccount(id) {
144
+ return this.provider.deleteAccount(id);
145
+ }
103
146
  /**
104
147
  * Implement abstract method: Discover and create accounts, returns empty array when disabled.
105
148
  *
@@ -1 +1 @@
1
- {"version":3,"file":"AccountProviderWrapper.cjs","sourceRoot":"","sources":["../../src/providers/AccountProviderWrapper.ts"],"names":[],"mappings":";;;AAUA,6EAAsE;AAEtE;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,mDAAwB;IAKlE,YACE,SAA4C,EAC5C,QAAkC;QAElC,KAAK,CAAC,SAAS,CAAC,CAAC;QARX,cAAS,GAAY,IAAI,CAAC;QAShC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEQ,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACM,IAAI,CAAC,QAA8C;QAC1D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gBAAgB,CAAC,OAGtB;QACC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;CACF;AAtID,wDAsIC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,QAAiB;IAEjB,OAAO,QAAQ,YAAY,sBAAsB,CAAC;AACpD,CAAC;AAJD,4DAIC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\n\n/**\n * A simple wrapper that adds disable functionality to any BaseBip44AccountProvider.\n * When disabled, the provider will not create new accounts and return empty results.\n */\nexport class AccountProviderWrapper extends BaseBip44AccountProvider {\n private isEnabled: boolean = true;\n\n private readonly provider: BaseBip44AccountProvider;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n provider: BaseBip44AccountProvider,\n ) {\n super(messenger);\n this.provider = provider;\n }\n\n override getName(): string {\n return this.provider.getName();\n }\n\n get capabilities(): KeyringCapabilities {\n return this.provider.capabilities;\n }\n\n /**\n * Forward initialization to the wrapped provider to ensure both\n * instances share the same visible account IDs.\n *\n * @param accounts - Account IDs to initialize with.\n */\n override init(accounts: Bip44Account<KeyringAccount>['id'][]): void {\n this.provider.init(accounts);\n }\n\n /**\n * Set the enabled state for this provider.\n *\n * @param enabled - Whether the provider should be enabled.\n */\n setEnabled(enabled: boolean): void {\n this.isEnabled = enabled;\n }\n\n /**\n * Check if the provider is disabled.\n *\n * @returns True if the provider is disabled, false otherwise.\n */\n isDisabled(): boolean {\n return !this.isEnabled;\n }\n\n /**\n * Override resyncAccounts to not execute it when disabled.\n *\n * @param accounts - List of local accounts.\n */\n override async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n if (!this.isEnabled) {\n return;\n }\n await this.provider.resyncAccounts(accounts);\n }\n\n /**\n * Override getAccounts to return empty array when disabled.\n *\n * @returns Array of accounts, or empty array if disabled.\n */\n override getAccounts(): Bip44Account<KeyringAccount>[] {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.getAccounts();\n }\n\n /**\n * Override getAccount to throw when disabled.\n *\n * @param id - The account ID to retrieve.\n * @returns The account with the specified ID.\n * @throws When disabled or account not found.\n */\n override getAccount(\n id: Bip44Account<KeyringAccount>['id'],\n ): Bip44Account<KeyringAccount> {\n if (!this.isEnabled) {\n throw new Error('Provider is disabled');\n }\n return this.provider.getAccount(id);\n }\n\n /**\n * Implement abstract method: Check if account is compatible.\n * Delegates directly to wrapped provider - no runtime checks needed!\n *\n * @param account - The account to check.\n * @returns True if the account is compatible.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean {\n return this.provider.isAccountCompatible(account);\n }\n\n /**\n * Implement abstract method: Create accounts, returns empty array when disabled.\n *\n * @param options - Account creation options.\n * @returns Promise resolving to created accounts, or empty array if disabled.\n */\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.createAccounts(options);\n }\n\n /**\n * Implement abstract method: Discover and create accounts, returns empty array when disabled.\n *\n * @param options - Account discovery options.\n * @param options.entropySource - The entropy source to use.\n * @param options.groupIndex - The group index to use.\n * @returns Promise resolving to discovered accounts, or empty array if disabled.\n */\n async discoverAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.discoverAccounts(options);\n }\n}\n\n/**\n * Simple type guard to check if a provider is wrapped.\n *\n * @param provider - The provider to check.\n * @returns True if the provider is an AccountProviderWrapper.\n */\nexport function isAccountProviderWrapper(\n provider: unknown,\n): provider is AccountProviderWrapper {\n return provider instanceof AccountProviderWrapper;\n}\n"]}
1
+ {"version":3,"file":"AccountProviderWrapper.cjs","sourceRoot":"","sources":["../../src/providers/AccountProviderWrapper.ts"],"names":[],"mappings":";;;AAUA,6EAAsE;AAEtE;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,mDAAwB;IAKlE,YACE,SAA4C,EAC5C,QAAkC;QAElC,KAAK,CAAC,SAAS,CAAC,CAAC;QARX,cAAS,GAAY,IAAI,CAAC;QAShC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEQ,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACM,IAAI,CAAC,QAA8C;QAC1D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,OAAgB;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,UAAU;QACR,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACM,KAAK,CAAC,cAAc,CAC3B,QAAyC;QAEzC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QACD,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACM,WAAW;QAClB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CA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AAC,OAAO,CAAC,CAAC;IACjD,CAAC;CACF;AAvLD,wDAuLC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,QAAiB;IAEjB,OAAO,QAAQ,YAAY,sBAAsB,CAAC;AACpD,CAAC;AAJD,4DAIC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\n\n/**\n * A simple wrapper that adds disable functionality to any BaseBip44AccountProvider.\n * When disabled, the provider will not create new accounts and return empty results.\n */\nexport class AccountProviderWrapper extends BaseBip44AccountProvider {\n private isEnabled: boolean = true;\n\n private readonly provider: BaseBip44AccountProvider;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n provider: BaseBip44AccountProvider,\n ) {\n super(messenger);\n this.provider = provider;\n }\n\n override getName(): string {\n return this.provider.getName();\n }\n\n get capabilities(): KeyringCapabilities {\n return this.provider.capabilities;\n }\n\n /**\n * Forward initialization to the wrapped provider to ensure both\n * instances share the same visible account IDs.\n *\n * @param accounts - Account IDs to initialize with.\n */\n override init(accounts: Bip44Account<KeyringAccount>['id'][]): void {\n this.provider.init(accounts);\n }\n\n /**\n * Returns the underlying (unwrapped) provider.\n *\n * Most callers should go through the wrapper's public surface so that the\n * `disabled` gating is respected. This escape hatch is reserved for\n * cleanup flows (e.g. wallet removal) that must see the wrapped\n * provider's accounts regardless of enabled state, so that snap-backed\n * accounts created while the provider was enabled can still be deleted\n * after it has been disabled.\n *\n * @returns The wrapped provider instance.\n */\n unwrap(): BaseBip44AccountProvider {\n return this.provider;\n }\n\n /**\n * Set the enabled state for this provider.\n *\n * @param enabled - Whether the provider should be enabled.\n */\n setEnabled(enabled: boolean): void {\n this.isEnabled = enabled;\n }\n\n /**\n * Check if the provider is disabled.\n *\n * @returns True if the provider is disabled, false otherwise.\n */\n isDisabled(): boolean {\n return !this.isEnabled;\n }\n\n /**\n * Override resyncAccounts to not execute it when disabled.\n *\n * @param accounts - List of local accounts.\n */\n override async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n if (!this.isEnabled) {\n return;\n }\n await this.provider.resyncAccounts(accounts);\n }\n\n /**\n * Override getAccounts to return empty array when disabled.\n *\n * @returns Array of accounts, or empty array if disabled.\n */\n override getAccounts(): Bip44Account<KeyringAccount>[] {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.getAccounts();\n }\n\n /**\n * Override getAccount to throw when disabled.\n *\n * @param id - The account ID to retrieve.\n * @returns The account with the specified ID.\n * @throws When disabled or account not found.\n */\n override getAccount(\n id: Bip44Account<KeyringAccount>['id'],\n ): Bip44Account<KeyringAccount> {\n if (!this.isEnabled) {\n throw new Error('Provider is disabled');\n }\n return this.provider.getAccount(id);\n }\n\n /**\n * Returns true immediately when disabled (a disabled provider is considered\n * aligned by definition). Delegates to the wrapped provider otherwise.\n *\n * @param context - The entropy source and group index to check.\n * @param context.entropySource - The entropy source to check against.\n * @param context.groupIndex - The group index to check against.\n * @param accountIds - Account IDs pre-filtered by the caller.\n * @returns Whether the provider is aligned for the given context.\n */\n override isAligned(\n context: { entropySource: EntropySourceId; groupIndex: number },\n accountIds: Bip44Account<KeyringAccount>['id'][],\n ): boolean {\n if (!this.isEnabled) {\n return true;\n }\n return this.provider.isAligned(context, accountIds);\n }\n\n /**\n * Implement abstract method: Check if account is compatible.\n * Delegates directly to wrapped provider - no runtime checks needed!\n *\n * @param account - The account to check.\n * @returns True if the account is compatible.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean {\n return this.provider.isAccountCompatible(account);\n }\n\n /**\n * Implement abstract method: Create accounts, returns empty array when disabled.\n *\n * @param options - Account creation options.\n * @returns Promise resolving to created accounts, or empty array if disabled.\n */\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.createAccounts(options);\n }\n\n /**\n * Forwards to the wrapped provider unconditionally, because deletion must run even\n * when the wrapper is disabled, so that wallet-removal flows can clean up\n * snap-backed accounts that were created while the provider was previously\n * enabled.\n *\n * @param id - The id of the account to delete.\n * @returns A promise that resolves when the account is deleted.\n */\n async deleteAccount(id: Bip44Account<KeyringAccount>['id']): Promise<void> {\n return this.provider.deleteAccount(id);\n }\n\n /**\n * Implement abstract method: Discover and create accounts, returns empty array when disabled.\n *\n * @param options - Account discovery options.\n * @param options.entropySource - The entropy source to use.\n * @param options.groupIndex - The group index to use.\n * @returns Promise resolving to discovered accounts, or empty array if disabled.\n */\n async discoverAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.discoverAccounts(options);\n }\n}\n\n/**\n * Simple type guard to check if a provider is wrapped.\n *\n * @param provider - The provider to check.\n * @returns True if the provider is an AccountProviderWrapper.\n */\nexport function isAccountProviderWrapper(\n provider: unknown,\n): provider is AccountProviderWrapper {\n return provider instanceof AccountProviderWrapper;\n}\n"]}
@@ -21,6 +21,19 @@ export declare class AccountProviderWrapper extends BaseBip44AccountProvider {
21
21
  * @param accounts - Account IDs to initialize with.
22
22
  */
23
23
  init(accounts: Bip44Account<KeyringAccount>['id'][]): void;
24
+ /**
25
+ * Returns the underlying (unwrapped) provider.
26
+ *
27
+ * Most callers should go through the wrapper's public surface so that the
28
+ * `disabled` gating is respected. This escape hatch is reserved for
29
+ * cleanup flows (e.g. wallet removal) that must see the wrapped
30
+ * provider's accounts regardless of enabled state, so that snap-backed
31
+ * accounts created while the provider was enabled can still be deleted
32
+ * after it has been disabled.
33
+ *
34
+ * @returns The wrapped provider instance.
35
+ */
36
+ unwrap(): BaseBip44AccountProvider;
24
37
  /**
25
38
  * Set the enabled state for this provider.
26
39
  *
@@ -53,6 +66,20 @@ export declare class AccountProviderWrapper extends BaseBip44AccountProvider {
53
66
  * @throws When disabled or account not found.
54
67
  */
55
68
  getAccount(id: Bip44Account<KeyringAccount>['id']): Bip44Account<KeyringAccount>;
69
+ /**
70
+ * Returns true immediately when disabled (a disabled provider is considered
71
+ * aligned by definition). Delegates to the wrapped provider otherwise.
72
+ *
73
+ * @param context - The entropy source and group index to check.
74
+ * @param context.entropySource - The entropy source to check against.
75
+ * @param context.groupIndex - The group index to check against.
76
+ * @param accountIds - Account IDs pre-filtered by the caller.
77
+ * @returns Whether the provider is aligned for the given context.
78
+ */
79
+ isAligned(context: {
80
+ entropySource: EntropySourceId;
81
+ groupIndex: number;
82
+ }, accountIds: Bip44Account<KeyringAccount>['id'][]): boolean;
56
83
  /**
57
84
  * Implement abstract method: Check if account is compatible.
58
85
  * Delegates directly to wrapped provider - no runtime checks needed!
@@ -68,6 +95,16 @@ export declare class AccountProviderWrapper extends BaseBip44AccountProvider {
68
95
  * @returns Promise resolving to created accounts, or empty array if disabled.
69
96
  */
70
97
  createAccounts(options: CreateAccountOptions): Promise<Bip44Account<KeyringAccount>[]>;
98
+ /**
99
+ * Forwards to the wrapped provider unconditionally, because deletion must run even
100
+ * when the wrapper is disabled, so that wallet-removal flows can clean up
101
+ * snap-backed accounts that were created while the provider was previously
102
+ * enabled.
103
+ *
104
+ * @param id - The id of the account to delete.
105
+ * @returns A promise that resolves when the account is deleted.
106
+ */
107
+ deleteAccount(id: Bip44Account<KeyringAccount>['id']): Promise<void>;
71
108
  /**
72
109
  * Implement abstract method: Discover and create accounts, returns empty array when disabled.
73
110
  *
@@ -1 +1 @@
1
- {"version":3,"file":"AccountProviderWrapper.d.cts","sourceRoot":"","sources":["../../src/providers/AccountProviderWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,E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AAW,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE;IAOtD;;;;;;OAMG;IACM,UAAU,CACjB,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GACrC,YAAY,CAAC,cAAc,CAAC;IAO/B;;;;;;;;;OASG;IACM,SAAS,CAChB,OAAO,EAAE;QAAE,aAAa,EAAE,eAAe,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAC/D,UAAU,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,GAC/C,OAAO;IAOV;;;;;;OAMG;IACH,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO;IAInE;;;;;OAKG;IACG,cAAc,CAClB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAO1C;;;;;;;;OAQG;IACG,aAAa,CAAC,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1E;;;;;;;OAOG;IACG,gBAAgB,CAAC,OAAO,EAAE;QAC9B,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAM5C;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,sBAAsB,CAEpC"}
@@ -21,6 +21,19 @@ export declare class AccountProviderWrapper extends BaseBip44AccountProvider {
21
21
  * @param accounts - Account IDs to initialize with.
22
22
  */
23
23
  init(accounts: Bip44Account<KeyringAccount>['id'][]): void;
24
+ /**
25
+ * Returns the underlying (unwrapped) provider.
26
+ *
27
+ * Most callers should go through the wrapper's public surface so that the
28
+ * `disabled` gating is respected. This escape hatch is reserved for
29
+ * cleanup flows (e.g. wallet removal) that must see the wrapped
30
+ * provider's accounts regardless of enabled state, so that snap-backed
31
+ * accounts created while the provider was enabled can still be deleted
32
+ * after it has been disabled.
33
+ *
34
+ * @returns The wrapped provider instance.
35
+ */
36
+ unwrap(): BaseBip44AccountProvider;
24
37
  /**
25
38
  * Set the enabled state for this provider.
26
39
  *
@@ -53,6 +66,20 @@ export declare class AccountProviderWrapper extends BaseBip44AccountProvider {
53
66
  * @throws When disabled or account not found.
54
67
  */
55
68
  getAccount(id: Bip44Account<KeyringAccount>['id']): Bip44Account<KeyringAccount>;
69
+ /**
70
+ * Returns true immediately when disabled (a disabled provider is considered
71
+ * aligned by definition). Delegates to the wrapped provider otherwise.
72
+ *
73
+ * @param context - The entropy source and group index to check.
74
+ * @param context.entropySource - The entropy source to check against.
75
+ * @param context.groupIndex - The group index to check against.
76
+ * @param accountIds - Account IDs pre-filtered by the caller.
77
+ * @returns Whether the provider is aligned for the given context.
78
+ */
79
+ isAligned(context: {
80
+ entropySource: EntropySourceId;
81
+ groupIndex: number;
82
+ }, accountIds: Bip44Account<KeyringAccount>['id'][]): boolean;
56
83
  /**
57
84
  * Implement abstract method: Check if account is compatible.
58
85
  * Delegates directly to wrapped provider - no runtime checks needed!
@@ -68,6 +95,16 @@ export declare class AccountProviderWrapper extends BaseBip44AccountProvider {
68
95
  * @returns Promise resolving to created accounts, or empty array if disabled.
69
96
  */
70
97
  createAccounts(options: CreateAccountOptions): Promise<Bip44Account<KeyringAccount>[]>;
98
+ /**
99
+ * Forwards to the wrapped provider unconditionally, because deletion must run even
100
+ * when the wrapper is disabled, so that wallet-removal flows can clean up
101
+ * snap-backed accounts that were created while the provider was previously
102
+ * enabled.
103
+ *
104
+ * @param id - The id of the account to delete.
105
+ * @returns A promise that resolves when the account is deleted.
106
+ */
107
+ deleteAccount(id: Bip44Account<KeyringAccount>['id']): Promise<void>;
71
108
  /**
72
109
  * Implement abstract method: Discover and create accounts, returns empty array when disabled.
73
110
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Acc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;;OAIG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;OAIG;IACY,cAAc,CAC3B,QAAQ,EAAE,YAAY,CAAC,eAAe,CAAC,EAAE,GACxC,OAAO,CAAC,IAAI,CAAC;IAOhB;;;;OAIG;IACM,WAAW,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE;IAOtD;;;;;;OAMG;IACM,UAAU,CACjB,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GACrC,YAAY,CAAC,cAAc,CAAC;IAO/B;;;;;;;;;OASG;IACM,SAAS,CAChB,OAAO,EAAE;QAAE,aAAa,EAAE,eAAe,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAC/D,UAAU,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,GAC/C,OAAO;IAOV;;;;;;OAMG;IACH,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO;IAInE;;;;;OAKG;IACG,cAAc,CAClB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAO1C;;;;;;;;OAQG;IACG,aAAa,CAAC,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1E;;;;;;;OAOG;IACG,gBAAgB,CAAC,OAAO,EAAE;QAC9B,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAM5C;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,sBAAsB,CAEpC"}
@@ -24,6 +24,21 @@ export class AccountProviderWrapper extends BaseBip44AccountProvider {
24
24
  init(accounts) {
25
25
  this.provider.init(accounts);
26
26
  }
27
+ /**
28
+ * Returns the underlying (unwrapped) provider.
29
+ *
30
+ * Most callers should go through the wrapper's public surface so that the
31
+ * `disabled` gating is respected. This escape hatch is reserved for
32
+ * cleanup flows (e.g. wallet removal) that must see the wrapped
33
+ * provider's accounts regardless of enabled state, so that snap-backed
34
+ * accounts created while the provider was enabled can still be deleted
35
+ * after it has been disabled.
36
+ *
37
+ * @returns The wrapped provider instance.
38
+ */
39
+ unwrap() {
40
+ return this.provider;
41
+ }
27
42
  /**
28
43
  * Set the enabled state for this provider.
29
44
  *
@@ -75,6 +90,22 @@ export class AccountProviderWrapper extends BaseBip44AccountProvider {
75
90
  }
76
91
  return this.provider.getAccount(id);
77
92
  }
93
+ /**
94
+ * Returns true immediately when disabled (a disabled provider is considered
95
+ * aligned by definition). Delegates to the wrapped provider otherwise.
96
+ *
97
+ * @param context - The entropy source and group index to check.
98
+ * @param context.entropySource - The entropy source to check against.
99
+ * @param context.groupIndex - The group index to check against.
100
+ * @param accountIds - Account IDs pre-filtered by the caller.
101
+ * @returns Whether the provider is aligned for the given context.
102
+ */
103
+ isAligned(context, accountIds) {
104
+ if (!this.isEnabled) {
105
+ return true;
106
+ }
107
+ return this.provider.isAligned(context, accountIds);
108
+ }
78
109
  /**
79
110
  * Implement abstract method: Check if account is compatible.
80
111
  * Delegates directly to wrapped provider - no runtime checks needed!
@@ -97,6 +128,18 @@ export class AccountProviderWrapper extends BaseBip44AccountProvider {
97
128
  }
98
129
  return this.provider.createAccounts(options);
99
130
  }
131
+ /**
132
+ * Forwards to the wrapped provider unconditionally, because deletion must run even
133
+ * when the wrapper is disabled, so that wallet-removal flows can clean up
134
+ * snap-backed accounts that were created while the provider was previously
135
+ * enabled.
136
+ *
137
+ * @param id - The id of the account to delete.
138
+ * @returns A promise that resolves when the account is deleted.
139
+ */
140
+ async deleteAccount(id) {
141
+ return this.provider.deleteAccount(id);
142
+ }
100
143
  /**
101
144
  * Implement abstract method: Discover and create accounts, returns empty array when disabled.
102
145
  *
@@ -1 +1 @@
1
- {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AC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACH,mBAAmB,CAAC,OAAqC;QACvD,OAAO,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAClB,OAA6B;QAE7B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,gBAAgB,CAAC,OAGtB;QACC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAiB;IAEjB,OAAO,QAAQ,YAAY,sBAAsB,CAAC;AACpD,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\n\n/**\n * A simple wrapper that adds disable functionality to any BaseBip44AccountProvider.\n * When disabled, the provider will not create new accounts and return empty results.\n */\nexport class AccountProviderWrapper extends BaseBip44AccountProvider {\n private isEnabled: boolean = true;\n\n private readonly provider: BaseBip44AccountProvider;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n provider: BaseBip44AccountProvider,\n ) {\n super(messenger);\n this.provider = provider;\n }\n\n override getName(): string {\n return this.provider.getName();\n }\n\n get capabilities(): KeyringCapabilities {\n return this.provider.capabilities;\n }\n\n /**\n * Forward initialization to the wrapped provider to ensure both\n * instances share the same visible account IDs.\n *\n * @param accounts - Account IDs to initialize with.\n */\n override init(accounts: Bip44Account<KeyringAccount>['id'][]): void {\n this.provider.init(accounts);\n }\n\n /**\n * Set the enabled state for this provider.\n *\n * @param enabled - Whether the provider should be enabled.\n */\n setEnabled(enabled: boolean): void {\n this.isEnabled = enabled;\n }\n\n /**\n * Check if the provider is disabled.\n *\n * @returns True if the provider is disabled, false otherwise.\n */\n isDisabled(): boolean {\n return !this.isEnabled;\n }\n\n /**\n * Override resyncAccounts to not execute it when disabled.\n *\n * @param accounts - List of local accounts.\n */\n override async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n if (!this.isEnabled) {\n return;\n }\n await this.provider.resyncAccounts(accounts);\n }\n\n /**\n * Override getAccounts to return empty array when disabled.\n *\n * @returns Array of accounts, or empty array if disabled.\n */\n override getAccounts(): Bip44Account<KeyringAccount>[] {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.getAccounts();\n }\n\n /**\n * Override getAccount to throw when disabled.\n *\n * @param id - The account ID to retrieve.\n * @returns The account with the specified ID.\n * @throws When disabled or account not found.\n */\n override getAccount(\n id: Bip44Account<KeyringAccount>['id'],\n ): Bip44Account<KeyringAccount> {\n if (!this.isEnabled) {\n throw new Error('Provider is disabled');\n }\n return this.provider.getAccount(id);\n }\n\n /**\n * Implement abstract method: Check if account is compatible.\n * Delegates directly to wrapped provider - no runtime checks needed!\n *\n * @param account - The account to check.\n * @returns True if the account is compatible.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean {\n return this.provider.isAccountCompatible(account);\n }\n\n /**\n * Implement abstract method: Create accounts, returns empty array when disabled.\n *\n * @param options - Account creation options.\n * @returns Promise resolving to created accounts, or empty array if disabled.\n */\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.createAccounts(options);\n }\n\n /**\n * Implement abstract method: Discover and create accounts, returns empty array when disabled.\n *\n * @param options - Account discovery options.\n * @param options.entropySource - The entropy source to use.\n * @param options.groupIndex - The group index to use.\n * @returns Promise resolving to discovered accounts, or empty array if disabled.\n */\n async discoverAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.discoverAccounts(options);\n }\n}\n\n/**\n * Simple type guard to check if a provider is wrapped.\n *\n * @param provider - The provider to check.\n * @returns True if the provider is an AccountProviderWrapper.\n */\nexport function isAccountProviderWrapper(\n provider: unknown,\n): provider is AccountProviderWrapper {\n return provider instanceof AccountProviderWrapper;\n}\n"]}
1
+ {"version":3,"file":"AccountProviderWrapper.mjs","sourceRoot":"","sources":["../../src/providers/AccountProviderWrapper.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AAEtE;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,wBAAwB;IAKlE,YACE,SAA4C,EAC5C,QAAkC;QAElC,KAAK,CAAC,SAAS,CAAC,CAAC;QARX,cAAS,GAAY,IAAI,CAAC;QAShC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEQ,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACM,IAAI,CAAC,QAA8C;QAC1D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,C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ACpD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAClB,OAA6B;QAE7B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,EAAsC;QACxD,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,gBAAgB,CAAC,OAGtB;QACC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAiB;IAEjB,OAAO,QAAQ,YAAY,sBAAsB,CAAC;AACpD,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport type { KeyringCapabilities } from '@metamask/keyring-api/v2';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\n\n/**\n * A simple wrapper that adds disable functionality to any BaseBip44AccountProvider.\n * When disabled, the provider will not create new accounts and return empty results.\n */\nexport class AccountProviderWrapper extends BaseBip44AccountProvider {\n private isEnabled: boolean = true;\n\n private readonly provider: BaseBip44AccountProvider;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n provider: BaseBip44AccountProvider,\n ) {\n super(messenger);\n this.provider = provider;\n }\n\n override getName(): string {\n return this.provider.getName();\n }\n\n get capabilities(): KeyringCapabilities {\n return this.provider.capabilities;\n }\n\n /**\n * Forward initialization to the wrapped provider to ensure both\n * instances share the same visible account IDs.\n *\n * @param accounts - Account IDs to initialize with.\n */\n override init(accounts: Bip44Account<KeyringAccount>['id'][]): void {\n this.provider.init(accounts);\n }\n\n /**\n * Returns the underlying (unwrapped) provider.\n *\n * Most callers should go through the wrapper's public surface so that the\n * `disabled` gating is respected. This escape hatch is reserved for\n * cleanup flows (e.g. wallet removal) that must see the wrapped\n * provider's accounts regardless of enabled state, so that snap-backed\n * accounts created while the provider was enabled can still be deleted\n * after it has been disabled.\n *\n * @returns The wrapped provider instance.\n */\n unwrap(): BaseBip44AccountProvider {\n return this.provider;\n }\n\n /**\n * Set the enabled state for this provider.\n *\n * @param enabled - Whether the provider should be enabled.\n */\n setEnabled(enabled: boolean): void {\n this.isEnabled = enabled;\n }\n\n /**\n * Check if the provider is disabled.\n *\n * @returns True if the provider is disabled, false otherwise.\n */\n isDisabled(): boolean {\n return !this.isEnabled;\n }\n\n /**\n * Override resyncAccounts to not execute it when disabled.\n *\n * @param accounts - List of local accounts.\n */\n override async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n if (!this.isEnabled) {\n return;\n }\n await this.provider.resyncAccounts(accounts);\n }\n\n /**\n * Override getAccounts to return empty array when disabled.\n *\n * @returns Array of accounts, or empty array if disabled.\n */\n override getAccounts(): Bip44Account<KeyringAccount>[] {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.getAccounts();\n }\n\n /**\n * Override getAccount to throw when disabled.\n *\n * @param id - The account ID to retrieve.\n * @returns The account with the specified ID.\n * @throws When disabled or account not found.\n */\n override getAccount(\n id: Bip44Account<KeyringAccount>['id'],\n ): Bip44Account<KeyringAccount> {\n if (!this.isEnabled) {\n throw new Error('Provider is disabled');\n }\n return this.provider.getAccount(id);\n }\n\n /**\n * Returns true immediately when disabled (a disabled provider is considered\n * aligned by definition). Delegates to the wrapped provider otherwise.\n *\n * @param context - The entropy source and group index to check.\n * @param context.entropySource - The entropy source to check against.\n * @param context.groupIndex - The group index to check against.\n * @param accountIds - Account IDs pre-filtered by the caller.\n * @returns Whether the provider is aligned for the given context.\n */\n override isAligned(\n context: { entropySource: EntropySourceId; groupIndex: number },\n accountIds: Bip44Account<KeyringAccount>['id'][],\n ): boolean {\n if (!this.isEnabled) {\n return true;\n }\n return this.provider.isAligned(context, accountIds);\n }\n\n /**\n * Implement abstract method: Check if account is compatible.\n * Delegates directly to wrapped provider - no runtime checks needed!\n *\n * @param account - The account to check.\n * @returns True if the account is compatible.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean {\n return this.provider.isAccountCompatible(account);\n }\n\n /**\n * Implement abstract method: Create accounts, returns empty array when disabled.\n *\n * @param options - Account creation options.\n * @returns Promise resolving to created accounts, or empty array if disabled.\n */\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.createAccounts(options);\n }\n\n /**\n * Forwards to the wrapped provider unconditionally, because deletion must run even\n * when the wrapper is disabled, so that wallet-removal flows can clean up\n * snap-backed accounts that were created while the provider was previously\n * enabled.\n *\n * @param id - The id of the account to delete.\n * @returns A promise that resolves when the account is deleted.\n */\n async deleteAccount(id: Bip44Account<KeyringAccount>['id']): Promise<void> {\n return this.provider.deleteAccount(id);\n }\n\n /**\n * Implement abstract method: Discover and create accounts, returns empty array when disabled.\n *\n * @param options - Account discovery options.\n * @param options.entropySource - The entropy source to use.\n * @param options.groupIndex - The group index to use.\n * @returns Promise resolving to discovered accounts, or empty array if disabled.\n */\n async discoverAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.discoverAccounts(options);\n }\n}\n\n/**\n * Simple type guard to check if a provider is wrapped.\n *\n * @param provider - The provider to check.\n * @returns True if the provider is an AccountProviderWrapper.\n */\nexport function isAccountProviderWrapper(\n provider: unknown,\n): provider is AccountProviderWrapper {\n return provider instanceof AccountProviderWrapper;\n}\n"]}
@@ -75,24 +75,6 @@ class BaseBip44AccountProvider {
75
75
  // but we know that the account is BIP-44 compatible here so it is safe to do so
76
76
  return this.messenger.call('AccountsController:getAccount', id);
77
77
  }
78
- /**
79
- * Run an operation against a V1 keyring selected by `selector`.
80
- *
81
- * Forwards to `KeyringController:withKeyring`. Use this for keyrings that
82
- * have not yet migrated to the unified V2 `Keyring` interface (e.g. the
83
- * snap keyring).
84
- *
85
- * @param selector - The selector identifying the keyring.
86
- * @param operation - The operation to run with the selected keyring.
87
- * @returns The result of the operation.
88
- */
89
- async withKeyring(selector, operation) {
90
- const result = await this.messenger.call('KeyringController:withKeyring', selector, ({ keyring, metadata }) => operation({
91
- keyring: keyring,
92
- metadata,
93
- }));
94
- return result;
95
- }
96
78
  /**
97
79
  * Run an operation against a V2 keyring selected by `selector`.
98
80
  *
@@ -111,6 +93,9 @@ class BaseBip44AccountProvider {
111
93
  }));
112
94
  return result;
113
95
  }
96
+ isAligned(_context, accountIds) {
97
+ return (accountIds.length >= 1 && accountIds.every((id) => this.accounts.has(id)));
98
+ }
114
99
  }
115
100
  exports.BaseBip44AccountProvider = BaseBip44AccountProvider;
116
101
  _BaseBip44AccountProvider_instances = new WeakSet(), _BaseBip44AccountProvider_getAccountIds = function _BaseBip44AccountProvider_getAccountIds() {
@@ -1 +1 @@
1
- {"version":3,"file":"BaseBip44AccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAAuD;AAoBvD;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,IAAA,4BAAc,EAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAND,oDAMC;AAED;;;;;G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,QAAQ,EAAE,EAAE,EAAE,CACxB,SAAS,CAAC;YACR,OAAO,EAAE,OAA0B;YACnC,QAAQ;SACT,CAAC,CACL,CAAC;QAEF,OAAO,MAAwB,CAAC;IAClC,CAAC;IAED;;;;;;;;;;OAUG;IACO,KAAK,CAAC,aAAa,CAI3B,QAA4C,EAC5C,SAM6B;QAE7B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACtC,iCAAiC,EACjC,QAAQ,EACR,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CACxB,SAAS,CAAC;YACR,OAAO,EAAE,OAA0B;YACnC,QAAQ;SACT,CAAC,CACL,CAAC;QAEF,OAAO,MAAwB,CAAC;IAClC,CAAC;CAqBF;AAhKD,4DAgKC;;IAlIG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { AccountProvider, Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport type {\n Keyring as KeyringV2,\n KeyringCapabilities,\n} from '@metamask/keyring-api/v2';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n KeyringSelectorV2,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\n\n/**\n * Asserts a keyring account is BIP-44 compatible.\n *\n * @param account - Keyring account to check.\n * @throws If the keyring account is not compatible.\n */\nexport function assertIsBip44Account(\n account: KeyringAccount,\n): asserts account is Bip44Account<KeyringAccount> {\n if (!isBip44Account(account)) {\n throw new Error('Created account is not BIP-44 compatible');\n }\n}\n\n/**\n * Asserts that a list of keyring accounts are all BIP-44 compatible.\n *\n * @param accounts - Keyring accounts to check.\n * @throws If any of the keyring account is not compatible.\n */\nexport function assertAreBip44Accounts(\n accounts: KeyringAccount[],\n): asserts accounts is Bip44Account<KeyringAccount>[] {\n accounts.forEach(assertIsBip44Account);\n}\n\nexport type Bip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> = AccountProvider<Account> & {\n /**\n * Provider capabilities, including supported scopes and BIP-44 options.\n *\n * @returns The provider capabilities.\n */\n get capabilities(): KeyringCapabilities;\n /**\n * Get the name of the provider.\n *\n * @returns The name of the provider.\n */\n getName(): string;\n /**\n * Initialize the provider with the given accounts.\n *\n * @param accounts - The accounts to initialize the provider with.\n */\n init(accounts: Bip44Account<KeyringAccount>['id'][]): void;\n /**\n * Check if the account is compatible with the provider.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n /**\n * Create accounts for the provider.\n *\n * @param options - The options for creating the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @param options.type - The type of account creation.\n * @returns The created accounts.\n */\n createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n */\n resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;\n};\n\nexport abstract class BaseBip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> implements Bip44AccountProvider<Account> {\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n protected accounts: Set<Bip44Account<KeyringAccount>['id']> = new Set();\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Add accounts to the provider.\n *\n * Note: There's an implicit assumption that the accounts are BIP-44 compatible.\n *\n * @param accounts - The accounts to add.\n */\n init(accounts: Account['id'][]): void {\n for (const account of accounts) {\n this.accounts.add(account);\n }\n }\n\n /**\n * Get the accounts list for the provider.\n *\n * @returns The accounts list.\n */\n #getAccountIds(): Account['id'][] {\n return [...this.accounts];\n }\n\n /**\n * Get the accounts list for the provider from the AccountsController.\n *\n * @returns The accounts list.\n */\n getAccounts(): Account[] {\n const accountsIds = this.#getAccountIds();\n const internalAccounts = this.messenger.call(\n 'AccountsController:getAccounts',\n accountsIds,\n );\n // we cast here because we know that the accounts are BIP-44 compatible\n return internalAccounts as unknown as Account[];\n }\n\n /**\n * Get the account for the provider.\n *\n * @param id - The account ID.\n * @returns The account.\n * @throws If the account is not found.\n */\n getAccount(id: Account['id']): Account {\n const hasAccount = this.accounts.has(id);\n\n if (!hasAccount) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n // We need to upcast here since InternalAccounts are not always BIP-44 compatible\n // but we know that the account is BIP-44 compatible here so it is safe to do so\n return this.messenger.call(\n 'AccountsController:getAccount',\n id,\n ) as unknown as Account;\n }\n\n /**\n * Run an operation against a V1 keyring selected by `selector`.\n *\n * Forwards to `KeyringController:withKeyring`. Use this for keyrings that\n * have not yet migrated to the unified V2 `Keyring` interface (e.g. the\n * snap keyring).\n *\n * @param selector - The selector identifying the keyring.\n * @param operation - The operation to run with the selected keyring.\n * @returns The result of the operation.\n */\n protected async withKeyring<SelectedKeyring, CallbackResult = void>(\n selector: KeyringSelector,\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SelectedKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n const result = await this.messenger.call(\n 'KeyringController:withKeyring',\n selector,\n ({ keyring, metadata }) =>\n operation({\n keyring: keyring as SelectedKeyring,\n metadata,\n }),\n );\n\n return result as CallbackResult;\n }\n\n /**\n * Run an operation against a V2 keyring selected by `selector`.\n *\n * Forwards to `KeyringController:withKeyringV2`. Use this for keyrings\n * that implement the unified V2 `Keyring` interface from\n * `@metamask/keyring-api/v2`.\n *\n * @param selector - The selector identifying the keyring.\n * @param operation - The operation to run with the selected keyring.\n * @returns The result of the operation.\n */\n protected async withKeyringV2<\n SelectedKeyring extends KeyringV2 = KeyringV2,\n CallbackResult = void,\n >(\n selector: KeyringSelectorV2<SelectedKeyring>,\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SelectedKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n const result = await this.messenger.call(\n 'KeyringController:withKeyringV2',\n selector,\n ({ keyring, metadata }) =>\n operation({\n keyring: keyring as SelectedKeyring,\n metadata,\n }),\n );\n\n return result as CallbackResult;\n }\n\n abstract get capabilities(): KeyringCapabilities;\n\n abstract getName(): string;\n\n abstract resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void>;\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n\n abstract discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account[]>;\n}\n"]}
1
+ {"version":3,"file":"BaseBip44AccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAAuD;AAmBvD;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,IAAA,4BAAc,EAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAND,oDAMC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,QAA0B;IAE1B,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACzC,CAAC;AAJD,wDAIC;AA6ED,MAAsB,wBAAwB;IAO5C,YAAY,SAA4C;;QAF9C,aAAQ,GAA4C,IAAI,GAAG,EAAE,CAAC;QAGtE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,IAAI,CAAC,QAAyB;QAC5B,KAAK,MAAM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,EAAE,CAAC,CAAC,CAC1E,CAAC;IACJ,CAAC;CAuBF;AAzID,4DAyIC;;IA3GG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { AccountProvider, Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport type {\n Keyring as KeyringV2,\n KeyringCapabilities,\n} from '@metamask/keyring-api/v2';\nimport type {\n KeyringMetadata,\n KeyringSelectorV2,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\n\n/**\n * Asserts a keyring account is BIP-44 compatible.\n *\n * @param account - Keyring account to check.\n * @throws If the keyring account is not compatible.\n */\nexport function assertIsBip44Account(\n account: KeyringAccount,\n): asserts account is Bip44Account<KeyringAccount> {\n if (!isBip44Account(account)) {\n throw new Error('Created account is not BIP-44 compatible');\n }\n}\n\n/**\n * Asserts that a list of keyring accounts are all BIP-44 compatible.\n *\n * @param accounts - Keyring accounts to check.\n * @throws If any of the keyring account is not compatible.\n */\nexport function assertAreBip44Accounts(\n accounts: KeyringAccount[],\n): asserts accounts is Bip44Account<KeyringAccount>[] {\n accounts.forEach(assertIsBip44Account);\n}\n\nexport type Bip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> = AccountProvider<Account> & {\n /**\n * Provider capabilities, including supported scopes and BIP-44 options.\n *\n * @returns The provider capabilities.\n */\n get capabilities(): KeyringCapabilities;\n /**\n * Get the name of the provider.\n *\n * @returns The name of the provider.\n */\n getName(): string;\n /**\n * Initialize the provider with the given accounts.\n *\n * @param accounts - The accounts to initialize the provider with.\n */\n init(accounts: Bip44Account<KeyringAccount>['id'][]): void;\n /**\n * Check if the account is compatible with the provider.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n /**\n * Create accounts for the provider.\n *\n * @param options - The options for creating the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @param options.type - The type of account creation.\n * @returns The created accounts.\n */\n createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n /**\n * Delete an account managed by this provider.\n *\n * Mirrors the v2 keyring `deleteAccount(accountId)` contract. Each provider\n * implementation is responsible for resolving any extra information it needs\n * (e.g. address for snap-based providers) and for performing the underlying\n * keyring removal.\n *\n * @param id - The id of the account to delete.\n */\n deleteAccount(id: Account['id']): Promise<void>;\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n */\n resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;\n /**\n * Check if the provider has an aligned (i.e. present and owned) account for\n * the given entropy source and group index.\n *\n * Callers pre-filter the relevant account IDs from the group and pass them\n * in so the provider needs no messenger call.\n *\n * @param context - The entropy source and group index to check.\n * @param context.entropySource - The entropy source to check against.\n * @param context.groupIndex - The group index to check against.\n * @param accountIds - Account IDs already associated with this provider for\n * the given group (may be empty if no alignment has happened yet).\n * @returns `true` when `accountIds` is non-empty and every ID is in the\n * provider's internal accounts Set.\n */\n isAligned(\n context: { entropySource: EntropySourceId; groupIndex: number },\n accountIds: Account['id'][],\n ): boolean;\n};\n\nexport abstract class BaseBip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> implements Bip44AccountProvider<Account> {\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n protected accounts: Set<Bip44Account<KeyringAccount>['id']> = new Set();\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Add accounts to the provider.\n *\n * Note: There's an implicit assumption that the accounts are BIP-44 compatible.\n *\n * @param accounts - The accounts to add.\n */\n init(accounts: Account['id'][]): void {\n for (const account of accounts) {\n this.accounts.add(account);\n }\n }\n\n /**\n * Get the accounts list for the provider.\n *\n * @returns The accounts list.\n */\n #getAccountIds(): Account['id'][] {\n return [...this.accounts];\n }\n\n /**\n * Get the accounts list for the provider from the AccountsController.\n *\n * @returns The accounts list.\n */\n getAccounts(): Account[] {\n const accountsIds = this.#getAccountIds();\n const internalAccounts = this.messenger.call(\n 'AccountsController:getAccounts',\n accountsIds,\n );\n // we cast here because we know that the accounts are BIP-44 compatible\n return internalAccounts as unknown as Account[];\n }\n\n /**\n * Get the account for the provider.\n *\n * @param id - The account ID.\n * @returns The account.\n * @throws If the account is not found.\n */\n getAccount(id: Account['id']): Account {\n const hasAccount = this.accounts.has(id);\n\n if (!hasAccount) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n // We need to upcast here since InternalAccounts are not always BIP-44 compatible\n // but we know that the account is BIP-44 compatible here so it is safe to do so\n return this.messenger.call(\n 'AccountsController:getAccount',\n id,\n ) as unknown as Account;\n }\n\n /**\n * Run an operation against a V2 keyring selected by `selector`.\n *\n * Forwards to `KeyringController:withKeyringV2`. Use this for keyrings\n * that implement the unified V2 `Keyring` interface from\n * `@metamask/keyring-api/v2`.\n *\n * @param selector - The selector identifying the keyring.\n * @param operation - The operation to run with the selected keyring.\n * @returns The result of the operation.\n */\n protected async withKeyringV2<\n SelectedKeyring extends KeyringV2 = KeyringV2,\n CallbackResult = void,\n >(\n selector: KeyringSelectorV2<SelectedKeyring>,\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SelectedKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n const result = await this.messenger.call(\n 'KeyringController:withKeyringV2',\n selector,\n ({ keyring, metadata }) =>\n operation({\n keyring: keyring as SelectedKeyring,\n metadata,\n }),\n );\n\n return result as CallbackResult;\n }\n\n isAligned(\n _context: { entropySource: EntropySourceId; groupIndex: number },\n accountIds: Account['id'][],\n ): boolean {\n return (\n accountIds.length >= 1 && accountIds.every((id) => this.accounts.has(id))\n );\n }\n\n abstract get capabilities(): KeyringCapabilities;\n\n abstract getName(): string;\n\n abstract resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void>;\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n\n abstract deleteAccount(id: Account['id']): Promise<void>;\n\n abstract discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account[]>;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { AccountProvider, Bip44Account } from "@metamask/account-api";
2
2
  import type { CreateAccountOptions, EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
3
3
  import type { Keyring as KeyringV2, KeyringCapabilities } from "@metamask/keyring-api/v2";
4
- import type { KeyringMetadata, KeyringSelector, KeyringSelectorV2 } from "@metamask/keyring-controller";
4
+ import type { KeyringMetadata, KeyringSelectorV2 } from "@metamask/keyring-controller";
5
5
  import type { InternalAccount } from "@metamask/keyring-internal-api";
6
6
  import type { MultichainAccountServiceMessenger } from "../types.cjs";
7
7
  /**
@@ -51,6 +51,17 @@ export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> =
51
51
  * @returns The created accounts.
52
52
  */
53
53
  createAccounts(options: CreateAccountOptions): Promise<Account[]>;
54
+ /**
55
+ * Delete an account managed by this provider.
56
+ *
57
+ * Mirrors the v2 keyring `deleteAccount(accountId)` contract. Each provider
58
+ * implementation is responsible for resolving any extra information it needs
59
+ * (e.g. address for snap-based providers) and for performing the underlying
60
+ * keyring removal.
61
+ *
62
+ * @param id - The id of the account to delete.
63
+ */
64
+ deleteAccount(id: Account['id']): Promise<void>;
54
65
  /**
55
66
  * Re-synchronize MetaMask accounts and the providers accounts if needed.
56
67
  *
@@ -59,6 +70,25 @@ export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> =
59
70
  * in-sync and use the same accounts (and same IDs).
60
71
  */
61
72
  resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
73
+ /**
74
+ * Check if the provider has an aligned (i.e. present and owned) account for
75
+ * the given entropy source and group index.
76
+ *
77
+ * Callers pre-filter the relevant account IDs from the group and pass them
78
+ * in so the provider needs no messenger call.
79
+ *
80
+ * @param context - The entropy source and group index to check.
81
+ * @param context.entropySource - The entropy source to check against.
82
+ * @param context.groupIndex - The group index to check against.
83
+ * @param accountIds - Account IDs already associated with this provider for
84
+ * the given group (may be empty if no alignment has happened yet).
85
+ * @returns `true` when `accountIds` is non-empty and every ID is in the
86
+ * provider's internal accounts Set.
87
+ */
88
+ isAligned(context: {
89
+ entropySource: EntropySourceId;
90
+ groupIndex: number;
91
+ }, accountIds: Account['id'][]): boolean;
62
92
  };
63
93
  export declare abstract class BaseBip44AccountProvider<Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>> implements Bip44AccountProvider<Account> {
64
94
  #private;
@@ -87,21 +117,6 @@ export declare abstract class BaseBip44AccountProvider<Account extends Bip44Acco
87
117
  * @throws If the account is not found.
88
118
  */
89
119
  getAccount(id: Account['id']): Account;
90
- /**
91
- * Run an operation against a V1 keyring selected by `selector`.
92
- *
93
- * Forwards to `KeyringController:withKeyring`. Use this for keyrings that
94
- * have not yet migrated to the unified V2 `Keyring` interface (e.g. the
95
- * snap keyring).
96
- *
97
- * @param selector - The selector identifying the keyring.
98
- * @param operation - The operation to run with the selected keyring.
99
- * @returns The result of the operation.
100
- */
101
- protected withKeyring<SelectedKeyring, CallbackResult = void>(selector: KeyringSelector, operation: ({ keyring, metadata, }: {
102
- keyring: SelectedKeyring;
103
- metadata: KeyringMetadata;
104
- }) => Promise<CallbackResult>): Promise<CallbackResult>;
105
120
  /**
106
121
  * Run an operation against a V2 keyring selected by `selector`.
107
122
  *
@@ -117,11 +132,16 @@ export declare abstract class BaseBip44AccountProvider<Account extends Bip44Acco
117
132
  keyring: SelectedKeyring;
118
133
  metadata: KeyringMetadata;
119
134
  }) => Promise<CallbackResult>): Promise<CallbackResult>;
135
+ isAligned(_context: {
136
+ entropySource: EntropySourceId;
137
+ groupIndex: number;
138
+ }, accountIds: Account['id'][]): boolean;
120
139
  abstract get capabilities(): KeyringCapabilities;
121
140
  abstract getName(): string;
122
141
  abstract resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
123
142
  abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;
124
143
  abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;
144
+ abstract deleteAccount(id: Account['id']): Promise<void>;
125
145
  abstract discoverAccounts({ entropySource, groupIndex, }: {
126
146
  entropySource: EntropySourceId;
127
147
  groupIndex: number;