@metamask-previews/account-api 0.2.0-e017e7a → 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 (56) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/api/group.cjs +13 -1
  3. package/dist/api/group.cjs.map +1 -1
  4. package/dist/api/group.d.cts +23 -3
  5. package/dist/api/group.d.cts.map +1 -1
  6. package/dist/api/group.d.mts +23 -3
  7. package/dist/api/group.d.mts.map +1 -1
  8. package/dist/api/group.mjs +12 -0
  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 +1 -140
  27. package/dist/api/multichain/wallet.cjs.map +1 -1
  28. package/dist/api/multichain/wallet.d.cts +11 -45
  29. package/dist/api/multichain/wallet.d.cts.map +1 -1
  30. package/dist/api/multichain/wallet.d.mts +11 -45
  31. package/dist/api/multichain/wallet.d.mts.map +1 -1
  32. package/dist/api/multichain/wallet.mjs +2 -139
  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 +2 -3
  36. package/dist/api/provider.d.cts.map +1 -1
  37. package/dist/api/provider.d.mts +2 -3
  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 +19 -23
  41. package/dist/api/wallet.cjs.map +1 -1
  42. package/dist/api/wallet.d.cts +20 -19
  43. package/dist/api/wallet.d.cts.map +1 -1
  44. package/dist/api/wallet.d.mts +20 -19
  45. package/dist/api/wallet.d.mts.map +1 -1
  46. package/dist/api/wallet.mjs +18 -22
  47. package/dist/api/wallet.mjs.map +1 -1
  48. package/package.json +3 -3
  49. package/dist/api/multichain/account.cjs +0 -213
  50. package/dist/api/multichain/account.cjs.map +0 -1
  51. package/dist/api/multichain/account.d.cts +0 -103
  52. package/dist/api/multichain/account.d.cts.map +0 -1
  53. package/dist/api/multichain/account.d.mts +0 -103
  54. package/dist/api/multichain/account.d.mts.map +0 -1
  55. package/dist/api/multichain/account.mjs +0 -206
  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 category, which is always {@link AccountWalletCategory.Entropy}.
82
- *
83
- * @returns The multichain account wallet category.
84
- */
85
- get category() {
86
- return wallet_1.AccountWalletCategory.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
  *
@@ -148,6 +9,6 @@ _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers
148
9
  * @returns The multichain account wallet ID.
149
10
  */
150
11
  function toMultichainAccountWalletId(entropySource) {
151
- return `${wallet_1.AccountWalletCategory.Entropy}:${entropySource}`;
12
+ return `${wallet_1.AccountWalletType.Entropy}:${entropySource}`;
152
13
  }
153
14
  //# sourceMappingURL=wallet.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuLA,kEAIC;AAtLD,2CAImB;AAGnB,wCAAmD;AAGnD,0CAAkD;AAQlD;;;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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cesContent":["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 { AccountWalletCategory } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletCategory.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 category, which is always {@link AccountWalletCategory.Entropy}.\n *\n * @returns The multichain account wallet category.\n */\n get category(): AccountWalletCategory.Entropy {\n return AccountWalletCategory.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 `${AccountWalletCategory.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,77 +1,43 @@
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
- import { AccountWalletCategory } from "../wallet.cjs";
5
+ import { AccountWalletType } from "../wallet.cjs";
8
6
  /**
9
7
  * Multichain account wallet ID.
10
8
  */
11
- export type MultichainAccountWalletId = `${AccountWalletCategory.Entropy}:${EntropySourceId}`;
9
+ export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
12
10
  /**
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 category, which is always {@link AccountWalletCategory.Entropy}.
37
- *
38
- * @returns The multichain account wallet category.
20
+ * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
39
21
  */
40
- get category(): AccountWalletCategory.Entropy;
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,qBAAqB,EAAE,sBAAkB;AAElD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,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E,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,77 +1,43 @@
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
- import { AccountWalletCategory } from "../wallet.mjs";
5
+ import { AccountWalletType } from "../wallet.mjs";
8
6
  /**
9
7
  * Multichain account wallet ID.
10
8
  */
11
- export type MultichainAccountWalletId = `${AccountWalletCategory.Entropy}:${EntropySourceId}`;
9
+ export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
12
10
  /**
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 category, which is always {@link AccountWalletCategory.Entropy}.
37
- *
38
- * @returns The multichain account wallet category.
20
+ * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
39
21
  */
40
- get category(): AccountWalletCategory.Entropy;
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,qBAAqB,EAAE,sBAAkB;AAElD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,GAAG,qBAAqB,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;AAExD;;;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,QAAQ,IAAI,qBAAqB,CAAC,OAAO,CAE5C;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,eAAe,CAEnC;IAED;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS;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;;;;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
- import { AccountWalletCategory } 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 category, which is always {@link AccountWalletCategory.Entropy}.
78
- *
79
- * @returns The multichain account wallet category.
80
- */
81
- get category() {
82
- return AccountWalletCategory.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();
1
+ import { AccountWalletType } from "../wallet.mjs";
139
2
  /**
140
3
  * Gets the multichain account wallet ID from its entropy source.
141
4
  *
@@ -143,6 +6,6 @@ _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers
143
6
  * @returns The multichain account wallet ID.
144
7
  */
145
8
  export function toMultichainAccountWalletId(entropySource) {
146
- return `${AccountWalletCategory.Entropy}:${entropySource}`;
9
+ return `${AccountWalletType.Entropy}:${entropySource}`;
147
10
  }
148
11
  //# sourceMappingURL=wallet.mjs.map
@@ -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,qBAAqB,EAAE,sBAAkB;AAQlD;;;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;gBAEpC,+BAA+B;gBAC/B,IAAI,OAAO,CAAC,EAAE,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC;oBACtC,SAAS;gBACX,CAAC;gBAED,gDAAgD;gBAChD,IAAI,iBAAiB,GAAG,uBAAA,IAAI,yCAAU,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC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S,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,qBAAqB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7D,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 { AccountWalletCategory } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletCategory.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 category, which is always {@link AccountWalletCategory.Entropy}.\n *\n * @returns The multichain account wallet category.\n */\n get category(): AccountWalletCategory.Entropy {\n return AccountWalletCategory.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 `${AccountWalletCategory.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 * @throws If the account ID does not belong to this provider.\n * @returns An account.\n */\n getAccount: (id: Account['id']) => Account;\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 { 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"]}
@@ -6,10 +6,9 @@ export type AccountProvider<Account extends KeyringAccount> = {
6
6
  /**
7
7
  * Gets an account for a given ID.
8
8
  *
9
- * @throws If the account ID does not belong to this provider.
10
- * @returns An account.
9
+ * @returns An account, or undefined if not found.
11
10
  */
12
- getAccount: (id: Account['id']) => Account;
11
+ getAccount: (id: Account['id']) => Account | undefined;
13
12
  /**
14
13
  * Gets all accounts for a given entropy source and group index.
15
14
  *
@@ -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;;;;;OAKG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC;IAE3C;;;;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,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"}
@@ -6,10 +6,9 @@ export type AccountProvider<Account extends KeyringAccount> = {
6
6
  /**
7
7
  * Gets an account for a given ID.
8
8
  *
9
- * @throws If the account ID does not belong to this provider.
10
- * @returns An account.
9
+ * @returns An account, or undefined if not found.
11
10
  */
12
- getAccount: (id: Account['id']) => Account;
11
+ getAccount: (id: Account['id']) => Account | undefined;
13
12
  /**
14
13
  * Gets all accounts for a given entropy source and group index.
15
14
  *
@@ -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;;;;;OAKG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC;IAE3C;;;;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,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 +1 @@
1
- {"version":3,"file":"provider.mjs","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 * @throws If the account ID does not belong to this provider.\n * @returns An account.\n */\n getAccount: (id: Account['id']) => Account;\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.mjs","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"]}