Skip to content

#4378 Migrate StoredKeyInfo to KeyInfoWithIdentity format #5976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion extension/js/common/platform/store/global-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type GlobalStoreDict = {
dev_outlook_allow?: boolean;
install_mobile_app_notification_dismissed?: boolean;
key_info_store_fingerprints_added?: boolean;
stored_key_info_migrated?: boolean;
contact_store_x509_fingerprints_and_longids_updated?: boolean;
contact_store_opgp_revoked_flags_updated?: boolean;
contact_store_searchable_pruned?: boolean;
Expand All @@ -36,7 +37,8 @@ export type GlobalIndex =
| 'contact_store_x509_fingerprints_and_longids_updated'
| 'contact_store_opgp_revoked_flags_updated'
| 'contact_store_searchable_pruned'
| 'local_drafts';
| 'local_drafts'
| 'stored_key_info_migrated';

/**
* Locally stored data that is not associated with any email account
Expand Down
17 changes: 16 additions & 1 deletion extension/js/service_worker/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,29 @@ const addKeyInfoFingerprints = async () => {
};

export const migrateGlobal = async () => {
const globalStore = await GlobalStore.get(['key_info_store_fingerprints_added', 'local_drafts']);
const globalStore = await GlobalStore.get(['key_info_store_fingerprints_added', 'local_drafts', 'stored_key_info_migrated']);
if (!globalStore.key_info_store_fingerprints_added) {
console.info('migrating KeyStorage to add fingerprints and emails of each key...');
await addKeyInfoFingerprints();
// eslint-disable-next-line @typescript-eslint/naming-convention
await GlobalStore.set({ key_info_store_fingerprints_added: true });
console.info('done migrating');
}
// Migrate StoredKeyInfo to KeyInfoWithIdentity format
// Ref: https://github.com/FlowCrypt/flowcrypt-browser/issues/4378
if (!globalStore.stored_key_info_migrated) {
console.info('migrating StoredKeyInfo to KeyInfoWithIdentity format');
const acctEmails = await GlobalStore.acctEmailsGet();
await Promise.all(
acctEmails.map(async acctEmail => {
// KeyStore.get returns updated key with KeyInfoWithIdentity type
const updatedKeyWithIdentity = await KeyStore.get(acctEmail);
await KeyStore.set(acctEmail, updatedKeyWithIdentity);
})
); // eslint-disable-next-line @typescript-eslint/naming-convention
await GlobalStore.set({ stored_key_info_migrated: true });
console.info('Migration to KeyInfoWithIdentity completed successfully');
}
// migrate local drafts (https://github.com/FlowCrypt/flowcrypt-browser/pull/3986)
if (typeof globalStore.local_drafts === 'undefined') {
console.info('migrating local drafts in old format...');
Expand Down