File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
packages/keyring-controller/src Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -527,6 +527,20 @@ function assertIsExportableKeyEncryptor(
527527 }
528528}
529529
530+ /**
531+ * Assert that the encryption key is set.
532+ *
533+ * @param encryptionKey - The encryption key to check.
534+ * @throws If the encryption key is not set.
535+ */
536+ function assertIsEncryptionKeySet (
537+ encryptionKey : string | undefined ,
538+ ) : asserts encryptionKey is string {
539+ if ( ! encryptionKey ) {
540+ throw new Error ( KeyringControllerError . EncryptionKeyNotSet ) ;
541+ }
542+ }
543+
530544/**
531545 * Assert that the provided password is a valid non-empty string.
532546 *
@@ -1471,6 +1485,16 @@ export class KeyringController extends BaseController<
14711485 }
14721486 }
14731487
1488+ /**
1489+ * Exports the vault encryption key.
1490+ *
1491+ * @returns The vault encryption key.
1492+ */
1493+ async exportEncryptionKey ( ) : Promise < string > {
1494+ assertIsEncryptionKeySet ( this . state . encryptionKey ) ;
1495+ return this . state . encryptionKey ;
1496+ }
1497+
14741498 /**
14751499 * Attempts to decrypt the current vault and load its keyrings,
14761500 * using the given password.
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ export enum KeyringControllerError {
44 UnsafeDirectKeyringAccess = 'KeyringController - Returning keyring instances is unsafe' ,
55 WrongPasswordType = 'KeyringController - Password must be of type string.' ,
66 InvalidEmptyPassword = 'KeyringController - Password cannot be empty.' ,
7+ EncryptionKeyNotSet = 'KeyringController - Encryption key not set.' ,
78 NoFirstAccount = 'KeyringController - First Account not found.' ,
89 DuplicatedAccount = 'KeyringController - The account you are trying to import is a duplicate' ,
910 VaultError = 'KeyringController - Cannot unlock without a previous vault.' ,
You can’t perform that action at this time.
0 commit comments