Skip to content

Commit aa42a1a

Browse files
author
Ioan Moldovan
authored
#4378 Migrate StoredKeyInfo to KeyInfoWithIdentity format (#5976)
* feat: migrated StoredKeyInfo to KeyInfoWithIdentity * fix * fix: comment
1 parent df9cf9f commit aa42a1a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

extension/js/common/platform/store/global-store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type GlobalStoreDict = {
1818
dev_outlook_allow?: boolean;
1919
install_mobile_app_notification_dismissed?: boolean;
2020
key_info_store_fingerprints_added?: boolean;
21+
stored_key_info_migrated?: boolean;
2122
contact_store_x509_fingerprints_and_longids_updated?: boolean;
2223
contact_store_opgp_revoked_flags_updated?: boolean;
2324
contact_store_searchable_pruned?: boolean;
@@ -36,7 +37,8 @@ export type GlobalIndex =
3637
| 'contact_store_x509_fingerprints_and_longids_updated'
3738
| 'contact_store_opgp_revoked_flags_updated'
3839
| 'contact_store_searchable_pruned'
39-
| 'local_drafts';
40+
| 'local_drafts'
41+
| 'stored_key_info_migrated';
4042

4143
/**
4244
* Locally stored data that is not associated with any email account

extension/js/service_worker/migrations.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,29 @@ const addKeyInfoFingerprints = async () => {
4242
};
4343

4444
export 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

Comments
 (0)