* refactor(bootstrap): add BootstrapShim * feat(security): [#209] generate public/private keys * refactor(encryption): move encryption utils to a service * feat(encryption): [wip] implement convertCryptoKeyToString * fix(user-settings): serialize crypto keys to strings * feat(user-settings): deserialize user settings from IndexedDB * feat(user-settings): upgrade persisted settings on boot * feat(user-settings): automatically migrate persisted user settings * refactor(encryption): simplify CryptoKey stringification * refactor(encryption): DRY up EncryptionService * feat(verification): send public key to new peers * refactor(encryption): use class instance * refactor(serialization): use class instance * refactor(verification): [wip] create usePeerVerification hook * feat(verification): encrypt verification token * feat(verification): send encrypted token to peer * feat(verification): verify peer * refactor(verification): use enum for verification state * feat(verification): expire verification requests * fix(updatePeer): update with fresh state data * feat(verification): display verification state * refactor(usePeerVerification): store verification timer in Peer * feat(verification): present tooltips explaining verification state * feat(ui): show full page loading indicator * feat(init): present bootup failure reasons * refactor(init): move init to its own file * feat(verification): show errors upon verification failure * refactor(verification): move workaround to usePeerVerification * feat(verification): present peer public keys * refactor(verification): move peer public key rendering to its own component * refactor(verification): only pass publicKey into renderer * feat(verification): show user's own public key * refactor(naming): rename Username to UserInfo * refactor(loading): encapsulate height styling * feat(verification): improve user messaging * refactor(style): improve formatting and variable names * feat(verification): add user info tooltip * docs(verification): explain verification
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { UserSettings } from 'models/settings'
|
|
import { AllowedKeyType, encryptionService } from 'services/Encryption'
|
|
|
|
export interface SerializedUserSettings
|
|
extends Omit<UserSettings, 'publicKey' | 'privateKey'> {
|
|
publicKey: string
|
|
privateKey: string
|
|
}
|
|
|
|
export class SerializationService {
|
|
serializeUserSettings = async (
|
|
userSettings: UserSettings
|
|
): Promise<SerializedUserSettings> => {
|
|
const {
|
|
publicKey: publicCryptoKey,
|
|
privateKey: privateCryptoKey,
|
|
...userSettingsRest
|
|
} = userSettings
|
|
|
|
const publicKey = await encryptionService.stringifyCryptoKey(
|
|
publicCryptoKey
|
|
)
|
|
|
|
const privateKey = await encryptionService.stringifyCryptoKey(
|
|
privateCryptoKey
|
|
)
|
|
|
|
return {
|
|
...userSettingsRest,
|
|
publicKey,
|
|
privateKey,
|
|
}
|
|
}
|
|
|
|
deserializeUserSettings = async (
|
|
serializedUserSettings: SerializedUserSettings
|
|
): Promise<UserSettings> => {
|
|
const {
|
|
publicKey: publicCryptoKeyString,
|
|
privateKey: privateCryptoKeyString,
|
|
...userSettingsForIndexedDbRest
|
|
} = serializedUserSettings
|
|
|
|
const publicKey = await encryptionService.parseCryptoKeyString(
|
|
publicCryptoKeyString,
|
|
AllowedKeyType.PUBLIC
|
|
)
|
|
const privateKey = await encryptionService.parseCryptoKeyString(
|
|
privateCryptoKeyString,
|
|
AllowedKeyType.PRIVATE
|
|
)
|
|
|
|
return {
|
|
...userSettingsForIndexedDbRest,
|
|
publicKey,
|
|
privateKey,
|
|
}
|
|
}
|
|
}
|
|
|
|
export const serializationService = new SerializationService()
|