mirror of
https://github.com/bitwarden/browser.git
synced 2025-02-27 03:11:35 +01:00
Simplify AccountKeys json parsing
This commit is contained in:
parent
77bbd3a863
commit
5370cc463d
@ -40,8 +40,8 @@ export class EncryptionPair<TEncrypted, TDecrypted> {
|
|||||||
|
|
||||||
static fromJSON<TEncrypted, TDecrypted>(
|
static fromJSON<TEncrypted, TDecrypted>(
|
||||||
obj: Jsonify<EncryptionPair<Jsonify<TEncrypted>, Jsonify<TDecrypted>>>,
|
obj: Jsonify<EncryptionPair<Jsonify<TEncrypted>, Jsonify<TDecrypted>>>,
|
||||||
decryptedFromJson?: (obj: Jsonify<TDecrypted>) => TDecrypted,
|
decryptedFromJson?: (decObj: Jsonify<TDecrypted>) => TDecrypted,
|
||||||
encryptedFromJson?: (obj: Jsonify<TEncrypted>) => TEncrypted
|
encryptedFromJson?: (encObj: Jsonify<TEncrypted>) => TEncrypted
|
||||||
) {
|
) {
|
||||||
const pair = new EncryptionPair<TEncrypted, TDecrypted>();
|
const pair = new EncryptionPair<TEncrypted, TDecrypted>();
|
||||||
if (obj?.encrypted) {
|
if (obj?.encrypted) {
|
||||||
@ -137,32 +137,26 @@ export class AccountKeys {
|
|||||||
SymmetricCryptoKey.fromJSON
|
SymmetricCryptoKey.fromJSON
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{ organizationKeys: AccountKeys.initMapEncryptionPairsFromJSON(obj?.organizationKeys) },
|
||||||
organizationKeys: EncryptionPair.fromJSON(obj?.organizationKeys, (obj: any) => {
|
{ providerKeys: AccountKeys.initMapEncryptionPairsFromJSON(obj?.providerKeys) },
|
||||||
const map = new Map<string, SymmetricCryptoKey>();
|
{ privateKey: EncryptionPair.fromJSON(obj?.privateKey) },
|
||||||
for (const orgId in obj) {
|
|
||||||
map.set(orgId, SymmetricCryptoKey.fromJSON(obj[orgId]));
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
providerKeys: EncryptionPair.fromJSON(obj?.providerKeys, (obj: any) => {
|
|
||||||
const map = new Map<string, SymmetricCryptoKey>();
|
|
||||||
for (const providerId in obj) {
|
|
||||||
map.set(providerId, SymmetricCryptoKey.fromJSON(obj[providerId]));
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
privateKey: EncryptionPair.fromJSON(obj?.privateKey),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
publicKey: Utils.fromByteStringToArray(obj?.publicKeySerialized)?.buffer,
|
publicKey: Utils.fromByteStringToArray(obj?.publicKeySerialized)?.buffer,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These `any` types are a result of Jsonify<Map<>> === {}
|
||||||
|
// Issue raised https://github.com/sindresorhus/type-fest/issues/457
|
||||||
|
static initMapEncryptionPairsFromJSON(obj: any) {
|
||||||
|
return EncryptionPair.fromJSON(obj, (decObj: any) => {
|
||||||
|
const map = new Map<string, SymmetricCryptoKey>();
|
||||||
|
for (const id in decObj) {
|
||||||
|
map.set(id, SymmetricCryptoKey.fromJSON(decObj[id]));
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AccountProfile {
|
export class AccountProfile {
|
||||||
|
Loading…
Reference in New Issue
Block a user