@metamask-previews/account-api 0.3.0-9522cc5 → 0.5.0-0e28ac0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +15 -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/wallet.cjs +3 -9
  35. package/dist/api/wallet.cjs.map +1 -1
  36. package/dist/api/wallet.d.cts +9 -10
  37. package/dist/api/wallet.d.cts.map +1 -1
  38. package/dist/api/wallet.d.mts +9 -10
  39. package/dist/api/wallet.d.mts.map +1 -1
  40. package/dist/api/wallet.mjs +3 -9
  41. package/dist/api/wallet.mjs.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/api/multichain/account.cjs +0 -230
  44. package/dist/api/multichain/account.cjs.map +0 -1
  45. package/dist/api/multichain/account.d.cts +0 -110
  46. package/dist/api/multichain/account.d.cts.map +0 -1
  47. package/dist/api/multichain/account.d.mts +0 -110
  48. package/dist/api/multichain/account.d.mts.map +0 -1
  49. package/dist/api/multichain/account.mjs +0 -223
  50. 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,WAAW,EAAE,EAAE,CAAC;gBAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;gBAEpC,+BAA+B;gBAC/B,IAAI,OAAO,CAAC,EAAE,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC;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AAC,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,IAAI,iBAAiB,CAAC,OAAO,CAEpC;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,eAAe,CAEnC;IAED;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAA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C;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,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,CAA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,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,IAAI,uBAAA,IAAI,0CAAW,EAAE,CAAC;YACvC,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;gBAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;gB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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"]}
@@ -9,17 +9,11 @@ exports.toAccountWalletId = toAccountWalletId;
9
9
  */
10
10
  var AccountWalletType;
11
11
  (function (AccountWalletType) {
12
- /**
13
- * Wallet grouping accounts based on their entropy source.
14
- */
12
+ /** Wallet grouping accounts based on their entropy source. */
15
13
  AccountWalletType["Entropy"] = "entropy";
16
- /**
17
- * Wallet grouping accounts based on their keyring's type.
18
- */
14
+ /** Wallet grouping accounts based on their keyring's type. */
19
15
  AccountWalletType["Keyring"] = "keyring";
20
- /**
21
- * Wallet grouping accounts associated with an account management Snap.
22
- */
16
+ /** Wallet grouping accounts associated with an account management Snap. */
23
17
  AccountWalletType["Snap"] = "snap";
24
18
  })(AccountWalletType || (exports.AccountWalletType = AccountWalletType = {}));
25
19
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":";;;AAqEA,8CAKC;AArED;;;;GAIG;AACH,IAAY,iBAeX;AAfD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,wCAAmB,CAAA;IAEnB;;OAEG;IACH,wCAAmB,CAAA;IAEnB;;OAEG;IACH,kCAAa,CAAA;AACf,CAAC,EAfW,iBAAiB,iCAAjB,iBAAiB,QAe5B;AAqCD;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,IAAuB,EACvB,EAAU;IAEV,OAAO,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type { AccountGroup, AccountGroupId } from './group';\n\n/**\n * Wallet type.\n *\n * Each wallet types groups accounts using different criterias.\n */\nexport enum AccountWalletType {\n /**\n * Wallet grouping accounts based on their entropy source.\n */\n Entropy = 'entropy',\n\n /**\n * Wallet grouping accounts based on their keyring's type.\n */\n Keyring = 'keyring',\n\n /**\n * Wallet grouping accounts associated with an account management Snap.\n */\n Snap = 'snap',\n}\n\n/**\n * Account wallet ID.\n */\nexport type AccountWalletId = `${AccountWalletType}:${string}`;\n\n/**\n * Account wallet that can hold multiple account groups.\n */\nexport type AccountWallet<Account extends KeyringAccount> = {\n /**\n * Account wallet ID.\n */\n get id(): AccountWalletId;\n\n /**\n * Account wallet type.\n */\n get type(): AccountWalletType;\n\n /**\n * Gets account group for a given ID.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined;\n\n /**\n * Gets all account groups.\n *\n * @returns Account groups.\n */\n getAccountGroups(): AccountGroup<Account>[];\n};\n\n/**\n * Convert a unique ID to a wallet ID for a given type.\n *\n * @param type - A wallet type.\n * @param id - A unique ID.\n * @returns A wallet ID.\n */\nexport function toAccountWalletId(\n type: AccountWalletType,\n id: string,\n): AccountWalletId {\n return `${type}:${id}`;\n}\n"]}
1
+ {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":";;;AAsEA,8CAKC;AAtED;;;;GAIG;AACH,IAAY,iBASX;AATD,WAAY,iBAAiB;IAC3B,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,2EAA2E;IAC3E,kCAAa,CAAA;AACf,CAAC,EATW,iBAAiB,iCAAjB,iBAAiB,QAS5B;AA4CD;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,IAAgB,EAChB,EAAU;IAEV,OAAO,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type { AccountGroup, AccountGroupId } from './group';\n\n/**\n * Wallet type.\n *\n * Each wallet types groups accounts using different criterias.\n */\nexport enum AccountWalletType {\n /** Wallet grouping accounts based on their entropy source. */\n Entropy = 'entropy',\n\n /** Wallet grouping accounts based on their keyring's type. */\n Keyring = 'keyring',\n\n /** Wallet grouping accounts associated with an account management Snap. */\n Snap = 'snap',\n}\n\n/**\n * Account wallet ID.\n */\nexport type AccountWalletId = `${AccountWalletType}:${string}`;\n\n/**\n * Account wallet that can hold multiple account groups.\n */\nexport type AccountWallet<Account extends KeyringAccount> = {\n /**\n * Account wallet ID.\n */\n get id(): AccountWalletId;\n\n /**\n * Account wallet type.\n */\n get type(): AccountWalletType;\n\n /**\n * Gets account group for a given ID.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined;\n\n /**\n * Gets all account groups.\n *\n * @returns Account groups.\n */\n getAccountGroups(): AccountGroup<Account>[];\n};\n\n/**\n * Type utility to compute a constrained {@link AccountWalletId} type given a\n * specifc {@link AccountWalletType}.\n */\nexport type AccountWalletIdOf<WalletType extends AccountWalletType> =\n `${WalletType}:${string}`;\n\n/**\n * Convert a unique ID to a wallet ID for a given type.\n *\n * @param type - A wallet type.\n * @param id - A unique ID.\n * @returns A wallet ID.\n */\nexport function toAccountWalletId<WalletType extends AccountWalletType>(\n type: WalletType,\n id: string,\n): AccountWalletIdOf<WalletType> {\n return `${type}:${id}`;\n}\n"]}
@@ -6,17 +6,11 @@ import type { AccountGroup, AccountGroupId } from "./group.cjs";
6
6
  * Each wallet types groups accounts using different criterias.
7
7
  */
8
8
  export declare enum AccountWalletType {
9
- /**
10
- * Wallet grouping accounts based on their entropy source.
11
- */
9
+ /** Wallet grouping accounts based on their entropy source. */
12
10
  Entropy = "entropy",
13
- /**
14
- * Wallet grouping accounts based on their keyring's type.
15
- */
11
+ /** Wallet grouping accounts based on their keyring's type. */
16
12
  Keyring = "keyring",
17
- /**
18
- * Wallet grouping accounts associated with an account management Snap.
19
- */
13
+ /** Wallet grouping accounts associated with an account management Snap. */
20
14
  Snap = "snap"
21
15
  }
22
16
  /**
@@ -49,6 +43,11 @@ export type AccountWallet<Account extends KeyringAccount> = {
49
43
  */
50
44
  getAccountGroups(): AccountGroup<Account>[];
51
45
  };
46
+ /**
47
+ * Type utility to compute a constrained {@link AccountWalletId} type given a
48
+ * specifc {@link AccountWalletType}.
49
+ */
50
+ export type AccountWalletIdOf<WalletType extends AccountWalletType> = `${WalletType}:${string}`;
52
51
  /**
53
52
  * Convert a unique ID to a wallet ID for a given type.
54
53
  *
@@ -56,5 +55,5 @@ export type AccountWallet<Account extends KeyringAccount> = {
56
55
  * @param id - A unique ID.
57
56
  * @returns A wallet ID.
58
57
  */
59
- export declare function toAccountWalletId(type: AccountWalletType, id: string): AccountWalletId;
58
+ export declare function toAccountWalletId<WalletType extends AccountWalletType>(type: WalletType, id: string): AccountWalletIdOf<WalletType>;
60
59
  //# sourceMappingURL=wallet.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,oBAAgB;AAE5D;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,iBAAiB,IAAI,MAAM,EAAE,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,cAAc,IAAI;IAC1D;;OAEG;IACH,IAAI,EAAE,IAAI,eAAe,CAAC;IAE1B;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC;IAE9B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAEvE;;;;OAIG;IACH,gBAAgB,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;CAC7C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,iBAAiB,EACvB,EAAE,EAAE,MAAM,GACT,eAAe,CAEjB"}
1
+ {"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,oBAAgB;AAE5D;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B,8DAA8D;IAC9D,OAAO,YAAY;IAEnB,8DAA8D;IAC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