@metamask-previews/keyring-controller 22.0.2-preview-ca9d0265 → 22.0.2-preview-e149187d
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 +8 -0
- package/dist/KeyringController.cjs +28 -7
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +11 -4
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +11 -4
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +28 -7
- package/dist/KeyringController.mjs.map +1 -1
- package/dist/constants.cjs +1 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -0
- package/dist/constants.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add method `exportEncryptionKey` ([#5984](https://github.com/MetaMask/core/pull/5984))
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Make salt optional with method `submitEncryptionKey` ([#5984](https://github.com/MetaMask/core/pull/5984))
|
|
17
|
+
|
|
10
18
|
## [22.0.2]
|
|
11
19
|
|
|
12
20
|
### Fixed
|
|
@@ -154,6 +154,17 @@ function assertIsExportableKeyEncryptor(encryptor) {
|
|
|
154
154
|
throw new Error(constants_1.KeyringControllerError.UnsupportedEncryptionKeyExport);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Assert that the encryption key is set.
|
|
159
|
+
*
|
|
160
|
+
* @param encryptionKey - The encryption key to check.
|
|
161
|
+
* @throws If the encryption key is not set.
|
|
162
|
+
*/
|
|
163
|
+
function assertIsEncryptionKeySet(encryptionKey) {
|
|
164
|
+
if (!encryptionKey) {
|
|
165
|
+
throw new Error(constants_1.KeyringControllerError.EncryptionKeyNotSet);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
157
168
|
/**
|
|
158
169
|
* Assert that the provided password is a valid non-empty string.
|
|
159
170
|
*
|
|
@@ -858,11 +869,12 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
858
869
|
});
|
|
859
870
|
}
|
|
860
871
|
/**
|
|
861
|
-
* Attempts to decrypt the current vault and load its keyrings,
|
|
862
|
-
*
|
|
872
|
+
* Attempts to decrypt the current vault and load its keyrings, using the
|
|
873
|
+
* given encryption key and salt. The optional salt can be used to check for
|
|
874
|
+
* consistency with the vault salt.
|
|
863
875
|
*
|
|
864
876
|
* @param encryptionKey - Key to unlock the keychain.
|
|
865
|
-
* @param encryptionSalt -
|
|
877
|
+
* @param encryptionSalt - Optional salt to unlock the keychain.
|
|
866
878
|
* @returns Promise resolving when the operation completes.
|
|
867
879
|
*/
|
|
868
880
|
async submitEncryptionKey(encryptionKey, encryptionSalt) {
|
|
@@ -886,6 +898,15 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
886
898
|
console.error('Failed to update vault during login:', error);
|
|
887
899
|
}
|
|
888
900
|
}
|
|
901
|
+
/**
|
|
902
|
+
* Exports the vault encryption key.
|
|
903
|
+
*
|
|
904
|
+
* @returns The vault encryption key.
|
|
905
|
+
*/
|
|
906
|
+
async exportEncryptionKey() {
|
|
907
|
+
assertIsEncryptionKeySet(this.state.encryptionKey);
|
|
908
|
+
return this.state.encryptionKey;
|
|
909
|
+
}
|
|
889
910
|
/**
|
|
890
911
|
* Attempts to decrypt the current vault and load its keyrings,
|
|
891
912
|
* using the given password.
|
|
@@ -1384,9 +1405,12 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1384
1405
|
}
|
|
1385
1406
|
else {
|
|
1386
1407
|
const parsedEncryptedVault = JSON.parse(encryptedVault);
|
|
1387
|
-
if (encryptionSalt !== parsedEncryptedVault.salt) {
|
|
1408
|
+
if (encryptionSalt && encryptionSalt !== parsedEncryptedVault.salt) {
|
|
1388
1409
|
throw new Error(constants_1.KeyringControllerError.ExpiredCredentials);
|
|
1389
1410
|
}
|
|
1411
|
+
else {
|
|
1412
|
+
encryptionSalt = parsedEncryptedVault.salt;
|
|
1413
|
+
}
|
|
1390
1414
|
if (typeof encryptionKey !== 'string') {
|
|
1391
1415
|
throw new TypeError(constants_1.KeyringControllerError.WrongPasswordType);
|
|
1392
1416
|
}
|
|
@@ -1395,9 +1419,6 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1395
1419
|
// This call is required on the first call because encryptionKey
|
|
1396
1420
|
// is not yet inside the memStore
|
|
1397
1421
|
updatedState.encryptionKey = encryptionKey;
|
|
1398
|
-
// we can safely assume that encryptionSalt is defined here
|
|
1399
|
-
// because we compare it with the salt from the vault
|
|
1400
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1401
1422
|
updatedState.encryptionSalt = encryptionSalt;
|
|
1402
1423
|
}
|
|
1403
1424
|
}
|