@metamask-previews/multichain-account-service 0.7.0-preview-ea6406b3 → 0.7.0-preview-1f2cfed

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 (78) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/MultichainAccountService.cjs +2 -11
  3. package/dist/MultichainAccountService.cjs.map +1 -1
  4. package/dist/MultichainAccountService.d.cts +0 -6
  5. package/dist/MultichainAccountService.d.cts.map +1 -1
  6. package/dist/MultichainAccountService.d.mts +0 -6
  7. package/dist/MultichainAccountService.d.mts.map +1 -1
  8. package/dist/MultichainAccountService.mjs +2 -11
  9. package/dist/MultichainAccountService.mjs.map +1 -1
  10. package/dist/MultichainAccountWallet.cjs +183 -156
  11. package/dist/MultichainAccountWallet.cjs.map +1 -1
  12. package/dist/MultichainAccountWallet.d.cts +17 -15
  13. package/dist/MultichainAccountWallet.d.cts.map +1 -1
  14. package/dist/MultichainAccountWallet.d.mts +17 -15
  15. package/dist/MultichainAccountWallet.d.mts.map +1 -1
  16. package/dist/MultichainAccountWallet.mjs +183 -156
  17. package/dist/MultichainAccountWallet.mjs.map +1 -1
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.cts.map +1 -1
  21. package/dist/index.d.mts +1 -1
  22. package/dist/index.d.mts.map +1 -1
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/providers/AccountProviderWrapper.cjs +2 -2
  25. package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
  26. package/dist/providers/AccountProviderWrapper.d.cts +1 -1
  27. package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
  28. package/dist/providers/AccountProviderWrapper.d.mts +1 -1
  29. package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
  30. package/dist/providers/AccountProviderWrapper.mjs +2 -2
  31. package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
  32. package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
  33. package/dist/providers/BaseBip44AccountProvider.d.cts +1 -1
  34. package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
  35. package/dist/providers/BaseBip44AccountProvider.d.mts +1 -1
  36. package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
  37. package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
  38. package/dist/providers/EvmAccountProvider.cjs +1 -1
  39. package/dist/providers/EvmAccountProvider.cjs.map +1 -1
  40. package/dist/providers/EvmAccountProvider.d.cts +1 -1
  41. package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
  42. package/dist/providers/EvmAccountProvider.d.mts +1 -1
  43. package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
  44. package/dist/providers/EvmAccountProvider.mjs +1 -1
  45. package/dist/providers/EvmAccountProvider.mjs.map +1 -1
  46. package/dist/providers/SnapAccountProvider.cjs.map +1 -1
  47. package/dist/providers/SnapAccountProvider.d.cts +1 -1
  48. package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
  49. package/dist/providers/SnapAccountProvider.d.mts +1 -1
  50. package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
  51. package/dist/providers/SnapAccountProvider.mjs.map +1 -1
  52. package/dist/providers/SolAccountProvider.cjs +1 -1
  53. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  54. package/dist/providers/SolAccountProvider.d.cts +1 -1
  55. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  56. package/dist/providers/SolAccountProvider.d.mts +1 -1
  57. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  58. package/dist/providers/SolAccountProvider.mjs +1 -1
  59. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  60. package/dist/tests/accounts.cjs +2 -2
  61. package/dist/tests/accounts.cjs.map +1 -1
  62. package/dist/tests/accounts.mjs +2 -2
  63. package/dist/tests/accounts.mjs.map +1 -1
  64. package/dist/tests/providers.cjs +5 -4
  65. package/dist/tests/providers.cjs.map +1 -1
  66. package/dist/tests/providers.d.cts +3 -2
  67. package/dist/tests/providers.d.cts.map +1 -1
  68. package/dist/tests/providers.d.mts +3 -2
  69. package/dist/tests/providers.d.mts.map +1 -1
  70. package/dist/tests/providers.mjs +3 -2
  71. package/dist/tests/providers.mjs.map +1 -1
  72. package/dist/types.cjs.map +1 -1
  73. package/dist/types.d.cts +7 -7
  74. package/dist/types.d.cts.map +1 -1
  75. package/dist/types.d.mts +7 -7
  76. package/dist/types.d.mts.map +1 -1
  77. package/dist/types.mjs.map +1 -1
  78. package/package.json +9 -8
@@ -1 +1 @@
1
- {"version":3,"file":"MultichainAccountWallet.d.cts","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EACV,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,IAAI,iCAAiC,EAC7D,8BAA8B;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAC5D,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAG/B,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAAoB;AACxD,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AAYjE;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC,CAAC;AAIF;;;GAGG;AACH,qBAAa,uBAAuB,CAClC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,CAC5C,YAAW,iCAAiC,CAAC,OAAO,CAAC;;gBAiBzC,EACV,SAAS,EACT,aAAa,EACb,SAAS,GACV,EAAE;QACD,SAAS,EAAE,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,aAAa,EAAE,eAAe,CAAC;QAC/B,SAAS,EAAE,iCAAiC,CAAC;KAC9C;IAYD;;;;;OAKG;IAC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C,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IA8F3C;;;;;OAKG;IACG,gCAAgC,IAAI,OAAO,CAC/C,sBAAsB,CAAC,OAAO,CAAC,CAChC;IAcD;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAMpC;;;;;;OAMG;IACG,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASnD;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAyE7C"}
@@ -1,16 +1,10 @@
1
1
  import { AccountWalletType } from "@metamask/account-api";
2
- import type { Bip44Account, MultichainAccountWalletId, MultichainAccountWallet as MultichainAccountWalletDefinition } from "@metamask/account-api";
2
+ import type { Bip44Account, MultichainAccountWalletId, MultichainAccountWallet as MultichainAccountWalletDefinition, MultichainAccountWalletStatus } from "@metamask/account-api";
3
3
  import type { AccountGroupId } from "@metamask/account-api";
4
4
  import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api";
5
5
  import { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
6
6
  import type { NamedAccountProvider } from "./providers/index.mjs";
7
7
  import type { MultichainAccountServiceMessenger } from "./types.mjs";
8
- /**
9
- * The metrics resulting from account discovery.
10
- */
11
- export type AccountDiscoveryMetrics = {
12
- [providerName: string]: number;
13
- };
14
8
  /**
15
9
  * A multichain account wallet that holds multiple multichain accounts (one multichain account per
16
10
  * group index).
@@ -47,6 +41,12 @@ export declare class MultichainAccountWallet<Account extends Bip44Account<Keyrin
47
41
  * @returns The multichain account wallet entropy source.
48
42
  */
49
43
  get entropySource(): EntropySourceId;
44
+ /**
45
+ * Gets the multichain account wallet current status.
46
+ *
47
+ * @returns The multichain account wallet current status.
48
+ */
49
+ get status(): MultichainAccountWalletStatus;
50
50
  /**
51
51
  * Gets multichain account for a given ID.
52
52
  * The default group ID will default to the multichain account with index 0.
@@ -83,6 +83,8 @@ export declare class MultichainAccountWallet<Account extends Bip44Account<Keyrin
83
83
  /**
84
84
  * Creates a multichain account group for a given group index.
85
85
  *
86
+ * NOTE: This operation WILL lock the wallet's mutex.
87
+ *
86
88
  * @param groupIndex - The group index to use.
87
89
  * @throws If any of the account providers fails to create their accounts.
88
90
  * @returns The multichain account group for this group index.
@@ -96,26 +98,26 @@ export declare class MultichainAccountWallet<Account extends Bip44Account<Keyrin
96
98
  */
97
99
  createNextMultichainAccountGroup(): Promise<MultichainAccountGroup<Account>>;
98
100
  /**
99
- * Gets whether alignment is currently in progress for this wallet.
101
+ * Align all accounts from each existing multichain account groups.
100
102
  *
101
- * @returns True if alignment is in progress, false otherwise.
102
- */
103
- getIsAlignmentInProgress(): boolean;
104
- /**
105
- * Align all multichain account groups.
103
+ * NOTE: This operation WILL lock the wallet's mutex.
106
104
  */
107
- alignGroups(): Promise<void>;
105
+ alignAccounts(): Promise<void>;
108
106
  /**
109
107
  * Align a specific multichain account group.
110
108
  *
109
+ * NOTE: This operation WILL lock the wallet's mutex.
110
+ *
111
111
  * @param groupIndex - The group index to align.
112
112
  */
113
113
  alignGroup(groupIndex: number): Promise<void>;
114
114
  /**
115
115
  * Discover and create accounts for all providers.
116
116
  *
117
+ * NOTE: This operation WILL lock the wallet's mutex.
118
+ *
117
119
  * @returns The discovered accounts for each provider.
118
120
  */
119
- discoverAndCreateAccounts(): Promise<AccountDiscoveryMetrics>;
121
+ discoverAccounts(): Promise<Account[]>;
120
122
  }
121
123
  //# sourceMappingURL=MultichainAccountWallet.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MultichainAccountWallet.d.mts","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EACV,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,IAAI,iCAAiC,EAC7D,8BAA8B;AAC/B,OAAO,KAAK,EAAE,cAAc,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DZ;;;;OAIG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAElC;IAED;;;;OAIG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAEpC;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,eAAe,CAEnC;IAED;;;;OAIG;IACH,IAAI,MAAM,IAAI,6BAA6B,CAE1C;IAkCD;;;;;;OAMG;IACH,eAAe,CACb,EAAE,EAAE,cAAc,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS;IAgB9C;;;;OAIG;IACH,gBAAgB,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE;IAIrD;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS;IAI9C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE;IAI/D;;;;OAIG;IACH,iBAAiB,IAAI,MAAM;IAU3B;;;;;;;;OAQG;IACG,4BAA4B,CAChC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IA8F3C;;;;;OAKG;IACG,gCAAgC,IAAI,OAAO,CAC/C,sBAAsB,CAAC,OAAO,CAAC,CAChC;IAcD;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAMpC;;;;;;OAMG;IACG,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASnD;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAyE7C"}
@@ -9,11 +9,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accountGroups, _MultichainAccountWallet_messenger, _MultichainAccountWallet_initialized, _MultichainAccountWallet_isAlignmentInProgress;
12
+ var _MultichainAccountWallet_instances, _MultichainAccountWallet_lock, _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accountGroups, _MultichainAccountWallet_messenger, _MultichainAccountWallet_initialized, _MultichainAccountWallet_status, _MultichainAccountWallet_withLock, _MultichainAccountWallet_alignAccounts;
13
13
  import { getGroupIndexFromMultichainAccountGroupId, isMultichainAccountGroupId, toMultichainAccountWalletId } from "@metamask/account-api";
14
14
  import { toDefaultAccountGroupId } from "@metamask/account-api";
15
15
  import { AccountWalletType } from "@metamask/account-api";
16
16
  import { createProjectLogger } from "@metamask/utils";
17
+ import { Mutex } from "async-mutex";
17
18
  import { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
18
19
  const log = createProjectLogger('multichain-account-service');
19
20
  /**
@@ -22,6 +23,8 @@ const log = createProjectLogger('multichain-account-service');
22
23
  */
23
24
  export class MultichainAccountWallet {
24
25
  constructor({ providers, entropySource, messenger, }) {
26
+ _MultichainAccountWallet_instances.add(this);
27
+ _MultichainAccountWallet_lock.set(this, new Mutex());
25
28
  _MultichainAccountWallet_id.set(this, void 0);
26
29
  _MultichainAccountWallet_providers.set(this, void 0);
27
30
  _MultichainAccountWallet_entropySource.set(this, void 0);
@@ -29,15 +32,17 @@ export class MultichainAccountWallet {
29
32
  _MultichainAccountWallet_messenger.set(this, void 0);
30
33
  // eslint-disable-next-line @typescript-eslint/prefer-readonly
31
34
  _MultichainAccountWallet_initialized.set(this, false);
32
- _MultichainAccountWallet_isAlignmentInProgress.set(this, false);
35
+ _MultichainAccountWallet_status.set(this, void 0);
33
36
  __classPrivateFieldSet(this, _MultichainAccountWallet_id, toMultichainAccountWalletId(entropySource), "f");
34
37
  __classPrivateFieldSet(this, _MultichainAccountWallet_providers, providers, "f");
35
38
  __classPrivateFieldSet(this, _MultichainAccountWallet_entropySource, entropySource, "f");
36
39
  __classPrivateFieldSet(this, _MultichainAccountWallet_messenger, messenger, "f");
37
40
  __classPrivateFieldSet(this, _MultichainAccountWallet_accountGroups, new Map(), "f");
38
41
  // Initial synchronization (don't emit events during initialization).
42
+ __classPrivateFieldSet(this, _MultichainAccountWallet_status, 'uninitialized', "f");
39
43
  this.sync();
40
44
  __classPrivateFieldSet(this, _MultichainAccountWallet_initialized, true, "f");
45
+ __classPrivateFieldSet(this, _MultichainAccountWallet_status, 'ready', "f");
41
46
  }
42
47
  /**
43
48
  * Force wallet synchronization.
@@ -108,6 +113,14 @@ export class MultichainAccountWallet {
108
113
  get entropySource() {
109
114
  return __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f");
110
115
  }
116
+ /**
117
+ * Gets the multichain account wallet current status.
118
+ *
119
+ * @returns The multichain account wallet current status.
120
+ */
121
+ get status() {
122
+ return __classPrivateFieldGet(this, _MultichainAccountWallet_status, "f");
123
+ }
111
124
  /**
112
125
  * Gets multichain account for a given ID.
113
126
  * The default group ID will default to the multichain account with index 0.
@@ -166,80 +179,84 @@ export class MultichainAccountWallet {
166
179
  /**
167
180
  * Creates a multichain account group for a given group index.
168
181
  *
182
+ * NOTE: This operation WILL lock the wallet's mutex.
183
+ *
169
184
  * @param groupIndex - The group index to use.
170
185
  * @throws If any of the account providers fails to create their accounts.
171
186
  * @returns The multichain account group for this group index.
172
187
  */
173
188
  async createMultichainAccountGroup(groupIndex) {
174
- const nextGroupIndex = this.getNextGroupIndex();
175
- if (groupIndex > nextGroupIndex) {
176
- throw new Error(`You cannot use a group index that is higher than the next available one: expected <=${nextGroupIndex}, got ${groupIndex}`);
177
- }
178
- let group = this.getMultichainAccountGroup(groupIndex);
179
- if (group) {
180
- // If the group already exists, we just `sync` it and returns the same
181
- // reference.
182
- group.sync();
183
- return group;
184
- }
185
- const results = await Promise.allSettled(__classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f").map((provider) => provider.createAccounts({
186
- entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
187
- groupIndex,
188
- })));
189
- // --------------------------------------------------------------------------------
190
- // READ THIS CAREFULLY:
191
- //
192
- // Since we're not "fully supporting multichain" for now, we still rely on single
193
- // :accountCreated events to sync multichain account groups and wallets. Which means
194
- // that even if of the provider fails, some accounts will still be created on some
195
- // other providers and will become "available" on the `AccountsController`, like:
196
- //
197
- // 1. Creating a multichain account group for index 1
198
- // 2. EvmAccountProvider.createAccounts returns the EVM account for index 1
199
- // * AccountsController WILL fire :accountCreated for this account
200
- // * This account WILL BE "available" on the AccountsController state
201
- // 3. SolAccountProvider.createAccounts fails to create a Solana account for index 1
202
- // * AccountsController WON't fire :accountCreated for this account
203
- // * This account WON'T be "available" on the Account
204
- // 4. MultichainAccountService will receive a :accountCreated for the EVM account from
205
- // step 2 and will create a new multichain account group for index 1, but it won't
206
- // receive any event for the Solana account of this group. Thus, this group won't be
207
- // "aligned" (missing "blockchain account" on this group).
208
- //
209
- // --------------------------------------------------------------------------------
210
- // If any of the provider failed to create their accounts, then we consider the
211
- // multichain account group to have failed too.
212
- if (results.some((result) => result.status === 'rejected')) {
213
- // NOTE: Some accounts might still have been created on other account providers. We
214
- // don't rollback them.
215
- const error = `Unable to create multichain account group for index: ${groupIndex}`;
216
- let warn = `${error}:`;
217
- for (const result of results) {
218
- if (result.status === 'rejected') {
219
- warn += `\n- ${result.reason}`;
220
- }
189
+ return await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_withLock).call(this, 'in-progress:create-accounts', async () => {
190
+ const nextGroupIndex = this.getNextGroupIndex();
191
+ if (groupIndex > nextGroupIndex) {
192
+ throw new Error(`You cannot use a group index that is higher than the next available one: expected <=${nextGroupIndex}, got ${groupIndex}`);
221
193
  }
222
- console.warn(warn);
223
- throw new Error(error);
224
- }
225
- // Because of the :accountAdded automatic sync, we might already have created the
226
- // group, so we first try to get it.
227
- group = this.getMultichainAccountGroup(groupIndex);
228
- if (!group) {
229
- // If for some reason it's still not created, we're creating it explicitly now:
230
- group = new MultichainAccountGroup({
231
- wallet: this,
232
- providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
194
+ let group = this.getMultichainAccountGroup(groupIndex);
195
+ if (group) {
196
+ // If the group already exists, we just `sync` it and returns the same
197
+ // reference.
198
+ group.sync();
199
+ return group;
200
+ }
201
+ const results = await Promise.allSettled(__classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f").map((provider) => provider.createAccounts({
202
+ entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
233
203
  groupIndex,
234
- messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
235
- });
236
- }
237
- // Register the account to our internal map.
238
- __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group); // `group` cannot be undefined here.
239
- if (__classPrivateFieldGet(this, _MultichainAccountWallet_initialized, "f")) {
240
- __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").publish('MultichainAccountService:multichainAccountGroupCreated', group);
241
- }
242
- return group;
204
+ })));
205
+ // --------------------------------------------------------------------------------
206
+ // READ THIS CAREFULLY:
207
+ //
208
+ // Since we're not "fully supporting multichain" for now, we still rely on single
209
+ // :accountCreated events to sync multichain account groups and wallets. Which means
210
+ // that even if of the provider fails, some accounts will still be created on some
211
+ // other providers and will become "available" on the `AccountsController`, like:
212
+ //
213
+ // 1. Creating a multichain account group for index 1
214
+ // 2. EvmAccountProvider.createAccounts returns the EVM account for index 1
215
+ // * AccountsController WILL fire :accountCreated for this account
216
+ // * This account WILL BE "available" on the AccountsController state
217
+ // 3. SolAccountProvider.createAccounts fails to create a Solana account for index 1
218
+ // * AccountsController WON't fire :accountCreated for this account
219
+ // * This account WON'T be "available" on the Account
220
+ // 4. MultichainAccountService will receive a :accountCreated for the EVM account from
221
+ // step 2 and will create a new multichain account group for index 1, but it won't
222
+ // receive any event for the Solana account of this group. Thus, this group won't be
223
+ // "aligned" (missing "blockchain account" on this group).
224
+ //
225
+ // --------------------------------------------------------------------------------
226
+ // If any of the provider failed to create their accounts, then we consider the
227
+ // multichain account group to have failed too.
228
+ if (results.some((result) => result.status === 'rejected')) {
229
+ // NOTE: Some accounts might still have been created on other account providers. We
230
+ // don't rollback them.
231
+ const error = `Unable to create multichain account group for index: ${groupIndex}`;
232
+ let warn = `${error}:`;
233
+ for (const result of results) {
234
+ if (result.status === 'rejected') {
235
+ warn += `\n- ${result.reason}`;
236
+ }
237
+ }
238
+ console.warn(warn);
239
+ throw new Error(error);
240
+ }
241
+ // Because of the :accountAdded automatic sync, we might already have created the
242
+ // group, so we first try to get it.
243
+ group = this.getMultichainAccountGroup(groupIndex);
244
+ if (!group) {
245
+ // If for some reason it's still not created, we're creating it explicitly now:
246
+ group = new MultichainAccountGroup({
247
+ wallet: this,
248
+ providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
249
+ groupIndex,
250
+ messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
251
+ });
252
+ }
253
+ // Register the account to our internal map.
254
+ __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group); // `group` cannot be undefined here.
255
+ if (__classPrivateFieldGet(this, _MultichainAccountWallet_initialized, "f")) {
256
+ __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").publish('MultichainAccountService:multichainAccountGroupCreated', group);
257
+ }
258
+ return group;
259
+ });
243
260
  }
244
261
  /**
245
262
  * Creates the next multichain account group.
@@ -251,113 +268,123 @@ export class MultichainAccountWallet {
251
268
  return this.createMultichainAccountGroup(this.getNextGroupIndex());
252
269
  }
253
270
  /**
254
- * Gets whether alignment is currently in progress for this wallet.
271
+ * Align all accounts from each existing multichain account groups.
255
272
  *
256
- * @returns True if alignment is in progress, false otherwise.
257
- */
258
- getIsAlignmentInProgress() {
259
- return __classPrivateFieldGet(this, _MultichainAccountWallet_isAlignmentInProgress, "f");
260
- }
261
- /**
262
- * Align all multichain account groups.
273
+ * NOTE: This operation WILL lock the wallet's mutex.
263
274
  */
264
- async alignGroups() {
265
- if (__classPrivateFieldGet(this, _MultichainAccountWallet_isAlignmentInProgress, "f")) {
266
- return; // Prevent concurrent alignments
267
- }
268
- __classPrivateFieldSet(this, _MultichainAccountWallet_isAlignmentInProgress, true, "f");
269
- try {
270
- const groups = this.getMultichainAccountGroups();
271
- await Promise.all(groups.map((g) => g.align()));
272
- }
273
- finally {
274
- __classPrivateFieldSet(this, _MultichainAccountWallet_isAlignmentInProgress, false, "f");
275
- }
275
+ async alignAccounts() {
276
+ await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_withLock).call(this, 'in-progress:alignment', async () => {
277
+ await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_alignAccounts).call(this);
278
+ });
276
279
  }
277
280
  /**
278
281
  * Align a specific multichain account group.
279
282
  *
283
+ * NOTE: This operation WILL lock the wallet's mutex.
284
+ *
280
285
  * @param groupIndex - The group index to align.
281
286
  */
282
287
  async alignGroup(groupIndex) {
283
- if (__classPrivateFieldGet(this, _MultichainAccountWallet_isAlignmentInProgress, "f")) {
284
- return; // Prevent concurrent alignments
285
- }
286
- __classPrivateFieldSet(this, _MultichainAccountWallet_isAlignmentInProgress, true, "f");
287
- try {
288
+ await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_withLock).call(this, 'in-progress:alignment', async () => {
288
289
  const group = this.getMultichainAccountGroup(groupIndex);
289
290
  if (group) {
290
291
  await group.align();
291
292
  }
292
- }
293
- finally {
294
- __classPrivateFieldSet(this, _MultichainAccountWallet_isAlignmentInProgress, false, "f");
295
- }
293
+ });
296
294
  }
297
295
  /**
298
296
  * Discover and create accounts for all providers.
299
297
  *
298
+ * NOTE: This operation WILL lock the wallet's mutex.
299
+ *
300
300
  * @returns The discovered accounts for each provider.
301
301
  */
302
- async discoverAndCreateAccounts() {
303
- // Start with the next available group index (so we can resume the discovery
304
- // from there).
305
- let maxGroupIndex = this.getNextGroupIndex();
306
- // One serialized loop per provider; all run concurrently
307
- const runProviderDiscovery = async (context) => {
308
- const message = (stepName, groupIndex) => `[${context.provider.getName()}] Discovery ${stepName} (groupIndex=${groupIndex})`;
309
- while (!context.stopped) {
310
- // Fast‑forward to current high‑water mark
311
- const targetGroupIndex = Math.max(context.groupIndex, maxGroupIndex);
312
- log(message('STARTED', targetGroupIndex));
313
- let accounts = [];
314
- try {
315
- accounts = await context.provider.discoverAndCreateAccounts({
316
- entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
317
- groupIndex: targetGroupIndex,
318
- });
319
- }
320
- catch (error) {
321
- context.stopped = true;
322
- console.error(error);
323
- log(message('FAILED', targetGroupIndex), error);
324
- break;
325
- }
326
- if (!accounts.length) {
327
- log(message('STOPPED', targetGroupIndex));
328
- context.stopped = true;
329
- break;
302
+ async discoverAccounts() {
303
+ return __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_withLock).call(this, 'in-progress:discovery', async () => {
304
+ // Start with the next available group index (so we can resume the discovery
305
+ // from there).
306
+ let maxGroupIndex = this.getNextGroupIndex();
307
+ // One serialized loop per provider; all run concurrently
308
+ const runProviderDiscovery = async (context) => {
309
+ const message = (stepName, groupIndex) => `[${context.provider.getName()}] Discovery ${stepName} (groupIndex=${groupIndex})`;
310
+ while (!context.stopped) {
311
+ // Fast‑forward to current high‑water mark
312
+ const targetGroupIndex = Math.max(context.groupIndex, maxGroupIndex);
313
+ log(message('STARTED', targetGroupIndex));
314
+ let accounts = [];
315
+ try {
316
+ accounts = await context.provider.discoverAccounts({
317
+ entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
318
+ groupIndex: targetGroupIndex,
319
+ });
320
+ }
321
+ catch (error) {
322
+ context.stopped = true;
323
+ console.error(error);
324
+ log(message('FAILED', targetGroupIndex), error);
325
+ break;
326
+ }
327
+ if (!accounts.length) {
328
+ log(message('STOPPED', targetGroupIndex));
329
+ context.stopped = true;
330
+ break;
331
+ }
332
+ log(message('SUCCEEDED', targetGroupIndex));
333
+ context.accounts = context.accounts.concat(accounts);
334
+ const nextGroupIndex = targetGroupIndex + 1;
335
+ context.groupIndex = nextGroupIndex;
336
+ if (nextGroupIndex > maxGroupIndex) {
337
+ maxGroupIndex = nextGroupIndex;
338
+ }
330
339
  }
331
- log(message('SUCCEEDED', targetGroupIndex));
332
- context.count += accounts.length;
333
- const nextGroupIndex = targetGroupIndex + 1;
334
- context.groupIndex = nextGroupIndex;
335
- if (nextGroupIndex > maxGroupIndex) {
336
- maxGroupIndex = nextGroupIndex;
337
- }
338
- }
339
- };
340
- const providerContexts = __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f").map((provider) => ({
341
- provider,
342
- stopped: false,
343
- groupIndex: maxGroupIndex,
344
- count: 0,
345
- }));
346
- // Start discovery for each providers.
347
- await Promise.all(providerContexts.map(runProviderDiscovery));
348
- // Sync the wallet after discovery to ensure that the newly added accounts are added into their groups.
349
- // We can potentially remove this if we know that this race condition is not an issue in practice.
350
- this.sync();
351
- // Align missing accounts from group. This is required to create missing account from non-discovered
352
- // indexes for some providers.
353
- await this.alignGroups();
354
- const discoveredAccounts = {};
355
- for (const context of providerContexts) {
356
- const providerName = context.provider.getName();
357
- discoveredAccounts[providerName] = context.count;
358
- }
359
- return discoveredAccounts;
340
+ };
341
+ const providerContexts = __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f").map((provider) => ({
342
+ provider,
343
+ stopped: false,
344
+ groupIndex: maxGroupIndex,
345
+ accounts: [],
346
+ }));
347
+ // Start discovery for each providers.
348
+ await Promise.all(providerContexts.map(runProviderDiscovery));
349
+ // Sync the wallet after discovery to ensure that the newly added accounts are added into their groups.
350
+ // We can potentially remove this if we know that this race condition is not an issue in practice.
351
+ this.sync();
352
+ // Align missing accounts from group. This is required to create missing account from non-discovered
353
+ // indexes for some providers.
354
+ await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_alignAccounts).call(this);
355
+ return providerContexts.flatMap((context) => context.accounts);
356
+ });
360
357
  }
361
358
  }
362
- _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accountGroups = new WeakMap(), _MultichainAccountWallet_messenger = new WeakMap(), _MultichainAccountWallet_initialized = new WeakMap(), _MultichainAccountWallet_isAlignmentInProgress = new WeakMap();
359
+ _MultichainAccountWallet_lock = new WeakMap(), _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accountGroups = new WeakMap(), _MultichainAccountWallet_messenger = new WeakMap(), _MultichainAccountWallet_initialized = new WeakMap(), _MultichainAccountWallet_status = new WeakMap(), _MultichainAccountWallet_instances = new WeakSet(), _MultichainAccountWallet_withLock =
360
+ /**
361
+ * Set the wallet status and run the associated operation callback.
362
+ *
363
+ * @param status - Wallet status associated with this operation.
364
+ * @param operation - Operation to run.
365
+ * @returns The operation's result.
366
+ * @throws {Error} If the wallet is already running a mutable operation.
367
+ */
368
+ async function _MultichainAccountWallet_withLock(status, operation) {
369
+ const release = await __classPrivateFieldGet(this, _MultichainAccountWallet_lock, "f").acquire();
370
+ try {
371
+ __classPrivateFieldSet(this, _MultichainAccountWallet_status, status, "f");
372
+ __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").publish('MultichainAccountService:walletStatusChange', this.id, __classPrivateFieldGet(this, _MultichainAccountWallet_status, "f"));
373
+ return await operation();
374
+ }
375
+ finally {
376
+ __classPrivateFieldSet(this, _MultichainAccountWallet_status, 'ready', "f");
377
+ __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").publish('MultichainAccountService:walletStatusChange', this.id, __classPrivateFieldGet(this, _MultichainAccountWallet_status, "f"));
378
+ release();
379
+ }
380
+ }, _MultichainAccountWallet_alignAccounts =
381
+ /**
382
+ * Align all multichain account groups.
383
+ *
384
+ * NOTE: This operation WILL NOT lock the wallet's mutex.
385
+ */
386
+ async function _MultichainAccountWallet_alignAccounts() {
387
+ const groups = this.getMultichainAccountGroups();
388
+ await Promise.all(groups.map((group) => group.align()));
389
+ };
363
390
  //# sourceMappingURL=MultichainAccountWallet.mjs.map