@metamask-previews/account-api 0.0.0-586437b
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/CHANGELOG.md +10 -0
- package/README.md +15 -0
- package/dist/api/group.cjs +27 -0
- package/dist/api/group.cjs.map +1 -0
- package/dist/api/group.d.cts +40 -0
- package/dist/api/group.d.cts.map +1 -0
- package/dist/api/group.d.mts +40 -0
- package/dist/api/group.d.mts.map +1 -0
- package/dist/api/group.mjs +22 -0
- package/dist/api/group.mjs.map +1 -0
- package/dist/api/index.cjs +20 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.d.cts +4 -0
- package/dist/api/index.d.cts.map +1 -0
- package/dist/api/index.d.mts +4 -0
- package/dist/api/index.d.mts.map +1 -0
- package/dist/api/index.mjs +4 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/api/multichain/adapters.cjs +240 -0
- package/dist/api/multichain/adapters.cjs.map +1 -0
- package/dist/api/multichain/adapters.d.cts +37 -0
- package/dist/api/multichain/adapters.d.cts.map +1 -0
- package/dist/api/multichain/adapters.d.mts +37 -0
- package/dist/api/multichain/adapters.d.mts.map +1 -0
- package/dist/api/multichain/adapters.mjs +235 -0
- package/dist/api/multichain/adapters.mjs.map +1 -0
- package/dist/api/multichain/id.cjs +43 -0
- package/dist/api/multichain/id.cjs.map +1 -0
- package/dist/api/multichain/id.d.cts +28 -0
- package/dist/api/multichain/id.d.cts.map +1 -0
- package/dist/api/multichain/id.d.mts +28 -0
- package/dist/api/multichain/id.d.mts.map +1 -0
- package/dist/api/multichain/id.mjs +38 -0
- package/dist/api/multichain/id.mjs.map +1 -0
- package/dist/api/multichain/index.cjs +18 -0
- package/dist/api/multichain/index.cjs.map +1 -0
- package/dist/api/multichain/index.d.cts +5 -0
- package/dist/api/multichain/index.d.cts.map +1 -0
- package/dist/api/multichain/index.d.mts +5 -0
- package/dist/api/multichain/index.d.mts.map +1 -0
- package/dist/api/multichain/index.mjs +2 -0
- package/dist/api/multichain/index.mjs.map +1 -0
- package/dist/api/multichain/providers.cjs +3 -0
- package/dist/api/multichain/providers.cjs.map +1 -0
- package/dist/api/multichain/providers.d.cts +18 -0
- package/dist/api/multichain/providers.d.cts.map +1 -0
- package/dist/api/multichain/providers.d.mts +18 -0
- package/dist/api/multichain/providers.d.mts.map +1 -0
- package/dist/api/multichain/providers.mjs +2 -0
- package/dist/api/multichain/providers.mjs.map +1 -0
- package/dist/api/multichain/types.cjs +3 -0
- package/dist/api/multichain/types.cjs.map +1 -0
- package/dist/api/multichain/types.d.cts +93 -0
- package/dist/api/multichain/types.d.cts.map +1 -0
- package/dist/api/multichain/types.d.mts +93 -0
- package/dist/api/multichain/types.d.mts.map +1 -0
- package/dist/api/multichain/types.mjs +2 -0
- package/dist/api/multichain/types.mjs.map +1 -0
- package/dist/api/wallet.cjs +21 -0
- package/dist/api/wallet.cjs.map +1 -0
- package/dist/api/wallet.d.cts +32 -0
- package/dist/api/wallet.d.cts.map +1 -0
- package/dist/api/wallet.d.mts +32 -0
- package/dist/api/wallet.d.mts.map +1 -0
- package/dist/api/wallet.mjs +17 -0
- package/dist/api/wallet.mjs.map +1 -0
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
|
2
|
+
// This rule seems to be triggering a false positive. Possibly eslint is not
|
|
3
|
+
// inferring the `InternalAccount` type correctly which causes issue with the
|
|
4
|
+
// union `| undefined`.
|
|
5
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
6
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
7
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
8
|
+
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");
|
|
9
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
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");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var _MultichainAccountAdapter_id, _MultichainAccountAdapter_wallet, _MultichainAccountAdapter_index, _MultichainAccountAdapter_providers, _MultichainAccountAdapter_providersByAccountId, _MultichainAccountAdapter_accounts, _MultichainAccountWalletAdapter_instances, _MultichainAccountWalletAdapter_id, _MultichainAccountWalletAdapter_providers, _MultichainAccountWalletAdapter_entropySource, _MultichainAccountWalletAdapter_accounts, _MultichainAccountWalletAdapter_createMultichainAccount;
|
|
17
|
+
import { isScopeEqualToAny } from "@metamask/keyring-utils";
|
|
18
|
+
import { getGroupIndexFromAccountGroupId, toDefaultAccountGroupId, toMultichainAccountId, toMultichainAccountWalletId } from "../index.mjs";
|
|
19
|
+
export class MultichainAccountAdapter {
|
|
20
|
+
constructor({ groupIndex, wallet, providers, }) {
|
|
21
|
+
_MultichainAccountAdapter_id.set(this, void 0);
|
|
22
|
+
_MultichainAccountAdapter_wallet.set(this, void 0);
|
|
23
|
+
_MultichainAccountAdapter_index.set(this, void 0);
|
|
24
|
+
_MultichainAccountAdapter_providers.set(this, void 0);
|
|
25
|
+
_MultichainAccountAdapter_providersByAccountId.set(this, void 0);
|
|
26
|
+
_MultichainAccountAdapter_accounts.set(this, void 0);
|
|
27
|
+
__classPrivateFieldSet(this, _MultichainAccountAdapter_id, toMultichainAccountId(wallet.id, groupIndex), "f");
|
|
28
|
+
__classPrivateFieldSet(this, _MultichainAccountAdapter_index, groupIndex, "f");
|
|
29
|
+
__classPrivateFieldSet(this, _MultichainAccountAdapter_wallet, wallet, "f");
|
|
30
|
+
__classPrivateFieldSet(this, _MultichainAccountAdapter_providers, providers, "f");
|
|
31
|
+
__classPrivateFieldSet(this, _MultichainAccountAdapter_accounts, new Map(), "f");
|
|
32
|
+
__classPrivateFieldSet(this, _MultichainAccountAdapter_providersByAccountId, new Map(), "f");
|
|
33
|
+
for (const provider of __classPrivateFieldGet(this, _MultichainAccountAdapter_providers, "f")) {
|
|
34
|
+
const accounts = provider.getAccounts({
|
|
35
|
+
entropySource: __classPrivateFieldGet(this, _MultichainAccountAdapter_wallet, "f").entropySource,
|
|
36
|
+
groupIndex: __classPrivateFieldGet(this, _MultichainAccountAdapter_index, "f"),
|
|
37
|
+
});
|
|
38
|
+
__classPrivateFieldGet(this, _MultichainAccountAdapter_accounts, "f").set(provider, accounts);
|
|
39
|
+
for (const id of accounts) {
|
|
40
|
+
__classPrivateFieldGet(this, _MultichainAccountAdapter_providersByAccountId, "f").set(id, provider);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
get id() {
|
|
45
|
+
return __classPrivateFieldGet(this, _MultichainAccountAdapter_id, "f");
|
|
46
|
+
}
|
|
47
|
+
get wallet() {
|
|
48
|
+
return __classPrivateFieldGet(this, _MultichainAccountAdapter_wallet, "f");
|
|
49
|
+
}
|
|
50
|
+
get index() {
|
|
51
|
+
return __classPrivateFieldGet(this, _MultichainAccountAdapter_index, "f");
|
|
52
|
+
}
|
|
53
|
+
hasAccounts() {
|
|
54
|
+
// Use this map, cause if there's no accounts, then this map will also
|
|
55
|
+
// be empty.
|
|
56
|
+
return __classPrivateFieldGet(this, _MultichainAccountAdapter_providersByAccountId, "f").size > 0;
|
|
57
|
+
}
|
|
58
|
+
getAccounts() {
|
|
59
|
+
let allAccounts = [];
|
|
60
|
+
for (const [provider, accounts] of __classPrivateFieldGet(this, _MultichainAccountAdapter_accounts, "f").entries()) {
|
|
61
|
+
allAccounts = allAccounts.concat(accounts.map((id) => provider.getAccount(id)));
|
|
62
|
+
}
|
|
63
|
+
return allAccounts;
|
|
64
|
+
}
|
|
65
|
+
getAccount(id) {
|
|
66
|
+
const provider = __classPrivateFieldGet(this, _MultichainAccountAdapter_providersByAccountId, "f").get(id);
|
|
67
|
+
return provider?.getAccount(id);
|
|
68
|
+
}
|
|
69
|
+
get(selector) {
|
|
70
|
+
const accounts = this.select(selector);
|
|
71
|
+
if (accounts.length > 1) {
|
|
72
|
+
throw new Error(`Too many account candidates, expected 1, got: ${accounts.length}`);
|
|
73
|
+
}
|
|
74
|
+
if (accounts.length === 0) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return accounts[0]; // This is safe, see checks above.
|
|
78
|
+
}
|
|
79
|
+
select(selector) {
|
|
80
|
+
return this.getAccounts().filter((account) => {
|
|
81
|
+
let selected = true;
|
|
82
|
+
if (selector.id) {
|
|
83
|
+
selected && (selected = account.id === selector.id);
|
|
84
|
+
}
|
|
85
|
+
if (selector.address) {
|
|
86
|
+
selected && (selected = account.address === selector.address);
|
|
87
|
+
}
|
|
88
|
+
if (selector.type) {
|
|
89
|
+
selected && (selected = account.type === selector.type);
|
|
90
|
+
}
|
|
91
|
+
if (selector.methods !== undefined) {
|
|
92
|
+
selected && (selected = selector.methods.some((method) => account.methods.includes(method)));
|
|
93
|
+
}
|
|
94
|
+
if (selector.scopes !== undefined) {
|
|
95
|
+
selected && (selected = selector.scopes.some((scope) => {
|
|
96
|
+
return (
|
|
97
|
+
// This will cover specific EVM EOA scopes as well.
|
|
98
|
+
isScopeEqualToAny(scope, account.scopes));
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
return selected;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
_MultichainAccountAdapter_id = new WeakMap(), _MultichainAccountAdapter_wallet = new WeakMap(), _MultichainAccountAdapter_index = new WeakMap(), _MultichainAccountAdapter_providers = new WeakMap(), _MultichainAccountAdapter_providersByAccountId = new WeakMap(), _MultichainAccountAdapter_accounts = new WeakMap();
|
|
106
|
+
export class MultichainAccountWalletAdapter {
|
|
107
|
+
constructor({ providers, entropySource, }) {
|
|
108
|
+
_MultichainAccountWalletAdapter_instances.add(this);
|
|
109
|
+
_MultichainAccountWalletAdapter_id.set(this, void 0);
|
|
110
|
+
_MultichainAccountWalletAdapter_providers.set(this, void 0);
|
|
111
|
+
_MultichainAccountWalletAdapter_entropySource.set(this, void 0);
|
|
112
|
+
_MultichainAccountWalletAdapter_accounts.set(this, void 0);
|
|
113
|
+
__classPrivateFieldSet(this, _MultichainAccountWalletAdapter_id, toMultichainAccountWalletId(entropySource), "f");
|
|
114
|
+
__classPrivateFieldSet(this, _MultichainAccountWalletAdapter_providers, providers, "f");
|
|
115
|
+
__classPrivateFieldSet(this, _MultichainAccountWalletAdapter_entropySource, entropySource, "f");
|
|
116
|
+
__classPrivateFieldSet(this, _MultichainAccountWalletAdapter_accounts, new Map(), "f");
|
|
117
|
+
let groupIndex = 0;
|
|
118
|
+
let hasAccounts = false;
|
|
119
|
+
do {
|
|
120
|
+
const multichainAccount = new MultichainAccountAdapter({
|
|
121
|
+
groupIndex,
|
|
122
|
+
wallet: this,
|
|
123
|
+
providers: __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_providers, "f"),
|
|
124
|
+
});
|
|
125
|
+
// We only add multichain account that has underlying accounts.
|
|
126
|
+
hasAccounts = multichainAccount.hasAccounts();
|
|
127
|
+
if (hasAccounts) {
|
|
128
|
+
__classPrivateFieldGet(this, _MultichainAccountWalletAdapter_accounts, "f").set(groupIndex, multichainAccount);
|
|
129
|
+
}
|
|
130
|
+
groupIndex += 1;
|
|
131
|
+
} while (hasAccounts);
|
|
132
|
+
}
|
|
133
|
+
get id() {
|
|
134
|
+
return __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_id, "f");
|
|
135
|
+
}
|
|
136
|
+
get entropySource() {
|
|
137
|
+
return __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_entropySource, "f");
|
|
138
|
+
}
|
|
139
|
+
getAccountGroup(groupId) {
|
|
140
|
+
// We consider the "default case" to be mapped to index 0.
|
|
141
|
+
if (groupId === toDefaultAccountGroupId(this.id)) {
|
|
142
|
+
return __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_accounts, "f").get(0);
|
|
143
|
+
}
|
|
144
|
+
const groupIndex = getGroupIndexFromAccountGroupId(groupId);
|
|
145
|
+
if (groupIndex === undefined) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
return __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_accounts, "f").get(groupIndex);
|
|
149
|
+
}
|
|
150
|
+
getAccountGroups() {
|
|
151
|
+
return this.getMultichainAccounts();
|
|
152
|
+
}
|
|
153
|
+
getMultichainAccount(groupIndex) {
|
|
154
|
+
return __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_accounts, "f").get(groupIndex);
|
|
155
|
+
}
|
|
156
|
+
getMultichainAccounts() {
|
|
157
|
+
return Array.from(__classPrivateFieldGet(this, _MultichainAccountWalletAdapter_accounts, "f").values()); // TODO: Prevent copy here.
|
|
158
|
+
}
|
|
159
|
+
getNextGroupIndex() {
|
|
160
|
+
// Assuming we cannot have indexes gaps.
|
|
161
|
+
return __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_accounts, "f").size; // No +1 here, group indexes starts at 0.
|
|
162
|
+
}
|
|
163
|
+
async createMultichainAccount(groupIndex) {
|
|
164
|
+
const nextGroupIndex = this.getNextGroupIndex();
|
|
165
|
+
if (groupIndex > nextGroupIndex) {
|
|
166
|
+
throw new Error(`You cannot use an group index that is higher than the next available one: expect <${nextGroupIndex}, got ${groupIndex}`);
|
|
167
|
+
}
|
|
168
|
+
for (const provider of __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_providers, "f")) {
|
|
169
|
+
await provider.createAccounts({
|
|
170
|
+
entropySource: __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_entropySource, "f"),
|
|
171
|
+
groupIndex,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
// Re-create and "refresh" the multichain account (we assume all account creations are
|
|
175
|
+
// idempotent, so we should get the same accounts and potentially some new accounts (if
|
|
176
|
+
// some account providers decide to return more of them this time).
|
|
177
|
+
return __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_instances, "m", _MultichainAccountWalletAdapter_createMultichainAccount).call(this, groupIndex);
|
|
178
|
+
}
|
|
179
|
+
async createNextMultichainAccount() {
|
|
180
|
+
return this.createMultichainAccount(this.getNextGroupIndex());
|
|
181
|
+
}
|
|
182
|
+
async discoverAndCreateMultichainAccounts() {
|
|
183
|
+
const multichainAccounts = [];
|
|
184
|
+
let discovered;
|
|
185
|
+
let groupIndex = 0;
|
|
186
|
+
do {
|
|
187
|
+
// Keep track if any accounts got discovered for that new index.
|
|
188
|
+
discovered = false;
|
|
189
|
+
const missingProviders = [];
|
|
190
|
+
for (const provider of __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_providers, "f")) {
|
|
191
|
+
const discoveredAccounts = await provider.discoverAndCreateAccounts({
|
|
192
|
+
entropySource: __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_entropySource, "f"),
|
|
193
|
+
groupIndex,
|
|
194
|
+
});
|
|
195
|
+
if (discoveredAccounts.length) {
|
|
196
|
+
// This provider has discovered and created accounts, meaning there might
|
|
197
|
+
// be something to discover on the next index.
|
|
198
|
+
discovered = true;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// This provider did not discover or create any accounts. We mark it as
|
|
202
|
+
// "missing", so we can create accounts on this index if other providers
|
|
203
|
+
// did discover something.
|
|
204
|
+
missingProviders.push(provider);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (discovered) {
|
|
208
|
+
// We only create missing accounts if one of the provider has discovered
|
|
209
|
+
// and created accounts.
|
|
210
|
+
for (const provider of missingProviders) {
|
|
211
|
+
await provider.createAccounts({
|
|
212
|
+
entropySource: __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_entropySource, "f"),
|
|
213
|
+
groupIndex,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
// We've got all the accounts now, we can create our multichain account.
|
|
217
|
+
multichainAccounts.push(__classPrivateFieldGet(this, _MultichainAccountWalletAdapter_instances, "m", _MultichainAccountWalletAdapter_createMultichainAccount).call(this, groupIndex));
|
|
218
|
+
// We have accounts, we need to check the next index.
|
|
219
|
+
groupIndex += 1;
|
|
220
|
+
}
|
|
221
|
+
} while (discovered);
|
|
222
|
+
return multichainAccounts;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
_MultichainAccountWalletAdapter_id = new WeakMap(), _MultichainAccountWalletAdapter_providers = new WeakMap(), _MultichainAccountWalletAdapter_entropySource = new WeakMap(), _MultichainAccountWalletAdapter_accounts = new WeakMap(), _MultichainAccountWalletAdapter_instances = new WeakSet(), _MultichainAccountWalletAdapter_createMultichainAccount = function _MultichainAccountWalletAdapter_createMultichainAccount(groupIndex) {
|
|
226
|
+
const multichainAccount = new MultichainAccountAdapter({
|
|
227
|
+
wallet: this,
|
|
228
|
+
providers: __classPrivateFieldGet(this, _MultichainAccountWalletAdapter_providers, "f"),
|
|
229
|
+
groupIndex,
|
|
230
|
+
});
|
|
231
|
+
// Register the account to our internal map.
|
|
232
|
+
__classPrivateFieldGet(this, _MultichainAccountWalletAdapter_accounts, "f").set(groupIndex, multichainAccount);
|
|
233
|
+
return multichainAccount;
|
|
234
|
+
};
|
|
235
|
+
//# sourceMappingURL=adapters.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.mjs","sourceRoot":"","sources":["../../../src/api/multichain/adapters.ts"],"names":[],"mappings":"AAAA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BAAiB,CAAC,CAAC;IAElD,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the `InternalAccount` type correctly which causes issue with the\n// union `| undefined`.\n\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { isScopeEqualToAny } from '@metamask/keyring-utils';\n\nimport type {\n AccountGroupId,\n AccountProvider,\n MultichainAccount,\n MultichainAccountId,\n MultichainAccountSelector,\n MultichainAccountWallet,\n MultichainAccountWalletId,\n} from '..';\nimport {\n getGroupIndexFromAccountGroupId,\n toDefaultAccountGroupId,\n toMultichainAccountId,\n toMultichainAccountWalletId,\n} from '..';\n\nexport class MultichainAccountAdapter<Account extends KeyringAccount>\n implements MultichainAccount<Account>\n{\n readonly #id: MultichainAccountId;\n\n readonly #wallet: MultichainAccountWallet<Account>;\n\n readonly #index: number;\n\n readonly #providers: AccountProvider<Account>[];\n\n readonly #providersByAccountId: Map<AccountId, AccountProvider<Account>>;\n\n readonly #accounts: Map<AccountProvider<Account>, AccountId[]>;\n\n constructor({\n groupIndex,\n wallet,\n providers,\n }: {\n groupIndex: number;\n wallet: MultichainAccountWallet<Account>;\n providers: AccountProvider<Account>[];\n }) {\n this.#id = toMultichainAccountId(wallet.id, groupIndex);\n this.#index = groupIndex;\n this.#wallet = wallet;\n this.#providers = providers;\n this.#accounts = new Map();\n this.#providersByAccountId = new Map();\n\n for (const provider of this.#providers) {\n const accounts = provider.getAccounts({\n entropySource: this.#wallet.entropySource,\n groupIndex: this.#index,\n });\n\n this.#accounts.set(provider, accounts);\n for (const id of accounts) {\n this.#providersByAccountId.set(id, provider);\n }\n }\n }\n\n get id(): MultichainAccountId {\n return this.#id;\n }\n\n get wallet(): MultichainAccountWallet<Account> {\n return this.#wallet;\n }\n\n get index(): number {\n return this.#index;\n }\n\n hasAccounts(): boolean {\n // Use this map, cause if there's no accounts, then this map will also\n // be empty.\n return this.#providersByAccountId.size > 0;\n }\n\n getAccounts(): Account[] {\n let allAccounts: Account[] = [];\n\n for (const [provider, accounts] of this.#accounts.entries()) {\n allAccounts = allAccounts.concat(\n accounts.map((id) => provider.getAccount(id)),\n );\n }\n\n return allAccounts;\n }\n\n getAccount(id: AccountId): Account | undefined {\n const provider = this.#providersByAccountId.get(id);\n\n return provider?.getAccount(id);\n }\n\n get(selector: MultichainAccountSelector): Account | undefined {\n const accounts = this.select(selector);\n\n if (accounts.length > 1) {\n throw new Error(\n `Too many account candidates, expected 1, got: ${accounts.length}`,\n );\n }\n\n if (accounts.length === 0) {\n return undefined;\n }\n\n return accounts[0]; // This is safe, see checks above.\n }\n\n select(selector: MultichainAccountSelector): Account[] {\n return this.getAccounts().filter((account) => {\n let selected = true;\n\n if (selector.id) {\n selected &&= account.id === selector.id;\n }\n if (selector.address) {\n selected &&= account.address === selector.address;\n }\n if (selector.type) {\n selected &&= account.type === selector.type;\n }\n if (selector.methods !== undefined) {\n selected &&= selector.methods.some((method) =>\n account.methods.includes(method),\n );\n }\n if (selector.scopes !== undefined) {\n selected &&= selector.scopes.some((scope) => {\n return (\n // This will cover specific EVM EOA scopes as well.\n isScopeEqualToAny(scope, account.scopes)\n );\n });\n }\n\n return selected;\n });\n }\n}\n\nexport class MultichainAccountWalletAdapter<Account extends KeyringAccount>\n implements MultichainAccountWallet<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 let groupIndex = 0;\n let hasAccounts = false;\n\n do {\n const multichainAccount = new MultichainAccountAdapter({\n groupIndex,\n wallet: this,\n providers: this.#providers,\n });\n\n // We only add multichain account that has underlying accounts.\n hasAccounts = multichainAccount.hasAccounts();\n if (hasAccounts) {\n this.#accounts.set(groupIndex, multichainAccount);\n }\n\n groupIndex += 1;\n } while (hasAccounts);\n }\n\n get id(): MultichainAccountWalletId {\n return this.#id;\n }\n\n get entropySource(): EntropySourceId {\n return this.#entropySource;\n }\n\n getAccountGroup(\n groupId: AccountGroupId,\n ): MultichainAccount<Account> | undefined {\n // We consider the \"default case\" to be mapped to index 0.\n if (groupId === toDefaultAccountGroupId(this.id)) {\n return this.#accounts.get(0);\n }\n\n const groupIndex = getGroupIndexFromAccountGroupId(groupId);\n if (groupIndex === undefined) {\n return undefined;\n }\n return this.#accounts.get(groupIndex);\n }\n\n getAccountGroups(): MultichainAccount<Account>[] {\n return this.getMultichainAccounts();\n }\n\n getMultichainAccount(\n groupIndex: number,\n ): MultichainAccount<Account> | undefined {\n return this.#accounts.get(groupIndex);\n }\n\n getMultichainAccounts(): MultichainAccount<Account>[] {\n return Array.from(this.#accounts.values()); // TODO: Prevent copy here.\n }\n\n #createMultichainAccount(groupIndex: number): MultichainAccount<Account> {\n const multichainAccount = new MultichainAccountAdapter({\n wallet: this,\n providers: this.#providers,\n groupIndex,\n });\n\n // Register the account to our internal map.\n this.#accounts.set(groupIndex, multichainAccount);\n\n return multichainAccount;\n }\n\n getNextGroupIndex(): number {\n // Assuming we cannot have indexes gaps.\n return this.#accounts.size; // No +1 here, group indexes starts at 0.\n }\n\n async createMultichainAccount(\n groupIndex: number,\n ): Promise<MultichainAccount<Account>> {\n const nextGroupIndex = this.getNextGroupIndex();\n if (groupIndex > nextGroupIndex) {\n throw new Error(\n `You cannot use an group index that is higher than the next available one: expect <${nextGroupIndex}, got ${groupIndex}`,\n );\n }\n\n for (const provider of this.#providers) {\n await provider.createAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n });\n }\n\n // Re-create and \"refresh\" the multichain account (we assume all account creations are\n // idempotent, so we should get the same accounts and potentially some new accounts (if\n // some account providers decide to return more of them this time).\n return this.#createMultichainAccount(groupIndex);\n }\n\n async createNextMultichainAccount(): Promise<MultichainAccount<Account>> {\n return this.createMultichainAccount(this.getNextGroupIndex());\n }\n\n async discoverAndCreateMultichainAccounts(): Promise<\n MultichainAccount<Account>[]\n > {\n const multichainAccounts: MultichainAccount<Account>[] = [];\n\n let discovered: boolean;\n let groupIndex = 0;\n\n do {\n // Keep track if any accounts got discovered for that new index.\n discovered = false;\n\n const missingProviders = [];\n for (const provider of this.#providers) {\n const discoveredAccounts = await provider.discoverAndCreateAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n });\n\n if (discoveredAccounts.length) {\n // This provider has discovered and created accounts, meaning there might\n // be something to discover on the next index.\n discovered = true;\n } else {\n // This provider did not discover or create any accounts. We mark it as\n // \"missing\", so we can create accounts on this index if other providers\n // did discover something.\n missingProviders.push(provider);\n }\n }\n\n if (discovered) {\n // We only create missing accounts if one of the provider has discovered\n // and created accounts.\n for (const provider of missingProviders) {\n await provider.createAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n });\n }\n\n // We've got all the accounts now, we can create our multichain account.\n multichainAccounts.push(this.#createMultichainAccount(groupIndex));\n\n // We have accounts, we need to check the next index.\n groupIndex += 1;\n }\n } while (discovered);\n\n return multichainAccounts;\n }\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toMultichainAccountWalletId = toMultichainAccountWalletId;
|
|
4
|
+
exports.toMultichainAccountId = toMultichainAccountId;
|
|
5
|
+
exports.getGroupIndexFromAccountGroupId = getGroupIndexFromAccountGroupId;
|
|
6
|
+
const wallet_1 = require("../wallet.cjs");
|
|
7
|
+
const GROUP_INDEX_REGEX = new RegExp(`^${wallet_1.AccountWalletCategory.Entropy}:.*:(?<groupIndex>\\d+)$`, 'u');
|
|
8
|
+
/**
|
|
9
|
+
* Gets the multichain account wallet ID from its entropy source.
|
|
10
|
+
*
|
|
11
|
+
* @param entropySource - Entropy source ID of that wallet.
|
|
12
|
+
* @returns The multichain account wallet ID.
|
|
13
|
+
*/
|
|
14
|
+
function toMultichainAccountWalletId(entropySource) {
|
|
15
|
+
return `${wallet_1.AccountWalletCategory.Entropy}:${entropySource}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets the multichain account ID from its multichain account wallet ID and its index.
|
|
19
|
+
*
|
|
20
|
+
* @param walletId - Multichain account wallet ID.
|
|
21
|
+
* @param groupIndex - Index of that multichain account.
|
|
22
|
+
* @returns The multichain account ID.
|
|
23
|
+
*/
|
|
24
|
+
function toMultichainAccountId(walletId, groupIndex) {
|
|
25
|
+
return `${walletId}:${groupIndex}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Gets the multichain account index from an account group ID.
|
|
29
|
+
*
|
|
30
|
+
* @param groupId - Account group ID.
|
|
31
|
+
* @returns The multichain account index if extractable, undefined otherwise.
|
|
32
|
+
*/
|
|
33
|
+
function getGroupIndexFromAccountGroupId(groupId) {
|
|
34
|
+
const matched = groupId.match(GROUP_INDEX_REGEX);
|
|
35
|
+
if (matched) {
|
|
36
|
+
if (matched.groups?.groupIndex !== undefined) {
|
|
37
|
+
return Number(matched.groups.groupIndex);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Unable to extract group index.
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=id.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.cjs","sourceRoot":"","sources":["../../../src/api/multichain/id.ts"],"names":[],"mappings":";;AAqBA,kEAIC;AASD,sDAKC;AAQD,0EAYC;AAxDD,0CAAkD;AAOlD,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAClC,IAAI,8BAAqB,CAAC,OAAO,0BAA0B,EAC3D,GAAG,CACJ,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,8BAAqB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,QAAmC,EACnC,UAAkB;IAElB,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,+BAA+B,CAC7C,OAAuB;IAEvB,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACjD,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,MAAM,EAAE,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7C,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { EntropySourceId } from '@metamask/keyring-api';\n\nimport type { AccountGroupId } from '../group';\nimport { AccountWalletCategory } from '../wallet';\n\nexport type MultichainAccountWalletId =\n `${AccountWalletCategory.Entropy}:${string}`;\n\nexport type MultichainAccountId = `${MultichainAccountWalletId}:${number}`; // Use number for the account group index.\n\nconst GROUP_INDEX_REGEX = new RegExp(\n `^${AccountWalletCategory.Entropy}:.*:(?<groupIndex>\\\\d+)$`,\n 'u',\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\n/**\n * Gets the multichain account ID from its multichain account wallet ID and its index.\n *\n * @param walletId - Multichain account wallet ID.\n * @param groupIndex - Index of that multichain account.\n * @returns The multichain account ID.\n */\nexport function toMultichainAccountId(\n walletId: MultichainAccountWalletId,\n groupIndex: number,\n): MultichainAccountId {\n return `${walletId}:${groupIndex}`;\n}\n\n/**\n * Gets the multichain account index from an account group ID.\n *\n * @param groupId - Account group ID.\n * @returns The multichain account index if extractable, undefined otherwise.\n */\nexport function getGroupIndexFromAccountGroupId(\n groupId: AccountGroupId,\n): number | undefined {\n const matched = groupId.match(GROUP_INDEX_REGEX);\n if (matched) {\n if (matched.groups?.groupIndex !== undefined) {\n return Number(matched.groups.groupIndex);\n }\n }\n\n // Unable to extract group index.\n return undefined;\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { EntropySourceId } from "@metamask/keyring-api";
|
|
2
|
+
import type { AccountGroupId } from "../group.cjs";
|
|
3
|
+
import { AccountWalletCategory } from "../wallet.cjs";
|
|
4
|
+
export type MultichainAccountWalletId = `${AccountWalletCategory.Entropy}:${string}`;
|
|
5
|
+
export type MultichainAccountId = `${MultichainAccountWalletId}:${number}`;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the multichain account wallet ID from its entropy source.
|
|
8
|
+
*
|
|
9
|
+
* @param entropySource - Entropy source ID of that wallet.
|
|
10
|
+
* @returns The multichain account wallet ID.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toMultichainAccountWalletId(entropySource: EntropySourceId): MultichainAccountWalletId;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the multichain account ID from its multichain account wallet ID and its index.
|
|
15
|
+
*
|
|
16
|
+
* @param walletId - Multichain account wallet ID.
|
|
17
|
+
* @param groupIndex - Index of that multichain account.
|
|
18
|
+
* @returns The multichain account ID.
|
|
19
|
+
*/
|
|
20
|
+
export declare function toMultichainAccountId(walletId: MultichainAccountWalletId, groupIndex: number): MultichainAccountId;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the multichain account index from an account group ID.
|
|
23
|
+
*
|
|
24
|
+
* @param groupId - Account group ID.
|
|
25
|
+
* @returns The multichain account index if extractable, undefined otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getGroupIndexFromAccountGroupId(groupId: AccountGroupId): number | undefined;
|
|
28
|
+
//# sourceMappingURL=id.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAC/C,OAAO,EAAE,qBAAqB,EAAE,sBAAkB;AAElD,MAAM,MAAM,yBAAyB,GACnC,GAAG,qBAAqB,CAAC,OAAO,IAAI,MAAM,EAAE,CAAC;AAE/C,MAAM,MAAM,mBAAmB,GAAG,GAAG,yBAAyB,IAAI,MAAM,EAAE,CAAC;AAO3E;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,yBAAyB,EACnC,UAAU,EAAE,MAAM,GACjB,mBAAmB,CAErB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,cAAc,GACtB,MAAM,GAAG,SAAS,CAUpB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { EntropySourceId } from "@metamask/keyring-api";
|
|
2
|
+
import type { AccountGroupId } from "../group.mjs";
|
|
3
|
+
import { AccountWalletCategory } from "../wallet.mjs";
|
|
4
|
+
export type MultichainAccountWalletId = `${AccountWalletCategory.Entropy}:${string}`;
|
|
5
|
+
export type MultichainAccountId = `${MultichainAccountWalletId}:${number}`;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the multichain account wallet ID from its entropy source.
|
|
8
|
+
*
|
|
9
|
+
* @param entropySource - Entropy source ID of that wallet.
|
|
10
|
+
* @returns The multichain account wallet ID.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toMultichainAccountWalletId(entropySource: EntropySourceId): MultichainAccountWalletId;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the multichain account ID from its multichain account wallet ID and its index.
|
|
15
|
+
*
|
|
16
|
+
* @param walletId - Multichain account wallet ID.
|
|
17
|
+
* @param groupIndex - Index of that multichain account.
|
|
18
|
+
* @returns The multichain account ID.
|
|
19
|
+
*/
|
|
20
|
+
export declare function toMultichainAccountId(walletId: MultichainAccountWalletId, groupIndex: number): MultichainAccountId;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the multichain account index from an account group ID.
|
|
23
|
+
*
|
|
24
|
+
* @param groupId - Account group ID.
|
|
25
|
+
* @returns The multichain account index if extractable, undefined otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getGroupIndexFromAccountGroupId(groupId: AccountGroupId): number | undefined;
|
|
28
|
+
//# sourceMappingURL=id.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAC/C,OAAO,EAAE,qBAAqB,EAAE,sBAAkB;AAElD,MAAM,MAAM,yBAAyB,GACnC,GAAG,qBAAqB,CAAC,OAAO,IAAI,MAAM,EAAE,CAAC;AAE/C,MAAM,MAAM,mBAAmB,GAAG,GAAG,yBAAyB,IAAI,MAAM,EAAE,CAAC;AAO3E;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,yBAAyB,EACnC,UAAU,EAAE,MAAM,GACjB,mBAAmB,CAErB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,cAAc,GACtB,MAAM,GAAG,SAAS,CAUpB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AccountWalletCategory } from "../wallet.mjs";
|
|
2
|
+
const GROUP_INDEX_REGEX = new RegExp(`^${AccountWalletCategory.Entropy}:.*:(?<groupIndex>\\d+)$`, 'u');
|
|
3
|
+
/**
|
|
4
|
+
* Gets the multichain account wallet ID from its entropy source.
|
|
5
|
+
*
|
|
6
|
+
* @param entropySource - Entropy source ID of that wallet.
|
|
7
|
+
* @returns The multichain account wallet ID.
|
|
8
|
+
*/
|
|
9
|
+
export function toMultichainAccountWalletId(entropySource) {
|
|
10
|
+
return `${AccountWalletCategory.Entropy}:${entropySource}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Gets the multichain account ID from its multichain account wallet ID and its index.
|
|
14
|
+
*
|
|
15
|
+
* @param walletId - Multichain account wallet ID.
|
|
16
|
+
* @param groupIndex - Index of that multichain account.
|
|
17
|
+
* @returns The multichain account ID.
|
|
18
|
+
*/
|
|
19
|
+
export function toMultichainAccountId(walletId, groupIndex) {
|
|
20
|
+
return `${walletId}:${groupIndex}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets the multichain account index from an account group ID.
|
|
24
|
+
*
|
|
25
|
+
* @param groupId - Account group ID.
|
|
26
|
+
* @returns The multichain account index if extractable, undefined otherwise.
|
|
27
|
+
*/
|
|
28
|
+
export function getGroupIndexFromAccountGroupId(groupId) {
|
|
29
|
+
const matched = groupId.match(GROUP_INDEX_REGEX);
|
|
30
|
+
if (matched) {
|
|
31
|
+
if (matched.groups?.groupIndex !== undefined) {
|
|
32
|
+
return Number(matched.groups.groupIndex);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Unable to extract group index.
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=id.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.mjs","sourceRoot":"","sources":["../../../src/api/multichain/id.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,sBAAkB;AAOlD,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAClC,IAAI,qBAAqB,CAAC,OAAO,0BAA0B,EAC3D,GAAG,CACJ,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,qBAAqB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAmC,EACnC,UAAkB;IAElB,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAuB;IAEvB,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACjD,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,MAAM,EAAE,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7C,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { EntropySourceId } from '@metamask/keyring-api';\n\nimport type { AccountGroupId } from '../group';\nimport { AccountWalletCategory } from '../wallet';\n\nexport type MultichainAccountWalletId =\n `${AccountWalletCategory.Entropy}:${string}`;\n\nexport type MultichainAccountId = `${MultichainAccountWalletId}:${number}`; // Use number for the account group index.\n\nconst GROUP_INDEX_REGEX = new RegExp(\n `^${AccountWalletCategory.Entropy}:.*:(?<groupIndex>\\\\d+)$`,\n 'u',\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\n/**\n * Gets the multichain account ID from its multichain account wallet ID and its index.\n *\n * @param walletId - Multichain account wallet ID.\n * @param groupIndex - Index of that multichain account.\n * @returns The multichain account ID.\n */\nexport function toMultichainAccountId(\n walletId: MultichainAccountWalletId,\n groupIndex: number,\n): MultichainAccountId {\n return `${walletId}:${groupIndex}`;\n}\n\n/**\n * Gets the multichain account index from an account group ID.\n *\n * @param groupId - Account group ID.\n * @returns The multichain account index if extractable, undefined otherwise.\n */\nexport function getGroupIndexFromAccountGroupId(\n groupId: AccountGroupId,\n): number | undefined {\n const matched = groupId.match(GROUP_INDEX_REGEX);\n if (matched) {\n if (matched.groups?.groupIndex !== undefined) {\n return Number(matched.groups.groupIndex);\n }\n }\n\n // Unable to extract group index.\n return undefined;\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./id.cjs"), exports);
|
|
18
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAqB","sourcesContent":["export * from './id';\nexport type * from './types';\nexport type * from './providers';\nexport type * from './adapters';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,yBAAqB;AACrB,iCAA6B;AAC7B,qCAAiC;AACjC,oCAAgC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,yBAAqB;AACrB,iCAA6B;AAC7B,qCAAiC;AACjC,oCAAgC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,yBAAqB","sourcesContent":["export * from './id';\nexport type * from './types';\nexport type * from './providers';\nexport type * from './adapters';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.cjs","sourceRoot":"","sources":["../../../src/api/multichain/providers.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\n\nexport type AccountProvider<Account extends KeyringAccount> = {\n getAccount: (id: AccountId) => Account; // Assuming getting an account from the provider can never fail.\n\n getAccounts: (opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => AccountId[];\n\n createAccounts: (opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<AccountId[]>;\n\n discoverAndCreateAccounts: (opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<AccountId[]>;\n};\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
+
import type { AccountId } from "@metamask/keyring-utils";
|
|
3
|
+
export type AccountProvider<Account extends KeyringAccount> = {
|
|
4
|
+
getAccount: (id: AccountId) => Account;
|
|
5
|
+
getAccounts: (opts: {
|
|
6
|
+
entropySource: EntropySourceId;
|
|
7
|
+
groupIndex: number;
|
|
8
|
+
}) => AccountId[];
|
|
9
|
+
createAccounts: (opts: {
|
|
10
|
+
entropySource: EntropySourceId;
|
|
11
|
+
groupIndex: number;
|
|
12
|
+
}) => Promise<AccountId[]>;
|
|
13
|
+
discoverAndCreateAccounts: (opts: {
|
|
14
|
+
entropySource: EntropySourceId;
|
|
15
|
+
groupIndex: number;
|
|
16
|
+
}) => Promise<AccountId[]>;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=providers.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAEzD,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D,UAAU,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC;IAEvC,WAAW,EAAE,CAAC,IAAI,EAAE;QAClB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,SAAS,EAAE,CAAC;IAElB,cAAc,EAAE,CAAC,IAAI,EAAE;QACrB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAE3B,yBAAyB,EAAE,CAAC,IAAI,EAAE;QAChC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
+
import type { AccountId } from "@metamask/keyring-utils";
|
|
3
|
+
export type AccountProvider<Account extends KeyringAccount> = {
|
|
4
|
+
getAccount: (id: AccountId) => Account;
|
|
5
|
+
getAccounts: (opts: {
|
|
6
|
+
entropySource: EntropySourceId;
|
|
7
|
+
groupIndex: number;
|
|
8
|
+
}) => AccountId[];
|
|
9
|
+
createAccounts: (opts: {
|
|
10
|
+
entropySource: EntropySourceId;
|
|
11
|
+
groupIndex: number;
|
|
12
|
+
}) => Promise<AccountId[]>;
|
|
13
|
+
discoverAndCreateAccounts: (opts: {
|
|
14
|
+
entropySource: EntropySourceId;
|
|
15
|
+
groupIndex: number;
|
|
16
|
+
}) => Promise<AccountId[]>;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=providers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAEzD,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D,UAAU,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC;IAEvC,WAAW,EAAE,CAAC,IAAI,EAAE;QAClB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,SAAS,EAAE,CAAC;IAElB,cAAc,EAAE,CAAC,IAAI,EAAE;QACrB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAE3B,yBAAyB,EAAE,CAAC,IAAI,EAAE;QAChC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.mjs","sourceRoot":"","sources":["../../../src/api/multichain/providers.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\n\nexport type AccountProvider<Account extends KeyringAccount> = {\n getAccount: (id: AccountId) => Account; // Assuming getting an account from the provider can never fail.\n\n getAccounts: (opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => AccountId[];\n\n createAccounts: (opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<AccountId[]>;\n\n discoverAndCreateAccounts: (opts: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<AccountId[]>;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/api/multichain/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport type { CaipChainId } from '@metamask/utils';\n\nimport type { MultichainAccountId, MultichainAccountWalletId } from './id';\nimport type { AccountGroup } from '../group';\nimport type { AccountWallet } from '../wallet';\n\nexport type AccountType = string;\n\nexport type AccountMethod = string;\n\nexport type MultichainAccountSelector = {\n id?: AccountId;\n address?: string;\n type?: AccountType;\n methods?: AccountMethod[];\n scopes?: CaipChainId[];\n};\n\nexport type MultichainAccount<Account extends KeyringAccount> =\n AccountGroup<Account> & {\n get id(): MultichainAccountId;\n\n get wallet(): MultichainAccountWallet<Account>;\n\n get index(): number;\n\n /**\n * Gets the \"blockchain\" accounts for this multichain account.\n *\n * @param id - Account ID.\n * @returns The \"blockchain\" accounts.\n */\n getAccounts(): Account[];\n\n /**\n * Gets the \"blockchain\" account for a given account ID.\n *\n * @param id - Account ID.\n * @returns The \"blockchain\" account or undefined if not found.\n */\n getAccount(id: AccountId): Account | undefined;\n\n /**\n * Query a \"blockchain\" account matching the selector.\n *\n * @param selector - Query selector.\n * @returns The \"blockchain\" account matching the selector or undefined if not matching.\n * @throws If multiple accounts match the selector.\n */\n get(selector: MultichainAccountSelector): Account | undefined;\n\n /**\n * Query \"blockchain\" accounts matching the selector.\n *\n * @param selector - Query selector.\n * @returns The \"blockchain\" accounts matching the selector.\n */\n select(selector: MultichainAccountSelector): Account[];\n };\n\nexport type MultichainAccountWallet<Account extends KeyringAccount> =\n AccountWallet<Account> & {\n get id(): MultichainAccountWalletId;\n\n get entropySource(): EntropySourceId;\n\n /**\n * Gets multichain account for a given index.\n *\n * @returns Multichain accounts.\n */\n getMultichainAccount(\n groupIndex: number,\n ): MultichainAccount<Account> | undefined;\n\n /**\n * Gets multichain accounts.\n *\n * @returns Multichain accounts.\n */\n getMultichainAccounts(): MultichainAccount<Account>[];\n\n /**\n * Gets the next available account index (named group index internally).\n *\n * @returns Next available group index.\n */\n getNextGroupIndex(): number;\n\n /**\n * Creates a new multichain account on a given group index.\n *\n * NOTE: This method is idempotent.\n *\n * @param groupIndex - Next available group index.\n * @returns New (or existing) multichain account for the given group index.\n */\n createMultichainAccount(\n groupIndex: number,\n ): Promise<MultichainAccount<Account>>;\n\n /**\n * Creates a new multichain account for the next available group index.\n *\n * @returns Next multichain account.\n */\n createNextMultichainAccount(): Promise<MultichainAccount<Account>>;\n\n /**\n * Discovers and automatically create multichain accounts for that wallet.\n *\n * @returns List of all multichain accounts that got discovered or automatically created.\n */\n discoverAndCreateMultichainAccounts(): Promise<\n MultichainAccount<Account>[]\n >;\n };\n"]}
|