@metamask-previews/multichain-account-service 0.2.1-preview-ec3106a5 → 0.2.1-preview-848266f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/dist/MultichainAccountService.cjs +18 -5
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +12 -3
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +12 -3
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +16 -3
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/tests/messenger.d.cts +2 -2
- package/dist/tests/messenger.d.cts.map +1 -1
- package/dist/tests/messenger.d.mts +2 -2
- package/dist/tests/messenger.d.mts.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +18 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +18 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
11
11
|
|
|
12
12
|
- Add multichain account/wallet syncs ([#6165](https://github.com/MetaMask/core/pull/6165))
|
|
13
13
|
- Those are getting sync'd during `AccountsController:account{Added,Removed}` events.
|
|
14
|
+
- Add actions `MultichainAccountService:getMultichain{Account,Accounts,AccountWallet,AccountWallets}` ([#6193](https://github.com/MetaMask/core/pull/6193))
|
|
14
15
|
|
|
15
16
|
### Changed
|
|
16
17
|
|
|
@@ -12,12 +12,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
};
|
|
13
13
|
var _MultichainAccountService_instances, _MultichainAccountService_messenger, _MultichainAccountService_providers, _MultichainAccountService_wallets, _MultichainAccountService_accountIdToContext, _MultichainAccountService_handleOnAccountAdded, _MultichainAccountService_handleOnAccountRemoved, _MultichainAccountService_getWallet;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MultichainAccountService = void 0;
|
|
15
|
+
exports.MultichainAccountService = exports.serviceName = void 0;
|
|
16
16
|
const account_api_1 = require("@metamask/account-api");
|
|
17
17
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
18
18
|
const EvmAccountProvider_1 = require("./providers/EvmAccountProvider.cjs");
|
|
19
19
|
const SolAccountProvider_1 = require("./providers/SolAccountProvider.cjs");
|
|
20
|
-
|
|
20
|
+
exports.serviceName = 'MultichainAccountService';
|
|
21
21
|
/**
|
|
22
22
|
* Service to expose multichain accounts capabilities.
|
|
23
23
|
*/
|
|
@@ -38,7 +38,7 @@ class MultichainAccountService {
|
|
|
38
38
|
/**
|
|
39
39
|
* The name of the service.
|
|
40
40
|
*/
|
|
41
|
-
this.name = serviceName;
|
|
41
|
+
this.name = exports.serviceName;
|
|
42
42
|
__classPrivateFieldSet(this, _MultichainAccountService_messenger, messenger, "f");
|
|
43
43
|
__classPrivateFieldSet(this, _MultichainAccountService_wallets, new Map(), "f");
|
|
44
44
|
__classPrivateFieldSet(this, _MultichainAccountService_accountIdToContext, new Map(), "f");
|
|
@@ -47,6 +47,10 @@ class MultichainAccountService {
|
|
|
47
47
|
new EvmAccountProvider_1.EvmAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
48
48
|
new SolAccountProvider_1.SolAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
49
49
|
], "f");
|
|
50
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccount', (...args) => this.getMultichainAccount(...args));
|
|
51
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccounts', (...args) => this.getMultichainAccounts(...args));
|
|
52
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccountWallet', (...args) => this.getMultichainAccountWallet(...args));
|
|
53
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccountWallets', (...args) => this.getMultichainAccountWallets(...args));
|
|
50
54
|
}
|
|
51
55
|
/**
|
|
52
56
|
* Initialize the service and constructs the internal reprensentation of
|
|
@@ -93,13 +97,22 @@ class MultichainAccountService {
|
|
|
93
97
|
/**
|
|
94
98
|
* Gets a reference to the multichain account wallet matching this entropy source.
|
|
95
99
|
*
|
|
96
|
-
* @param
|
|
100
|
+
* @param options - Options.
|
|
101
|
+
* @param options.entropySource - The entropy source of the multichain account.
|
|
97
102
|
* @throws If none multichain account match this entropy.
|
|
98
103
|
* @returns A reference to the multichain account wallet.
|
|
99
104
|
*/
|
|
100
|
-
getMultichainAccountWallet(entropySource) {
|
|
105
|
+
getMultichainAccountWallet({ entropySource, }) {
|
|
101
106
|
return __classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_getWallet).call(this, entropySource);
|
|
102
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Gets an array of all multichain account wallets.
|
|
110
|
+
*
|
|
111
|
+
* @returns An array of all multichain account wallets.
|
|
112
|
+
*/
|
|
113
|
+
getMultichainAccountWallets() {
|
|
114
|
+
return Array.from(__classPrivateFieldGet(this, _MultichainAccountService_wallets, "f").values());
|
|
115
|
+
}
|
|
103
116
|
/**
|
|
104
117
|
* Gets a reference to the multichain account matching this entropy source and group index.
|
|
105
118
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.cjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":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mEAAmE;QACnE,sBAAsB;QACtB,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE;YACvC,MAAM;YACN,iBAAiB;SAClB,CAAC,CAAC;KACJ;AACH,CAAC,+GAEuB,EAAyB;IAC/C,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 type {\n MultichainAccountWalletId,\n AccountProvider,\n Bip44Account,\n} from '@metamask/account-api';\nimport {\n isBip44Account,\n MultichainAccountWallet,\n toMultichainAccountWalletId,\n type MultichainAccount,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport { SolAccountProvider } from './providers/SolAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\n\nconst serviceName = 'MultichainAccountService';\n\n/**\n * The options that {@link MultichainAccountService} takes.\n */\ntype MultichainAccountServiceOptions = {\n messenger: MultichainAccountServiceMessenger;\n};\n\n/** Reverse mapping object used to map account IDs and their wallet/multichain account. */\ntype AccountContext<Account extends Bip44Account<KeyringAccount>> = {\n wallet: MultichainAccountWallet<Account>;\n multichainAccount: MultichainAccount<Account>;\n};\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #providers: AccountProvider<Bip44Account<InternalAccount>>[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<InternalAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<InternalAccount>['id'],\n AccountContext<Bip44Account<InternalAccount>>\n >;\n\n /**\n * The name of the service.\n */\n name: typeof serviceName = serviceName;\n\n /**\n * Constructs a new MultichainAccountService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * MultichainAccountService.\n */\n constructor({ messenger }: MultichainAccountServiceOptions) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n this.#accountIdToContext = new Map();\n // TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.\n this.#providers = [\n new EvmAccountProvider(this.#messenger),\n new SolAccountProvider(this.#messenger),\n ];\n }\n\n /**\n * Initialize the service and constructs the internal reprensentation of\n * multichain accounts and wallets.\n */\n init(): void {\n // Create initial wallets.\n const { keyrings } = this.#messenger.call('KeyringController:getState');\n for (const keyring of keyrings) {\n if (keyring.type === (KeyringTypes.hd as string)) {\n // Only HD keyrings have an entropy source/SRP.\n const entropySource = keyring.metadata.id;\n\n // This will automatically \"associate\" all multichain accounts for that wallet\n // (based on the accounts owned by each account providers).\n const wallet = new MultichainAccountWallet({\n entropySource,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // Reverse mapping between account ID and their multichain wallet/account:\n for (const multichainAccount of wallet.getMultichainAccounts()) {\n for (const account of multichainAccount.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n }\n }\n\n this.#messenger.subscribe('AccountsController:accountAdded', (account) =>\n this.#handleOnAccountAdded(account),\n );\n this.#messenger.subscribe('AccountsController:accountRemoved', (id) =>\n this.#handleOnAccountRemoved(id),\n );\n }\n\n #handleOnAccountAdded(account: InternalAccount): void {\n // We completely omit non-BIP-44 accounts!\n if (!isBip44Account(account)) {\n return;\n }\n\n let sync = true;\n\n let wallet = this.#wallets.get(\n toMultichainAccountWalletId(account.options.entropy.id),\n );\n if (!wallet) {\n // That's a new wallet.\n wallet = new MultichainAccountWallet({\n entropySource: account.options.entropy.id,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // If that's a new wallet wallet. There's nothing to \"force-sync\".\n sync = false;\n }\n\n let multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n if (!multichainAccount) {\n // This new account is a new multichain account, let the wallet know\n // it has to re-sync with its providers.\n if (sync) {\n wallet.sync();\n }\n\n multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n\n // If that's a new multichain account. There's nothing to \"force-sync\".\n sync = false;\n }\n\n // We have to check against `undefined` in case `getMultichainAccount` is\n // not able to find this multichain account (which should not be possible...)\n if (multichainAccount) {\n if (sync) {\n multichainAccount.sync();\n }\n\n // Same here, this account should have been already grouped in that\n // multichain account.\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n\n #handleOnAccountRemoved(id: InternalAccount['id']): void {\n // Force sync of the appropriate wallet if an account got removed.\n const found = this.#accountIdToContext.get(id);\n if (found) {\n const { wallet } = found;\n\n wallet.sync();\n }\n\n // Safe to call delete even if the `id` was not referencing a BIP-44 account.\n this.#accountIdToContext.delete(id);\n }\n\n #getWallet(\n entropySource: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n const wallet = this.#wallets.get(\n toMultichainAccountWalletId(entropySource),\n );\n\n if (!wallet) {\n throw new Error('Unknown wallet, no wallet matching this entropy source');\n }\n\n return wallet;\n }\n\n /**\n * Gets a reference to the wallet and multichain account for a given account ID.\n *\n * @param id - Account ID.\n * @returns An object with references to the wallet and multichain account associated for\n * that account ID, or undefined if this account ID is not part of any.\n */\n getMultichainAccountAndWallet(\n id: InternalAccount['id'],\n ): AccountContext<Bip44Account<InternalAccount>> | undefined {\n return this.#accountIdToContext.get(id);\n }\n\n /**\n * Gets a reference to the multichain account wallet matching this entropy source.\n *\n * @param 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: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n return this.#getWallet(entropySource);\n }\n\n /**\n * Gets a reference to the multichain account matching this entropy source and group index.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @param options.groupIndex - The group index of the multichain account.\n * @throws If none multichain account match this entropy source and group index.\n * @returns A reference to the multichain account.\n */\n getMultichainAccount({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccount<Bip44Account<InternalAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccount(groupIndex);\n\n if (!multichainAccount) {\n throw new Error(`No multichain account for index: ${groupIndex}`);\n }\n\n return multichainAccount;\n }\n\n /**\n * Gets all multichain accounts for a given entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source to query.\n * @throws If no multichain accounts match this entropy source.\n * @returns A list of all multichain accounts.\n */\n getMultichainAccounts({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccount<Bip44Account<InternalAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccounts();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.cjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,uDAK+B;AAE/B,qEAA4D;AAG5D,2EAAoE;AACpE,2EAAoE;AAGvD,QAAA,WAAW,GAAG,0BAA0B,CAAC;AAetD;;GAEG;AACH,MAAa,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E;QACX,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC3E;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n MultichainAccountWalletId,\n AccountProvider,\n Bip44Account,\n} from '@metamask/account-api';\nimport {\n isBip44Account,\n MultichainAccountWallet,\n toMultichainAccountWalletId,\n type MultichainAccount,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport { SolAccountProvider } from './providers/SolAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\n\nexport const serviceName = 'MultichainAccountService';\n\n/**\n * The options that {@link MultichainAccountService} takes.\n */\ntype MultichainAccountServiceOptions = {\n messenger: MultichainAccountServiceMessenger;\n};\n\n/** Reverse mapping object used to map account IDs and their wallet/multichain account. */\ntype AccountContext<Account extends Bip44Account<KeyringAccount>> = {\n wallet: MultichainAccountWallet<Account>;\n multichainAccount: MultichainAccount<Account>;\n};\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #providers: AccountProvider<Bip44Account<InternalAccount>>[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<InternalAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<InternalAccount>['id'],\n AccountContext<Bip44Account<InternalAccount>>\n >;\n\n /**\n * The name of the service.\n */\n name: typeof serviceName = serviceName;\n\n /**\n * Constructs a new MultichainAccountService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * MultichainAccountService.\n */\n constructor({ messenger }: MultichainAccountServiceOptions) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n this.#accountIdToContext = new Map();\n // TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.\n this.#providers = [\n new EvmAccountProvider(this.#messenger),\n new SolAccountProvider(this.#messenger),\n ];\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccount',\n (...args) => this.getMultichainAccount(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccounts',\n (...args) => this.getMultichainAccounts(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallet',\n (...args) => this.getMultichainAccountWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallets',\n (...args) => this.getMultichainAccountWallets(...args),\n );\n }\n\n /**\n * Initialize the service and constructs the internal reprensentation of\n * multichain accounts and wallets.\n */\n init(): void {\n // Create initial wallets.\n const { keyrings } = this.#messenger.call('KeyringController:getState');\n for (const keyring of keyrings) {\n if (keyring.type === (KeyringTypes.hd as string)) {\n // Only HD keyrings have an entropy source/SRP.\n const entropySource = keyring.metadata.id;\n\n // This will automatically \"associate\" all multichain accounts for that wallet\n // (based on the accounts owned by each account providers).\n const wallet = new MultichainAccountWallet({\n entropySource,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // Reverse mapping between account ID and their multichain wallet/account:\n for (const multichainAccount of wallet.getMultichainAccounts()) {\n for (const account of multichainAccount.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n }\n }\n\n this.#messenger.subscribe('AccountsController:accountAdded', (account) =>\n this.#handleOnAccountAdded(account),\n );\n this.#messenger.subscribe('AccountsController:accountRemoved', (id) =>\n this.#handleOnAccountRemoved(id),\n );\n }\n\n #handleOnAccountAdded(account: InternalAccount): void {\n // We completely omit non-BIP-44 accounts!\n if (!isBip44Account(account)) {\n return;\n }\n\n let sync = true;\n\n let wallet = this.#wallets.get(\n toMultichainAccountWalletId(account.options.entropy.id),\n );\n if (!wallet) {\n // That's a new wallet.\n wallet = new MultichainAccountWallet({\n entropySource: account.options.entropy.id,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // If that's a new wallet wallet. There's nothing to \"force-sync\".\n sync = false;\n }\n\n let multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n if (!multichainAccount) {\n // This new account is a new multichain account, let the wallet know\n // it has to re-sync with its providers.\n if (sync) {\n wallet.sync();\n }\n\n multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n\n // If that's a new multichain account. There's nothing to \"force-sync\".\n sync = false;\n }\n\n // We have to check against `undefined` in case `getMultichainAccount` is\n // not able to find this multichain account (which should not be possible...)\n if (multichainAccount) {\n if (sync) {\n multichainAccount.sync();\n }\n\n // Same here, this account should have been already grouped in that\n // multichain account.\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n\n #handleOnAccountRemoved(id: InternalAccount['id']): void {\n // Force sync of the appropriate wallet if an account got removed.\n const found = this.#accountIdToContext.get(id);\n if (found) {\n const { wallet } = found;\n\n wallet.sync();\n }\n\n // Safe to call delete even if the `id` was not referencing a BIP-44 account.\n this.#accountIdToContext.delete(id);\n }\n\n #getWallet(\n entropySource: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n const wallet = this.#wallets.get(\n toMultichainAccountWalletId(entropySource),\n );\n\n if (!wallet) {\n throw new Error('Unknown wallet, no wallet matching this entropy source');\n }\n\n return wallet;\n }\n\n /**\n * Gets a reference to the wallet and multichain account for a given account ID.\n *\n * @param id - Account ID.\n * @returns An object with references to the wallet and multichain account associated for\n * that account ID, or undefined if this account ID is not part of any.\n */\n getMultichainAccountAndWallet(\n id: InternalAccount['id'],\n ): AccountContext<Bip44Account<InternalAccount>> | undefined {\n return this.#accountIdToContext.get(id);\n }\n\n /**\n * Gets a reference to the multichain account wallet matching this entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @throws If none multichain account match this entropy.\n * @returns A reference to the multichain account wallet.\n */\n getMultichainAccountWallet({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n return this.#getWallet(entropySource);\n }\n\n /**\n * Gets an array of all multichain account wallets.\n *\n * @returns An array of all multichain account wallets.\n */\n getMultichainAccountWallets(): MultichainAccountWallet<\n Bip44Account<InternalAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n /**\n * Gets a reference to the multichain account matching this entropy source and group index.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @param options.groupIndex - The group index of the multichain account.\n * @throws If none multichain account match this entropy source and group index.\n * @returns A reference to the multichain account.\n */\n getMultichainAccount({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccount<Bip44Account<InternalAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccount(groupIndex);\n\n if (!multichainAccount) {\n throw new Error(`No multichain account for index: ${groupIndex}`);\n }\n\n return multichainAccount;\n }\n\n /**\n * Gets all multichain accounts for a given entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source to query.\n * @throws If no multichain accounts match this entropy source.\n * @returns A list of all multichain accounts.\n */\n getMultichainAccounts({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccount<Bip44Account<InternalAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccounts();\n }\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import { MultichainAccountWallet, type MultichainAccount } from "@metamask/accou
|
|
|
3
3
|
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
4
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
5
5
|
import type { MultichainAccountServiceMessenger } from "./types.cjs";
|
|
6
|
-
declare const serviceName = "MultichainAccountService";
|
|
6
|
+
export declare const serviceName = "MultichainAccountService";
|
|
7
7
|
/**
|
|
8
8
|
* The options that {@link MultichainAccountService} takes.
|
|
9
9
|
*/
|
|
@@ -48,11 +48,20 @@ export declare class MultichainAccountService {
|
|
|
48
48
|
/**
|
|
49
49
|
* Gets a reference to the multichain account wallet matching this entropy source.
|
|
50
50
|
*
|
|
51
|
-
* @param
|
|
51
|
+
* @param options - Options.
|
|
52
|
+
* @param options.entropySource - The entropy source of the multichain account.
|
|
52
53
|
* @throws If none multichain account match this entropy.
|
|
53
54
|
* @returns A reference to the multichain account wallet.
|
|
54
55
|
*/
|
|
55
|
-
getMultichainAccountWallet(entropySource
|
|
56
|
+
getMultichainAccountWallet({ entropySource, }: {
|
|
57
|
+
entropySource: EntropySourceId;
|
|
58
|
+
}): MultichainAccountWallet<Bip44Account<InternalAccount>>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets an array of all multichain account wallets.
|
|
61
|
+
*
|
|
62
|
+
* @returns An array of all multichain account wallets.
|
|
63
|
+
*/
|
|
64
|
+
getMultichainAccountWallets(): MultichainAccountWallet<Bip44Account<InternalAccount>>[];
|
|
56
65
|
/**
|
|
57
66
|
* Gets a reference to the multichain account matching this entropy source and group index.
|
|
58
67
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.d.cts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAEL,uBAAuB,EAEvB,KAAK,iBAAiB,EACvB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAItE,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AAEjE,
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.d.cts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAEL,uBAAuB,EAEvB,KAAK,iBAAiB,EACvB,8BAA8B;AAC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G;IACH,qBAAqB,CAAC,EACpB,aAAa,GACd,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;KAChC,GAAG,iBAAiB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,EAAE;CAGvD"}
|
|
@@ -3,7 +3,7 @@ import { MultichainAccountWallet, type MultichainAccount } from "@metamask/accou
|
|
|
3
3
|
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
4
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
5
5
|
import type { MultichainAccountServiceMessenger } from "./types.mjs";
|
|
6
|
-
declare const serviceName = "MultichainAccountService";
|
|
6
|
+
export declare const serviceName = "MultichainAccountService";
|
|
7
7
|
/**
|
|
8
8
|
* The options that {@link MultichainAccountService} takes.
|
|
9
9
|
*/
|
|
@@ -48,11 +48,20 @@ export declare class MultichainAccountService {
|
|
|
48
48
|
/**
|
|
49
49
|
* Gets a reference to the multichain account wallet matching this entropy source.
|
|
50
50
|
*
|
|
51
|
-
* @param
|
|
51
|
+
* @param options - Options.
|
|
52
|
+
* @param options.entropySource - The entropy source of the multichain account.
|
|
52
53
|
* @throws If none multichain account match this entropy.
|
|
53
54
|
* @returns A reference to the multichain account wallet.
|
|
54
55
|
*/
|
|
55
|
-
getMultichainAccountWallet(entropySource
|
|
56
|
+
getMultichainAccountWallet({ entropySource, }: {
|
|
57
|
+
entropySource: EntropySourceId;
|
|
58
|
+
}): MultichainAccountWallet<Bip44Account<InternalAccount>>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets an array of all multichain account wallets.
|
|
61
|
+
*
|
|
62
|
+
* @returns An array of all multichain account wallets.
|
|
63
|
+
*/
|
|
64
|
+
getMultichainAccountWallets(): MultichainAccountWallet<Bip44Account<InternalAccount>>[];
|
|
56
65
|
/**
|
|
57
66
|
* Gets a reference to the multichain account matching this entropy source and group index.
|
|
58
67
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountService.d.mts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAEL,uBAAuB,EAEvB,KAAK,iBAAiB,EACvB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAItE,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AAEjE,
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.d.mts","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAEL,uBAAuB,EAEvB,KAAK,iBAAiB,EACvB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAItE,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AAEjE,eAAO,MAAM,WAAW,6BAA6B,CAAC;AAEtD;;GAEG;AACH,KAAK,+BAA+B,GAAG;IACrC,SAAS,EAAE,iCAAiC,CAAC;CAC9C,CAAC;AAEF,0FAA0F;AAC1F,KAAK,cAAc,CAAC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAAI;IAClE,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACzC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CAC/C,CAAC;AAEF;;GAEG;AACH,qBAAa,wBAAwB;;IAenC;;OAEG;IACH,IAAI,EAAE,OAAO,WAAW,CAAe;IAEvC;;;;;;OAMG;gBACS,EAAE,SAAS,EAAE,EAAE,+BAA+B;IA4B1D;;;OAGG;IACH,IAAI,IAAI,IAAI;IAwHZ;;;;;;OAMG;IACH,6BAA6B,CAC3B,EAAE,EAAE,eAAe,CAAC,IAAI,CAAC,GACxB,cAAc,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,GAAG,SAAS;IAI5D;;;;;;;OAOG;IACH,0BAA0B,CAAC,EACzB,aAAa,GACd,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;KAChC,GAAG,uBAAuB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAI1D;;;;OAIG;IACH,2BAA2B,IAAI,uBAAuB,CACpD,YAAY,CAAC,eAAe,CAAC,CAC9B,EAAE;IAIH;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,iBAAiB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAWpD;;;;;;;OAOG;IACH,qBAAqB,CAAC,EACpB,aAAa,GACd,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;KAChC,GAAG,iBAAiB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,EAAE;CAGvD"}
|
|
@@ -14,7 +14,7 @@ import { isBip44Account, MultichainAccountWallet, toMultichainAccountWalletId }
|
|
|
14
14
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
15
15
|
import { EvmAccountProvider } from "./providers/EvmAccountProvider.mjs";
|
|
16
16
|
import { SolAccountProvider } from "./providers/SolAccountProvider.mjs";
|
|
17
|
-
const serviceName = 'MultichainAccountService';
|
|
17
|
+
export const serviceName = 'MultichainAccountService';
|
|
18
18
|
/**
|
|
19
19
|
* Service to expose multichain accounts capabilities.
|
|
20
20
|
*/
|
|
@@ -44,6 +44,10 @@ export class MultichainAccountService {
|
|
|
44
44
|
new EvmAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
45
45
|
new SolAccountProvider(__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f")),
|
|
46
46
|
], "f");
|
|
47
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccount', (...args) => this.getMultichainAccount(...args));
|
|
48
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccounts', (...args) => this.getMultichainAccounts(...args));
|
|
49
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccountWallet', (...args) => this.getMultichainAccountWallet(...args));
|
|
50
|
+
__classPrivateFieldGet(this, _MultichainAccountService_messenger, "f").registerActionHandler('MultichainAccountService:getMultichainAccountWallets', (...args) => this.getMultichainAccountWallets(...args));
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* Initialize the service and constructs the internal reprensentation of
|
|
@@ -90,13 +94,22 @@ export class MultichainAccountService {
|
|
|
90
94
|
/**
|
|
91
95
|
* Gets a reference to the multichain account wallet matching this entropy source.
|
|
92
96
|
*
|
|
93
|
-
* @param
|
|
97
|
+
* @param options - Options.
|
|
98
|
+
* @param options.entropySource - The entropy source of the multichain account.
|
|
94
99
|
* @throws If none multichain account match this entropy.
|
|
95
100
|
* @returns A reference to the multichain account wallet.
|
|
96
101
|
*/
|
|
97
|
-
getMultichainAccountWallet(entropySource) {
|
|
102
|
+
getMultichainAccountWallet({ entropySource, }) {
|
|
98
103
|
return __classPrivateFieldGet(this, _MultichainAccountService_instances, "m", _MultichainAccountService_getWallet).call(this, entropySource);
|
|
99
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Gets an array of all multichain account wallets.
|
|
107
|
+
*
|
|
108
|
+
* @returns An array of all multichain account wallets.
|
|
109
|
+
*/
|
|
110
|
+
getMultichainAccountWallets() {
|
|
111
|
+
return Array.from(__classPrivateFieldGet(this, _MultichainAccountService_wallets, "f").values());
|
|
112
|
+
}
|
|
100
113
|
/**
|
|
101
114
|
* Gets a reference to the multichain account matching this entropy source and group index.
|
|
102
115
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Multichain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E,IAAI,GAAG,KAAK,CAAC;KACd;IAED,yEAAyE;IACzE,6EAA6E;IAC7E,IAAI,iBAAiB,EAAE;QACrB,IAAI,IAAI,EAAE;YACR,iBAAiB,CAAC,IAAI,EAAE,CAAC;SAC1B;QAED,mEAAmE;QACnE,sBAAsB;QACtB,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE;YACvC,MAAM;YACN,iBAAiB;SAClB,CAAC,CAAC;KACJ;AACH,CAAC,+GAEuB,EAAyB;IAC/C,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 type {\n MultichainAccountWalletId,\n AccountProvider,\n Bip44Account,\n} from '@metamask/account-api';\nimport {\n isBip44Account,\n MultichainAccountWallet,\n toMultichainAccountWalletId,\n type MultichainAccount,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport { SolAccountProvider } from './providers/SolAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\n\nconst serviceName = 'MultichainAccountService';\n\n/**\n * The options that {@link MultichainAccountService} takes.\n */\ntype MultichainAccountServiceOptions = {\n messenger: MultichainAccountServiceMessenger;\n};\n\n/** Reverse mapping object used to map account IDs and their wallet/multichain account. */\ntype AccountContext<Account extends Bip44Account<KeyringAccount>> = {\n wallet: MultichainAccountWallet<Account>;\n multichainAccount: MultichainAccount<Account>;\n};\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #providers: AccountProvider<Bip44Account<InternalAccount>>[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<InternalAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<InternalAccount>['id'],\n AccountContext<Bip44Account<InternalAccount>>\n >;\n\n /**\n * The name of the service.\n */\n name: typeof serviceName = serviceName;\n\n /**\n * Constructs a new MultichainAccountService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * MultichainAccountService.\n */\n constructor({ messenger }: MultichainAccountServiceOptions) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n this.#accountIdToContext = new Map();\n // TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.\n this.#providers = [\n new EvmAccountProvider(this.#messenger),\n new SolAccountProvider(this.#messenger),\n ];\n }\n\n /**\n * Initialize the service and constructs the internal reprensentation of\n * multichain accounts and wallets.\n */\n init(): void {\n // Create initial wallets.\n const { keyrings } = this.#messenger.call('KeyringController:getState');\n for (const keyring of keyrings) {\n if (keyring.type === (KeyringTypes.hd as string)) {\n // Only HD keyrings have an entropy source/SRP.\n const entropySource = keyring.metadata.id;\n\n // This will automatically \"associate\" all multichain accounts for that wallet\n // (based on the accounts owned by each account providers).\n const wallet = new MultichainAccountWallet({\n entropySource,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // Reverse mapping between account ID and their multichain wallet/account:\n for (const multichainAccount of wallet.getMultichainAccounts()) {\n for (const account of multichainAccount.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n }\n }\n\n this.#messenger.subscribe('AccountsController:accountAdded', (account) =>\n this.#handleOnAccountAdded(account),\n );\n this.#messenger.subscribe('AccountsController:accountRemoved', (id) =>\n this.#handleOnAccountRemoved(id),\n );\n }\n\n #handleOnAccountAdded(account: InternalAccount): void {\n // We completely omit non-BIP-44 accounts!\n if (!isBip44Account(account)) {\n return;\n }\n\n let sync = true;\n\n let wallet = this.#wallets.get(\n toMultichainAccountWalletId(account.options.entropy.id),\n );\n if (!wallet) {\n // That's a new wallet.\n wallet = new MultichainAccountWallet({\n entropySource: account.options.entropy.id,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // If that's a new wallet wallet. There's nothing to \"force-sync\".\n sync = false;\n }\n\n let multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n if (!multichainAccount) {\n // This new account is a new multichain account, let the wallet know\n // it has to re-sync with its providers.\n if (sync) {\n wallet.sync();\n }\n\n multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n\n // If that's a new multichain account. There's nothing to \"force-sync\".\n sync = false;\n }\n\n // We have to check against `undefined` in case `getMultichainAccount` is\n // not able to find this multichain account (which should not be possible...)\n if (multichainAccount) {\n if (sync) {\n multichainAccount.sync();\n }\n\n // Same here, this account should have been already grouped in that\n // multichain account.\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n\n #handleOnAccountRemoved(id: InternalAccount['id']): void {\n // Force sync of the appropriate wallet if an account got removed.\n const found = this.#accountIdToContext.get(id);\n if (found) {\n const { wallet } = found;\n\n wallet.sync();\n }\n\n // Safe to call delete even if the `id` was not referencing a BIP-44 account.\n this.#accountIdToContext.delete(id);\n }\n\n #getWallet(\n entropySource: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n const wallet = this.#wallets.get(\n toMultichainAccountWalletId(entropySource),\n );\n\n if (!wallet) {\n throw new Error('Unknown wallet, no wallet matching this entropy source');\n }\n\n return wallet;\n }\n\n /**\n * Gets a reference to the wallet and multichain account for a given account ID.\n *\n * @param id - Account ID.\n * @returns An object with references to the wallet and multichain account associated for\n * that account ID, or undefined if this account ID is not part of any.\n */\n getMultichainAccountAndWallet(\n id: InternalAccount['id'],\n ): AccountContext<Bip44Account<InternalAccount>> | undefined {\n return this.#accountIdToContext.get(id);\n }\n\n /**\n * Gets a reference to the multichain account wallet matching this entropy source.\n *\n * @param 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: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n return this.#getWallet(entropySource);\n }\n\n /**\n * Gets a reference to the multichain account matching this entropy source and group index.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @param options.groupIndex - The group index of the multichain account.\n * @throws If none multichain account match this entropy source and group index.\n * @returns A reference to the multichain account.\n */\n getMultichainAccount({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccount<Bip44Account<InternalAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccount(groupIndex);\n\n if (!multichainAccount) {\n throw new Error(`No multichain account for index: ${groupIndex}`);\n }\n\n return multichainAccount;\n }\n\n /**\n * Gets all multichain accounts for a given entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source to query.\n * @throws If no multichain accounts match this entropy source.\n * @returns A list of all multichain accounts.\n */\n getMultichainAccounts({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccount<Bip44Account<InternalAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccounts();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainAccountService.mjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],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,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 type {\n MultichainAccountWalletId,\n AccountProvider,\n Bip44Account,\n} from '@metamask/account-api';\nimport {\n isBip44Account,\n MultichainAccountWallet,\n toMultichainAccountWalletId,\n type MultichainAccount,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport { SolAccountProvider } from './providers/SolAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\n\nexport const serviceName = 'MultichainAccountService';\n\n/**\n * The options that {@link MultichainAccountService} takes.\n */\ntype MultichainAccountServiceOptions = {\n messenger: MultichainAccountServiceMessenger;\n};\n\n/** Reverse mapping object used to map account IDs and their wallet/multichain account. */\ntype AccountContext<Account extends Bip44Account<KeyringAccount>> = {\n wallet: MultichainAccountWallet<Account>;\n multichainAccount: MultichainAccount<Account>;\n};\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #providers: AccountProvider<Bip44Account<InternalAccount>>[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<InternalAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<InternalAccount>['id'],\n AccountContext<Bip44Account<InternalAccount>>\n >;\n\n /**\n * The name of the service.\n */\n name: typeof serviceName = serviceName;\n\n /**\n * Constructs a new MultichainAccountService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * MultichainAccountService.\n */\n constructor({ messenger }: MultichainAccountServiceOptions) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n this.#accountIdToContext = new Map();\n // TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.\n this.#providers = [\n new EvmAccountProvider(this.#messenger),\n new SolAccountProvider(this.#messenger),\n ];\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccount',\n (...args) => this.getMultichainAccount(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccounts',\n (...args) => this.getMultichainAccounts(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallet',\n (...args) => this.getMultichainAccountWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallets',\n (...args) => this.getMultichainAccountWallets(...args),\n );\n }\n\n /**\n * Initialize the service and constructs the internal reprensentation of\n * multichain accounts and wallets.\n */\n init(): void {\n // Create initial wallets.\n const { keyrings } = this.#messenger.call('KeyringController:getState');\n for (const keyring of keyrings) {\n if (keyring.type === (KeyringTypes.hd as string)) {\n // Only HD keyrings have an entropy source/SRP.\n const entropySource = keyring.metadata.id;\n\n // This will automatically \"associate\" all multichain accounts for that wallet\n // (based on the accounts owned by each account providers).\n const wallet = new MultichainAccountWallet({\n entropySource,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // Reverse mapping between account ID and their multichain wallet/account:\n for (const multichainAccount of wallet.getMultichainAccounts()) {\n for (const account of multichainAccount.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n }\n }\n\n this.#messenger.subscribe('AccountsController:accountAdded', (account) =>\n this.#handleOnAccountAdded(account),\n );\n this.#messenger.subscribe('AccountsController:accountRemoved', (id) =>\n this.#handleOnAccountRemoved(id),\n );\n }\n\n #handleOnAccountAdded(account: InternalAccount): void {\n // We completely omit non-BIP-44 accounts!\n if (!isBip44Account(account)) {\n return;\n }\n\n let sync = true;\n\n let wallet = this.#wallets.get(\n toMultichainAccountWalletId(account.options.entropy.id),\n );\n if (!wallet) {\n // That's a new wallet.\n wallet = new MultichainAccountWallet({\n entropySource: account.options.entropy.id,\n providers: this.#providers,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // If that's a new wallet wallet. There's nothing to \"force-sync\".\n sync = false;\n }\n\n let multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n if (!multichainAccount) {\n // This new account is a new multichain account, let the wallet know\n // it has to re-sync with its providers.\n if (sync) {\n wallet.sync();\n }\n\n multichainAccount = wallet.getMultichainAccount(\n account.options.entropy.groupIndex,\n );\n\n // If that's a new multichain account. There's nothing to \"force-sync\".\n sync = false;\n }\n\n // We have to check against `undefined` in case `getMultichainAccount` is\n // not able to find this multichain account (which should not be possible...)\n if (multichainAccount) {\n if (sync) {\n multichainAccount.sync();\n }\n\n // Same here, this account should have been already grouped in that\n // multichain account.\n this.#accountIdToContext.set(account.id, {\n wallet,\n multichainAccount,\n });\n }\n }\n\n #handleOnAccountRemoved(id: InternalAccount['id']): void {\n // Force sync of the appropriate wallet if an account got removed.\n const found = this.#accountIdToContext.get(id);\n if (found) {\n const { wallet } = found;\n\n wallet.sync();\n }\n\n // Safe to call delete even if the `id` was not referencing a BIP-44 account.\n this.#accountIdToContext.delete(id);\n }\n\n #getWallet(\n entropySource: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n const wallet = this.#wallets.get(\n toMultichainAccountWalletId(entropySource),\n );\n\n if (!wallet) {\n throw new Error('Unknown wallet, no wallet matching this entropy source');\n }\n\n return wallet;\n }\n\n /**\n * Gets a reference to the wallet and multichain account for a given account ID.\n *\n * @param id - Account ID.\n * @returns An object with references to the wallet and multichain account associated for\n * that account ID, or undefined if this account ID is not part of any.\n */\n getMultichainAccountAndWallet(\n id: InternalAccount['id'],\n ): AccountContext<Bip44Account<InternalAccount>> | undefined {\n return this.#accountIdToContext.get(id);\n }\n\n /**\n * Gets a reference to the multichain account wallet matching this entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @throws If none multichain account match this entropy.\n * @returns A reference to the multichain account wallet.\n */\n getMultichainAccountWallet({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountWallet<Bip44Account<InternalAccount>> {\n return this.#getWallet(entropySource);\n }\n\n /**\n * Gets an array of all multichain account wallets.\n *\n * @returns An array of all multichain account wallets.\n */\n getMultichainAccountWallets(): MultichainAccountWallet<\n Bip44Account<InternalAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n /**\n * Gets a reference to the multichain account matching this entropy source and group index.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @param options.groupIndex - The group index of the multichain account.\n * @throws If none multichain account match this entropy source and group index.\n * @returns A reference to the multichain account.\n */\n getMultichainAccount({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccount<Bip44Account<InternalAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccount(groupIndex);\n\n if (!multichainAccount) {\n throw new Error(`No multichain account for index: ${groupIndex}`);\n }\n\n return multichainAccount;\n }\n\n /**\n * Gets all multichain accounts for a given entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source to query.\n * @throws If no multichain accounts match this entropy source.\n * @returns A list of all multichain accounts.\n */\n getMultichainAccounts({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccount<Bip44Account<InternalAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccounts();\n }\n}\n"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AASA,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA","sourcesContent":["export type {\n MultichainAccountServiceActions,\n MultichainAccountServiceEvents,\n MultichainAccountServiceMessenger,\n MultichainAccountServiceGetMultichainAccountAction,\n MultichainAccountServiceGetMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountWalletsAction,\n MultichainAccountServiceGetMultichainAccountsAction,\n} from './types';\nexport { MultichainAccountService } from './MultichainAccountService';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { MultichainAccountServiceActions, MultichainAccountServiceEvents, MultichainAccountServiceMessenger, } from "./types.cjs";
|
|
1
|
+
export type { MultichainAccountServiceActions, MultichainAccountServiceEvents, MultichainAccountServiceMessenger, MultichainAccountServiceGetMultichainAccountAction, MultichainAccountServiceGetMultichainAccountWalletAction, MultichainAccountServiceGetMultichainAccountWalletsAction, MultichainAccountServiceGetMultichainAccountsAction, } from "./types.cjs";
|
|
2
2
|
export { MultichainAccountService } from "./MultichainAccountService.cjs";
|
|
3
3
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,kDAAkD,EAClD,wDAAwD,EACxD,yDAAyD,EACzD,mDAAmD,GACpD,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,uCAAmC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { MultichainAccountServiceActions, MultichainAccountServiceEvents, MultichainAccountServiceMessenger, } from "./types.mjs";
|
|
1
|
+
export type { MultichainAccountServiceActions, MultichainAccountServiceEvents, MultichainAccountServiceMessenger, MultichainAccountServiceGetMultichainAccountAction, MultichainAccountServiceGetMultichainAccountWalletAction, MultichainAccountServiceGetMultichainAccountWalletsAction, MultichainAccountServiceGetMultichainAccountsAction, } from "./types.mjs";
|
|
2
2
|
export { MultichainAccountService } from "./MultichainAccountService.mjs";
|
|
3
3
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,kDAAkD,EAClD,wDAAwD,EACxD,yDAAyD,EACzD,mDAAmD,GACpD,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,uCAAmC"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,uCAAmC","sourcesContent":["export type {\n MultichainAccountServiceActions,\n MultichainAccountServiceEvents,\n MultichainAccountServiceMessenger,\n MultichainAccountServiceGetMultichainAccountAction,\n MultichainAccountServiceGetMultichainAccountWalletAction,\n MultichainAccountServiceGetMultichainAccountWalletsAction,\n MultichainAccountServiceGetMultichainAccountsAction,\n} from './types';\nexport { MultichainAccountService } from './MultichainAccountService';\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Messenger } from "@metamask/base-controller";
|
|
2
|
-
import type { AllowedActions, AllowedEvents, MultichainAccountServiceMessenger } from "../types.cjs";
|
|
2
|
+
import type { AllowedActions, AllowedEvents, MultichainAccountServiceActions, MultichainAccountServiceMessenger } from "../types.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new root messenger instance for testing.
|
|
5
5
|
*
|
|
6
6
|
* @returns A new Messenger instance.
|
|
7
7
|
*/
|
|
8
|
-
export declare function getRootMessenger(): Messenger<AllowedActions, AllowedEvents>;
|
|
8
|
+
export declare function getRootMessenger(): Messenger<MultichainAccountServiceActions | AllowedActions, AllowedEvents>;
|
|
9
9
|
/**
|
|
10
10
|
* Retrieves a restricted messenger for the MultichainAccountService.
|
|
11
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messenger.d.cts","sourceRoot":"","sources":["../../src/tests/messenger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAEtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,
|
|
1
|
+
{"version":3,"file":"messenger.d.cts","sourceRoot":"","sources":["../../src/tests/messenger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAEtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,+BAA+B,EAE/B,iCAAiC,EAClC,qBAAiB;AAElB;;;;GAIG;AACH,wBAAgB,gBAAgB,+EAK/B;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GAC7C,iCAAiC,CAiBnC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Messenger } from "@metamask/base-controller";
|
|
2
|
-
import type { AllowedActions, AllowedEvents, MultichainAccountServiceMessenger } from "../types.mjs";
|
|
2
|
+
import type { AllowedActions, AllowedEvents, MultichainAccountServiceActions, MultichainAccountServiceMessenger } from "../types.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new root messenger instance for testing.
|
|
5
5
|
*
|
|
6
6
|
* @returns A new Messenger instance.
|
|
7
7
|
*/
|
|
8
|
-
export declare function getRootMessenger(): Messenger<AllowedActions, AllowedEvents>;
|
|
8
|
+
export declare function getRootMessenger(): Messenger<MultichainAccountServiceActions | AllowedActions, AllowedEvents>;
|
|
9
9
|
/**
|
|
10
10
|
* Retrieves a restricted messenger for the MultichainAccountService.
|
|
11
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messenger.d.mts","sourceRoot":"","sources":["../../src/tests/messenger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAEtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,
|
|
1
|
+
{"version":3,"file":"messenger.d.mts","sourceRoot":"","sources":["../../src/tests/messenger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAEtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,+BAA+B,EAE/B,iCAAiC,EAClC,qBAAiB;AAElB;;;;GAIG;AACH,wBAAgB,gBAAgB,+EAK/B;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GAC7C,iCAAiC,CAiBnC"}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport type { RestrictedMessenger } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerWithKeyringAction,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest as SnapControllerHandleSnapRequestAction } from '@metamask/snaps-controllers';\n\n/**\n * All actions that {@link MultichainAccountService} registers so that other\n * modules can call them.\n */\nexport type MultichainAccountServiceActions
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport type { RestrictedMessenger } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerWithKeyringAction,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest as SnapControllerHandleSnapRequestAction } from '@metamask/snaps-controllers';\n\nimport type {\n MultichainAccountService,\n serviceName,\n} from './MultichainAccountService';\n\nexport type MultichainAccountServiceGetMultichainAccountAction = {\n type: `${typeof serviceName}:getMultichainAccount`;\n handler: MultichainAccountService['getMultichainAccount'];\n};\n\nexport type MultichainAccountServiceGetMultichainAccountsAction = {\n type: `${typeof serviceName}:getMultichainAccounts`;\n handler: MultichainAccountService['getMultichainAccounts'];\n};\n\nexport type MultichainAccountServiceGetMultichainAccountWalletAction = {\n type: `${typeof serviceName}:getMultichainAccountWallet`;\n handler: MultichainAccountService['getMultichainAccountWallet'];\n};\n\nexport type MultichainAccountServiceGetMultichainAccountWalletsAction = {\n type: `${typeof serviceName}:getMultichainAccountWallets`;\n handler: MultichainAccountService['getMultichainAccountWallets'];\n};\n\n/**\n * All actions that {@link MultichainAccountService} registers so that other\n * modules can call them.\n */\nexport type MultichainAccountServiceActions =\n | MultichainAccountServiceGetMultichainAccountAction\n | MultichainAccountServiceGetMultichainAccountsAction\n | MultichainAccountServiceGetMultichainAccountWalletAction\n | MultichainAccountServiceGetMultichainAccountWalletsAction;\n\n/**\n * All events that {@link MultichainAccountService} publishes so that other modules\n * can subscribe to them.\n */\nexport type MultichainAccountServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link MultichainAccountService}\n * calls.\n */\nexport type AllowedActions =\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerGetAccountAction\n | AccountsControllerGetAccountByAddressAction\n | SnapControllerHandleSnapRequestAction\n | KeyringControllerWithKeyringAction\n | KeyringControllerGetStateAction;\n\n/**\n * All events published by other modules that {@link MultichainAccountService}\n * subscribes to.\n */\nexport type AllowedEvents =\n | KeyringControllerStateChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent;\n\n/**\n * The messenger restricted to actions and events that\n * {@link MultichainAccountService} needs to access.\n */\nexport type MultichainAccountServiceMessenger = RestrictedMessenger<\n 'MultichainAccountService',\n MultichainAccountServiceActions | AllowedActions,\n MultichainAccountServiceEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -2,11 +2,28 @@ import type { AccountsControllerAccountAddedEvent, AccountsControllerAccountRemo
|
|
|
2
2
|
import type { RestrictedMessenger } from "@metamask/base-controller";
|
|
3
3
|
import type { KeyringControllerGetStateAction, KeyringControllerStateChangeEvent, KeyringControllerWithKeyringAction } from "@metamask/keyring-controller";
|
|
4
4
|
import type { HandleSnapRequest as SnapControllerHandleSnapRequestAction } from "@metamask/snaps-controllers";
|
|
5
|
+
import type { MultichainAccountService, serviceName } from "./MultichainAccountService.cjs";
|
|
6
|
+
export type MultichainAccountServiceGetMultichainAccountAction = {
|
|
7
|
+
type: `${typeof serviceName}:getMultichainAccount`;
|
|
8
|
+
handler: MultichainAccountService['getMultichainAccount'];
|
|
9
|
+
};
|
|
10
|
+
export type MultichainAccountServiceGetMultichainAccountsAction = {
|
|
11
|
+
type: `${typeof serviceName}:getMultichainAccounts`;
|
|
12
|
+
handler: MultichainAccountService['getMultichainAccounts'];
|
|
13
|
+
};
|
|
14
|
+
export type MultichainAccountServiceGetMultichainAccountWalletAction = {
|
|
15
|
+
type: `${typeof serviceName}:getMultichainAccountWallet`;
|
|
16
|
+
handler: MultichainAccountService['getMultichainAccountWallet'];
|
|
17
|
+
};
|
|
18
|
+
export type MultichainAccountServiceGetMultichainAccountWalletsAction = {
|
|
19
|
+
type: `${typeof serviceName}:getMultichainAccountWallets`;
|
|
20
|
+
handler: MultichainAccountService['getMultichainAccountWallets'];
|
|
21
|
+
};
|
|
5
22
|
/**
|
|
6
23
|
* All actions that {@link MultichainAccountService} registers so that other
|
|
7
24
|
* modules can call them.
|
|
8
25
|
*/
|
|
9
|
-
export type MultichainAccountServiceActions =
|
|
26
|
+
export type MultichainAccountServiceActions = MultichainAccountServiceGetMultichainAccountAction | MultichainAccountServiceGetMultichainAccountsAction | MultichainAccountServiceGetMultichainAccountWalletAction | MultichainAccountServiceGetMultichainAccountWalletsAction;
|
|
10
27
|
/**
|
|
11
28
|
* All events that {@link MultichainAccountService} publishes so that other modules
|
|
12
29
|
* can subscribe to them.
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,qCAAqC,EACrC,kCAAkC,EAClC,2CAA2C,EAC3C,8CAA8C,EAC/C,sCAAsC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AACrE,OAAO,KAAK,EACV,+BAA+B,EAC/B,iCAAiC,EACjC,kCAAkC,EACnC,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,IAAI,qCAAqC,EAAE,oCAAoC;AAE9G;;;GAGG;AACH,MAAM,MAAM,+BAA+B,
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"A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+B,CAAC;AAEpC;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,iCAAiC,GACjC,mCAAmC,GACnC,qCAAqC,CAAC;AAE1C;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GAAG,mBAAmB,CACjE,0BAA0B,EAC1B,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,EAC9C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -2,11 +2,28 @@ import type { AccountsControllerAccountAddedEvent, AccountsControllerAccountRemo
|
|
|
2
2
|
import type { RestrictedMessenger } from "@metamask/base-controller";
|
|
3
3
|
import type { KeyringControllerGetStateAction, KeyringControllerStateChangeEvent, KeyringControllerWithKeyringAction } from "@metamask/keyring-controller";
|
|
4
4
|
import type { HandleSnapRequest as SnapControllerHandleSnapRequestAction } from "@metamask/snaps-controllers";
|
|
5
|
+
import type { MultichainAccountService, serviceName } from "./MultichainAccountService.mjs";
|
|
6
|
+
export type MultichainAccountServiceGetMultichainAccountAction = {
|
|
7
|
+
type: `${typeof serviceName}:getMultichainAccount`;
|
|
8
|
+
handler: MultichainAccountService['getMultichainAccount'];
|
|
9
|
+
};
|
|
10
|
+
export type MultichainAccountServiceGetMultichainAccountsAction = {
|
|
11
|
+
type: `${typeof serviceName}:getMultichainAccounts`;
|
|
12
|
+
handler: MultichainAccountService['getMultichainAccounts'];
|
|
13
|
+
};
|
|
14
|
+
export type MultichainAccountServiceGetMultichainAccountWalletAction = {
|
|
15
|
+
type: `${typeof serviceName}:getMultichainAccountWallet`;
|
|
16
|
+
handler: MultichainAccountService['getMultichainAccountWallet'];
|
|
17
|
+
};
|
|
18
|
+
export type MultichainAccountServiceGetMultichainAccountWalletsAction = {
|
|
19
|
+
type: `${typeof serviceName}:getMultichainAccountWallets`;
|
|
20
|
+
handler: MultichainAccountService['getMultichainAccountWallets'];
|
|
21
|
+
};
|
|
5
22
|
/**
|
|
6
23
|
* All actions that {@link MultichainAccountService} registers so that other
|
|
7
24
|
* modules can call them.
|
|
8
25
|
*/
|
|
9
|
-
export type MultichainAccountServiceActions =
|
|
26
|
+
export type MultichainAccountServiceActions = MultichainAccountServiceGetMultichainAccountAction | MultichainAccountServiceGetMultichainAccountsAction | MultichainAccountServiceGetMultichainAccountWalletAction | MultichainAccountServiceGetMultichainAccountWalletsAction;
|
|
10
27
|
/**
|
|
11
28
|
* All events that {@link MultichainAccountService} publishes so that other modules
|
|
12
29
|
* can subscribe to them.
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,qCAAqC,EACrC,kCAAkC,EAClC,2CAA2C,EAC3C,8CAA8C,EAC/C,sCAAsC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AACrE,OAAO,KAAK,EACV,+BAA+B,EAC/B,iCAAiC,EACjC,kCAAkC,EACnC,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,IAAI,qCAAqC,EAAE,oCAAoC;AAE9G;;;GAGG;AACH,MAAM,MAAM,+BAA+B,
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,qCAAqC,EACrC,kCAAkC,EAClC,2CAA2C,EAC3C,8CAA8C,EAC/C,sCAAsC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AACrE,OAAO,KAAK,EACV,+BAA+B,EAC/B,iCAAiC,EACjC,kCAAkC,EACnC,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,IAAI,qCAAqC,EAAE,oCAAoC;AAE9G,OAAO,KAAK,EACV,wBAAwB,EACxB,WAAW,EACZ,uCAAmC;AAEpC,MAAM,MAAM,k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mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport type { RestrictedMessenger } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerWithKeyringAction,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest as SnapControllerHandleSnapRequestAction } from '@metamask/snaps-controllers';\n\n/**\n * All actions that {@link MultichainAccountService} registers so that other\n * modules can call them.\n */\nexport type MultichainAccountServiceActions
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport type { RestrictedMessenger } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerWithKeyringAction,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest as SnapControllerHandleSnapRequestAction } from '@metamask/snaps-controllers';\n\nimport type {\n MultichainAccountService,\n serviceName,\n} from './MultichainAccountService';\n\nexport type MultichainAccountServiceGetMultichainAccountAction = {\n type: `${typeof serviceName}:getMultichainAccount`;\n handler: MultichainAccountService['getMultichainAccount'];\n};\n\nexport type MultichainAccountServiceGetMultichainAccountsAction = {\n type: `${typeof serviceName}:getMultichainAccounts`;\n handler: MultichainAccountService['getMultichainAccounts'];\n};\n\nexport type MultichainAccountServiceGetMultichainAccountWalletAction = {\n type: `${typeof serviceName}:getMultichainAccountWallet`;\n handler: MultichainAccountService['getMultichainAccountWallet'];\n};\n\nexport type MultichainAccountServiceGetMultichainAccountWalletsAction = {\n type: `${typeof serviceName}:getMultichainAccountWallets`;\n handler: MultichainAccountService['getMultichainAccountWallets'];\n};\n\n/**\n * All actions that {@link MultichainAccountService} registers so that other\n * modules can call them.\n */\nexport type MultichainAccountServiceActions =\n | MultichainAccountServiceGetMultichainAccountAction\n | MultichainAccountServiceGetMultichainAccountsAction\n | MultichainAccountServiceGetMultichainAccountWalletAction\n | MultichainAccountServiceGetMultichainAccountWalletsAction;\n\n/**\n * All events that {@link MultichainAccountService} publishes so that other modules\n * can subscribe to them.\n */\nexport type MultichainAccountServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link MultichainAccountService}\n * calls.\n */\nexport type AllowedActions =\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerGetAccountAction\n | AccountsControllerGetAccountByAddressAction\n | SnapControllerHandleSnapRequestAction\n | KeyringControllerWithKeyringAction\n | KeyringControllerGetStateAction;\n\n/**\n * All events published by other modules that {@link MultichainAccountService}\n * subscribes to.\n */\nexport type AllowedEvents =\n | KeyringControllerStateChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent;\n\n/**\n * The messenger restricted to actions and events that\n * {@link MultichainAccountService} needs to access.\n */\nexport type MultichainAccountServiceMessenger = RestrictedMessenger<\n 'MultichainAccountService',\n MultichainAccountServiceActions | AllowedActions,\n MultichainAccountServiceEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|