@metamask-previews/account-api 0.1.0-e86c8ec → 0.1.0-f024bb4
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.
- package/dist/api/group.cjs.map +1 -1
- package/dist/api/group.d.cts +7 -5
- package/dist/api/group.d.cts.map +1 -1
- package/dist/api/group.d.mts +7 -5
- package/dist/api/group.d.mts.map +1 -1
- package/dist/api/group.mjs.map +1 -1
- package/dist/api/index.cjs +0 -1
- package/dist/api/index.cjs.map +1 -1
- package/dist/api/index.d.cts +0 -3
- package/dist/api/index.d.cts.map +1 -1
- package/dist/api/index.d.mts +0 -3
- package/dist/api/index.d.mts.map +1 -1
- package/dist/api/index.mjs +0 -1
- package/dist/api/index.mjs.map +1 -1
- package/dist/api/wallet.cjs.map +1 -1
- package/dist/api/wallet.d.cts +0 -1
- package/dist/api/wallet.d.cts.map +1 -1
- package/dist/api/wallet.d.mts +0 -1
- package/dist/api/wallet.d.mts.map +1 -1
- package/dist/api/wallet.mjs.map +1 -1
- package/package.json +2 -5
- package/dist/api/multichain/account.cjs +0 -186
- package/dist/api/multichain/account.cjs.map +0 -1
- package/dist/api/multichain/account.d.cts +0 -95
- package/dist/api/multichain/account.d.cts.map +0 -1
- package/dist/api/multichain/account.d.mts +0 -95
- package/dist/api/multichain/account.d.mts.map +0 -1
- package/dist/api/multichain/account.mjs +0 -179
- package/dist/api/multichain/account.mjs.map +0 -1
- package/dist/api/multichain/index.cjs +0 -19
- package/dist/api/multichain/index.cjs.map +0 -1
- package/dist/api/multichain/index.d.cts +0 -3
- package/dist/api/multichain/index.d.cts.map +0 -1
- package/dist/api/multichain/index.d.mts +0 -3
- package/dist/api/multichain/index.d.mts.map +0 -1
- package/dist/api/multichain/index.mjs +0 -3
- package/dist/api/multichain/index.mjs.map +0 -1
- package/dist/api/multichain/wallet.cjs +0 -158
- package/dist/api/multichain/wallet.cjs.map +0 -1
- package/dist/api/multichain/wallet.d.cts +0 -83
- package/dist/api/multichain/wallet.d.cts.map +0 -1
- package/dist/api/multichain/wallet.d.mts +0 -83
- package/dist/api/multichain/wallet.d.mts.map +0 -1
- package/dist/api/multichain/wallet.mjs +0 -153
- package/dist/api/multichain/wallet.mjs.map +0 -1
- package/dist/api/provider.cjs +0 -3
- package/dist/api/provider.cjs.map +0 -1
- package/dist/api/provider.d.cts +0 -13
- package/dist/api/provider.d.cts.map +0 -1
- package/dist/api/provider.d.mts +0 -13
- package/dist/api/provider.d.mts.map +0 -1
- package/dist/api/provider.mjs +0 -2
- package/dist/api/provider.mjs.map +0 -1
- package/dist/api/selector.cjs +0 -3
- package/dist/api/selector.cjs.map +0 -1
- package/dist/api/selector.d.cts +0 -27
- package/dist/api/selector.d.cts.map +0 -1
- package/dist/api/selector.d.mts +0 -27
- package/dist/api/selector.d.mts.map +0 -1
- package/dist/api/selector.mjs +0 -2
- package/dist/api/selector.mjs.map +0 -1
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
import { MultichainAccount } from "./account.mjs";
|
|
3
|
-
import type { AccountGroupId } from "../group.mjs";
|
|
4
|
-
import type { AccountProvider } from "../provider.mjs";
|
|
5
|
-
import type { AccountWallet } from "../wallet.mjs";
|
|
6
|
-
import { AccountWalletCategory } from "../wallet.mjs";
|
|
7
|
-
/**
|
|
8
|
-
* Multichain account wallet ID.
|
|
9
|
-
*/
|
|
10
|
-
export type MultichainAccountWalletId = `${AccountWalletCategory.Entropy}:${EntropySourceId}`;
|
|
11
|
-
/**
|
|
12
|
-
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
13
|
-
* group index).
|
|
14
|
-
*/
|
|
15
|
-
export declare class MultichainAccountWallet<Account extends KeyringAccount> implements AccountWallet<Account> {
|
|
16
|
-
#private;
|
|
17
|
-
constructor({ providers, entropySource, }: {
|
|
18
|
-
providers: AccountProvider<Account>[];
|
|
19
|
-
entropySource: EntropySourceId;
|
|
20
|
-
});
|
|
21
|
-
/**
|
|
22
|
-
* Gets the highest group index from multiple account providers for a given
|
|
23
|
-
* entropy source.
|
|
24
|
-
*
|
|
25
|
-
* @param providers - Account providers.
|
|
26
|
-
* @param entropySource - Entropy source to filter on.
|
|
27
|
-
* @returns The highest group index for a given entropy source.
|
|
28
|
-
*/
|
|
29
|
-
static getHighestGroupIndexFrom<Account extends KeyringAccount>(providers: AccountProvider<Account>[], entropySource: EntropySourceId): number;
|
|
30
|
-
/**
|
|
31
|
-
* Gets the multichain account wallet ID.
|
|
32
|
-
*
|
|
33
|
-
* @returns The multichain account wallet ID.
|
|
34
|
-
*/
|
|
35
|
-
get id(): MultichainAccountWalletId;
|
|
36
|
-
/**
|
|
37
|
-
* Gets the multichain account wallet category, which is always {@link AccountWalletCategory.Entropy}.
|
|
38
|
-
*
|
|
39
|
-
* @returns The multichain account wallet category.
|
|
40
|
-
*/
|
|
41
|
-
get category(): AccountWalletCategory.Entropy;
|
|
42
|
-
/**
|
|
43
|
-
* Gets the multichain account wallet entropy source.
|
|
44
|
-
*
|
|
45
|
-
* @returns The multichain account wallet entropy source.
|
|
46
|
-
*/
|
|
47
|
-
get entropySource(): EntropySourceId;
|
|
48
|
-
/**
|
|
49
|
-
* Gets multichain account for a given ID.
|
|
50
|
-
* The default group ID will default to the multichain account with index 0.
|
|
51
|
-
*
|
|
52
|
-
* @param id - Account group ID.
|
|
53
|
-
* @returns Account group.
|
|
54
|
-
*/
|
|
55
|
-
getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
|
|
58
|
-
*
|
|
59
|
-
* @returns The multichain accounts.
|
|
60
|
-
*/
|
|
61
|
-
getAccountGroups(): MultichainAccount<Account>[];
|
|
62
|
-
/**
|
|
63
|
-
* Gets multichain account for a given index.
|
|
64
|
-
*
|
|
65
|
-
* @param groupIndex - Multichain account index.
|
|
66
|
-
* @returns The multichain account associated with the given index.
|
|
67
|
-
*/
|
|
68
|
-
getMultichainAccount(groupIndex: number): MultichainAccount<Account> | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* Gets all multichain accounts.
|
|
71
|
-
*
|
|
72
|
-
* @returns The multichain accounts.
|
|
73
|
-
*/
|
|
74
|
-
getMultichainAccounts(): MultichainAccount<Account>[];
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Gets the multichain account wallet ID from its entropy source.
|
|
78
|
-
*
|
|
79
|
-
* @param entropySource - Entropy source ID of that wallet.
|
|
80
|
-
* @returns The multichain account wallet ID.
|
|
81
|
-
*/
|
|
82
|
-
export declare function toMultichainAccountWalletId(entropySource: EntropySourceId): MultichainAccountWalletId;
|
|
83
|
-
//# sourceMappingURL=wallet.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,EAGL,iBAAiB,EAClB,sBAAkB;AACnB,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,CAAC,OAAO,SAAS,cAAc,CACjE,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;IAgCD;;;;;;;OAOG;IACH,MAAM,CAAC,wBAAwB,CAAC,OAAO,SAAS,cAAc,EAC5D,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,EACrC,aAAa,EAAE,eAAe,GAC7B,MAAM;IAmBT;;;;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;IAgB3E;;;;OAIG;IACH,gBAAgB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAIhD;;;;;OAKG;IACH,oBAAoB,CAClB,UAAU,EAAE,MAAM,GACjB,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS;IAIzC;;;;OAIG;IACH,qBAAqB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;CAGtD;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
|
|
@@ -1,153 +0,0 @@
|
|
|
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 { KeyringAccountEntropyTypeOption } from "@metamask/keyring-api";
|
|
14
|
-
import { getGroupIndexFromMultichainAccountId, isMultichainAccountId, MultichainAccount } from "./account.mjs";
|
|
15
|
-
import { toDefaultAccountGroupId } from "../group.mjs";
|
|
16
|
-
import { AccountWalletCategory } from "../wallet.mjs";
|
|
17
|
-
/**
|
|
18
|
-
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
19
|
-
* group index).
|
|
20
|
-
*/
|
|
21
|
-
export class MultichainAccountWallet {
|
|
22
|
-
constructor({ providers, entropySource, }) {
|
|
23
|
-
_MultichainAccountWallet_id.set(this, void 0);
|
|
24
|
-
_MultichainAccountWallet_providers.set(this, void 0);
|
|
25
|
-
_MultichainAccountWallet_entropySource.set(this, void 0);
|
|
26
|
-
_MultichainAccountWallet_accounts.set(this, void 0);
|
|
27
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_id, toMultichainAccountWalletId(entropySource), "f");
|
|
28
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_providers, providers, "f");
|
|
29
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_entropySource, entropySource, "f");
|
|
30
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_accounts, new Map(), "f");
|
|
31
|
-
// NOTE: This will traverse all accounts to compute the max index. We could try
|
|
32
|
-
// to minimize the number of filtering we're doing on each providers if this
|
|
33
|
-
// becomes too costly.
|
|
34
|
-
const maxGroupIndex = MultichainAccountWallet.getHighestGroupIndexFrom(providers, entropySource);
|
|
35
|
-
// NOTE: We could have some gap for now, until we fully implement the
|
|
36
|
-
// gap/alignment mechanisms to backfill all "missing accounts".
|
|
37
|
-
for (let groupIndex = 0; groupIndex <= maxGroupIndex; groupIndex++) {
|
|
38
|
-
// Use "lower or equal", since we need to "include" the max index (which
|
|
39
|
-
// can also be 0)
|
|
40
|
-
const multichainAccount = new MultichainAccount({
|
|
41
|
-
groupIndex,
|
|
42
|
-
wallet: this,
|
|
43
|
-
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
44
|
-
});
|
|
45
|
-
// We only add multichain account that has underlying accounts.
|
|
46
|
-
if (multichainAccount.hasAccounts()) {
|
|
47
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").set(groupIndex, multichainAccount);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Gets the highest group index from multiple account providers for a given
|
|
53
|
-
* entropy source.
|
|
54
|
-
*
|
|
55
|
-
* @param providers - Account providers.
|
|
56
|
-
* @param entropySource - Entropy source to filter on.
|
|
57
|
-
* @returns The highest group index for a given entropy source.
|
|
58
|
-
*/
|
|
59
|
-
static getHighestGroupIndexFrom(providers, entropySource) {
|
|
60
|
-
let max = -1;
|
|
61
|
-
for (const provider of providers) {
|
|
62
|
-
for (const account of provider.getAccounts()) {
|
|
63
|
-
if (account.options.entropy &&
|
|
64
|
-
account.options.entropy.type ===
|
|
65
|
-
KeyringAccountEntropyTypeOption.Mnemonic &&
|
|
66
|
-
account.options.entropy.id === entropySource) {
|
|
67
|
-
max = Math.max(max, account.options.entropy.groupIndex);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return max;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Gets the multichain account wallet ID.
|
|
75
|
-
*
|
|
76
|
-
* @returns The multichain account wallet ID.
|
|
77
|
-
*/
|
|
78
|
-
get id() {
|
|
79
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_id, "f");
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Gets the multichain account wallet category, which is always {@link AccountWalletCategory.Entropy}.
|
|
83
|
-
*
|
|
84
|
-
* @returns The multichain account wallet category.
|
|
85
|
-
*/
|
|
86
|
-
get category() {
|
|
87
|
-
return AccountWalletCategory.Entropy;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets the multichain account wallet entropy source.
|
|
91
|
-
*
|
|
92
|
-
* @returns The multichain account wallet entropy source.
|
|
93
|
-
*/
|
|
94
|
-
get entropySource() {
|
|
95
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f");
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets multichain account for a given ID.
|
|
99
|
-
* The default group ID will default to the multichain account with index 0.
|
|
100
|
-
*
|
|
101
|
-
* @param id - Account group ID.
|
|
102
|
-
* @returns Account group.
|
|
103
|
-
*/
|
|
104
|
-
getAccountGroup(id) {
|
|
105
|
-
// We consider the "default case" to be mapped to index 0.
|
|
106
|
-
if (id === toDefaultAccountGroupId(this.id)) {
|
|
107
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(0);
|
|
108
|
-
}
|
|
109
|
-
// If it is not a valid ID, we cannot extract the group index
|
|
110
|
-
// from it, so we fail fast.
|
|
111
|
-
if (!isMultichainAccountId(id)) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
const groupIndex = getGroupIndexFromMultichainAccountId(id);
|
|
115
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
|
|
119
|
-
*
|
|
120
|
-
* @returns The multichain accounts.
|
|
121
|
-
*/
|
|
122
|
-
getAccountGroups() {
|
|
123
|
-
return this.getMultichainAccounts();
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Gets multichain account for a given index.
|
|
127
|
-
*
|
|
128
|
-
* @param groupIndex - Multichain account index.
|
|
129
|
-
* @returns The multichain account associated with the given index.
|
|
130
|
-
*/
|
|
131
|
-
getMultichainAccount(groupIndex) {
|
|
132
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Gets all multichain accounts.
|
|
136
|
-
*
|
|
137
|
-
* @returns The multichain accounts.
|
|
138
|
-
*/
|
|
139
|
-
getMultichainAccounts() {
|
|
140
|
-
return Array.from(__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").values()); // TODO: Prevent copy here.
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
_MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accounts = new WeakMap();
|
|
144
|
-
/**
|
|
145
|
-
* Gets the multichain account wallet ID from its entropy source.
|
|
146
|
-
*
|
|
147
|
-
* @param entropySource - Entropy source ID of that wallet.
|
|
148
|
-
* @returns The multichain account wallet ID.
|
|
149
|
-
*/
|
|
150
|
-
export function toMultichainAccountWalletId(entropySource) {
|
|
151
|
-
return `${AccountWalletCategory.Entropy}:${entropySource}`;
|
|
152
|
-
}
|
|
153
|
-
//# sourceMappingURL=wallet.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,+BAA+B,EAGhC,8BAA8B;AAE/B,OAAO,EACL,oCAAoC,EACpC,qBAAqB,EACrB,iBAAiB,EAClB,sBAAkB;AAEnB,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAGnD,OAAO,EAAE,qBAAqB,EAAE,sBAAkB;AAQlD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAW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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 KeyringAccountEntropyTypeOption,\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport {\n getGroupIndexFromMultichainAccountId,\n isMultichainAccountId,\n MultichainAccount,\n} from './account';\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<Account extends 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 // NOTE: This will traverse all accounts to compute the max index. We could try\n // to minimize the number of filtering we're doing on each providers if this\n // becomes too costly.\n const maxGroupIndex = MultichainAccountWallet.getHighestGroupIndexFrom(\n providers,\n entropySource,\n );\n\n // NOTE: We could have some gap for now, until we fully implement the\n // gap/alignment mechanisms to backfill all \"missing accounts\".\n for (let groupIndex = 0; groupIndex <= maxGroupIndex; groupIndex++) {\n // Use \"lower or equal\", since we need to \"include\" the max index (which\n // can also be 0)\n const multichainAccount = new MultichainAccount<Account>({\n groupIndex,\n wallet: this,\n providers: this.#providers,\n });\n\n // We only add multichain account that has underlying accounts.\n if (multichainAccount.hasAccounts()) {\n this.#accounts.set(groupIndex, multichainAccount);\n }\n }\n }\n\n /**\n * Gets the highest group index from multiple account providers for a given\n * entropy source.\n *\n * @param providers - Account providers.\n * @param entropySource - Entropy source to filter on.\n * @returns The highest group index for a given entropy source.\n */\n static getHighestGroupIndexFrom<Account extends KeyringAccount>(\n providers: AccountProvider<Account>[],\n entropySource: EntropySourceId,\n ): number {\n let max = -1;\n\n for (const provider of providers) {\n for (const account of provider.getAccounts()) {\n if (\n account.options.entropy &&\n account.options.entropy.type ===\n KeyringAccountEntropyTypeOption.Mnemonic &&\n account.options.entropy.id === entropySource\n ) {\n max = Math.max(max, account.options.entropy.groupIndex);\n }\n }\n }\n\n return max;\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"]}
|
package/dist/api/provider.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 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"]}
|
package/dist/api/provider.d.cts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
/**
|
|
3
|
-
* An account provider is reponsible of providing accounts to an account group.
|
|
4
|
-
*/
|
|
5
|
-
export type AccountProvider<Account extends KeyringAccount> = {
|
|
6
|
-
/**
|
|
7
|
-
* Gets all accounts for a given entropy source and group index.
|
|
8
|
-
*
|
|
9
|
-
* @returns A list of all account for this provider.
|
|
10
|
-
*/
|
|
11
|
-
getAccounts: () => Account[];
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=provider.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;CAC9B,CAAC"}
|
package/dist/api/provider.d.mts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
/**
|
|
3
|
-
* An account provider is reponsible of providing accounts to an account group.
|
|
4
|
-
*/
|
|
5
|
-
export type AccountProvider<Account extends KeyringAccount> = {
|
|
6
|
-
/**
|
|
7
|
-
* Gets all accounts for a given entropy source and group index.
|
|
8
|
-
*
|
|
9
|
-
* @returns A list of all account for this provider.
|
|
10
|
-
*/
|
|
11
|
-
getAccounts: () => Account[];
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=provider.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;CAC9B,CAAC"}
|
package/dist/api/provider.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 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"]}
|
package/dist/api/selector.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.cjs","sourceRoot":"","sources":["../../src/api/selector.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * Selector to query a specific account based on some criteria.\n */\nexport type AccountSelector<Account extends KeyringAccount> = {\n /**\n * Query by account ID.\n */\n id?: Account['id'];\n\n /**\n * Query by account address.\n */\n address?: Account['address'];\n\n /**\n * Query by account type.\n */\n type?: Account['type'];\n\n /**\n * Query by account methods.\n */\n methods?: Account['methods'];\n\n /**\n * Query by account scopes.\n */\n scopes?: Account['scopes'];\n};\n"]}
|
package/dist/api/selector.d.cts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
/**
|
|
3
|
-
* Selector to query a specific account based on some criteria.
|
|
4
|
-
*/
|
|
5
|
-
export type AccountSelector<Account extends KeyringAccount> = {
|
|
6
|
-
/**
|
|
7
|
-
* Query by account ID.
|
|
8
|
-
*/
|
|
9
|
-
id?: Account['id'];
|
|
10
|
-
/**
|
|
11
|
-
* Query by account address.
|
|
12
|
-
*/
|
|
13
|
-
address?: Account['address'];
|
|
14
|
-
/**
|
|
15
|
-
* Query by account type.
|
|
16
|
-
*/
|
|
17
|
-
type?: Account['type'];
|
|
18
|
-
/**
|
|
19
|
-
* Query by account methods.
|
|
20
|
-
*/
|
|
21
|
-
methods?: Account['methods'];
|
|
22
|
-
/**
|
|
23
|
-
* Query by account scopes.
|
|
24
|
-
*/
|
|
25
|
-
scopes?: Account['scopes'];
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=selector.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.d.cts","sourceRoot":"","sources":["../../src/api/selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;OAEG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAE7B;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAE7B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5B,CAAC"}
|
package/dist/api/selector.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
/**
|
|
3
|
-
* Selector to query a specific account based on some criteria.
|
|
4
|
-
*/
|
|
5
|
-
export type AccountSelector<Account extends KeyringAccount> = {
|
|
6
|
-
/**
|
|
7
|
-
* Query by account ID.
|
|
8
|
-
*/
|
|
9
|
-
id?: Account['id'];
|
|
10
|
-
/**
|
|
11
|
-
* Query by account address.
|
|
12
|
-
*/
|
|
13
|
-
address?: Account['address'];
|
|
14
|
-
/**
|
|
15
|
-
* Query by account type.
|
|
16
|
-
*/
|
|
17
|
-
type?: Account['type'];
|
|
18
|
-
/**
|
|
19
|
-
* Query by account methods.
|
|
20
|
-
*/
|
|
21
|
-
methods?: Account['methods'];
|
|
22
|
-
/**
|
|
23
|
-
* Query by account scopes.
|
|
24
|
-
*/
|
|
25
|
-
scopes?: Account['scopes'];
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=selector.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.d.mts","sourceRoot":"","sources":["../../src/api/selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;OAEG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAE7B;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAE7B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5B,CAAC"}
|
package/dist/api/selector.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.mjs","sourceRoot":"","sources":["../../src/api/selector.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * Selector to query a specific account based on some criteria.\n */\nexport type AccountSelector<Account extends KeyringAccount> = {\n /**\n * Query by account ID.\n */\n id?: Account['id'];\n\n /**\n * Query by account address.\n */\n address?: Account['address'];\n\n /**\n * Query by account type.\n */\n type?: Account['type'];\n\n /**\n * Query by account methods.\n */\n methods?: Account['methods'];\n\n /**\n * Query by account scopes.\n */\n scopes?: Account['scopes'];\n};\n"]}
|