@metamask-previews/keyring-controller 7.1.0-preview.3dbf14f

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 ADDED
@@ -0,0 +1,161 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [7.1.0]
10
+ ### Added
11
+ - Add `getEncryptionPublicKey` method on KeyringController ([#1569](https://github.com/MetaMask/core/pull/1569))
12
+
13
+ ## [7.0.0]
14
+ ### Changed
15
+ - **BREAKING**: Remove `keyringTypes` property from the KeyringController state ([#1441](https://github.com/MetaMask/core/pull/1441))
16
+ - **BREAKING**: Constructor `KeyringControllerOptions` type changed ([#1441](https://github.com/MetaMask/core/pull/1441))
17
+ - The `KeyringControllerOptions.state` accepted type is now `{ vault?: string }`
18
+ - The `KeyringControllerOptions.keyringBuilders` type is now `{ (): Keyring<Json>; type: string }[]`
19
+ - **BREAKING**: The `address` type accepted by the `removeAccount` method is now `Hex` ([#1441](https://github.com/MetaMask/core/pull/1441))
20
+ - **BREAKING**: The `signTypedMessage` method now returns a `Promise<string>` ([#1441](https://github.com/MetaMask/core/pull/1441))
21
+ - **BREAKING**: The `signTransaction` method now requires a `TypedTransaction` from `@ethereumjs/tx@^4` for the `transaction` argument, and returns a `Promise<TxData>` ([#1441](https://github.com/MetaMask/core/pull/1441))
22
+ - **BREAKING:** Rename `Keyring` type to `KeyringObject` ([#1441](https://github.com/MetaMask/core/pull/1441))
23
+ - **BREAKING:** `addNewAccount` now throws if address of new account is not a hex string ([#1441](https://github.com/MetaMask/core/pull/1441))
24
+ - **BREAKING:** `exportSeedPhrase` now throws if first keyring does not have a mnemonic ([#1441](https://github.com/MetaMask/core/pull/1441))
25
+ - **BREAKING:** `verifySeedPhrase` now throws if HD keyring does not have a mnemonic ([#1441](https://github.com/MetaMask/core/pull/1441))
26
+ - Update return type of `getAccountKeyringType` to `Promise<string>` ([#1441](https://github.com/MetaMask/core/pull/1441))
27
+ - Update `@metamask/eth-keyring-controller` to `^13.0.0` ([#1441](https://github.com/MetaMask/core/pull/1441))
28
+ - Update `@metamask/utils` to `^6.2.0` ([#1514](https://github.com/MetaMask/core/pull/1514))
29
+ - Update `@ethereumjs/tx` to `^4.2.0` ([#1514](https://github.com/MetaMask/core/pull/1514))
30
+ - Update `@ethereumjs/common` to `^3.2.0` ([#1514](https://github.com/MetaMask/core/pull/1514))
31
+ - Update `@keystonehq/metamask-airgapped-keyring` to `^0.13.1` ([#1514](https://github.com/MetaMask/core/pull/1514))
32
+
33
+ ## [6.1.0]
34
+ ### Changed
35
+ - Bump @metamask/eth-sig-util to ^6.0.0 ([#1483](https://github.com/MetaMask/core/pull/1483))
36
+
37
+ ## [6.0.0]
38
+ ### Added
39
+ - Add messenger events `KeyringController:lock` and `KeyringController:unlock`, emitted when the inner EthKeyringController is locked/unlocked ([#1378](https://github.com/MetaMask/core/pull/1378))
40
+ - Also add corresponding types `KeyringControllerLockEvent` and `KeyringControllerUnlockEvent`
41
+ - Add `KeyringController:accountRemoved` event, fired whenever an account is removed through `removeAccount` ([#1416](https://github.com/MetaMask/core/pull/1416))
42
+
43
+ ### Changed
44
+ - **BREAKING:** Update constructor to take a single argument, an options bag, instead of three arguments ([#1378](https://github.com/MetaMask/core/pull/1378))
45
+ - **BREAKING:** Update controller so state is now accessible via `controller.state` instead of `controller.store.getState()` ([#1378](https://github.com/MetaMask/core/pull/1378))
46
+ - **BREAKING:** Update KeyringController to take a required `messenger` option ([#1378](https://github.com/MetaMask/core/pull/1378))
47
+ - The messenger will now publish `KeyringController:stateChange` on state changes thanks to BaseControllerV2
48
+ - The messenger features a `KeyringController:getState` action thanks to BaseControllerV2
49
+ - Add types `KeyringControllerGetStateAction` and `KeyringControllerStateChangeEvent` for the above
50
+ - Add type `KeyringControllerMessenger`
51
+ - **BREAKING:** Update `keyringState` property in the return value of several methods from a type of `KeyringMemState` to `KeyringControllerMemState` ([#1378](https://github.com/MetaMask/core/pull/1378))
52
+ - The affected methods are:
53
+ - `addNewAccount`
54
+ - `addNewAccountWithoutUpdate`
55
+ - `createNewVaultAndRestore`
56
+ - `createNewVaultAndKeychain`
57
+ - `importAccountWithStrategy`
58
+ - `removeAccount`
59
+ - `setLocked`
60
+ - `submitEncryptionKey`
61
+ - `submitPassword`
62
+ - The new type omits `vault`, `encryptionKey`, and `encryptionSalt`
63
+ - **BREAKING:** Remove `KeyringState`, `KeyringMemState`, and `KeyringConfig` in favor of new types `KeyringControllerState`, `KeyringControllerMemState`, `KeyringControllerActions`, `KeyringControllerEvents`, and `KeyringControllerOptions` ([#1378](https://github.com/MetaMask/core/pull/1378))
64
+ - `KeyringControllerState` is like the previous `KeyringMemState` but with an extra `vault` property
65
+ - `KeyringControllerMemState` is like the previous `KeyringMemState` but without `encryptionKey` or `encryptionSalt`
66
+ - `KeyringControllerOptions` incorporates the previous set of options and `KeyringConfig`
67
+ - Add `immer` as a dependency ([#1378](https://github.com/MetaMask/core/pull/1378))
68
+
69
+ ### Removed
70
+ - **BREAKING:** Remove `subscribe` and `unsubscribe` methods ([#1378](https://github.com/MetaMask/core/pull/1378))
71
+ - State changes can be directly subscribed to (or unsubscribed from) via the messenger if necessary
72
+ - **BREAKING:** Remove `lock` and `unlock` methods ([#1378](https://github.com/MetaMask/core/pull/1378))
73
+ - `KeyringController:lock` and `KeyringController:unlock` may now be subscribed to via the messenger if necessary
74
+ - **BREAKING:** Remove `fullUpdate` method ([#1378](https://github.com/MetaMask/core/pull/1378))
75
+ - There is no need to call this method anymore because the controller should always be up to date with the EthKeyringController instance
76
+ - **BREAKING:** Remove `index` from the `Keyring` type ([#1378](https://github.com/MetaMask/core/pull/1378))
77
+
78
+ ## [5.1.0]
79
+ ### Added
80
+ - Add `cancelQRSynchronization` method ([#1387](https://github.com/MetaMask/core.git/pull/1387))
81
+
82
+ ## [5.0.0]
83
+ ### Added
84
+ - Add support for encryption keys ([#1342](https://github.com/MetaMask/core/pull/1342))
85
+ - The configuration option `cacheEncryptionKey` has been added, along with two new state properties (`encryptionKey` and `encryptionSalt`) and a new method (`submitEncryptionKey`)
86
+ - All new state and config entries are optional, so this will have no effect if you're not using this feature.
87
+ - Make `addNewAccount` idempotent ([#1298](https://github.com/MetaMask/core/pull/1298))
88
+ - The `addNewAccount` method now takes an optional `accountCount` parameter. If provided, we ensure that this can be called repeatedly with the same result.
89
+ - Add deprecated `getKeyringForAccount` and `getKeyringsByType` methods ([#1376](https://github.com/MetaMask/core/pull/1376), [#1386](https://github.com/MetaMask/core/pull/1386))
90
+
91
+ ### Changed
92
+ - **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
93
+ - **BREAKING:** Change return type of `createNewVaultAndRestore` from `string | number[]` to `Uint8Array` ([#1349](https://github.com/MetaMask/core/pull/1349))
94
+ - **BREAKING:** Change return type of `verifySeedPhrase` from `string` to `Uint8Array` ([#1338](https://github.com/MetaMask/core/pull/1338))
95
+ - **BREAKING:** Replace `validatePassword` with `verifyPassword` ([#1348](https://github.com/MetaMask/core/pull/1348))
96
+ - `verifyPassword` is asynchronous, unlike `validatePassword` which was not.
97
+ - `verifyPassword` does not return a boolean to indicate whether the password is valid. Instead an error is thrown when it's invalid.
98
+ - **BREAKING:** `createNewVaultAndKeychain` will now skip vault creation if one already exists, rather than replacing it ([#1324](https://github.com/MetaMask/core/pull/1324))
99
+ - If you do want to replace a vault if one exists, you will have to remove it first before this is called.
100
+ - **BREAKING:** `importAccountWithStrategy` and `addNewAccount` no longer update the selected address ([#1296](https://github.com/MetaMask/core/pull/1296), [#1309](https://github.com/MetaMask/core/pull/1309))
101
+ - If you want the newly imported account to be selected, you will have to do that manually after this is called.
102
+ - **BREAKING:** Change `importAccountWithStrategy` return type ([#1295](https://github.com/MetaMask/core/pull/1295))
103
+ - `importAccountWithStrategy` now returns an object with `keyringState` and `importedAccountAddress`, rather than just the keyring state.
104
+ - **BREAKING:** Change `addNewAccount` return type ([#1294](https://github.com/MetaMask/core/pull/1294))
105
+ - `addNewAccount` now returns an object with `keyringState` and `addedAccountAddress`, rather than just the keyring state.
106
+ - **BREAKING:** Add `@metamask/preferences-controller` peer dependency ([#1393](https://github.com/MetaMask/core/pull/1393))
107
+ - Bump @metamask/eth-keyring-controller from 10.0.0 to 10.0.1 ([#1280](https://github.com/MetaMask/core/pull/1280))
108
+ - Bump @metamask/eth-sig-util from 5.0.2 to 5.0.3 ([#1278](https://github.com/MetaMask/core/pull/1278))
109
+ - Update `@metamask/preferences-controller` dependency
110
+
111
+ ### Fixed
112
+ - Improve validation of `from` address in `signTypedMessage` ([#1293](https://github.com/MetaMask/core/pull/1293))
113
+ - Improve private key validation in `importAccountWithStrategy` ([#1297](https://github.com/MetaMask/core/pull/1297))
114
+ - A more helpful error is now thrown when the given private key has the wrong length
115
+ - Keep `vault` state in sync with the internal `EthKeyringController` vault state ([#1384](https://github.com/MetaMask/core/pull/1384))
116
+ - Previously the `vault` state would never be updated after construction, becoming stale as account changes were made
117
+ - The old behavior was especially confusing because the `subscribe` method is overridden to return state change events from the internal `EthKeyingController` state, resulting in state change events being out of sync with controller state. They should be the same now.
118
+
119
+ ## [4.0.0]
120
+ ### Removed
121
+ - **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
122
+ - Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
123
+
124
+ ## [3.0.0]
125
+ ### Changed
126
+ - **BREAKING:**: Bump eth-keyring-controller version to @metamask/eth-keyring-controller v10 ([#1072](https://github.com/MetaMask/core.git/pull/1072))
127
+ - `exportSeedPhrase` now returns a `Uint8Array` typed SRP (can be converted to a string using [this approach](https://github.com/MetaMask/eth-hd-keyring/blob/53b0570559595ba5b3fd8c80e900d847cd6dee3d/index.js#L40)). It was previously a Buffer.
128
+ - The HD keyring included with the keyring controller has been updated from v4 to v6. See [the `eth-hd-keyring` changelog entries for v5 and v6](https://github.com/MetaMask/eth-hd-keyring/blob/main/CHANGELOG.md#600) for further details on breaking changes.
129
+
130
+ ## [2.0.0]
131
+ ### Changed
132
+ - **BREAKING:**: Require ES2020 support or greater ([#914](https://github.com/MetaMask/controllers/pull/914))
133
+ - This change was introduced by an indirect dependency on `ethereumjs/util` v8
134
+ - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
135
+ - Update `@metamask/eth-sig-util` to v5 ([#914](https://github.com/MetaMask/controllers/pull/914))
136
+ - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
137
+
138
+ ## [1.0.1]
139
+ ### Changed
140
+ - Relax dependencies on `@metamask/base-controller`, `@metamask/controller-utils`, `@metamask/message-manager`, and `@metamask/preferences-controller` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
141
+
142
+ ## [1.0.0]
143
+ ### Added
144
+ - Initial release
145
+ - As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely:
146
+ - Everything in `src/keyring`
147
+
148
+ All changes listed after this point were applied to this package following the monorepo conversion.
149
+
150
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@7.1.0...HEAD
151
+ [7.1.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@7.0.0...@metamask/keyring-controller@7.1.0
152
+ [7.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@6.1.0...@metamask/keyring-controller@7.0.0
153
+ [6.1.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@6.0.0...@metamask/keyring-controller@6.1.0
154
+ [6.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@5.1.0...@metamask/keyring-controller@6.0.0
155
+ [5.1.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@5.0.0...@metamask/keyring-controller@5.1.0
156
+ [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@4.0.0...@metamask/keyring-controller@5.0.0
157
+ [4.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@3.0.0...@metamask/keyring-controller@4.0.0
158
+ [3.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@2.0.0...@metamask/keyring-controller@3.0.0
159
+ [2.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@1.0.1...@metamask/keyring-controller@2.0.0
160
+ [1.0.1]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@1.0.0...@metamask/keyring-controller@1.0.1
161
+ [1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/keyring-controller@1.0.0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 MetaMask
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # `@metamask/keyring-controller`
2
+
3
+ Stores identities seen in the wallet and manages interactions such as signing.
4
+
5
+ ## Installation
6
+
7
+ `yarn add @metamask/keyring-controller`
8
+
9
+ or
10
+
11
+ `npm install @metamask/keyring-controller`
12
+
13
+ ## Contributing
14
+
15
+ This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
@@ -0,0 +1,369 @@
1
+ import type { TxData, TypedTransaction } from '@ethereumjs/tx';
2
+ import { type MetaMaskKeyring as QRKeyring, type IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
3
+ import type { RestrictedControllerMessenger } from '@metamask/base-controller';
4
+ import { BaseControllerV2 } from '@metamask/base-controller';
5
+ import type { PersonalMessageParams, TypedMessageParams } from '@metamask/message-manager';
6
+ import type { PreferencesController } from '@metamask/preferences-controller';
7
+ import { type Hex, type Keyring, type Json } from '@metamask/utils';
8
+ import type { Patch } from 'immer';
9
+ declare const name = "KeyringController";
10
+ /**
11
+ * Available keyring types
12
+ */
13
+ export declare enum KeyringTypes {
14
+ simple = "Simple Key Pair",
15
+ hd = "HD Key Tree",
16
+ qr = "QR Hardware Wallet Device"
17
+ }
18
+ /**
19
+ * @type KeyringControllerState
20
+ *
21
+ * Keyring controller state
22
+ * @property vault - Encrypted string representing keyring data
23
+ * @property isUnlocked - Whether vault is unlocked
24
+ * @property keyringTypes - Account types
25
+ * @property keyrings - Group of accounts
26
+ * @property encryptionKey - Keyring encryption key
27
+ * @property encryptionSalt - Keyring encryption salt
28
+ */
29
+ export declare type KeyringControllerState = {
30
+ vault?: string;
31
+ isUnlocked: boolean;
32
+ keyrings: KeyringObject[];
33
+ encryptionKey?: string;
34
+ encryptionSalt?: string;
35
+ };
36
+ export declare type KeyringControllerMemState = Omit<KeyringControllerState, 'vault' | 'encryptionKey' | 'encryptionSalt'>;
37
+ export declare type KeyringControllerGetStateAction = {
38
+ type: `${typeof name}:getState`;
39
+ handler: () => KeyringControllerState;
40
+ };
41
+ export declare type KeyringControllerStateChangeEvent = {
42
+ type: `${typeof name}:stateChange`;
43
+ payload: [KeyringControllerState, Patch[]];
44
+ };
45
+ export declare type KeyringControllerAccountRemovedEvent = {
46
+ type: `${typeof name}:accountRemoved`;
47
+ payload: [string];
48
+ };
49
+ export declare type KeyringControllerLockEvent = {
50
+ type: `${typeof name}:lock`;
51
+ payload: [];
52
+ };
53
+ export declare type KeyringControllerUnlockEvent = {
54
+ type: `${typeof name}:unlock`;
55
+ payload: [];
56
+ };
57
+ export declare type KeyringControllerActions = KeyringControllerGetStateAction;
58
+ export declare type KeyringControllerEvents = KeyringControllerStateChangeEvent | KeyringControllerLockEvent | KeyringControllerUnlockEvent | KeyringControllerAccountRemovedEvent;
59
+ export declare type KeyringControllerMessenger = RestrictedControllerMessenger<typeof name, KeyringControllerActions, KeyringControllerEvents, string, string>;
60
+ export declare type KeyringControllerOptions = {
61
+ removeIdentity: PreferencesController['removeIdentity'];
62
+ syncIdentities: PreferencesController['syncIdentities'];
63
+ updateIdentities: PreferencesController['updateIdentities'];
64
+ setSelectedAddress: PreferencesController['setSelectedAddress'];
65
+ setAccountLabel?: PreferencesController['setAccountLabel'];
66
+ encryptor?: any;
67
+ keyringBuilders?: {
68
+ (): Keyring<Json>;
69
+ type: string;
70
+ }[];
71
+ cacheEncryptionKey?: boolean;
72
+ messenger: KeyringControllerMessenger;
73
+ state?: {
74
+ vault?: string;
75
+ };
76
+ };
77
+ /**
78
+ * @type KeyringObject
79
+ *
80
+ * Keyring object to return in fullUpdate
81
+ * @property type - Keyring type
82
+ * @property accounts - Associated accounts
83
+ */
84
+ export declare type KeyringObject = {
85
+ accounts: string[];
86
+ type: string;
87
+ };
88
+ /**
89
+ * A strategy for importing an account
90
+ */
91
+ export declare enum AccountImportStrategy {
92
+ privateKey = "privateKey",
93
+ json = "json"
94
+ }
95
+ /**
96
+ * The `signTypedMessage` version
97
+ *
98
+ * @see https://docs.metamask.io/guide/signing-data.html
99
+ */
100
+ export declare enum SignTypedDataVersion {
101
+ V1 = "V1",
102
+ V3 = "V3",
103
+ V4 = "V4"
104
+ }
105
+ /**
106
+ * Controller responsible for establishing and managing user identity.
107
+ *
108
+ * This class is a wrapper around the `eth-keyring-controller` package. The
109
+ * `eth-keyring-controller` manages the "vault", which is an encrypted store of private keys, and
110
+ * it manages the wallet "lock" state. This wrapper class has convenience methods for interacting
111
+ * with the internal keyring controller and handling certain complex operations that involve the
112
+ * keyrings.
113
+ */
114
+ export declare class KeyringController extends BaseControllerV2<typeof name, KeyringControllerState, KeyringControllerMessenger> {
115
+ #private;
116
+ private readonly mutex;
117
+ private readonly removeIdentity;
118
+ private readonly syncIdentities;
119
+ private readonly updateIdentities;
120
+ private readonly setSelectedAddress;
121
+ private readonly setAccountLabel?;
122
+ /**
123
+ * Creates a KeyringController instance.
124
+ *
125
+ * @param opts - Initial options used to configure this controller
126
+ * @param opts.removeIdentity - Remove the identity with the given address.
127
+ * @param opts.syncIdentities - Sync identities with the given list of addresses.
128
+ * @param opts.updateIdentities - Generate an identity for each address given that doesn't already have an identity.
129
+ * @param opts.setSelectedAddress - Set the selected address.
130
+ * @param opts.setAccountLabel - Set a new name for account.
131
+ * @param opts.encryptor - An optional object for defining encryption schemes.
132
+ * @param opts.keyringBuilders - Set a new name for account.
133
+ * @param opts.cacheEncryptionKey - Whether to cache or not encryption key.
134
+ * @param opts.messenger - A restricted controller messenger.
135
+ * @param opts.state - Initial state to set on this controller.
136
+ */
137
+ constructor({ removeIdentity, syncIdentities, updateIdentities, setSelectedAddress, setAccountLabel, encryptor, keyringBuilders, cacheEncryptionKey, messenger, state, }: KeyringControllerOptions);
138
+ /**
139
+ * Adds a new account to the default (first) HD seed phrase keyring.
140
+ *
141
+ * @param accountCount - Number of accounts before adding a new one, used to
142
+ * make the method idempotent.
143
+ * @returns Promise resolving to keyring current state and added account
144
+ * address.
145
+ */
146
+ addNewAccount(accountCount?: number): Promise<{
147
+ keyringState: KeyringControllerMemState;
148
+ addedAccountAddress: string;
149
+ }>;
150
+ /**
151
+ * Adds a new account to the specified keyring.
152
+ *
153
+ * @param keyring - Keyring to add the account to.
154
+ * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.
155
+ * @returns Promise resolving to keyring current state and added account
156
+ */
157
+ addNewAccountForKeyring(keyring: Keyring<Json>, accountCount?: number): Promise<Hex>;
158
+ /**
159
+ * Adds a new account to the default (first) HD seed phrase keyring without updating identities in preferences.
160
+ *
161
+ * @returns Promise resolving to current state when the account is added.
162
+ */
163
+ addNewAccountWithoutUpdate(): Promise<KeyringControllerMemState>;
164
+ /**
165
+ * Effectively the same as creating a new keychain then populating it
166
+ * using the given seed phrase.
167
+ *
168
+ * @param password - Password to unlock keychain.
169
+ * @param seed - A BIP39-compliant seed phrase as Uint8Array,
170
+ * either as a string or an array of UTF-8 bytes that represent the string.
171
+ * @returns Promise resolving to the restored keychain object.
172
+ */
173
+ createNewVaultAndRestore(password: string, seed: Uint8Array): Promise<KeyringControllerMemState>;
174
+ /**
175
+ * Create a new primary keychain and wipe any previous keychains.
176
+ *
177
+ * @param password - Password to unlock the new vault.
178
+ * @returns Newly-created keychain object.
179
+ */
180
+ createNewVaultAndKeychain(password: string): Promise<KeyringControllerMemState>;
181
+ /**
182
+ * Adds a new keyring of the given `type`.
183
+ *
184
+ * @param type - Keyring type name.
185
+ * @param opts - Keyring options.
186
+ * @throws If a builder for the given `type` does not exist.
187
+ * @returns Promise resolving to the added keyring.
188
+ */
189
+ addNewKeyring(type: KeyringTypes | string, opts?: unknown): Promise<Keyring<Json>>;
190
+ /**
191
+ * Method to verify a given password validity. Throws an
192
+ * error if the password is invalid.
193
+ *
194
+ * @param password - Password of the keyring.
195
+ */
196
+ verifyPassword(password: string): Promise<void>;
197
+ /**
198
+ * Returns the status of the vault.
199
+ *
200
+ * @returns Boolean returning true if the vault is unlocked.
201
+ */
202
+ isUnlocked(): boolean;
203
+ /**
204
+ * Gets the seed phrase of the HD keyring.
205
+ *
206
+ * @param password - Password of the keyring.
207
+ * @returns Promise resolving to the seed phrase.
208
+ */
209
+ exportSeedPhrase(password: string): Promise<Uint8Array>;
210
+ /**
211
+ * Gets the private key from the keyring controlling an address.
212
+ *
213
+ * @param password - Password of the keyring.
214
+ * @param address - Address to export.
215
+ * @returns Promise resolving to the private key for an address.
216
+ */
217
+ exportAccount(password: string, address: string): Promise<string>;
218
+ /**
219
+ * Returns the public addresses of all accounts for the current keyring.
220
+ *
221
+ * @returns A promise resolving to an array of addresses.
222
+ */
223
+ getAccounts(): Promise<string[]>;
224
+ /**
225
+ * Get encryption public key.
226
+ *
227
+ * @param account - An account address.
228
+ * @param opts - Additional encryption options.
229
+ * @throws If the `account` does not exist or does not support the `getEncryptionPublicKey` method
230
+ * @returns Promise resolving to encyption public key of the `account` if one exists.
231
+ */
232
+ getEncryptionPublicKey(account: string, opts?: Record<string, unknown>): Promise<string>;
233
+ /**
234
+ * Returns the currently initialized keyring that manages
235
+ * the specified `address` if one exists.
236
+ *
237
+ * @deprecated Use of this method is discouraged as actions executed directly on
238
+ * keyrings are not being reflected in the KeyringController state and not
239
+ * persisted in the vault.
240
+ * @param account - An account address.
241
+ * @returns Promise resolving to keyring of the `account` if one exists.
242
+ */
243
+ getKeyringForAccount(account: string): Promise<unknown>;
244
+ /**
245
+ * Returns all keyrings of the given type.
246
+ *
247
+ * @deprecated Use of this method is discouraged as actions executed directly on
248
+ * keyrings are not being reflected in the KeyringController state and not
249
+ * persisted in the vault.
250
+ * @param type - Keyring type name.
251
+ * @returns An array of keyrings of the given type.
252
+ */
253
+ getKeyringsByType(type: KeyringTypes | string): unknown[];
254
+ /**
255
+ * Persist all serialized keyrings in the vault.
256
+ *
257
+ * @returns Promise resolving with `true` value when the
258
+ * operation completes.
259
+ */
260
+ persistAllKeyrings(): Promise<boolean>;
261
+ /**
262
+ * Imports an account with the specified import strategy.
263
+ *
264
+ * @param strategy - Import strategy name.
265
+ * @param args - Array of arguments to pass to the underlying stategy.
266
+ * @throws Will throw when passed an unrecognized strategy.
267
+ * @returns Promise resolving to keyring current state and imported account
268
+ * address.
269
+ */
270
+ importAccountWithStrategy(strategy: AccountImportStrategy, args: any[]): Promise<{
271
+ keyringState: KeyringControllerMemState;
272
+ importedAccountAddress: string;
273
+ }>;
274
+ /**
275
+ * Removes an account from keyring state.
276
+ *
277
+ * @param address - Address of the account to remove.
278
+ * @fires KeyringController:accountRemoved
279
+ * @returns Promise resolving current state when this account removal completes.
280
+ */
281
+ removeAccount(address: Hex): Promise<KeyringControllerMemState>;
282
+ /**
283
+ * Deallocates all secrets and locks the wallet.
284
+ *
285
+ * @returns Promise resolving to current state.
286
+ */
287
+ setLocked(): Promise<KeyringControllerMemState>;
288
+ /**
289
+ * Signs message by calling down into a specific keyring.
290
+ *
291
+ * @param messageParams - PersonalMessageParams object to sign.
292
+ * @returns Promise resolving to a signed message string.
293
+ */
294
+ signMessage(messageParams: PersonalMessageParams): Promise<string>;
295
+ /**
296
+ * Signs personal message by calling down into a specific keyring.
297
+ *
298
+ * @param messageParams - PersonalMessageParams object to sign.
299
+ * @returns Promise resolving to a signed message string.
300
+ */
301
+ signPersonalMessage(messageParams: PersonalMessageParams): Promise<string>;
302
+ /**
303
+ * Signs typed message by calling down into a specific keyring.
304
+ *
305
+ * @param messageParams - TypedMessageParams object to sign.
306
+ * @param version - Compatibility version EIP712.
307
+ * @throws Will throw when passed an unrecognized version.
308
+ * @returns Promise resolving to a signed message string or an error if any.
309
+ */
310
+ signTypedMessage(messageParams: TypedMessageParams, version: SignTypedDataVersion): Promise<string>;
311
+ /**
312
+ * Signs a transaction by calling down into a specific keyring.
313
+ *
314
+ * @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.
315
+ * @param from - Address to sign from, should be in keychain.
316
+ * @returns Promise resolving to a signed transaction string.
317
+ */
318
+ signTransaction(transaction: TypedTransaction, from: string): Promise<TxData>;
319
+ /**
320
+ * Attempts to decrypt the current vault and load its keyrings,
321
+ * using the given encryption key and salt.
322
+ *
323
+ * @param encryptionKey - Key to unlock the keychain.
324
+ * @param encryptionSalt - Salt to unlock the keychain.
325
+ * @returns Promise resolving to the current state.
326
+ */
327
+ submitEncryptionKey(encryptionKey: string, encryptionSalt: string): Promise<KeyringControllerMemState>;
328
+ /**
329
+ * Attempts to decrypt the current vault and load its keyrings,
330
+ * using the given password.
331
+ *
332
+ * @param password - Password to unlock the keychain.
333
+ * @returns Promise resolving to the current state.
334
+ */
335
+ submitPassword(password: string): Promise<KeyringControllerMemState>;
336
+ /**
337
+ * Verifies the that the seed phrase restores the current keychain's accounts.
338
+ *
339
+ * @returns Promise resolving to the seed phrase as Uint8Array.
340
+ */
341
+ verifySeedPhrase(): Promise<Uint8Array>;
342
+ /**
343
+ * Get qr hardware keyring.
344
+ *
345
+ * @returns The added keyring
346
+ */
347
+ getOrAddQRKeyring(): Promise<QRKeyring>;
348
+ restoreQRKeyring(serialized: any): Promise<void>;
349
+ resetQRKeyringState(): Promise<void>;
350
+ getQRKeyringState(): Promise<IQRKeyringState>;
351
+ submitQRCryptoHDKey(cryptoHDKey: string): Promise<void>;
352
+ submitQRCryptoAccount(cryptoAccount: string): Promise<void>;
353
+ submitQRSignature(requestId: string, ethSignature: string): Promise<void>;
354
+ cancelQRSignRequest(): Promise<void>;
355
+ /**
356
+ * Cancels qr keyring sync.
357
+ */
358
+ cancelQRSynchronization(): Promise<void>;
359
+ connectQRHardware(page: number): Promise<{
360
+ balance: string;
361
+ address: string;
362
+ index: number;
363
+ }[]>;
364
+ unlockQRHardwareWalletAccount(index: number): Promise<void>;
365
+ getAccountKeyringType(account: string): Promise<string>;
366
+ forgetQRDevice(): Promise<void>;
367
+ }
368
+ export default KeyringController;
369
+ //# sourceMappingURL=KeyringController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringController.d.ts","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,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