@metamask-previews/account-api 0.3.0-9522cc5 → 0.6.0-9cb78a8

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 (56) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/dist/api/group.cjs +1 -1
  3. package/dist/api/group.cjs.map +1 -1
  4. package/dist/api/group.d.cts +9 -4
  5. package/dist/api/group.d.cts.map +1 -1
  6. package/dist/api/group.d.mts +9 -4
  7. package/dist/api/group.d.mts.map +1 -1
  8. package/dist/api/group.mjs +1 -1
  9. package/dist/api/group.mjs.map +1 -1
  10. package/dist/api/multichain/group.cjs +42 -0
  11. package/dist/api/multichain/group.cjs.map +1 -0
  12. package/dist/api/multichain/group.d.cts +68 -0
  13. package/dist/api/multichain/group.d.cts.map +1 -0
  14. package/dist/api/multichain/group.d.mts +68 -0
  15. package/dist/api/multichain/group.d.mts.map +1 -0
  16. package/dist/api/multichain/group.mjs +37 -0
  17. package/dist/api/multichain/group.mjs.map +1 -0
  18. package/dist/api/multichain/index.cjs +1 -1
  19. package/dist/api/multichain/index.cjs.map +1 -1
  20. package/dist/api/multichain/index.d.cts +1 -1
  21. package/dist/api/multichain/index.d.cts.map +1 -1
  22. package/dist/api/multichain/index.d.mts +1 -1
  23. package/dist/api/multichain/index.d.mts.map +1 -1
  24. package/dist/api/multichain/index.mjs +1 -1
  25. package/dist/api/multichain/index.mjs.map +1 -1
  26. package/dist/api/multichain/wallet.cjs +0 -139
  27. package/dist/api/multichain/wallet.cjs.map +1 -1
  28. package/dist/api/multichain/wallet.d.cts +8 -42
  29. package/dist/api/multichain/wallet.d.cts.map +1 -1
  30. package/dist/api/multichain/wallet.d.mts +8 -42
  31. package/dist/api/multichain/wallet.d.mts.map +1 -1
  32. package/dist/api/multichain/wallet.mjs +0 -137
  33. package/dist/api/multichain/wallet.mjs.map +1 -1
  34. package/dist/api/provider.cjs.map +1 -1
  35. package/dist/api/provider.d.cts +30 -2
  36. package/dist/api/provider.d.cts.map +1 -1
  37. package/dist/api/provider.d.mts +30 -2
  38. package/dist/api/provider.d.mts.map +1 -1
  39. package/dist/api/provider.mjs.map +1 -1
  40. package/dist/api/wallet.cjs +3 -9
  41. package/dist/api/wallet.cjs.map +1 -1
  42. package/dist/api/wallet.d.cts +9 -10
  43. package/dist/api/wallet.d.cts.map +1 -1
  44. package/dist/api/wallet.d.mts +9 -10
  45. package/dist/api/wallet.d.mts.map +1 -1
  46. package/dist/api/wallet.mjs +3 -9
  47. package/dist/api/wallet.mjs.map +1 -1
  48. package/package.json +2 -5
  49. package/dist/api/multichain/account.cjs +0 -230
  50. package/dist/api/multichain/account.cjs.map +0 -1
  51. package/dist/api/multichain/account.d.cts +0 -110
  52. package/dist/api/multichain/account.d.cts.map +0 -1
  53. package/dist/api/multichain/account.d.mts +0 -110
  54. package/dist/api/multichain/account.d.mts.map +0 -1
  55. package/dist/api/multichain/account.mjs +0 -223
  56. package/dist/api/multichain/account.mjs.map +0 -1
@@ -1,146 +1,7 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- 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");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accounts;
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.MultichainAccountWallet = void 0;
16
3
  exports.toMultichainAccountWalletId = toMultichainAccountWalletId;
17
- const account_1 = require("./account.cjs");
18
- const group_1 = require("../group.cjs");
19
4
  const wallet_1 = require("../wallet.cjs");
20
- /**
21
- * A multichain account wallet that holds multiple multichain accounts (one multichain account per
22
- * group index).
23
- */
24
- class MultichainAccountWallet {
25
- constructor({ providers, entropySource, }) {
26
- _MultichainAccountWallet_id.set(this, void 0);
27
- _MultichainAccountWallet_providers.set(this, void 0);
28
- _MultichainAccountWallet_entropySource.set(this, void 0);
29
- _MultichainAccountWallet_accounts.set(this, void 0);
30
- __classPrivateFieldSet(this, _MultichainAccountWallet_id, toMultichainAccountWalletId(entropySource), "f");
31
- __classPrivateFieldSet(this, _MultichainAccountWallet_providers, providers, "f");
32
- __classPrivateFieldSet(this, _MultichainAccountWallet_entropySource, entropySource, "f");
33
- __classPrivateFieldSet(this, _MultichainAccountWallet_accounts, new Map(), "f");
34
- // Initial synchronization.
35
- this.sync();
36
- }
37
- /**
38
- * Force wallet synchronization.
39
- *
40
- * This can be used if account providers got new accounts that the wallet
41
- * doesn't know about.
42
- */
43
- sync() {
44
- for (const provider of __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f")) {
45
- for (const account of provider.getAccounts()) {
46
- const { entropy } = account.options;
47
- // Filter for this wallet only.
48
- if (entropy.id !== this.entropySource) {
49
- continue;
50
- }
51
- // This multichain account might exists already.
52
- let multichainAccount = __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(entropy.groupIndex);
53
- if (!multichainAccount) {
54
- multichainAccount = new account_1.MultichainAccount({
55
- groupIndex: entropy.groupIndex,
56
- wallet: this,
57
- providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
58
- });
59
- __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").set(entropy.groupIndex, multichainAccount);
60
- }
61
- }
62
- }
63
- // Now force-sync all remaining multichain accounts.
64
- for (const [groupIndex, multichainAccount] of __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").entries()) {
65
- multichainAccount.sync();
66
- // Clean up old multichain accounts.
67
- if (!multichainAccount.hasAccounts()) {
68
- __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").delete(groupIndex);
69
- }
70
- }
71
- }
72
- /**
73
- * Gets the multichain account wallet ID.
74
- *
75
- * @returns The multichain account wallet ID.
76
- */
77
- get id() {
78
- return __classPrivateFieldGet(this, _MultichainAccountWallet_id, "f");
79
- }
80
- /**
81
- * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
82
- *
83
- * @returns The multichain account wallet type.
84
- */
85
- get type() {
86
- return wallet_1.AccountWalletType.Entropy;
87
- }
88
- /**
89
- * Gets the multichain account wallet entropy source.
90
- *
91
- * @returns The multichain account wallet entropy source.
92
- */
93
- get entropySource() {
94
- return __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f");
95
- }
96
- /**
97
- * Gets multichain account for a given ID.
98
- * The default group ID will default to the multichain account with index 0.
99
- *
100
- * @param id - Account group ID.
101
- * @returns Account group.
102
- */
103
- getAccountGroup(id) {
104
- // We consider the "default case" to be mapped to index 0.
105
- if (id === (0, group_1.toDefaultAccountGroupId)(this.id)) {
106
- return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(0);
107
- }
108
- // If it is not a valid ID, we cannot extract the group index
109
- // from it, so we fail fast.
110
- if (!(0, account_1.isMultichainAccountId)(id)) {
111
- return undefined;
112
- }
113
- const groupIndex = (0, account_1.getGroupIndexFromMultichainAccountId)(id);
114
- return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
115
- }
116
- /**
117
- * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
118
- *
119
- * @returns The multichain accounts.
120
- */
121
- getAccountGroups() {
122
- return this.getMultichainAccounts();
123
- }
124
- /**
125
- * Gets multichain account for a given index.
126
- *
127
- * @param groupIndex - Multichain account index.
128
- * @returns The multichain account associated with the given index.
129
- */
130
- getMultichainAccount(groupIndex) {
131
- return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
132
- }
133
- /**
134
- * Gets all multichain accounts.
135
- *
136
- * @returns The multichain accounts.
137
- */
138
- getMultichainAccounts() {
139
- return Array.from(__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").values()); // TODO: Prevent copy here.
140
- }
141
- }
142
- exports.MultichainAccountWallet = MultichainAccountWallet;
143
- _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accounts = new WeakMap();
144
5
  /**
145
6
  * Gets the multichain account wallet ID from its entropy source.
146
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuLA,kEAIC;AAtLD,2CAImB;AAGnB,wCAAmD;AAGnD,0CAA8C;AAQ9C;;;GAGG;AACH,MAAa,uBAAuB;IAYlC,YAAY,EACV,SAAS,EACT,aAAa,GAId;QAdQ,8CAA+B;QAE/B,qDAAuC;QAEvC,yDAAgC;QAEhC,oDAAmD;QAS1D,uBAAA,IAAI,+BAAO,2BAA2B,CAAC,aAAa,CAAC,MAAA,CAAC;QACtD,uBAAA,IAAI,sCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,qCAAa,IAAI,GAAG,EAAE,MAAA,CAAC;QAE3B,2BAA2B;QAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,IAAI;QACF,KAAK,MAAM,QAAQ,IAAI,uBAAA,IAAI,0CAAW,EAAE,CAAC;YACvC,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC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IACH,eAAe,CAAC,EAAkB;QAChC,0DAA0D;QAC1D,IAAI,EAAE,KAAK,IAAA,+BAAuB,EAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5C,OAAO,uBAAA,IAAI,yCAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;QAED,6DAA6D;QAC7D,4BAA4B;QAC5B,IAAI,CAAC,IAAA,+BAAqB,EAAC,EAAE,CAAC,EAAE,CAAC;YAC/B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,UAAU,GAAG,IAAA,8CAAoC,EAAC,EAAE,CAAC,CAAC;QAC5D,OAAO,uBAAA,IAAI,yCAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAClB,UAAkB;QAElB,OAAO,uBAAA,IAAI,yCAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,qBAAqB;QACnB,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,yCAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,2BAA2B;IACzE,CAAC;CACF;AApJD,0DAoJC;;AAED;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,0BAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport {\n getGroupIndexFromMultichainAccountId,\n isMultichainAccountId,\n MultichainAccount,\n} from './account';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountGroupId } from '../group';\nimport { toDefaultAccountGroupId } from '../group';\nimport type { AccountProvider } from '../provider';\nimport type { AccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport class MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> implements AccountWallet<Account>\n{\n readonly #id: MultichainAccountWalletId;\n\n readonly #providers: AccountProvider<Account>[];\n\n readonly #entropySource: EntropySourceId;\n\n readonly #accounts: Map<number, MultichainAccount<Account>>;\n\n constructor({\n providers,\n entropySource,\n }: {\n providers: AccountProvider<Account>[];\n entropySource: EntropySourceId;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#accounts = new Map();\n\n // Initial synchronization.\n this.sync();\n }\n\n /**\n * Force wallet synchronization.\n *\n * This can be used if account providers got new accounts that the wallet\n * doesn't know about.\n */\n sync(): void {\n for (const provider of this.#providers) {\n for (const account of provider.getAccounts()) {\n const { entropy } = account.options;\n\n // Filter for this wallet only.\n if (entropy.id !== this.entropySource) {\n continue;\n }\n\n // This multichain account might exists already.\n let multichainAccount = this.#accounts.get(entropy.groupIndex);\n if (!multichainAccount) {\n multichainAccount = new MultichainAccount<Account>({\n groupIndex: entropy.groupIndex,\n wallet: this,\n providers: this.#providers,\n });\n\n this.#accounts.set(entropy.groupIndex, multichainAccount);\n }\n }\n }\n\n // Now force-sync all remaining multichain accounts.\n for (const [groupIndex, multichainAccount] of this.#accounts.entries()) {\n multichainAccount.sync();\n\n // Clean up old multichain accounts.\n if (!multichainAccount.hasAccounts()) {\n this.#accounts.delete(groupIndex);\n }\n }\n }\n\n /**\n * Gets the multichain account wallet ID.\n *\n * @returns The multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId {\n return this.#id;\n }\n\n /**\n * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n *\n * @returns The multichain account wallet type.\n */\n get type(): AccountWalletType.Entropy {\n return AccountWalletType.Entropy;\n }\n\n /**\n * Gets the multichain account wallet entropy source.\n *\n * @returns The multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId {\n return this.#entropySource;\n }\n\n /**\n * Gets multichain account for a given ID.\n * The default group ID will default to the multichain account with index 0.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined {\n // We consider the \"default case\" to be mapped to index 0.\n if (id === toDefaultAccountGroupId(this.id)) {\n return this.#accounts.get(0);\n }\n\n // If it is not a valid ID, we cannot extract the group index\n // from it, so we fail fast.\n if (!isMultichainAccountId(id)) {\n return undefined;\n }\n\n const groupIndex = getGroupIndexFromMultichainAccountId(id);\n return this.#accounts.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.\n *\n * @returns The multichain accounts.\n */\n getAccountGroups(): MultichainAccount<Account>[] {\n return this.getMultichainAccounts();\n }\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccount(\n groupIndex: number,\n ): MultichainAccount<Account> | undefined {\n return this.#accounts.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccounts(): MultichainAccount<Account>[] {\n return Array.from(this.#accounts.values()); // TODO: Prevent copy here.\n }\n}\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n"]}
1
+ {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;AA8DA,kEAIC;AA1DD,0CAA8C;AAgD9C;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,0BAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport type { MultichainAccountGroup } from './group';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport type MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> = AccountWallet<Account> & {\n /**\n * Multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId;\n\n /**\n * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n */\n get type(): AccountWalletType.Entropy;\n\n /**\n * Multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId;\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined;\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[];\n};\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n"]}
@@ -1,8 +1,6 @@
1
1
  import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api";
2
- import { MultichainAccount } from "./account.cjs";
2
+ import type { MultichainAccountGroup } from "./group.cjs";
3
3
  import type { Bip44Account } from "../bip44.cjs";
4
- import type { AccountGroupId } from "../group.cjs";
5
- import type { AccountProvider } from "../provider.cjs";
6
4
  import type { AccountWallet } from "../wallet.cjs";
7
5
  import { AccountWalletType } from "../wallet.cjs";
8
6
  /**
@@ -13,65 +11,33 @@ export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropyS
13
11
  * A multichain account wallet that holds multiple multichain accounts (one multichain account per
14
12
  * group index).
15
13
  */
16
- export declare class MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> implements AccountWallet<Account> {
17
- #private;
18
- constructor({ providers, entropySource, }: {
19
- providers: AccountProvider<Account>[];
20
- entropySource: EntropySourceId;
21
- });
14
+ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = AccountWallet<Account> & {
22
15
  /**
23
- * Force wallet synchronization.
24
- *
25
- * This can be used if account providers got new accounts that the wallet
26
- * doesn't know about.
27
- */
28
- sync(): void;
29
- /**
30
- * Gets the multichain account wallet ID.
31
- *
32
- * @returns The multichain account wallet ID.
16
+ * Multichain account wallet ID.
33
17
  */
34
18
  get id(): MultichainAccountWalletId;
35
19
  /**
36
- * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
37
- *
38
- * @returns The multichain account wallet type.
20
+ * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
39
21
  */
40
22
  get type(): AccountWalletType.Entropy;
41
23
  /**
42
- * Gets the multichain account wallet entropy source.
43
- *
44
- * @returns The multichain account wallet entropy source.
24
+ * Multichain account wallet entropy source.
45
25
  */
46
26
  get entropySource(): EntropySourceId;
47
- /**
48
- * Gets multichain account for a given ID.
49
- * The default group ID will default to the multichain account with index 0.
50
- *
51
- * @param id - Account group ID.
52
- * @returns Account group.
53
- */
54
- getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined;
55
- /**
56
- * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
57
- *
58
- * @returns The multichain accounts.
59
- */
60
- getAccountGroups(): MultichainAccount<Account>[];
61
27
  /**
62
28
  * Gets multichain account for a given index.
63
29
  *
64
30
  * @param groupIndex - Multichain account index.
65
31
  * @returns The multichain account associated with the given index.
66
32
  */
67
- getMultichainAccount(groupIndex: number): MultichainAccount<Account> | undefined;
33
+ getMultichainAccountGroup(groupIndex: number): MultichainAccountGroup<Account> | undefined;
68
34
  /**
69
35
  * Gets all multichain accounts.
70
36
  *
71
37
  * @returns The multichain accounts.
72
38
  */
73
- getMultichainAccounts(): MultichainAccount<Account>[];
74
- }
39
+ getMultichainAccountGroups(): MultichainAccountGroup<Account>[];
40
+ };
75
41
  /**
76
42
  * Gets the multichain account wallet ID from its entropy source.
77
43
  *
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,EAGL,iBAAiB,EAClB,sBAAkB;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAoB;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAkB;AAC/C,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,GAAG,iBAAiB,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;AAEpD;;;GAGG;AACH,qBAAa,uBAAuB,CAClC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,CAC5C,YAAW,aAAa,CAAC,OAAO,CAAC;;gBAUrB,EACV,SAAS,EACT,aAAa,GACd,EAAE;QACD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,aAAa,EAAE,eAAe,CAAC;KAChC;IAUD;;;;;OAKG;IACH,IAAI,IAAI,IAAI;IAmCZ;;;;OAIG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAElC;IAED;;;;OAIG;IACH,IAAI,IAAI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;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
@@ -1,8 +1,6 @@
1
1
  import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api";
2
- import { MultichainAccount } from "./account.mjs";
2
+ import type { MultichainAccountGroup } from "./group.mjs";
3
3
  import type { Bip44Account } from "../bip44.mjs";
4
- import type { AccountGroupId } from "../group.mjs";
5
- import type { AccountProvider } from "../provider.mjs";
6
4
  import type { AccountWallet } from "../wallet.mjs";
7
5
  import { AccountWalletType } from "../wallet.mjs";
8
6
  /**
@@ -13,65 +11,33 @@ export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropyS
13
11
  * A multichain account wallet that holds multiple multichain accounts (one multichain account per
14
12
  * group index).
15
13
  */
16
- export declare class MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> implements AccountWallet<Account> {
17
- #private;
18
- constructor({ providers, entropySource, }: {
19
- providers: AccountProvider<Account>[];
20
- entropySource: EntropySourceId;
21
- });
14
+ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = AccountWallet<Account> & {
22
15
  /**
23
- * Force wallet synchronization.
24
- *
25
- * This can be used if account providers got new accounts that the wallet
26
- * doesn't know about.
27
- */
28
- sync(): void;
29
- /**
30
- * Gets the multichain account wallet ID.
31
- *
32
- * @returns The multichain account wallet ID.
16
+ * Multichain account wallet ID.
33
17
  */
34
18
  get id(): MultichainAccountWalletId;
35
19
  /**
36
- * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
37
- *
38
- * @returns The multichain account wallet type.
20
+ * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
39
21
  */
40
22
  get type(): AccountWalletType.Entropy;
41
23
  /**
42
- * Gets the multichain account wallet entropy source.
43
- *
44
- * @returns The multichain account wallet entropy source.
24
+ * Multichain account wallet entropy source.
45
25
  */
46
26
  get entropySource(): EntropySourceId;
47
- /**
48
- * Gets multichain account for a given ID.
49
- * The default group ID will default to the multichain account with index 0.
50
- *
51
- * @param id - Account group ID.
52
- * @returns Account group.
53
- */
54
- getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined;
55
- /**
56
- * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
57
- *
58
- * @returns The multichain accounts.
59
- */
60
- getAccountGroups(): MultichainAccount<Account>[];
61
27
  /**
62
28
  * Gets multichain account for a given index.
63
29
  *
64
30
  * @param groupIndex - Multichain account index.
65
31
  * @returns The multichain account associated with the given index.
66
32
  */
67
- getMultichainAccount(groupIndex: number): MultichainAccount<Account> | undefined;
33
+ getMultichainAccountGroup(groupIndex: number): MultichainAccountGroup<Account> | undefined;
68
34
  /**
69
35
  * Gets all multichain accounts.
70
36
  *
71
37
  * @returns The multichain accounts.
72
38
  */
73
- getMultichainAccounts(): MultichainAccount<Account>[];
74
- }
39
+ getMultichainAccountGroups(): MultichainAccountGroup<Account>[];
40
+ };
75
41
  /**
76
42
  * Gets the multichain account wallet ID from its entropy source.
77
43
  *
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,EAGL,iBAAiB,EAClB,sBAAkB;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAoB;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAkB;AAC/C,OAAO,EAAE,iBAAiB,E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7C,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAkB;AAC/C,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,GAAG,iBAAiB,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,aAAa,CAAC,OAAO,CAAC,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAAC;IAEpC;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC;IAEtC;;OAEG;IACH,IAAI,aAAa,IAAI,eAAe,CAAC;IAErC;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
@@ -1,141 +1,4 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accounts;
13
- import { getGroupIndexFromMultichainAccountId, isMultichainAccountId, MultichainAccount } from "./account.mjs";
14
- import { toDefaultAccountGroupId } from "../group.mjs";
15
1
  import { AccountWalletType } from "../wallet.mjs";
16
- /**
17
- * A multichain account wallet that holds multiple multichain accounts (one multichain account per
18
- * group index).
19
- */
20
- export class MultichainAccountWallet {
21
- constructor({ providers, entropySource, }) {
22
- _MultichainAccountWallet_id.set(this, void 0);
23
- _MultichainAccountWallet_providers.set(this, void 0);
24
- _MultichainAccountWallet_entropySource.set(this, void 0);
25
- _MultichainAccountWallet_accounts.set(this, void 0);
26
- __classPrivateFieldSet(this, _MultichainAccountWallet_id, toMultichainAccountWalletId(entropySource), "f");
27
- __classPrivateFieldSet(this, _MultichainAccountWallet_providers, providers, "f");
28
- __classPrivateFieldSet(this, _MultichainAccountWallet_entropySource, entropySource, "f");
29
- __classPrivateFieldSet(this, _MultichainAccountWallet_accounts, new Map(), "f");
30
- // Initial synchronization.
31
- this.sync();
32
- }
33
- /**
34
- * Force wallet synchronization.
35
- *
36
- * This can be used if account providers got new accounts that the wallet
37
- * doesn't know about.
38
- */
39
- sync() {
40
- for (const provider of __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f")) {
41
- for (const account of provider.getAccounts()) {
42
- const { entropy } = account.options;
43
- // Filter for this wallet only.
44
- if (entropy.id !== this.entropySource) {
45
- continue;
46
- }
47
- // This multichain account might exists already.
48
- let multichainAccount = __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(entropy.groupIndex);
49
- if (!multichainAccount) {
50
- multichainAccount = new MultichainAccount({
51
- groupIndex: entropy.groupIndex,
52
- wallet: this,
53
- providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
54
- });
55
- __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").set(entropy.groupIndex, multichainAccount);
56
- }
57
- }
58
- }
59
- // Now force-sync all remaining multichain accounts.
60
- for (const [groupIndex, multichainAccount] of __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").entries()) {
61
- multichainAccount.sync();
62
- // Clean up old multichain accounts.
63
- if (!multichainAccount.hasAccounts()) {
64
- __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").delete(groupIndex);
65
- }
66
- }
67
- }
68
- /**
69
- * Gets the multichain account wallet ID.
70
- *
71
- * @returns The multichain account wallet ID.
72
- */
73
- get id() {
74
- return __classPrivateFieldGet(this, _MultichainAccountWallet_id, "f");
75
- }
76
- /**
77
- * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
78
- *
79
- * @returns The multichain account wallet type.
80
- */
81
- get type() {
82
- return AccountWalletType.Entropy;
83
- }
84
- /**
85
- * Gets the multichain account wallet entropy source.
86
- *
87
- * @returns The multichain account wallet entropy source.
88
- */
89
- get entropySource() {
90
- return __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f");
91
- }
92
- /**
93
- * Gets multichain account for a given ID.
94
- * The default group ID will default to the multichain account with index 0.
95
- *
96
- * @param id - Account group ID.
97
- * @returns Account group.
98
- */
99
- getAccountGroup(id) {
100
- // We consider the "default case" to be mapped to index 0.
101
- if (id === toDefaultAccountGroupId(this.id)) {
102
- return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(0);
103
- }
104
- // If it is not a valid ID, we cannot extract the group index
105
- // from it, so we fail fast.
106
- if (!isMultichainAccountId(id)) {
107
- return undefined;
108
- }
109
- const groupIndex = getGroupIndexFromMultichainAccountId(id);
110
- return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
111
- }
112
- /**
113
- * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
114
- *
115
- * @returns The multichain accounts.
116
- */
117
- getAccountGroups() {
118
- return this.getMultichainAccounts();
119
- }
120
- /**
121
- * Gets multichain account for a given index.
122
- *
123
- * @param groupIndex - Multichain account index.
124
- * @returns The multichain account associated with the given index.
125
- */
126
- getMultichainAccount(groupIndex) {
127
- return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
128
- }
129
- /**
130
- * Gets all multichain accounts.
131
- *
132
- * @returns The multichain accounts.
133
- */
134
- getMultichainAccounts() {
135
- return Array.from(__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").values()); // TODO: Prevent copy here.
136
- }
137
- }
138
- _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accounts = new WeakMap();
139
2
  /**
140
3
  * Gets the multichain account wallet ID from its entropy source.
141
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EACL,oCAAoC,EACpC,qBAAqB,EACrB,iBAAiB,EAClB,sBAAkB;AAGnB,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAGnD,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAQ9C;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAYlC,YAAY,EACV,SAAS,EACT,aAAa,GAId;QAdQ,8CAA+B;QAE/B,qDAAuC;QAEvC,yDAAgC;QAEhC,oDAAmD;QAS1D,uBAAA,IAAI,+BAAO,2BAA2B,CAAC,aAAa,CAAC,MAAA,CAAC;QACtD,uBAAA,IAAI,sCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,qCAAa,IAAI,GAAG,EAAE,MAAA,CAAC;QAE3B,2BAA2B;QAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,IAAI;QACF,KAAK,MAAM,QAAQ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ACH,IAAI,aAAa;QACf,OAAO,uBAAA,IAAI,8CAAe,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,eAAe,CAAC,EAAkB;QAChC,0DAA0D;QAC1D,IAAI,EAAE,KAAK,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5C,OAAO,uBAAA,IAAI,yCAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;QAED,6DAA6D;QAC7D,4BAA4B;QAC5B,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC,EAAE,CAAC;YAC/B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,UAAU,GAAG,oCAAoC,CAAC,EAAE,CAAC,CAAC;QAC5D,OAAO,uBAAA,IAAI,yCAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAClB,UAAkB;QAElB,OAAO,uBAAA,IAAI,yCAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,qBAAqB;QACnB,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,yCAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,2BAA2B;IACzE,CAAC;CACF;;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,iBAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport {\n getGroupIndexFromMultichainAccountId,\n isMultichainAccountId,\n MultichainAccount,\n} from './account';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountGroupId } from '../group';\nimport { toDefaultAccountGroupId } from '../group';\nimport type { AccountProvider } from '../provider';\nimport type { AccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport class MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> implements AccountWallet<Account>\n{\n readonly #id: MultichainAccountWalletId;\n\n readonly #providers: AccountProvider<Account>[];\n\n readonly #entropySource: EntropySourceId;\n\n readonly #accounts: Map<number, MultichainAccount<Account>>;\n\n constructor({\n providers,\n entropySource,\n }: {\n providers: AccountProvider<Account>[];\n entropySource: EntropySourceId;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#accounts = new Map();\n\n // Initial synchronization.\n this.sync();\n }\n\n /**\n * Force wallet synchronization.\n *\n * This can be used if account providers got new accounts that the wallet\n * doesn't know about.\n */\n sync(): void {\n for (const provider of this.#providers) {\n for (const account of provider.getAccounts()) {\n const { entropy } = account.options;\n\n // Filter for this wallet only.\n if (entropy.id !== this.entropySource) {\n continue;\n }\n\n // This multichain account might exists already.\n let multichainAccount = this.#accounts.get(entropy.groupIndex);\n if (!multichainAccount) {\n multichainAccount = new MultichainAccount<Account>({\n groupIndex: entropy.groupIndex,\n wallet: this,\n providers: this.#providers,\n });\n\n this.#accounts.set(entropy.groupIndex, multichainAccount);\n }\n }\n }\n\n // Now force-sync all remaining multichain accounts.\n for (const [groupIndex, multichainAccount] of this.#accounts.entries()) {\n multichainAccount.sync();\n\n // Clean up old multichain accounts.\n if (!multichainAccount.hasAccounts()) {\n this.#accounts.delete(groupIndex);\n }\n }\n }\n\n /**\n * Gets the multichain account wallet ID.\n *\n * @returns The multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId {\n return this.#id;\n }\n\n /**\n * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n *\n * @returns The multichain account wallet type.\n */\n get type(): AccountWalletType.Entropy {\n return AccountWalletType.Entropy;\n }\n\n /**\n * Gets the multichain account wallet entropy source.\n *\n * @returns The multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId {\n return this.#entropySource;\n }\n\n /**\n * Gets multichain account for a given ID.\n * The default group ID will default to the multichain account with index 0.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined {\n // We consider the \"default case\" to be mapped to index 0.\n if (id === toDefaultAccountGroupId(this.id)) {\n return this.#accounts.get(0);\n }\n\n // If it is not a valid ID, we cannot extract the group index\n // from it, so we fail fast.\n if (!isMultichainAccountId(id)) {\n return undefined;\n }\n\n const groupIndex = getGroupIndexFromMultichainAccountId(id);\n return this.#accounts.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.\n *\n * @returns The multichain accounts.\n */\n getAccountGroups(): MultichainAccount<Account>[] {\n return this.getMultichainAccounts();\n }\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccount(\n groupIndex: number,\n ): MultichainAccount<Account> | undefined {\n return this.#accounts.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccounts(): MultichainAccount<Account>[] {\n return Array.from(this.#accounts.values()); // TODO: Prevent copy here.\n }\n}\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n"]}
1
+ {"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAgD9C;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,iBAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport type { MultichainAccountGroup } from './group';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport type MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> = AccountWallet<Account> & {\n /**\n * Multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId;\n\n /**\n * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n */\n get type(): AccountWalletType.Entropy;\n\n /**\n * Multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId;\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined;\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[];\n};\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.cjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @returns An account, or undefined if not found.\n */\n getAccount: (id: Account['id']) => Account | undefined;\n\n /**\n * Gets all accounts for a given entropy source and group index.\n *\n * @returns A list of all account for this provider.\n */\n getAccounts: () => Account[];\n};\n"]}
1
+ {"version":3,"file":"provider.cjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @returns An account, or undefined if not found.\n */\n getAccount: (id: Account['id']) => Account | undefined;\n\n /**\n * Gets all accounts for this provider.\n *\n * @returns A list of all account for this provider.\n */\n getAccounts: () => Account[];\n\n /**\n * Creates accounts for a given entropy source and a given group\n * index.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of created accounts.\n */\n createAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n\n /**\n * Discover accounts for a given entropy source and a given group\n * index.\n *\n * NOTE: This method needs to also create the discovered accounts.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of discovered and created accounts.\n */\n discoverAndCreateAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n};\n"]}
@@ -1,4 +1,4 @@
1
- import type { KeyringAccount } from "@metamask/keyring-api";
1
+ import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
2
2
  /**
3
3
  * An account provider is reponsible of providing accounts to an account group.
4
4
  */
@@ -10,10 +10,38 @@ export type AccountProvider<Account extends KeyringAccount> = {
10
10
  */
11
11
  getAccount: (id: Account['id']) => Account | undefined;
12
12
  /**
13
- * Gets all accounts for a given entropy source and group index.
13
+ * Gets all accounts for this provider.
14
14
  *
15
15
  * @returns A list of all account for this provider.
16
16
  */
17
17
  getAccounts: () => Account[];
18
+ /**
19
+ * Creates accounts for a given entropy source and a given group
20
+ * index.
21
+ *
22
+ * @param options - Options.
23
+ * @param options.entropySource - Entropy source to use.
24
+ * @param options.groupIndex - Group index to use.
25
+ * @returns The list of created accounts.
26
+ */
27
+ createAccounts: (options: {
28
+ entropySource: EntropySourceId;
29
+ groupIndex: number;
30
+ }) => Promise<Account[]>;
31
+ /**
32
+ * Discover accounts for a given entropy source and a given group
33
+ * index.
34
+ *
35
+ * NOTE: This method needs to also create the discovered accounts.
36
+ *
37
+ * @param options - Options.
38
+ * @param options.entropySource - Entropy source to use.
39
+ * @param options.groupIndex - Group index to use.
40
+ * @returns The list of discovered and created accounts.
41
+ */
42
+ discoverAndCreateAccounts: (options: {
43
+ entropySource: EntropySourceId;
44
+ groupIndex: number;
45
+ }) => Promise<Account[]>;
18
46
  };
19
47
  //# sourceMappingURL=provider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.cts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;CAC9B,CAAC"}
1
+ {"version":3,"file":"provider.d.cts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;IAE7B;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE;QACxB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEzB;;;;;;;;;;OAUG;IACH,yBAAyB,EAAE,CAAC,OAAO,EAAE;QACnC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CAC1B,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { KeyringAccount } from "@metamask/keyring-api";
1
+ import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
2
2
  /**
3
3
  * An account provider is reponsible of providing accounts to an account group.
4
4
  */
@@ -10,10 +10,38 @@ export type AccountProvider<Account extends KeyringAccount> = {
10
10
  */
11
11
  getAccount: (id: Account['id']) => Account | undefined;
12
12
  /**
13
- * Gets all accounts for a given entropy source and group index.
13
+ * Gets all accounts for this provider.
14
14
  *
15
15
  * @returns A list of all account for this provider.
16
16
  */
17
17
  getAccounts: () => Account[];
18
+ /**
19
+ * Creates accounts for a given entropy source and a given group
20
+ * index.
21
+ *
22
+ * @param options - Options.
23
+ * @param options.entropySource - Entropy source to use.
24
+ * @param options.groupIndex - Group index to use.
25
+ * @returns The list of created accounts.
26
+ */
27
+ createAccounts: (options: {
28
+ entropySource: EntropySourceId;
29
+ groupIndex: number;
30
+ }) => Promise<Account[]>;
31
+ /**
32
+ * Discover accounts for a given entropy source and a given group
33
+ * index.
34
+ *
35
+ * NOTE: This method needs to also create the discovered accounts.
36
+ *
37
+ * @param options - Options.
38
+ * @param options.entropySource - Entropy source to use.
39
+ * @param options.groupIndex - Group index to use.
40
+ * @returns The list of discovered and created accounts.
41
+ */
42
+ discoverAndCreateAccounts: (options: {
43
+ entropySource: EntropySourceId;
44
+ groupIndex: number;
45
+ }) => Promise<Account[]>;
18
46
  };
19
47
  //# sourceMappingURL=provider.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.mts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;CAC9B,CAAC"}
1
+ {"version":3,"file":"provider.d.mts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;IAE7B;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE;QACxB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEzB;;;;;;;;;;OAUG;IACH,yBAAyB,EAAE,CAAC,OAAO,EAAE;QACnC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CAC1B,CAAC"}