@metamask-previews/multichain-account-service 0.4.0-preview-7dfc3145 → 0.5.0-preview-f108d6a
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 -3
- package/dist/MultichainAccountService.cjs +1 -26
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +2 -10
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +2 -10
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +1 -26
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/providers/SnapAccountProvider.cjs +1 -5
- package/dist/providers/SnapAccountProvider.cjs.map +1 -1
- package/dist/providers/SnapAccountProvider.d.cts +0 -1
- package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
- package/dist/providers/SnapAccountProvider.d.mts +0 -1
- package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
- package/dist/providers/SnapAccountProvider.mjs +0 -3
- package/dist/providers/SnapAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +1 -1
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +1 -1
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/index.cjs +0 -1
- package/dist/providers/index.cjs.map +1 -1
- package/dist/providers/index.d.cts +0 -1
- package/dist/providers/index.d.cts.map +1 -1
- package/dist/providers/index.d.mts +0 -1
- package/dist/providers/index.d.mts.map +1 -1
- package/dist/providers/index.mjs +0 -1
- package/dist/providers/index.mjs.map +1 -1
- package/dist/tests/providers.cjs +0 -1
- package/dist/tests/providers.cjs.map +1 -1
- package/dist/tests/providers.d.cts +0 -1
- package/dist/tests/providers.d.cts.map +1 -1
- package/dist/tests/providers.d.mts +0 -1
- package/dist/tests/providers.d.mts.map +1 -1
- package/dist/tests/providers.mjs +0 -1
- package/dist/tests/providers.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -5
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -5
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +6 -6
- package/dist/providers/ProviderWrapper.cjs +0 -102
- package/dist/providers/ProviderWrapper.cjs.map +0 -1
- package/dist/providers/ProviderWrapper.d.cts +0 -69
- package/dist/providers/ProviderWrapper.d.cts.map +0 -1
- package/dist/providers/ProviderWrapper.d.mts +0 -69
- package/dist/providers/ProviderWrapper.d.mts.map +0 -1
- package/dist/providers/ProviderWrapper.mjs +0 -97
- package/dist/providers/ProviderWrapper.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,15 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Bump `@metamask/base-controller` from `^8.1.0` to `^8.2.0` ([#6355](https://github.com/MetaMask/core/pull/6355))
|
|
13
|
+
|
|
14
|
+
## [0.5.0]
|
|
15
|
+
|
|
10
16
|
### Added
|
|
11
17
|
|
|
12
18
|
- Allow for multichain account group alignment through the `align` method ([#6326](https://github.com/MetaMask/core/pull/6326))
|
|
13
19
|
- You can now call alignment from the group, wallet and service levels.
|
|
14
|
-
- Add `setBasicFunctionality` method to control providers state and trigger wallets alignment ([#6332](https://github.com/MetaMask/core/pull/6332))
|
|
15
|
-
- Add `ProviderWrapper` to handle Snap account providers behavior when disabled
|
|
16
20
|
|
|
17
21
|
### Changed
|
|
18
22
|
|
|
23
|
+
- **BREAKING:** Bump peer dependency `@metamask/accounts-controller` from `^32.0.0` to `^33.0.0` ([#6345](https://github.com/MetaMask/core/pull/6345))
|
|
24
|
+
- **BREAKING:** Bump peer dependency `@metamask/keyring-controller` from `^22.0.0` to `^23.0.0` ([#6345](https://github.com/MetaMask/core/pull/6345))
|
|
19
25
|
- Bump `@metamask/base-controller` from `^8.0.1` to `^8.1.0` ([#6284](https://github.com/MetaMask/core/pull/6284))
|
|
20
26
|
- Bump accounts related packages ([#6309](https://github.com/MetaMask/core/pull/6309))
|
|
21
27
|
- Bump `@metamask/keyring-api` from `^20.0.0` to `^20.1.0`
|
|
@@ -72,7 +78,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
72
78
|
- Add `MultichainAccountService` ([#6141](https://github.com/MetaMask/core/pull/6141)), ([#6165](https://github.com/MetaMask/core/pull/6165))
|
|
73
79
|
- This service manages multichain accounts/wallets.
|
|
74
80
|
|
|
75
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@0.
|
|
81
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@0.5.0...HEAD
|
|
82
|
+
[0.5.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@0.4.0...@metamask/multichain-account-service@0.5.0
|
|
76
83
|
[0.4.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@0.3.0...@metamask/multichain-account-service@0.4.0
|
|
77
84
|
[0.3.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@0.2.1...@metamask/multichain-account-service@0.3.0
|
|
78
85
|
[0.2.1]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@0.2.0...@metamask/multichain-account-service@0.2.1
|
|
@@ -17,7 +17,6 @@ const account_api_1 = require("@metamask/account-api");
|
|
|
17
17
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
18
18
|
const MultichainAccountWallet_1 = require("./MultichainAccountWallet.cjs");
|
|
19
19
|
const EvmAccountProvider_1 = require("./providers/EvmAccountProvider.cjs");
|
|
20
|
-
const ProviderWrapper_1 = require("./providers/ProviderWrapper.cjs");
|
|
21
20
|
const SolAccountProvider_1 = require("./providers/SolAccountProvider.cjs");
|
|
22
21
|
exports.serviceName = 'MultichainAccountService';
|
|
23
22
|
/**
|
|
@@ -49,7 +48,7 @@ class MultichainAccountService {
|
|
|
49
48
|
// TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.
|
|
50
49
|
__classPrivateFieldSet(this, _MultichainAccountService_providers, [
|
|
51
50
|
new EvmAccountProvider_1.EvmAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
52
|
-
new
|
|
51
|
+
new SolAccountProvider_1.SolAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
53
52
|
// Custom account providers that can be provided by the MetaMask client.
|
|
54
53
|
...providers,
|
|
55
54
|
], "f");
|
|
@@ -59,7 +58,6 @@ class MultichainAccountService {
|
|
|
59
58
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccountWallets', (...args) => this.getMultichainAccountWallets(...args));
|
|
60
59
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:createNextMultichainAccountGroup', (...args) => this.createNextMultichainAccountGroup(...args));
|
|
61
60
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:createMultichainAccountGroup', (...args) => this.createMultichainAccountGroup(...args));
|
|
62
|
-
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:setBasicFunctionality', (...args) => this.setBasicFunctionality(...args));
|
|
63
61
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:alignWallets', (...args) => this.alignWallets(...args));
|
|
64
62
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:alignWallet', (...args) => this.alignWallet(...args));
|
|
65
63
|
}
|
|
@@ -173,29 +171,6 @@ class MultichainAccountService {
|
|
|
173
171
|
async createMultichainAccountGroup({ groupIndex, entropySource, }) {
|
|
174
172
|
return await __classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_getWallet).call(this, entropySource).createMultichainAccountGroup(groupIndex);
|
|
175
173
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Set basic functionality state and trigger alignment if enabled.
|
|
178
|
-
* When basic functionality is disabled, snap-based providers are disabled.
|
|
179
|
-
* When enabled, all snap providers are enabled and wallet alignment is triggered.
|
|
180
|
-
* EVM providers are never disabled as they're required for basic wallet functionality.
|
|
181
|
-
*
|
|
182
|
-
* @param enabled - Whether basic functionality is enabled.
|
|
183
|
-
*/
|
|
184
|
-
async setBasicFunctionality(enabled) {
|
|
185
|
-
console.log(`MultichainAccountService: Setting basic functionality ${enabled ? 'enabled' : 'disabled'}`);
|
|
186
|
-
// Loop through providers and disable only wrapped ones when basic functionality is disabled
|
|
187
|
-
for (const provider of __classPrivateFieldGet(this, _MultichainAccountService_providers, "f")) {
|
|
188
|
-
if ((0, ProviderWrapper_1.isProviderWrapper)(provider)) {
|
|
189
|
-
provider.setDisabled(!enabled);
|
|
190
|
-
}
|
|
191
|
-
// Regular providers (like EVM) are never disabled for basic functionality
|
|
192
|
-
}
|
|
193
|
-
// Trigger alignment only when basic functionality is enabled
|
|
194
|
-
if (enabled) {
|
|
195
|
-
console.log('Triggered wallet alignment...');
|
|
196
|
-
await this.alignWallets();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
174
|
/**
|
|
200
175
|
* Align all multichain account wallets.
|
|
201
176
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.cjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAG+B;AAO/B,qEAA4D;AAG5D,2EAAoE;AACpE,2EAAoE;AACpE,qEAGqC;AACrC,2EAAoE;AAGvD,QAAA,WAAW,GAAG,0BAA0B,CAAC;AAkBtD;;GAEG;AACH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AAC;SACf;QAED,KAAK,GAAG,MAAM,CAAC,yBAAyB,CACtC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CACnC,CAAC;QAEF,uEAAuE;QACvE,IAAI,GAAG,KAAK,CAAC;KACd;IAED,yEAAyE;IACzE,6EAA6E;IAC7E,IAAI,KAAK,EAAE;QACT,IAAI,IAAI,EAAE;YACR,KAAK,CAAC,IAAI,EAAE,CAAC;SACd;QAED,mEAAmE;QACnE,sBAAsB;QACtB,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE;YACvC,MAAM;YACN,KAAK;SACN,CAAC,CAAC;KACJ;AACH,CAAC,+GAEuB,EAAwB;IAC9C,kEAAkE;IAClE,MAAM,KAAK,GAAG,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC/C,IAAI,KAAK,EAAE;QACT,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;QAEzB,MAAM,CAAC,IAAI,EAAE,CAAC;KACf;IAED,6EAA6E;IAC7E,uBAAA,IAAI,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 {\n isBip44Account,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type {\n MultichainAccountWalletId,\n Bip44Account,\n AccountProvider,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport type { MultichainAccountGroup } from './MultichainAccountGroup';\nimport { MultichainAccountWallet } from './MultichainAccountWallet';\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport {\n ProviderWrapper,\n isProviderWrapper,\n} from './providers/ProviderWrapper';\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 Account extends Bip44Account<KeyringAccount>,\n> = {\n messenger: MultichainAccountServiceMessenger;\n providers?: AccountProvider<Account>[];\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 group: MultichainAccountGroup<Account>;\n};\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #providers: (\n | AccountProvider<Bip44Account<KeyringAccount>>\n | ProviderWrapper\n )[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<KeyringAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<KeyringAccount>['id'],\n AccountContext<Bip44Account<KeyringAccount>>\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 * @param options.providers - Optional list of account\n * providers.\n */\n constructor({\n messenger,\n providers = [],\n }: MultichainAccountServiceOptions<Bip44Account<KeyringAccount>>) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n this.#accountIdToContext = new Map();\n\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 ProviderWrapper(new SolAccountProvider(this.#messenger)),\n // Custom account providers that can be provided by the MetaMask client.\n ...providers,\n ];\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroup',\n (...args) => this.getMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroups',\n (...args) => this.getMultichainAccountGroups(...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 this.#messenger.registerActionHandler(\n 'MultichainAccountService:createNextMultichainAccountGroup',\n (...args) => this.createNextMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createMultichainAccountGroup',\n (...args) => this.createMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:setBasicFunctionality',\n (...args) => this.setBasicFunctionality(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallets',\n (...args) => this.alignWallets(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallet',\n (...args) => this.alignWallet(...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 group of wallet.getMultichainAccountGroups()) {\n for (const account of group.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n group,\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: KeyringAccount): 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 group = wallet.getMultichainAccountGroup(\n account.options.entropy.groupIndex,\n );\n if (!group) {\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 group = wallet.getMultichainAccountGroup(\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 (group) {\n if (sync) {\n group.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 group,\n });\n }\n }\n\n #handleOnAccountRemoved(id: KeyringAccount['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<KeyringAccount>> {\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 the account's context which contains its multichain wallet and\n * multichain account group references.\n *\n * @param id - Account ID.\n * @returns The account context if any, undefined otherwise.\n */\n getAccountContext(\n id: KeyringAccount['id'],\n ): AccountContext<Bip44Account<KeyringAccount>> | 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<KeyringAccount>> {\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<KeyringAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n /**\n * Gets a reference to the multichain account group matching this entropy source\n * and a 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 getMultichainAccountGroup({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccountGroup(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 account groups 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 getMultichainAccountGroups({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccountGroups();\n }\n\n /**\n * Creates the next multichain account group.\n *\n * @param options - Options.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The next multichain account group.\n */\n async createNextMultichainAccountGroup({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(\n entropySource,\n ).createNextMultichainAccountGroup();\n }\n\n /**\n * Creates a multichain account group.\n *\n * @param options - Options.\n * @param options.groupIndex - The group index to use.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup({\n groupIndex,\n entropySource,\n }: {\n groupIndex: number;\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(entropySource).createMultichainAccountGroup(\n groupIndex,\n );\n }\n\n /**\n * Set basic functionality state and trigger alignment if enabled.\n * When basic functionality is disabled, snap-based providers are disabled.\n * When enabled, all snap providers are enabled and wallet alignment is triggered.\n * EVM providers are never disabled as they're required for basic wallet functionality.\n *\n * @param enabled - Whether basic functionality is enabled.\n */\n async setBasicFunctionality(enabled: boolean): Promise<void> {\n console.log(\n `MultichainAccountService: Setting basic functionality ${enabled ? 'enabled' : 'disabled'}`,\n );\n\n // Loop through providers and disable only wrapped ones when basic functionality is disabled\n for (const provider of this.#providers) {\n if (isProviderWrapper(provider)) {\n provider.setDisabled(!enabled);\n }\n // Regular providers (like EVM) are never disabled for basic functionality\n }\n\n // Trigger alignment only when basic functionality is enabled\n if (enabled) {\n console.log('Triggered wallet alignment...');\n await this.alignWallets();\n }\n }\n\n /**\n * Align all multichain account wallets.\n */\n async alignWallets(): Promise<void> {\n const wallets = this.getMultichainAccountWallets();\n await Promise.all(wallets.map((w) => w.alignGroups()));\n }\n\n /**\n * Align a specific multichain account wallet.\n *\n * @param entropySource - The entropy source of the multichain account wallet.\n */\n async alignWallet(entropySource: EntropySourceId): Promise<void> {\n const wallet = this.getMultichainAccountWallet({ entropySource });\n await wallet.alignGroups();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.cjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"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IAC/C,IAAI,KAAK,EAAE;QACT,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;QAEzB,MAAM,CAAC,IAAI,EAAE,CAAC;KACf;IAED,6EAA6E;IAC7E,uBAAA,IAAI,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 {\n isBip44Account,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type {\n MultichainAccountWalletId,\n Bip44Account,\n} from '@metamask/account-api';\nimport type { AccountProvider } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport type { MultichainAccountGroup } from './MultichainAccountGroup';\nimport { MultichainAccountWallet } from './MultichainAccountWallet';\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 Account extends Bip44Account<KeyringAccount>,\n> = {\n messenger: MultichainAccountServiceMessenger;\n providers?: AccountProvider<Account>[];\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 group: MultichainAccountGroup<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<KeyringAccount>>[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<KeyringAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<KeyringAccount>['id'],\n AccountContext<Bip44Account<KeyringAccount>>\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 * @param options.providers - Optional list of account\n * providers.\n */\n constructor({\n messenger,\n providers = [],\n }: MultichainAccountServiceOptions<Bip44Account<KeyringAccount>>) {\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 // Custom account providers that can be provided by the MetaMask client.\n ...providers,\n ];\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroup',\n (...args) => this.getMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroups',\n (...args) => this.getMultichainAccountGroups(...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 this.#messenger.registerActionHandler(\n 'MultichainAccountService:createNextMultichainAccountGroup',\n (...args) => this.createNextMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createMultichainAccountGroup',\n (...args) => this.createMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallets',\n (...args) => this.alignWallets(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallet',\n (...args) => this.alignWallet(...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 group of wallet.getMultichainAccountGroups()) {\n for (const account of group.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n group,\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: KeyringAccount): 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 group = wallet.getMultichainAccountGroup(\n account.options.entropy.groupIndex,\n );\n if (!group) {\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 group = wallet.getMultichainAccountGroup(\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 (group) {\n if (sync) {\n group.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 group,\n });\n }\n }\n\n #handleOnAccountRemoved(id: KeyringAccount['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<KeyringAccount>> {\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 the account's context which contains its multichain wallet and\n * multichain account group references.\n *\n * @param id - Account ID.\n * @returns The account context if any, undefined otherwise.\n */\n getAccountContext(\n id: KeyringAccount['id'],\n ): AccountContext<Bip44Account<KeyringAccount>> | 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<KeyringAccount>> {\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<KeyringAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n /**\n * Gets a reference to the multichain account group matching this entropy source\n * and a 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 getMultichainAccountGroup({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccountGroup(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 account groups 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 getMultichainAccountGroups({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccountGroups();\n }\n\n /**\n * Creates the next multichain account group.\n *\n * @param options - Options.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The next multichain account group.\n */\n async createNextMultichainAccountGroup({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(\n entropySource,\n ).createNextMultichainAccountGroup();\n }\n\n /**\n * Creates a multichain account group.\n *\n * @param options - Options.\n * @param options.groupIndex - The group index to use.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup({\n groupIndex,\n entropySource,\n }: {\n groupIndex: number;\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(entropySource).createMultichainAccountGroup(\n groupIndex,\n );\n }\n\n /**\n * Align all multichain account wallets.\n */\n async alignWallets(): Promise<void> {\n const wallets = this.getMultichainAccountWallets();\n await Promise.all(wallets.map((w) => w.alignGroups()));\n }\n\n /**\n * Align a specific multichain account wallet.\n *\n * @param entropySource - The entropy source of the multichain account wallet.\n */\n async alignWallet(entropySource: EntropySourceId): Promise<void> {\n const wallet = this.getMultichainAccountWallet({ entropySource });\n await wallet.alignGroups();\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Bip44Account
|
|
1
|
+
import type { Bip44Account } from "@metamask/account-api";
|
|
2
|
+
import type { AccountProvider } from "@metamask/account-api";
|
|
2
3
|
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
3
4
|
import type { MultichainAccountGroup } from "./MultichainAccountGroup.cjs";
|
|
4
5
|
import { MultichainAccountWallet } from "./MultichainAccountWallet.cjs";
|
|
@@ -112,15 +113,6 @@ export declare class MultichainAccountService {
|
|
|
112
113
|
groupIndex: number;
|
|
113
114
|
entropySource: EntropySourceId;
|
|
114
115
|
}): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>>;
|
|
115
|
-
/**
|
|
116
|
-
* Set basic functionality state and trigger alignment if enabled.
|
|
117
|
-
* When basic functionality is disabled, snap-based providers are disabled.
|
|
118
|
-
* When enabled, all snap providers are enabled and wallet alignment is triggered.
|
|
119
|
-
* EVM providers are never disabled as they're required for basic wallet functionality.
|
|
120
|
-
*
|
|
121
|
-
* @param enabled - Whether basic functionality is enabled.
|
|
122
|
-
*/
|
|
123
|
-
setBasicFunctionality(enabled: boolean): Promise<void>;
|
|
124
116
|
/**
|
|
125
117
|
* Align all multichain account wallets.
|
|
126
118
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.d.cts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,YAAY,
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.d.cts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,YAAY,EACb,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAG7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,qCAAiC;AACvE,OAAO,EAAE,uBAAuB,E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sB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IAWxD;;;;;;;OAOG;IACH,0BAA0B,CAAC,EACzB,aAAa,GACd,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;KAChC,GAAG,sBAAsB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,EAAE;IAI1D;;;;;;OAMG;IACG,gCAAgC,CAAC,EACrC,aAAa,GACd,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;KAChC,GAAG,OAAO,CAAC,sBAAsB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC;IAMjE;;;;;;;OAOG;IACG,4BAA4B,CAAC,EACjC,UAAU,EACV,aAAa,GACd,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,eAAe,CAAC;KAChC,GAAG,OAAO,CAAC,sBAAsB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC;IAMjE;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAKnC;;;;OAIG;IACG,WAAW,CAAC,aAAa,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAIjE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Bip44Account
|
|
1
|
+
import type { Bip44Account } from "@metamask/account-api";
|
|
2
|
+
import type { AccountProvider } from "@metamask/account-api";
|
|
2
3
|
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
3
4
|
import type { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
|
|
4
5
|
import { MultichainAccountWallet } from "./MultichainAccountWallet.mjs";
|
|
@@ -112,15 +113,6 @@ export declare class MultichainAccountService {
|
|
|
112
113
|
groupIndex: number;
|
|
113
114
|
entropySource: EntropySourceId;
|
|
114
115
|
}): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>>;
|
|
115
|
-
/**
|
|
116
|
-
* Set basic functionality state and trigger alignment if enabled.
|
|
117
|
-
* When basic functionality is disabled, snap-based providers are disabled.
|
|
118
|
-
* When enabled, all snap providers are enabled and wallet alignment is triggered.
|
|
119
|
-
* EVM providers are never disabled as they're required for basic wallet functionality.
|
|
120
|
-
*
|
|
121
|
-
* @param enabled - Whether basic functionality is enabled.
|
|
122
|
-
*/
|
|
123
|
-
setBasicFunctionality(enabled: boolean): Promise<void>;
|
|
124
116
|
/**
|
|
125
117
|
* Align all multichain account wallets.
|
|
126
118
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.d.mts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,YAAY,
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.d.mts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,YAAY,EACb,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAG7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,qCAAiC;AACvE,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AAGpE,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AAEjE,eAAO,MAAM,WAAW,6BAA6B,CAAC;AAEtD;;GAEG;AACH,KAAK,+BAA+B,CAClC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C;IACF,SAAS,EAAE,iCAAiC,CAAC;IAC7C,SAAS,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;CACxC,CAAC;AAEF,0FAA0F;AAC1F,KAAK,cAAc,CAAC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAAI;IAClE,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACzC,KAAK,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,qBAAa,wBA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C,sBAAsB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC;IAMjE;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAKnC;;;;OAIG;IACG,WAAW,CAAC,aAAa,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAIjE"}
|
|
@@ -14,7 +14,6 @@ import { isBip44Account, toMultichainAccountWalletId } from "@metamask/account-a
|
|
|
14
14
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
15
15
|
import { MultichainAccountWallet } from "./MultichainAccountWallet.mjs";
|
|
16
16
|
import { EvmAccountProvider } from "./providers/EvmAccountProvider.mjs";
|
|
17
|
-
import { ProviderWrapper, isProviderWrapper } from "./providers/ProviderWrapper.mjs";
|
|
18
17
|
import { SolAccountProvider } from "./providers/SolAccountProvider.mjs";
|
|
19
18
|
export const serviceName = 'MultichainAccountService';
|
|
20
19
|
/**
|
|
@@ -46,7 +45,7 @@ export class MultichainAccountService {
|
|
|
46
45
|
// TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.
|
|
47
46
|
__classPrivateFieldSet(this, _MultichainAccountService_providers, [
|
|
48
47
|
new EvmAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
49
|
-
new
|
|
48
|
+
new SolAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
50
49
|
// Custom account providers that can be provided by the MetaMask client.
|
|
51
50
|
...providers,
|
|
52
51
|
], "f");
|
|
@@ -56,7 +55,6 @@ export class MultichainAccountService {
|
|
|
56
55
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccountWallets', (...args) => this.getMultichainAccountWallets(...args));
|
|
57
56
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:createNextMultichainAccountGroup', (...args) => this.createNextMultichainAccountGroup(...args));
|
|
58
57
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:createMultichainAccountGroup', (...args) => this.createMultichainAccountGroup(...args));
|
|
59
|
-
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:setBasicFunctionality', (...args) => this.setBasicFunctionality(...args));
|
|
60
58
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:alignWallets', (...args) => this.alignWallets(...args));
|
|
61
59
|
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:alignWallet', (...args) => this.alignWallet(...args));
|
|
62
60
|
}
|
|
@@ -170,29 +168,6 @@ export class MultichainAccountService {
|
|
|
170
168
|
async createMultichainAccountGroup({ groupIndex, entropySource, }) {
|
|
171
169
|
return await __classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_getWallet).call(this, entropySource).createMultichainAccountGroup(groupIndex);
|
|
172
170
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Set basic functionality state and trigger alignment if enabled.
|
|
175
|
-
* When basic functionality is disabled, snap-based providers are disabled.
|
|
176
|
-
* When enabled, all snap providers are enabled and wallet alignment is triggered.
|
|
177
|
-
* EVM providers are never disabled as they're required for basic wallet functionality.
|
|
178
|
-
*
|
|
179
|
-
* @param enabled - Whether basic functionality is enabled.
|
|
180
|
-
*/
|
|
181
|
-
async setBasicFunctionality(enabled) {
|
|
182
|
-
console.log(`MultichainAccountService: Setting basic functionality ${enabled ? 'enabled' : 'disabled'}`);
|
|
183
|
-
// Loop through providers and disable only wrapped ones when basic functionality is disabled
|
|
184
|
-
for (const provider of __classPrivateFieldGet(this, _MultichainAccountService_providers, "f")) {
|
|
185
|
-
if (isProviderWrapper(provider)) {
|
|
186
|
-
provider.setDisabled(!enabled);
|
|
187
|
-
}
|
|
188
|
-
// Regular providers (like EVM) are never disabled for basic functionality
|
|
189
|
-
}
|
|
190
|
-
// Trigger alignment only when basic functionality is enabled
|
|
191
|
-
if (enabled) {
|
|
192
|
-
console.log('Triggered wallet alignment...');
|
|
193
|
-
await this.alignWallets();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
171
|
/**
|
|
197
172
|
* Align all multichain account wallets.
|
|
198
173
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.mjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,cAAc,EACd,2BAA2B,EAC5B,8BAA8B;AAO/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AACpE,OAAO,EACL,eAAe,EACf,iBAAiB,EAClB,wCAAoC;AACrC,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AAGpE,MAAM,CAAC,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAkBtD;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAuBnC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,SAAS,GAAG,EAAE,GACgD;;QAlCvD,sDAA8C;QAE9C,sDAGL;QAEK,oDAGP;QAEO,+DAGP;QAEF;;WAEG;QACH,SAAI,GAAuB,WAAW,CAAC;QAerC,uBAAA,IAAI,uCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,qCAAY,IAAI,GAAG,EAAE,MAAA,CAAC;QAC1B,uBAAA,IAAI,gDAAuB,IAAI,GAAG,EAAE,MAAA,CAAC;QAErC,mFAAmF;QACnF,uBAAA,IAAI,uCAAc;YAChB,IAAI,kBAAkB,CAAC,uBAAA,IAAI,2CAAW,CAAC;YACvC,IAAI,eAAe,CAAC,IAAI,kBAAkB,CAAC,uBAAA,IAAI,2CAAW,CAAC,CAAC;YAC5D,wEAAwE;YACxE,GAAG,SAAS;SACb,MAAA,CAAC;QAEF,uBAAA,IAAI,2CAAW,CAAC,qBAA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ACf;IAED,6EAA6E;IAC7E,uBAAA,IAAI,oDAAoB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACtC,CAAC,qFAGC,aAA8B;IAE9B,MAAM,MAAM,GAAG,uBAAA,IAAI,yCAAS,CAAC,GAAG,CAC9B,2BAA2B,CAAC,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 {\n isBip44Account,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type {\n MultichainAccountWalletId,\n Bip44Account,\n AccountProvider,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport type { MultichainAccountGroup } from './MultichainAccountGroup';\nimport { MultichainAccountWallet } from './MultichainAccountWallet';\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport {\n ProviderWrapper,\n isProviderWrapper,\n} from './providers/ProviderWrapper';\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 Account extends Bip44Account<KeyringAccount>,\n> = {\n messenger: MultichainAccountServiceMessenger;\n providers?: AccountProvider<Account>[];\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 group: MultichainAccountGroup<Account>;\n};\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #providers: (\n | AccountProvider<Bip44Account<KeyringAccount>>\n | ProviderWrapper\n )[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<KeyringAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<KeyringAccount>['id'],\n AccountContext<Bip44Account<KeyringAccount>>\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 * @param options.providers - Optional list of account\n * providers.\n */\n constructor({\n messenger,\n providers = [],\n }: MultichainAccountServiceOptions<Bip44Account<KeyringAccount>>) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n this.#accountIdToContext = new Map();\n\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 ProviderWrapper(new SolAccountProvider(this.#messenger)),\n // Custom account providers that can be provided by the MetaMask client.\n ...providers,\n ];\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroup',\n (...args) => this.getMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroups',\n (...args) => this.getMultichainAccountGroups(...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 this.#messenger.registerActionHandler(\n 'MultichainAccountService:createNextMultichainAccountGroup',\n (...args) => this.createNextMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createMultichainAccountGroup',\n (...args) => this.createMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:setBasicFunctionality',\n (...args) => this.setBasicFunctionality(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallets',\n (...args) => this.alignWallets(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallet',\n (...args) => this.alignWallet(...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 group of wallet.getMultichainAccountGroups()) {\n for (const account of group.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n group,\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: KeyringAccount): 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 group = wallet.getMultichainAccountGroup(\n account.options.entropy.groupIndex,\n );\n if (!group) {\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 group = wallet.getMultichainAccountGroup(\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 (group) {\n if (sync) {\n group.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 group,\n });\n }\n }\n\n #handleOnAccountRemoved(id: KeyringAccount['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<KeyringAccount>> {\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 the account's context which contains its multichain wallet and\n * multichain account group references.\n *\n * @param id - Account ID.\n * @returns The account context if any, undefined otherwise.\n */\n getAccountContext(\n id: KeyringAccount['id'],\n ): AccountContext<Bip44Account<KeyringAccount>> | 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<KeyringAccount>> {\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<KeyringAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n /**\n * Gets a reference to the multichain account group matching this entropy source\n * and a 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 getMultichainAccountGroup({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccountGroup(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 account groups 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 getMultichainAccountGroups({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccountGroups();\n }\n\n /**\n * Creates the next multichain account group.\n *\n * @param options - Options.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The next multichain account group.\n */\n async createNextMultichainAccountGroup({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(\n entropySource,\n ).createNextMultichainAccountGroup();\n }\n\n /**\n * Creates a multichain account group.\n *\n * @param options - Options.\n * @param options.groupIndex - The group index to use.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup({\n groupIndex,\n entropySource,\n }: {\n groupIndex: number;\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(entropySource).createMultichainAccountGroup(\n groupIndex,\n );\n }\n\n /**\n * Set basic functionality state and trigger alignment if enabled.\n * When basic functionality is disabled, snap-based providers are disabled.\n * When enabled, all snap providers are enabled and wallet alignment is triggered.\n * EVM providers are never disabled as they're required for basic wallet functionality.\n *\n * @param enabled - Whether basic functionality is enabled.\n */\n async setBasicFunctionality(enabled: boolean): Promise<void> {\n console.log(\n `MultichainAccountService: Setting basic functionality ${enabled ? 'enabled' : 'disabled'}`,\n );\n\n // Loop through providers and disable only wrapped ones when basic functionality is disabled\n for (const provider of this.#providers) {\n if (isProviderWrapper(provider)) {\n provider.setDisabled(!enabled);\n }\n // Regular providers (like EVM) are never disabled for basic functionality\n }\n\n // Trigger alignment only when basic functionality is enabled\n if (enabled) {\n console.log('Triggered wallet alignment...');\n await this.alignWallets();\n }\n }\n\n /**\n * Align all multichain account wallets.\n */\n async alignWallets(): Promise<void> {\n const wallets = this.getMultichainAccountWallets();\n await Promise.all(wallets.map((w) => w.alignGroups()));\n }\n\n /**\n * Align a specific multichain account wallet.\n *\n * @param entropySource - The entropy source of the multichain account wallet.\n */\n async alignWallet(entropySource: EntropySourceId): Promise<void> {\n const wallet = this.getMultichainAccountWallet({ entropySource });\n await wallet.alignGroups();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.mjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,cAAc,EACd,2BAA2B,EAC5B,8BAA8B;AAO/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AACpE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AAGpE,MAAM,CAAC,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAkBtD;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAoBnC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,SAAS,GAAG,EAAE,GACgD;;QA/BvD,sDAA8C;QAE9C,sDAA4D;QAE5D,oDAGP;QAEO,+DAGP;QAEF;;WAEG;QACH,SAAI,GAAuB,WAAW,CAAC;QAerC,uBAAA,IAAI,uCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,qCAAY,IAAI,GAAG,EAAE,MAAA,CAAC;QAC1B,uBAAA,IAAI,gDAAuB,IAAI,GAAG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O,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CACnC,CAAC;IACF,IAAI,CAAC,KAAK,EAAE;QACV,oEAAoE;QACpE,wCAAwC;QACxC,IAAI,IAAI,EAAE;YACR,MAAM,CAAC,IAAI,EAAE,CAAC;SACf;QAED,KAAK,GAAG,MAAM,CAAC,yBAAyB,CACtC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CACnC,CAAC;QAEF,uEAAuE;QACvE,IAAI,GAAG,KAAK,CAAC;KACd;IAED,yEAAyE;IACzE,6EAA6E;IAC7E,IAAI,KAAK,EAAE;QACT,IAAI,IAAI,EAAE;YACR,KAAK,CAAC,IAAI,EAAE,CAAC;SACd;QAED,mEAAmE;QACnE,sBAAsB;QACtB,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE;YACvC,MAAM;YACN,KAAK;SACN,CAAC,CAAC;KACJ;AACH,CAAC,+GAEuB,EAAwB;IAC9C,kEAAkE;IAClE,MAAM,KAAK,GAAG,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC/C,IAAI,KAAK,EAAE;QACT,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;QAEzB,MAAM,CAAC,IAAI,EAAE,CAAC;KACf;IAED,6EAA6E;IAC7E,uBAAA,IAAI,oDAAoB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACtC,CAAC,qFAGC,aAA8B;IAE9B,MAAM,MAAM,GAAG,uBAAA,IAAI,yCAAS,CAAC,GAAG,CAC9B,2BAA2B,CAAC,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 {\n isBip44Account,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type {\n MultichainAccountWalletId,\n Bip44Account,\n} from '@metamask/account-api';\nimport type { AccountProvider } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport type { MultichainAccountGroup } from './MultichainAccountGroup';\nimport { MultichainAccountWallet } from './MultichainAccountWallet';\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 Account extends Bip44Account<KeyringAccount>,\n> = {\n messenger: MultichainAccountServiceMessenger;\n providers?: AccountProvider<Account>[];\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 group: MultichainAccountGroup<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<KeyringAccount>>[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<KeyringAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<KeyringAccount>['id'],\n AccountContext<Bip44Account<KeyringAccount>>\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 * @param options.providers - Optional list of account\n * providers.\n */\n constructor({\n messenger,\n providers = [],\n }: MultichainAccountServiceOptions<Bip44Account<KeyringAccount>>) {\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 // Custom account providers that can be provided by the MetaMask client.\n ...providers,\n ];\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroup',\n (...args) => this.getMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroups',\n (...args) => this.getMultichainAccountGroups(...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 this.#messenger.registerActionHandler(\n 'MultichainAccountService:createNextMultichainAccountGroup',\n (...args) => this.createNextMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createMultichainAccountGroup',\n (...args) => this.createMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallets',\n (...args) => this.alignWallets(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallet',\n (...args) => this.alignWallet(...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 group of wallet.getMultichainAccountGroups()) {\n for (const account of group.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n group,\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: KeyringAccount): 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 group = wallet.getMultichainAccountGroup(\n account.options.entropy.groupIndex,\n );\n if (!group) {\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 group = wallet.getMultichainAccountGroup(\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 (group) {\n if (sync) {\n group.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 group,\n });\n }\n }\n\n #handleOnAccountRemoved(id: KeyringAccount['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<KeyringAccount>> {\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 the account's context which contains its multichain wallet and\n * multichain account group references.\n *\n * @param id - Account ID.\n * @returns The account context if any, undefined otherwise.\n */\n getAccountContext(\n id: KeyringAccount['id'],\n ): AccountContext<Bip44Account<KeyringAccount>> | 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<KeyringAccount>> {\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<KeyringAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n /**\n * Gets a reference to the multichain account group matching this entropy source\n * and a 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 getMultichainAccountGroup({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccountGroup(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 account groups 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 getMultichainAccountGroups({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccountGroups();\n }\n\n /**\n * Creates the next multichain account group.\n *\n * @param options - Options.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The next multichain account group.\n */\n async createNextMultichainAccountGroup({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(\n entropySource,\n ).createNextMultichainAccountGroup();\n }\n\n /**\n * Creates a multichain account group.\n *\n * @param options - Options.\n * @param options.groupIndex - The group index to use.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup({\n groupIndex,\n entropySource,\n }: {\n groupIndex: number;\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(entropySource).createMultichainAccountGroup(\n groupIndex,\n );\n }\n\n /**\n * Align all multichain account wallets.\n */\n async alignWallets(): Promise<void> {\n const wallets = this.getMultichainAccountWallets();\n await Promise.all(wallets.map((w) => w.alignGroups()));\n }\n\n /**\n * Align a specific multichain account wallet.\n *\n * @param entropySource - The entropy source of the multichain account wallet.\n */\n async alignWallet(entropySource: EntropySourceId): Promise<void> {\n const wallet = this.getMultichainAccountWallet({ entropySource });\n await wallet.alignGroups();\n }\n}\n"]}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SnapAccountProvider =
|
|
3
|
+
exports.SnapAccountProvider = void 0;
|
|
4
4
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
5
5
|
const BaseAccountProvider_1 = require("./BaseAccountProvider.cjs");
|
|
6
|
-
const isSnapAccountProvider = (provider) => {
|
|
7
|
-
return (provider !== null && typeof provider === 'object' && 'snapId' in provider);
|
|
8
|
-
};
|
|
9
|
-
exports.isSnapAccountProvider = isSnapAccountProvider;
|
|
10
6
|
class SnapAccountProvider extends BaseAccountProvider_1.BaseAccountProvider {
|
|
11
7
|
constructor(snapId, messenger) {
|
|
12
8
|
super(messenger);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":";;;AAGA,qEAA4D;AAK5D,mEAA4D;
|
|
1
|
+
{"version":3,"file":"SnapAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":";;;AAGA,qEAA4D;AAK5D,mEAA4D;AAM5D,MAAsB,mBAAoB,SAAQ,yCAAmB;IAGnE,YAAY,MAAc,EAAE,SAA4C;QACtE,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAES,KAAK,CAAC,+BAA+B;QAC7C,iFAAiF;QACjF,gFAAgF;QAChF,sCAAsC;QACtC,+EAA+E;QAC/E,iFAAiF;QACjF,wDAAwD;QACxD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAG1C,EAAE,IAAI,EAAE,iCAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CACnD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CACpC,CAAC;QAEF,OAAO,CAAC,OAAO,EAAE,EAAE,CACjB,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE;YAClC,4BAA4B,EAAE,KAAK;YACnC,mBAAmB,EAAE,KAAK;YAC1B,kBAAkB,EAAE,KAAK;SAC1B,CAAC,CAAC;IACP,CAAC;CAaF;AA1CD,kDA0CC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Json, SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { BaseAccountProvider } from './BaseAccountProvider';\n\nexport type RestrictedSnapKeyringCreateAccount = (\n options: Record<string, Json>,\n) => Promise<KeyringAccount>;\n\nexport abstract class SnapAccountProvider extends BaseAccountProvider {\n readonly snapId: SnapId;\n\n constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger) {\n super(messenger);\n\n this.snapId = snapId;\n }\n\n protected async getRestrictedSnapAccountCreator(): Promise<RestrictedSnapKeyringCreateAccount> {\n // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but\n // we have to use the `SnapKeyring` instance to be able to create Solana account\n // without triggering UI confirmation.\n // Also, creating account that way won't invalidate the Snap keyring state. The\n // account will get created and persisted properly with the Snap account creation\n // flow \"asynchronously\" (with `notify:accountCreated`).\n const createAccount = await this.withKeyring<\n SnapKeyring,\n SnapKeyring['createAccount']\n >({ type: KeyringTypes.snap }, async ({ keyring }) =>\n keyring.createAccount.bind(keyring),\n );\n\n return (options) =>\n createAccount(this.snapId, options, {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n });\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n\n abstract createAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n\n abstract discoverAndCreateAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n}\n"]}
|
|
@@ -5,7 +5,6 @@ import type { Json, SnapId } from "@metamask/snaps-sdk";
|
|
|
5
5
|
import type { MultichainAccountServiceMessenger } from "src/types";
|
|
6
6
|
import { BaseAccountProvider } from "./BaseAccountProvider.cjs";
|
|
7
7
|
export type RestrictedSnapKeyringCreateAccount = (options: Record<string, Json>) => Promise<KeyringAccount>;
|
|
8
|
-
export declare const isSnapAccountProvider: (provider: unknown) => provider is SnapAccountProvider;
|
|
9
8
|
export declare abstract class SnapAccountProvider extends BaseAccountProvider {
|
|
10
9
|
readonly snapId: SnapId;
|
|
11
10
|
constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B;AACxD,OAAO,KAAK,EAAE,iCAAiC,EAAE,kBAAkB;AAEnE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,MAAM,MAAM,kCAAkC,GAAG,CAC/C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAC1B,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B,
|
|
1
|
+
{"version":3,"file":"SnapAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B;AACxD,OAAO,KAAK,EAAE,iCAAiC,EAAE,kBAAkB;AAEnE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,MAAM,MAAM,kCAAkC,GAAG,CAC/C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAC1B,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B,8BAAsB,mBAAoB,SAAQ,mBAAmB;IACnE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,iCAAiC;cAMxD,+BAA+B,IAAI,OAAO,CAAC,kCAAkC,CAAC;IAsB9F,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAE7E,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE;QAC/B,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAE3C,QAAQ,CAAC,yBAAyB,CAAC,OAAO,EAAE;QAC1C,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAC5C"}
|
|
@@ -5,7 +5,6 @@ import type { Json, SnapId } from "@metamask/snaps-sdk";
|
|
|
5
5
|
import type { MultichainAccountServiceMessenger } from "src/types";
|
|
6
6
|
import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
|
|
7
7
|
export type RestrictedSnapKeyringCreateAccount = (options: Record<string, Json>) => Promise<KeyringAccount>;
|
|
8
|
-
export declare const isSnapAccountProvider: (provider: unknown) => provider is SnapAccountProvider;
|
|
9
8
|
export declare abstract class SnapAccountProvider extends BaseAccountProvider {
|
|
10
9
|
readonly snapId: SnapId;
|
|
11
10
|
constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B;AACxD,OAAO,KAAK,EAAE,iCAAiC,EAAE,kBA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AAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAC5C"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
2
2
|
import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
|
|
3
|
-
export const isSnapAccountProvider = (provider) => {
|
|
4
|
-
return (provider !== null && typeof provider === 'object' && 'snapId' in provider);
|
|
5
|
-
};
|
|
6
3
|
export class SnapAccountProvider extends BaseAccountProvider {
|
|
7
4
|
constructor(snapId, messenger) {
|
|
8
5
|
super(messenger);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAK5D,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAM5D,MAAM,
|
|
1
|
+
{"version":3,"file":"SnapAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAK5D,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAM5D,MAAM,OAAgB,mBAAoB,SAAQ,mBAAmB;IAGnE,YAAY,MAAc,EAAE,SAA4C;QACtE,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAES,KAAK,CAAC,+BAA+B;QAC7C,iFAAiF;QACjF,gFAAgF;QAChF,sCAAsC;QACtC,+EAA+E;QAC/E,iFAAiF;QACjF,wDAAwD;QACxD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAG1C,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CACnD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CACpC,CAAC;QAEF,OAAO,CAAC,OAAO,EAAE,EAAE,CACjB,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE;YAClC,4BAA4B,EAAE,KAAK;YACnC,mBAAmB,EAAE,KAAK;YAC1B,kBAAkB,EAAE,KAAK;SAC1B,CAAC,CAAC;IACP,CAAC;CAaF","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Json, SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { BaseAccountProvider } from './BaseAccountProvider';\n\nexport type RestrictedSnapKeyringCreateAccount = (\n options: Record<string, Json>,\n) => Promise<KeyringAccount>;\n\nexport abstract class SnapAccountProvider extends BaseAccountProvider {\n readonly snapId: SnapId;\n\n constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger) {\n super(messenger);\n\n this.snapId = snapId;\n }\n\n protected async getRestrictedSnapAccountCreator(): Promise<RestrictedSnapKeyringCreateAccount> {\n // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but\n // we have to use the `SnapKeyring` instance to be able to create Solana account\n // without triggering UI confirmation.\n // Also, creating account that way won't invalidate the Snap keyring state. The\n // account will get created and persisted properly with the Snap account creation\n // flow \"asynchronously\" (with `notify:accountCreated`).\n const createAccount = await this.withKeyring<\n SnapKeyring,\n SnapKeyring['createAccount']\n >({ type: KeyringTypes.snap }, async ({ keyring }) =>\n keyring.createAccount.bind(keyring),\n );\n\n return (options) =>\n createAccount(this.snapId, options, {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n });\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n\n abstract createAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n\n abstract discoverAndCreateAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;AAEA,uDAG+B;AAC/B,qEAA4D;AAK5D,mEAA+D;AAC/D,mEAA4D;AAE5D,MAAa,kBAAmB,SAAQ,yCAAmB;IAGzD,YAAY,SAA4C;QACtD,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;QAEnE,4DAA4D;QAC5D,uFAAuF;QACvF,mBAAmB;QACnB,MAAM,cAAc,GAAG,cAAc,UAAU,MAAM,CAAC;QACtD,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;YAClC,aAAa;YACb,cAAc;SACf,CAAC,CAAC;QAEH,+DAA+D;QAC/D,qEAAqE;QACrE,mBAAmB;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;YACxB,IAAI,EAAE,6CAA+B,CAAC,QAAQ;YAC9C,EAAE,EAAE,aAAa;YACjB,UAAU;YACV,cAAc;SACf,CAAC;QAEF,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAA,4CAAsB,EAAC,QAAQ,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AArDH,gDAsDC;AArDQ,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { assertAreBip44Accounts } from './BaseAccountProvider';\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount({\n entropySource,\n derivationPath,\n });\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n const accounts = [account];\n assertAreBip44Accounts(accounts);\n\n return accounts;\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n })
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;AAEA,uDAG+B;AAC/B,qEAA4D;AAK5D,mEAA+D;AAC/D,mEAA4D;AAE5D,MAAa,kBAAmB,SAAQ,yCAAmB;IAGzD,YAAY,SAA4C;QACtD,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;QAEnE,4DAA4D;QAC5D,uFAAuF;QACvF,mBAAmB;QACnB,MAAM,cAAc,GAAG,cAAc,UAAU,MAAM,CAAC;QACtD,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;YAClC,aAAa;YACb,cAAc;SACf,CAAC,CAAC;QAEH,+DAA+D;QAC/D,qEAAqE;QACrE,mBAAmB;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;YACxB,IAAI,EAAE,6CAA+B,CAAC,QAAQ;YAC9C,EAAE,EAAE,aAAa;YACjB,UAAU;YACV,cAAc;SACf,CAAC;QAEF,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAA,4CAAsB,EAAC,QAAQ,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AArDH,gDAsDC;AArDQ,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { assertAreBip44Accounts } from './BaseAccountProvider';\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount({\n entropySource,\n derivationPath,\n });\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n const accounts = [account];\n assertAreBip44Accounts(accounts);\n\n return accounts;\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
|
|
@@ -15,6 +15,6 @@ export declare class SolAccountProvider extends SnapAccountProvider {
|
|
|
15
15
|
discoverAndCreateAccounts(_: {
|
|
16
16
|
entropySource: EntropySourceId;
|
|
17
17
|
groupIndex: number;
|
|
18
|
-
}): Promise<
|
|
18
|
+
}): Promise<never[]>;
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=SolAccountProvider.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAM7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,iCAAiC,EAAE,kBAAkB;AAGnE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,cAAc,SAAgD;gBAEzD,SAAS,EAAE,iCAAiC;IAIxD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IA4BrC,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAM7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,iCAAiC,EAAE,kBAAkB;AAGnE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,cAAc,SAAgD;gBAEzD,SAAS,EAAE,iCAAiC;IAIxD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IA4BrC,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
|
|
@@ -15,6 +15,6 @@ export declare class SolAccountProvider extends SnapAccountProvider {
|
|
|
15
15
|
discoverAndCreateAccounts(_: {
|
|
16
16
|
entropySource: EntropySourceId;
|
|
17
17
|
groupIndex: number;
|
|
18
|
-
}): Promise<
|
|
18
|
+
}): Promise<never[]>;
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=SolAccountProvider.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAM7E,OAAO,KAAK,E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YAC9C,EAAE,EAAE,aAAa;YACjB,UAAU;YACV,cAAc;SACf,CAAC;QAEF,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,sBAAsB,CAAC,QAAQ,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AApDM,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { assertAreBip44Accounts } from './BaseAccountProvider';\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount({\n entropySource,\n derivationPath,\n });\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n const accounts = [account];\n assertAreBip44Accounts(accounts);\n\n return accounts;\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n })
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAK5D,OAAO,EAAE,sBAAsB,EAAE,kCAA8B;AAC/D,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IAGzD,YAAY,SAA4C;QACtD,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;QAEnE,4DAA4D;QAC5D,uFAAuF;QACvF,mBAAmB;QACnB,MAAM,cAAc,GAAG,cAAc,UAAU,MAAM,CAAC;QACtD,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;YAClC,aAAa;YACb,cAAc;SACf,CAAC,CAAC;QAEH,+DAA+D;QAC/D,qEAAqE;QACrE,mBAAmB;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;YACxB,IAAI,EAAE,+BAA+B,CAAC,QAAQ;YAC9C,EAAE,EAAE,aAAa;YACjB,UAAU;YACV,cAAc;SACf,CAAC;QAEF,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,sBAAsB,CAAC,QAAQ,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AApDM,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { assertAreBip44Accounts } from './BaseAccountProvider';\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount({\n entropySource,\n derivationPath,\n });\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n const accounts = [account];\n assertAreBip44Accounts(accounts);\n\n return accounts;\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
|