@@ -1478,30 +1478,35 @@ export class KeyringController extends BaseController<
1478
1478
*/
1479
1479
async exportEncryptionKey ( ) : Promise < string > {
1480
1480
this . #assertIsUnlocked( ) ;
1481
- // There is a case where the controller is unlocked but the encryption key
1482
- // is not set, even when #cacheEncryptionKey is true. This happens when
1483
- // calling changePassword with the existing password. In this case, the
1484
- // encryption key is deleted, but the state is not recreated, because the
1485
- // session state does not change in this case, and #updateVault is not
1486
- // called in #persistOrRollback.
1487
- if ( ! this . state . encryptionKey ) {
1488
- assertIsExportableKeyEncryptor ( this . #encryptor) ;
1489
- assertIsValidPassword ( this . #password) ;
1490
- const result = await this . #encryptor. decryptWithDetail (
1491
- this . #password,
1492
- // Ignoring undefined. Assuming vault is set when unlocked.
1493
- this . state . vault as string ,
1494
- ) ;
1495
- if ( this . #cacheEncryptionKey) {
1496
- this . update ( ( state ) => {
1497
- state . encryptionKey = result . exportedKeyString ;
1498
- state . encryptionSalt = result . salt ;
1481
+
1482
+ return await this . #withControllerLock( async ( ) => {
1483
+ // There is a case where the controller is unlocked but the encryption key
1484
+ // is not set, even when #cacheEncryptionKey is true. This happens when
1485
+ // calling changePassword with the existing password. In this case, the
1486
+ // encryption key is deleted, but the state is not recreated, because the
1487
+ // session state does not change in this case, and #updateVault is not
1488
+ // called in #persistOrRollback.
1489
+ if ( ! this . state . encryptionKey ) {
1490
+ return await this . #withVaultLock( async ( ) => {
1491
+ assertIsExportableKeyEncryptor ( this . #encryptor) ;
1492
+ assertIsValidPassword ( this . #password) ;
1493
+ const result = await this . #encryptor. decryptWithDetail (
1494
+ this . #password,
1495
+ // Ignoring undefined. Assuming vault is set when unlocked.
1496
+ this . state . vault as string ,
1497
+ ) ;
1498
+ if ( this . #cacheEncryptionKey) {
1499
+ this . update ( ( state ) => {
1500
+ state . encryptionKey = result . exportedKeyString ;
1501
+ state . encryptionSalt = result . salt ;
1502
+ } ) ;
1503
+ }
1504
+ return result . exportedKeyString ;
1499
1505
} ) ;
1500
1506
}
1501
- return result . exportedKeyString ;
1502
- }
1503
1507
1504
- return this . state . encryptionKey ;
1508
+ return this . state . encryptionKey ;
1509
+ } ) ;
1505
1510
}
1506
1511
1507
1512
/**
0 commit comments