@metamask-previews/multichain-account-service 0.2.1-preview-0cb117e2 → 0.2.1-preview-7509efdb
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 +1 -11
- package/dist/MultichainAccountService.cjs +36 -113
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +5 -36
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +5 -36
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +35 -112
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/BaseAccountProvider.cjs +19 -4
- package/dist/providers/BaseAccountProvider.cjs.map +1 -1
- package/dist/providers/BaseAccountProvider.d.cts +19 -5
- package/dist/providers/BaseAccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseAccountProvider.d.mts +19 -5
- package/dist/providers/BaseAccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseAccountProvider.mjs +17 -3
- package/dist/providers/BaseAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts +1 -2
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts +1 -2
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +1 -2
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +1 -2
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/tests/accounts.cjs +3 -7
- package/dist/tests/accounts.cjs.map +1 -1
- package/dist/tests/accounts.d.cts +0 -1
- package/dist/tests/accounts.d.cts.map +1 -1
- package/dist/tests/accounts.d.mts +0 -1
- package/dist/tests/accounts.d.mts.map +1 -1
- package/dist/tests/accounts.mjs +1 -5
- package/dist/tests/accounts.mjs.map +1 -1
- package/dist/tests/messenger.cjs +1 -5
- package/dist/tests/messenger.cjs.map +1 -1
- package/dist/tests/messenger.d.cts +2 -2
- package/dist/tests/messenger.d.cts.map +1 -1
- package/dist/tests/messenger.d.mts +2 -2
- package/dist/tests/messenger.d.mts.map +1 -1
- package/dist/tests/messenger.mjs +1 -5
- package/dist/tests/messenger.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -20
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -20
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,16 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Add multichain account/wallet syncs ([#6165](https://github.com/MetaMask/core/pull/6165))
|
|
13
|
-
- Those are getting sync'd during `AccountsController:account{Added,Removed}` events.
|
|
14
|
-
- Add actions `MultichainAccountService:getMultichain{Account,Accounts,AccountWallet,AccountWallets}` ([#6193](https://github.com/MetaMask/core/pull/6193))
|
|
15
|
-
|
|
16
|
-
### Changed
|
|
17
|
-
|
|
18
|
-
- **BREAKING:** Add `@metamask/account-api` peer dependency ([#6115](https://github.com/MetaMask/core/pull/6115)), ([#6146](https://github.com/MetaMask/core/pull/6146))
|
|
19
|
-
|
|
20
10
|
## [0.2.1]
|
|
21
11
|
|
|
22
12
|
### Fixed
|
|
@@ -33,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
33
23
|
|
|
34
24
|
### Added
|
|
35
25
|
|
|
36
|
-
- Add `MultichainAccountService` ([#6141](https://github.com/MetaMask/core/pull/6141))
|
|
26
|
+
- Add `MultichainAccountService` ([#6141](https://github.com/MetaMask/core/pull/6141))
|
|
37
27
|
- This service manages multichain accounts/wallets.
|
|
38
28
|
|
|
39
29
|
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@0.2.1...HEAD
|
|
@@ -10,14 +10,23 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _MultichainAccountService_instances, _MultichainAccountService_messenger, _MultichainAccountService_providers, _MultichainAccountService_wallets,
|
|
13
|
+
var _MultichainAccountService_instances, _MultichainAccountService_messenger, _MultichainAccountService_providers, _MultichainAccountService_wallets, _MultichainAccountService_setMultichainAccountWallets, _MultichainAccountService_getWallet;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MultichainAccountService =
|
|
15
|
+
exports.MultichainAccountService = void 0;
|
|
16
16
|
const account_api_1 = require("@metamask/account-api");
|
|
17
17
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
18
18
|
const EvmAccountProvider_1 = require("./providers/EvmAccountProvider.cjs");
|
|
19
19
|
const SolAccountProvider_1 = require("./providers/SolAccountProvider.cjs");
|
|
20
|
-
|
|
20
|
+
const serviceName = 'MultichainAccountService';
|
|
21
|
+
/**
|
|
22
|
+
* Select keyrings from keyring controller state.
|
|
23
|
+
*
|
|
24
|
+
* @param state - The keyring controller state.
|
|
25
|
+
* @returns The keyrings.
|
|
26
|
+
*/
|
|
27
|
+
function selectKeyringControllerKeyrings(state) {
|
|
28
|
+
return state.keyrings;
|
|
29
|
+
}
|
|
21
30
|
/**
|
|
22
31
|
* Service to expose multichain accounts capabilities.
|
|
23
32
|
*/
|
|
@@ -34,84 +43,29 @@ class MultichainAccountService {
|
|
|
34
43
|
_MultichainAccountService_messenger.set(this, void 0);
|
|
35
44
|
_MultichainAccountService_providers.set(this, void 0);
|
|
36
45
|
_MultichainAccountService_wallets.set(this, void 0);
|
|
37
|
-
_MultichainAccountService_accountIdToContext.set(this, void 0);
|
|
38
46
|
/**
|
|
39
47
|
* The name of the service.
|
|
40
48
|
*/
|
|
41
|
-
this.name =
|
|
49
|
+
this.name = serviceName;
|
|
42
50
|
__classPrivateFieldSet(this, _MultichainAccountService_messenger, messenger, "f");
|
|
43
51
|
__classPrivateFieldSet(this, _MultichainAccountService_wallets, new Map(), "f");
|
|
44
|
-
__classPrivateFieldSet(this, _MultichainAccountService_accountIdToContext, new Map(), "f");
|
|
45
52
|
// TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.
|
|
46
53
|
__classPrivateFieldSet(this, _MultichainAccountService_providers, [
|
|
47
54
|
new EvmAccountProvider_1.EvmAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
48
55
|
new SolAccountProvider_1.SolAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
49
56
|
], "f");
|
|
50
|
-
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccount', (...args) => this.getMultichainAccount(...args));
|
|
51
|
-
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccounts', (...args) => this.getMultichainAccounts(...args));
|
|
52
|
-
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccountWallet', (...args) => this.getMultichainAccountWallet(...args));
|
|
53
|
-
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccountWallets', (...args) => this.getMultichainAccountWallets(...args));
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
56
59
|
* Initialize the service and constructs the internal reprensentation of
|
|
57
60
|
* multichain accounts and wallets.
|
|
58
61
|
*/
|
|
59
62
|
init() {
|
|
60
|
-
//
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// This will automatically "associate" all multichain accounts for that wallet
|
|
67
|
-
// (based on the accounts owned by each account providers).
|
|
68
|
-
const wallet = new account_api_1.MultichainAccountWallet({
|
|
69
|
-
entropySource,
|
|
70
|
-
providers: __classPrivateFieldGet(this, _MultichainAccountService_providers, "f"),
|
|
71
|
-
});
|
|
72
|
-
__classPrivateFieldGet(this, _MultichainAccountService_wallets, "f").set(wallet.id, wallet);
|
|
73
|
-
// Reverse mapping between account ID and their multichain wallet/account:
|
|
74
|
-
for (const multichainAccount of wallet.getMultichainAccounts()) {
|
|
75
|
-
for (const account of multichainAccount.getAccounts()) {
|
|
76
|
-
__classPrivateFieldGet(this, _MultichainAccountService_accountIdToContext, "f").set(account.id, {
|
|
77
|
-
wallet,
|
|
78
|
-
multichainAccount,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").subscribe('AccountsController:accountAdded', (account) => __classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_handleOnAccountAdded).call(this, account));
|
|
85
|
-
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").subscribe('AccountsController:accountRemoved', (id) => __classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_handleOnAccountRemoved).call(this, id));
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Gets a reference to the wallet and multichain account for a given account ID.
|
|
89
|
-
*
|
|
90
|
-
* @param id - Account ID.
|
|
91
|
-
* @returns An object with references to the wallet and multichain account associated for
|
|
92
|
-
* that account ID, or undefined if this account ID is not part of any.
|
|
93
|
-
*/
|
|
94
|
-
getMultichainAccountAndWallet(id) {
|
|
95
|
-
return __classPrivateFieldGet(this, _MultichainAccountService_accountIdToContext, "f").get(id);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets a reference to the multichain account wallet matching this entropy source.
|
|
99
|
-
*
|
|
100
|
-
* @param options - Options.
|
|
101
|
-
* @param options.entropySource - The entropy source of the multichain account.
|
|
102
|
-
* @throws If none multichain account match this entropy.
|
|
103
|
-
* @returns A reference to the multichain account wallet.
|
|
104
|
-
*/
|
|
105
|
-
getMultichainAccountWallet({ entropySource, }) {
|
|
106
|
-
return __classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_getWallet).call(this, entropySource);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Gets an array of all multichain account wallets.
|
|
110
|
-
*
|
|
111
|
-
* @returns An array of all multichain account wallets.
|
|
112
|
-
*/
|
|
113
|
-
getMultichainAccountWallets() {
|
|
114
|
-
return Array.from(__classPrivateFieldGet(this, _MultichainAccountService_wallets, "f").values());
|
|
63
|
+
// Gather all entropy sources first.
|
|
64
|
+
const state = __classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").call('KeyringController:getState');
|
|
65
|
+
__classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_setMultichainAccountWallets).call(this, state.keyrings);
|
|
66
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").subscribe('KeyringController:stateChange', (keyrings) => {
|
|
67
|
+
__classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_setMultichainAccountWallets).call(this, keyrings);
|
|
68
|
+
}, selectKeyringControllerKeyrings);
|
|
115
69
|
}
|
|
116
70
|
/**
|
|
117
71
|
* Gets a reference to the multichain account matching this entropy source and group index.
|
|
@@ -142,56 +96,25 @@ class MultichainAccountService {
|
|
|
142
96
|
}
|
|
143
97
|
}
|
|
144
98
|
exports.MultichainAccountService = MultichainAccountService;
|
|
145
|
-
_MultichainAccountService_messenger = new WeakMap(), _MultichainAccountService_providers = new WeakMap(), _MultichainAccountService_wallets = new WeakMap(),
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
let multichainAccount = wallet.getMultichainAccount(account.options.entropy.groupIndex);
|
|
163
|
-
if (!multichainAccount) {
|
|
164
|
-
// This new account is a new multichain account, let the wallet know
|
|
165
|
-
// it has to re-sync with its providers.
|
|
166
|
-
if (sync) {
|
|
167
|
-
wallet.sync();
|
|
168
|
-
}
|
|
169
|
-
multichainAccount = wallet.getMultichainAccount(account.options.entropy.groupIndex);
|
|
170
|
-
// If that's a new multichain account. There's nothing to "force-sync".
|
|
171
|
-
sync = false;
|
|
172
|
-
}
|
|
173
|
-
// We have to check against `undefined` in case `getMultichainAccount` is
|
|
174
|
-
// not able to find this multichain account (which should not be possible...)
|
|
175
|
-
if (multichainAccount) {
|
|
176
|
-
if (sync) {
|
|
177
|
-
multichainAccount.sync();
|
|
99
|
+
_MultichainAccountService_messenger = new WeakMap(), _MultichainAccountService_providers = new WeakMap(), _MultichainAccountService_wallets = new WeakMap(), _MultichainAccountService_instances = new WeakSet(), _MultichainAccountService_setMultichainAccountWallets = function _MultichainAccountService_setMultichainAccountWallets(keyrings) {
|
|
100
|
+
for (const keyring of keyrings) {
|
|
101
|
+
if (keyring.type === keyring_controller_1.KeyringTypes.hd) {
|
|
102
|
+
// Only HD keyrings have an entropy source/SRP.
|
|
103
|
+
const entropySource = keyring.metadata.id;
|
|
104
|
+
// Do not re-create wallets if they exists. Even if a keyrings got new accounts, this
|
|
105
|
+
// will be handled by the `*AccountProvider`s which are always in-sync with their
|
|
106
|
+
// keyrings and controllers (like the `AccountsController`).
|
|
107
|
+
if (!__classPrivateFieldGet(this, _MultichainAccountService_wallets, "f").has((0, account_api_1.toMultichainAccountWalletId)(entropySource))) {
|
|
108
|
+
// This will automatically "associate" all multichain accounts for that wallet
|
|
109
|
+
// (based on the accounts owned by each account providers).
|
|
110
|
+
const wallet = new account_api_1.MultichainAccountWallet({
|
|
111
|
+
entropySource,
|
|
112
|
+
providers: __classPrivateFieldGet(this, _MultichainAccountService_providers, "f"),
|
|
113
|
+
});
|
|
114
|
+
__classPrivateFieldGet(this, _MultichainAccountService_wallets, "f").set(wallet.id, wallet);
|
|
115
|
+
}
|
|
178
116
|
}
|
|
179
|
-
// Same here, this account should have been already grouped in that
|
|
180
|
-
// multichain account.
|
|
181
|
-
__classPrivateFieldGet(this, _MultichainAccountService_accountIdToContext, "f").set(account.id, {
|
|
182
|
-
wallet,
|
|
183
|
-
multichainAccount,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}, _MultichainAccountService_handleOnAccountRemoved = function _MultichainAccountService_handleOnAccountRemoved(id) {
|
|
187
|
-
// Force sync of the appropriate wallet if an account got removed.
|
|
188
|
-
const found = __classPrivateFieldGet(this, _MultichainAccountService_accountIdToContext, "f").get(id);
|
|
189
|
-
if (found) {
|
|
190
|
-
const { wallet } = found;
|
|
191
|
-
wallet.sync();
|
|
192
117
|
}
|
|
193
|
-
// Safe to call delete even if the `id` was not referencing a BIP-44 account.
|
|
194
|
-
__classPrivateFieldGet(this, _MultichainAccountService_accountIdToContext, "f").delete(id);
|
|
195
118
|
}, _MultichainAccountService_getWallet = function _MultichainAccountService_getWallet(entropySource) {
|
|
196
119
|
const wallet = __classPrivateFieldGet(this, _MultichainAccountService_wallets, "f").get((0, account_api_1.toMultichainAccountWalletId)(entropySource));
|
|
197
120
|
if (!wallet) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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AAI,oDAAoB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACtC,CAAC,qFAGC,aAA8B;IAE9B,MAAM,MAAM,GAAG,uBAAA,IAAI,yCAAS,CAAC,GAAG,CAC9B,IAAA,yCAA2B,EAAC,aAAa,CAAC,CAC3C,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC3E;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n MultichainAccountWalletId,\n AccountProvider,\n Bip44Account,\n} from '@metamask/account-api';\nimport {\n isBip44Account,\n MultichainAccountWallet,\n toMultichainAccountWalletId,\n type MultichainAccount,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport { SolAccountProvider } from './providers/SolAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\n\nexport const serviceName = 'MultichainAccountService';\n\n/**\n * The options that {@link MultichainAccountService} takes.\n */\ntype MultichainAccountServiceOptions = {\n messenger: MultichainAccountServiceMessenger;\n};\n\n/** Reverse mapping object used to map account IDs and their wallet/multichain account. */\ntype AccountContext<Account extends Bip44Account<KeyringAccount>> = {\n wallet: MultichainAccountWallet<Account>;\n multichainAccount: MultichainAccount<Account>;\n};\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #providers: AccountProvider<Bip44Account<InternalAccount>>[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<InternalAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<InternalAccount>['id'],\n AccountContext<Bip44Account<InternalAccount>>\n >;\n\n /**\n * The name of the service.\n */\n name: typeof serviceName = serviceName;\n\n /**\n * Constructs a new MultichainAccountService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * MultichainAccountService.\n */\n constructor({ messenger }: MultichainAccountServiceOptions) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n this.#accountIdToContext = new Map();\n // TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.\n this.#providers = [\n new EvmAccountProvider(this.#messenger),\n new SolAccountProvider(this.#messenger),\n ];\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccount',\n (...args) => this.getMultichainAccount(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccounts',\n (...args) => this.getMultichainAccounts(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallet',\n (...args) => this.getMultichainAccountWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallets',\n (...args) => this.getMultichainAccountWallets(...args),\n );\n }\n\n /**\n * Initialize the service and constructs the internal reprensentation of\n * multichain accounts and wallets.\n */\n init(): void {\n // Create initial wallets.\n const { keyrings } = this.#messenger.call('KeyringController:getState');\n for (const keyring of keyrings) {\n if (keyring.type === (KeyringTypes.hd as string)) {\n // Only HD keyrings have an entropy source/SRP.\n const entropySource = keyring.metadata.id;\n\n // This will automatically \"associate\" all multichain accounts for that wallet\n // (based on the accounts owned by each account providers).\n const wallet = new MultichainAccountWallet({\n entropySource,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // Reverse mapping between account ID and their multichain wallet/account:\n for (const multichainAccount of wallet.getMultichainAccounts()) {\n for (const account of multichainAccount.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n }\n }\n\n this.#messenger.subscribe('AccountsController:accountAdded', (account) =>\n this.#handleOnAccountAdded(account),\n );\n this.#messenger.subscribe('AccountsController:accountRemoved', (id) =>\n this.#handleOnAccountRemoved(id),\n );\n }\n\n #handleOnAccountAdded(account: InternalAccount): void {\n // We completely omit non-BIP-44 accounts!\n if (!isBip44Account(account)) {\n return;\n }\n\n let sync = true;\n\n let wallet = this.#wallets.get(\n toMultichainAccountWalletId(account.options.entropy.id),\n );\n if (!wallet) {\n // That's a new wallet.\n wallet = new MultichainAccountWallet({\n entropySource: account.options.entropy.id,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // If that's a new wallet wallet. There's nothing to \"force-sync\".\n sync = false;\n }\n\n let multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n if (!multichainAccount) {\n // This new account is a new multichain account, let the wallet know\n // it has to re-sync with its providers.\n if (sync) {\n wallet.sync();\n }\n\n multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n\n // If that's a new multichain account. There's nothing to \"force-sync\".\n sync = false;\n }\n\n // We have to check against `undefined` in case `getMultichainAccount` is\n // not able to find this multichain account (which should not be possible...)\n if (multichainAccount) {\n if (sync) {\n multichainAccount.sync();\n }\n\n // Same here, this account should have been already grouped in that\n // multichain account.\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n\n #handleOnAccountRemoved(id: InternalAccount['id']): void {\n // Force sync of the appropriate wallet if an account got removed.\n const found = this.#accountIdToContext.get(id);\n if (found) {\n const { wallet } = found;\n\n wallet.sync();\n }\n\n // Safe to call delete even if the `id` was not referencing a BIP-44 account.\n this.#accountIdToContext.delete(id);\n }\n\n #getWallet(\n entropySource: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n const wallet = this.#wallets.get(\n toMultichainAccountWalletId(entropySource),\n );\n\n if (!wallet) {\n throw new Error('Unknown wallet, no wallet matching this entropy source');\n }\n\n return wallet;\n }\n\n /**\n * Gets a reference to the wallet and multichain account for a given account ID.\n *\n * @param id - Account ID.\n * @returns An object with references to the wallet and multichain account associated for\n * that account ID, or undefined if this account ID is not part of any.\n */\n getMultichainAccountAndWallet(\n id: InternalAccount['id'],\n ): AccountContext<Bip44Account<InternalAccount>> | undefined {\n return this.#accountIdToContext.get(id);\n }\n\n /**\n * Gets a reference to the multichain account wallet matching this entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @throws If none multichain account match this entropy.\n * @returns A reference to the multichain account wallet.\n */\n getMultichainAccountWallet({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n return this.#getWallet(entropySource);\n }\n\n /**\n * Gets an array of all multichain account wallets.\n *\n * @returns An array of all multichain account wallets.\n */\n getMultichainAccountWallets(): MultichainAccountWallet<\n Bip44Account<InternalAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n /**\n * Gets a reference to the multichain account matching this entropy source and group index.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @param options.groupIndex - The group index of the multichain account.\n * @throws If none multichain account match this entropy source and group index.\n * @returns A reference to the multichain account.\n */\n getMultichainAccount({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccount<Bip44Account<InternalAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccount(groupIndex);\n\n if (!multichainAccount) {\n throw new Error(`No multichain account for index: ${groupIndex}`);\n }\n\n return multichainAccount;\n }\n\n /**\n * Gets all multichain accounts for a given entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source to query.\n * @throws If no multichain accounts match this entropy source.\n * @returns A list of all multichain accounts.\n */\n getMultichainAccounts({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccount<Bip44Account<InternalAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccounts();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.cjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,uDAI+B;AAM/B,qEAA4D;AAG5D,2EA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B,MAAM,IAAI,KAAK,CAAC,oCAAoC,UAAU,EAAE,CAAC,CAAC;SACnE;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACH,qBAAqB,CAAC,EACpB,aAAa,GAGd;QACC,OAAO,uBAAA,IAAI,gFAAW,MAAf,IAAI,EAAY,aAAa,CAAC,CAAC,qBAAqB,EAAE,CAAC;IAChE,CAAC;CACF;AAhID,4DAgIC;yUA9E8B,QAAyB;IACpD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,IAAI,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,EAAa,EAAE;YAChD,+CAA+C;YAC/C,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAE1C,qFAAqF;YACrF,iFAAiF;YACjF,4DAA4D;YAC5D,IAAI,CAAC,uBAAA,IAAI,yCAAS,CAAC,GAAG,CAAC,IAAA,yCAA2B,EAAC,aAAa,CAAC,CAAC,EAAE;gBAClE,8EAA8E;gBAC9E,2DAA2D;gBAC3D,MAAM,MAAM,GAAG,IAAI,qCAAuB,CAAC;oBACzC,aAAa;oBACb,SAAS,EAAE,uBAAA,IAAI,2CAAW;iBAC3B,CAAC,CAAC;gBAEH,uBAAA,IAAI,yCAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;aACtC;SACF;KACF;AACH,CAAC,qFAGC,aAA8B;IAE9B,MAAM,MAAM,GAAG,uBAAA,IAAI,yCAAS,CAAC,GAAG,CAC9B,IAAA,yCAA2B,EAAC,aAAa,CAAC,CAC3C,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC3E;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n MultichainAccountWalletId,\n AccountProvider,\n} from '@metamask/account-api';\nimport {\n MultichainAccountWallet,\n toMultichainAccountWalletId,\n type MultichainAccount,\n} from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport type {\n KeyringControllerState,\n KeyringObject,\n} from '@metamask/keyring-controller';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport { SolAccountProvider } from './providers/SolAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\n\nconst serviceName = 'MultichainAccountService';\n\n/**\n * The options that {@link MultichainAccountService} takes.\n */\ntype MultichainAccountServiceOptions = {\n messenger: MultichainAccountServiceMessenger;\n};\n\n/**\n * Select keyrings from keyring controller state.\n *\n * @param state - The keyring controller state.\n * @returns The keyrings.\n */\nfunction selectKeyringControllerKeyrings(state: KeyringControllerState) {\n return state.keyrings;\n}\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #providers: AccountProvider<InternalAccount>[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<InternalAccount>\n >;\n\n /**\n * The name of the service.\n */\n name: typeof serviceName = serviceName;\n\n /**\n * Constructs a new MultichainAccountService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * MultichainAccountService.\n */\n constructor({ messenger }: MultichainAccountServiceOptions) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n // TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.\n this.#providers = [\n new EvmAccountProvider(this.#messenger),\n new SolAccountProvider(this.#messenger),\n ];\n }\n\n /**\n * Initialize the service and constructs the internal reprensentation of\n * multichain accounts and wallets.\n */\n init(): void {\n // Gather all entropy sources first.\n const state = this.#messenger.call('KeyringController:getState');\n this.#setMultichainAccountWallets(state.keyrings);\n\n this.#messenger.subscribe(\n 'KeyringController:stateChange',\n (keyrings) => {\n this.#setMultichainAccountWallets(keyrings);\n },\n selectKeyringControllerKeyrings,\n );\n }\n\n #setMultichainAccountWallets(keyrings: KeyringObject[]) {\n for (const keyring of keyrings) {\n if (keyring.type === (KeyringTypes.hd as string)) {\n // Only HD keyrings have an entropy source/SRP.\n const entropySource = keyring.metadata.id;\n\n // Do not re-create wallets if they exists. Even if a keyrings got new accounts, this\n // will be handled by the `*AccountProvider`s which are always in-sync with their\n // keyrings and controllers (like the `AccountsController`).\n if (!this.#wallets.has(toMultichainAccountWalletId(entropySource))) {\n // This will automatically \"associate\" all multichain accounts for that wallet\n // (based on the accounts owned by each account providers).\n const wallet = new MultichainAccountWallet({\n entropySource,\n providers: this.#providers,\n });\n\n this.#wallets.set(wallet.id, wallet);\n }\n }\n }\n }\n\n #getWallet(\n entropySource: EntropySourceId,\n ): MultichainAccountWallet<InternalAccount> {\n const wallet = this.#wallets.get(\n toMultichainAccountWalletId(entropySource),\n );\n\n if (!wallet) {\n throw new Error('Unknown wallet, no wallet matching this entropy source');\n }\n\n return wallet;\n }\n\n /**\n * Gets a reference to the multichain account matching this entropy source and group index.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @param options.groupIndex - The group index of the multichain account.\n * @throws If none multichain account match this entropy source and group index.\n * @returns A reference to the multichain account.\n */\n getMultichainAccount({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccount<InternalAccount> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccount(groupIndex);\n\n if (!multichainAccount) {\n throw new Error(`No multichain account for index: ${groupIndex}`);\n }\n\n return multichainAccount;\n }\n\n /**\n * Gets all multichain accounts for a given entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source to query.\n * @throws If no multichain accounts match this entropy source.\n * @returns A list of all multichain accounts.\n */\n getMultichainAccounts({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccount<InternalAccount>[] {\n return this.#getWallet(entropySource).getMultichainAccounts();\n }\n}\n"]}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
1
|
+
import { type MultichainAccount } from "@metamask/account-api";
|
|
2
|
+
import type { EntropySourceId } from "@metamask/keyring-api";
|
|
4
3
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
5
4
|
import type { MultichainAccountServiceMessenger } from "./types.cjs";
|
|
6
|
-
|
|
5
|
+
declare const serviceName = "MultichainAccountService";
|
|
7
6
|
/**
|
|
8
7
|
* The options that {@link MultichainAccountService} takes.
|
|
9
8
|
*/
|
|
10
9
|
type MultichainAccountServiceOptions = {
|
|
11
10
|
messenger: MultichainAccountServiceMessenger;
|
|
12
11
|
};
|
|
13
|
-
/** Reverse mapping object used to map account IDs and their wallet/multichain account. */
|
|
14
|
-
type AccountContext<Account extends Bip44Account<KeyringAccount>> = {
|
|
15
|
-
wallet: MultichainAccountWallet<Account>;
|
|
16
|
-
multichainAccount: MultichainAccount<Account>;
|
|
17
|
-
};
|
|
18
12
|
/**
|
|
19
13
|
* Service to expose multichain accounts capabilities.
|
|
20
14
|
*/
|
|
@@ -37,31 +31,6 @@ export declare class MultichainAccountService {
|
|
|
37
31
|
* multichain accounts and wallets.
|
|
38
32
|
*/
|
|
39
33
|
init(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Gets a reference to the wallet and multichain account for a given account ID.
|
|
42
|
-
*
|
|
43
|
-
* @param id - Account ID.
|
|
44
|
-
* @returns An object with references to the wallet and multichain account associated for
|
|
45
|
-
* that account ID, or undefined if this account ID is not part of any.
|
|
46
|
-
*/
|
|
47
|
-
getMultichainAccountAndWallet(id: InternalAccount['id']): AccountContext<Bip44Account<InternalAccount>> | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Gets a reference to the multichain account wallet matching this entropy source.
|
|
50
|
-
*
|
|
51
|
-
* @param options - Options.
|
|
52
|
-
* @param options.entropySource - The entropy source of the multichain account.
|
|
53
|
-
* @throws If none multichain account match this entropy.
|
|
54
|
-
* @returns A reference to the multichain account wallet.
|
|
55
|
-
*/
|
|
56
|
-
getMultichainAccountWallet({ entropySource, }: {
|
|
57
|
-
entropySource: EntropySourceId;
|
|
58
|
-
}): MultichainAccountWallet<Bip44Account<InternalAccount>>;
|
|
59
|
-
/**
|
|
60
|
-
* Gets an array of all multichain account wallets.
|
|
61
|
-
*
|
|
62
|
-
* @returns An array of all multichain account wallets.
|
|
63
|
-
*/
|
|
64
|
-
getMultichainAccountWallets(): MultichainAccountWallet<Bip44Account<InternalAccount>>[];
|
|
65
34
|
/**
|
|
66
35
|
* Gets a reference to the multichain account matching this entropy source and group index.
|
|
67
36
|
*
|
|
@@ -74,7 +43,7 @@ export declare class MultichainAccountService {
|
|
|
74
43
|
getMultichainAccount({ entropySource, groupIndex, }: {
|
|
75
44
|
entropySource: EntropySourceId;
|
|
76
45
|
groupIndex: number;
|
|
77
|
-
}): MultichainAccount<
|
|
46
|
+
}): MultichainAccount<InternalAccount>;
|
|
78
47
|
/**
|
|
79
48
|
* Gets all multichain accounts for a given entropy source.
|
|
80
49
|
*
|
|
@@ -85,7 +54,7 @@ export declare class MultichainAccountService {
|
|
|
85
54
|
*/
|
|
86
55
|
getMultichainAccounts({ entropySource, }: {
|
|
87
56
|
entropySource: EntropySourceId;
|
|
88
|
-
}): MultichainAccount<
|
|
57
|
+
}): MultichainAccount<InternalAccount>[];
|
|
89
58
|
}
|
|
90
59
|
export {};
|
|
91
60
|
//# sourceMappingURL=MultichainAccountService.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.d.cts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.d.cts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,iBAAiB,EACvB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAM7D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAItE,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AAEjE,QAAA,MAAM,WAAW,6BAA6B,CAAC;AAE/C;;GAEG;AACH,KAAK,+BAA+B,GAAG;IACrC,SAAS,EAAE,iCAAiC,CAAC;CAC9C,CAAC;AAYF;;GAEG;AACH,qBAAa,wBAAwB;;IAUnC;;OAEG;IACH,IAAI,EAAE,OAAO,WAAW,CAAe;IAEvC;;;;;;OAMG;gBACS,EAAE,SAAS,EAAE,EAAE,+BAA+B;IAU1D;;;OAGG;IACH,IAAI,IAAI,IAAI;IAmDZ;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,iBAAiB,CAAC,eAAe,CAAC;IAWtC;;;;;;;OAOG;IACH,qBAAqB,CAAC,EACpB,aAAa,GACd,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;KAChC,GAAG,iBAAiB,CAAC,eAAe,CAAC,EAAE;CAGzC"}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
1
|
+
import { type MultichainAccount } from "@metamask/account-api";
|
|
2
|
+
import type { EntropySourceId } from "@metamask/keyring-api";
|
|
4
3
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
5
4
|
import type { MultichainAccountServiceMessenger } from "./types.mjs";
|
|
6
|
-
|
|
5
|
+
declare const serviceName = "MultichainAccountService";
|
|
7
6
|
/**
|
|
8
7
|
* The options that {@link MultichainAccountService} takes.
|
|
9
8
|
*/
|
|
10
9
|
type MultichainAccountServiceOptions = {
|
|
11
10
|
messenger: MultichainAccountServiceMessenger;
|
|
12
11
|
};
|
|
13
|
-
/** Reverse mapping object used to map account IDs and their wallet/multichain account. */
|
|
14
|
-
type AccountContext<Account extends Bip44Account<KeyringAccount>> = {
|
|
15
|
-
wallet: MultichainAccountWallet<Account>;
|
|
16
|
-
multichainAccount: MultichainAccount<Account>;
|
|
17
|
-
};
|
|
18
12
|
/**
|
|
19
13
|
* Service to expose multichain accounts capabilities.
|
|
20
14
|
*/
|
|
@@ -37,31 +31,6 @@ export declare class MultichainAccountService {
|
|
|
37
31
|
* multichain accounts and wallets.
|
|
38
32
|
*/
|
|
39
33
|
init(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Gets a reference to the wallet and multichain account for a given account ID.
|
|
42
|
-
*
|
|
43
|
-
* @param id - Account ID.
|
|
44
|
-
* @returns An object with references to the wallet and multichain account associated for
|
|
45
|
-
* that account ID, or undefined if this account ID is not part of any.
|
|
46
|
-
*/
|
|
47
|
-
getMultichainAccountAndWallet(id: InternalAccount['id']): AccountContext<Bip44Account<InternalAccount>> | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Gets a reference to the multichain account wallet matching this entropy source.
|
|
50
|
-
*
|
|
51
|
-
* @param options - Options.
|
|
52
|
-
* @param options.entropySource - The entropy source of the multichain account.
|
|
53
|
-
* @throws If none multichain account match this entropy.
|
|
54
|
-
* @returns A reference to the multichain account wallet.
|
|
55
|
-
*/
|
|
56
|
-
getMultichainAccountWallet({ entropySource, }: {
|
|
57
|
-
entropySource: EntropySourceId;
|
|
58
|
-
}): MultichainAccountWallet<Bip44Account<InternalAccount>>;
|
|
59
|
-
/**
|
|
60
|
-
* Gets an array of all multichain account wallets.
|
|
61
|
-
*
|
|
62
|
-
* @returns An array of all multichain account wallets.
|
|
63
|
-
*/
|
|
64
|
-
getMultichainAccountWallets(): MultichainAccountWallet<Bip44Account<InternalAccount>>[];
|
|
65
34
|
/**
|
|
66
35
|
* Gets a reference to the multichain account matching this entropy source and group index.
|
|
67
36
|
*
|
|
@@ -74,7 +43,7 @@ export declare class MultichainAccountService {
|
|
|
74
43
|
getMultichainAccount({ entropySource, groupIndex, }: {
|
|
75
44
|
entropySource: EntropySourceId;
|
|
76
45
|
groupIndex: number;
|
|
77
|
-
}): MultichainAccount<
|
|
46
|
+
}): MultichainAccount<InternalAccount>;
|
|
78
47
|
/**
|
|
79
48
|
* Gets all multichain accounts for a given entropy source.
|
|
80
49
|
*
|
|
@@ -85,7 +54,7 @@ export declare class MultichainAccountService {
|
|
|
85
54
|
*/
|
|
86
55
|
getMultichainAccounts({ entropySource, }: {
|
|
87
56
|
entropySource: EntropySourceId;
|
|
88
|
-
}): MultichainAccount<
|
|
57
|
+
}): MultichainAccount<InternalAccount>[];
|
|
89
58
|
}
|
|
90
59
|
export {};
|
|
91
60
|
//# sourceMappingURL=MultichainAccountService.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.d.mts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.d.mts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,iBAAiB,EACvB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAM7D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAItE,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AAEjE,QAAA,MAAM,WAAW,6BAA6B,CAAC;AAE/C;;GAEG;AACH,KAAK,+BAA+B,GAAG;IACrC,SAAS,EAAE,iCAAiC,CAAC;CAC9C,CAAC;AAYF;;GAEG;AACH,qBAAa,wBAAwB;;IAUnC;;OAEG;IACH,IAAI,EAAE,OAAO,WAAW,CAAe;IAEvC;;;;;;OAMG;gBACS,EAAE,SAAS,EAAE,EAAE,+BAA+B;IAU1D;;;OAGG;IACH,IAAI,IAAI,IAAI;IAmDZ;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,iBAAiB,CAAC,eAAe,CAAC;IAWtC;;;;;;;OAOG;IACH,qBAAqB,CAAC,EACpB,aAAa,GACd,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;KAChC,GAAG,iBAAiB,CAAC,eAAe,CAAC,EAAE;CAGzC"}
|