@@ -42,14 +42,29 @@ const addKeyInfoFingerprints = async () => {
4242} ;
4343
4444export const migrateGlobal = async ( ) => {
45- const globalStore = await GlobalStore . get ( [ 'key_info_store_fingerprints_added' , 'local_drafts' ] ) ;
45+ const globalStore = await GlobalStore . get ( [ 'key_info_store_fingerprints_added' , 'local_drafts' , 'stored_key_info_migrated' ] ) ;
4646 if ( ! globalStore . key_info_store_fingerprints_added ) {
4747 console . info ( 'migrating KeyStorage to add fingerprints and emails of each key...' ) ;
4848 await addKeyInfoFingerprints ( ) ;
4949 // eslint-disable-next-line @typescript-eslint/naming-convention
5050 await GlobalStore . set ( { key_info_store_fingerprints_added : true } ) ;
5151 console . info ( 'done migrating' ) ;
5252 }
53+ // Migrate StoredKeyInfo to KeyInfoWithIdentity format
54+ // Ref: https://github.com/FlowCrypt/flowcrypt-browser/issues/4378
55+ if ( ! globalStore . stored_key_info_migrated ) {
56+ console . info ( 'migrating StoredKeyInfo to KeyInfoWithIdentity format' ) ;
57+ const acctEmails = await GlobalStore . acctEmailsGet ( ) ;
58+ await Promise . all (
59+ acctEmails . map ( async acctEmail => {
60+ // KeyStore.get returns updated key with KeyInfoWithIdentity type
61+ const updatedKeyWithIdentity = await KeyStore . get ( acctEmail ) ;
62+ await KeyStore . set ( acctEmail , updatedKeyWithIdentity ) ;
63+ } )
64+ ) ; // eslint-disable-next-line @typescript-eslint/naming-convention
65+ await GlobalStore . set ( { stored_key_info_migrated : true } ) ;
66+ console . info ( 'Migration to KeyInfoWithIdentity completed successfully' ) ;
67+ }
5368 // migrate local drafts (https://github.com/FlowCrypt/flowcrypt-browser/pull/3986)
5469 if ( typeof globalStore . local_drafts === 'undefined' ) {
5570 console . info ( 'migrating local drafts in old format...' ) ;
0 commit comments