diff --git a/libs/common/src/platform/models/domain/account-keys.spec.ts b/libs/common/src/platform/models/domain/account-keys.spec.ts deleted file mode 100644 index 6bdb08edd51..00000000000 --- a/libs/common/src/platform/models/domain/account-keys.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { makeStaticByteArray } from "../../../../spec"; -import { Utils } from "../../misc/utils"; - -import { AccountKeys, EncryptionPair } from "./account"; - -describe("AccountKeys", () => { - describe("toJSON", () => { - it("should serialize itself", () => { - const keys = new AccountKeys(); - const buffer = makeStaticByteArray(64); - keys.publicKey = buffer; - - const bufferSpy = jest.spyOn(Utils, "fromBufferToByteString"); - keys.toJSON(); - expect(bufferSpy).toHaveBeenCalledWith(buffer); - }); - - it("should serialize public key as a string", () => { - const keys = new AccountKeys(); - keys.publicKey = Utils.fromByteStringToArray("hello"); - const json = JSON.stringify(keys); - expect(json).toContain('"publicKey":"hello"'); - }); - }); - - describe("fromJSON", () => { - it("should deserialize public key to a buffer", () => { - const keys = AccountKeys.fromJSON({ - publicKey: "hello", - }); - expect(keys.publicKey).toEqual(Utils.fromByteStringToArray("hello")); - }); - - it("should deserialize privateKey", () => { - const spy = jest.spyOn(EncryptionPair, "fromJSON"); - AccountKeys.fromJSON({ - privateKey: { encrypted: "encrypted", decrypted: "decrypted" }, - } as any); - expect(spy).toHaveBeenCalled(); - }); - }); -}); diff --git a/libs/common/src/platform/models/domain/account.spec.ts b/libs/common/src/platform/models/domain/account.spec.ts index 307fde62f93..caa0b6a3f4e 100644 --- a/libs/common/src/platform/models/domain/account.spec.ts +++ b/libs/common/src/platform/models/domain/account.spec.ts @@ -1,4 +1,4 @@ -import { Account, AccountKeys, AccountProfile } from "./account"; +import { Account, AccountProfile } from "./account"; describe("Account", () => { describe("fromJSON", () => { @@ -7,12 +7,10 @@ describe("Account", () => { }); it("should call all the sub-fromJSONs", () => { - const keysSpy = jest.spyOn(AccountKeys, "fromJSON"); const profileSpy = jest.spyOn(AccountProfile, "fromJSON"); Account.fromJSON({}); - expect(keysSpy).toHaveBeenCalled(); expect(profileSpy).toHaveBeenCalled(); }); }); diff --git a/libs/common/src/platform/models/domain/account.ts b/libs/common/src/platform/models/domain/account.ts index b9d10f47e97..1365a33cc9b 100644 --- a/libs/common/src/platform/models/domain/account.ts +++ b/libs/common/src/platform/models/domain/account.ts @@ -2,95 +2,6 @@ // @ts-strict-ignore import { Jsonify } from "type-fest"; -import { DeepJsonify } from "../../../types/deep-jsonify"; -import { Utils } from "../../misc/utils"; - -import { SymmetricCryptoKey } from "./symmetric-crypto-key"; - -export class EncryptionPair { - encrypted?: TEncrypted; - decrypted?: TDecrypted; - - toJSON() { - return { - encrypted: this.encrypted, - decrypted: - this.decrypted instanceof ArrayBuffer - ? Utils.fromBufferToByteString(this.decrypted) - : this.decrypted, - }; - } - - static fromJSON( - obj: { encrypted?: Jsonify; decrypted?: string | Jsonify }, - decryptedFromJson?: (decObj: Jsonify | string) => TDecrypted, - encryptedFromJson?: (encObj: Jsonify) => TEncrypted, - ) { - if (obj == null) { - return null; - } - - const pair = new EncryptionPair(); - if (obj?.encrypted != null) { - pair.encrypted = encryptedFromJson - ? encryptedFromJson(obj.encrypted) - : (obj.encrypted as TEncrypted); - } - if (obj?.decrypted != null) { - pair.decrypted = decryptedFromJson - ? decryptedFromJson(obj.decrypted) - : (obj.decrypted as TDecrypted); - } - return pair; - } -} - -export class AccountKeys { - publicKey?: Uint8Array; - - /** @deprecated July 2023, left for migration purposes*/ - cryptoSymmetricKey?: EncryptionPair = new EncryptionPair< - string, - SymmetricCryptoKey - >(); - - toJSON() { - // If you pass undefined into fromBufferToByteString, you will get an empty string back - // which will cause all sorts of headaches down the line when you try to getPublicKey - // and expect a Uint8Array and get an empty string instead. - return Utils.merge(this, { - publicKey: this.publicKey ? Utils.fromBufferToByteString(this.publicKey) : undefined, - }); - } - - static fromJSON(obj: DeepJsonify): AccountKeys { - if (obj == null) { - return null; - } - return Object.assign(new AccountKeys(), obj, { - cryptoSymmetricKey: EncryptionPair.fromJSON( - obj?.cryptoSymmetricKey, - SymmetricCryptoKey.fromJSON, - ), - publicKey: Utils.fromByteStringToArray(obj?.publicKey), - }); - } - - static initRecordEncryptionPairsFromJSON(obj: any) { - return EncryptionPair.fromJSON(obj, (decObj: any) => { - if (obj == null) { - return null; - } - - const record: Record = {}; - for (const id in decObj) { - record[id] = SymmetricCryptoKey.fromJSON(decObj[id]); - } - return record; - }); - } -} - export class AccountProfile { name?: string; email?: string; @@ -107,15 +18,10 @@ export class AccountProfile { } export class Account { - keys?: AccountKeys = new AccountKeys(); profile?: AccountProfile = new AccountProfile(); constructor(init: Partial) { Object.assign(this, { - keys: { - ...new AccountKeys(), - ...init?.keys, - }, profile: { ...new AccountProfile(), ...init?.profile, @@ -129,7 +35,6 @@ export class Account { } return Object.assign(new Account({}), json, { - keys: AccountKeys.fromJSON(json?.keys), profile: AccountProfile.fromJSON(json?.profile), }); } diff --git a/libs/common/src/platform/models/domain/encrypted-object.ts b/libs/common/src/platform/models/domain/encrypted-object.ts deleted file mode 100644 index 3caa7ae68d1..00000000000 --- a/libs/common/src/platform/models/domain/encrypted-object.ts +++ /dev/null @@ -1,8 +0,0 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore - -export class EncryptedObject { - iv: Uint8Array; - data: Uint8Array; - mac: Uint8Array; -} diff --git a/libs/common/src/platform/models/domain/encryption-pair.spec.ts b/libs/common/src/platform/models/domain/encryption-pair.spec.ts deleted file mode 100644 index 1418c125ed6..00000000000 --- a/libs/common/src/platform/models/domain/encryption-pair.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Utils } from "../../misc/utils"; - -import { EncryptionPair } from "./account"; - -describe("EncryptionPair", () => { - describe("toJSON", () => { - it("should populate decryptedSerialized for buffer arrays", () => { - const pair = new EncryptionPair(); - pair.decrypted = Utils.fromByteStringToArray("hello").buffer; - const json = pair.toJSON(); - expect(json.decrypted).toEqual("hello"); - }); - - it("should populate decryptedSerialized for TypesArrays", () => { - const pair = new EncryptionPair(); - pair.decrypted = Utils.fromByteStringToArray("hello"); - const json = pair.toJSON(); - expect(json.decrypted).toEqual(new Uint8Array([104, 101, 108, 108, 111])); - }); - - it("should serialize encrypted and decrypted", () => { - const pair = new EncryptionPair(); - pair.encrypted = "hello"; - pair.decrypted = "world"; - const json = pair.toJSON(); - expect(json.encrypted).toEqual("hello"); - expect(json.decrypted).toEqual("world"); - }); - }); - - describe("fromJSON", () => { - it("should deserialize encrypted and decrypted", () => { - const pair = EncryptionPair.fromJSON({ - encrypted: "hello", - decrypted: "world", - }); - expect(pair.encrypted).toEqual("hello"); - expect(pair.decrypted).toEqual("world"); - }); - }); -}); diff --git a/libs/common/src/platform/services/state.service.ts b/libs/common/src/platform/services/state.service.ts index 284c8a7f2dc..cc5e5d07396 100644 --- a/libs/common/src/platform/services/state.service.ts +++ b/libs/common/src/platform/services/state.service.ts @@ -254,15 +254,6 @@ export class StateService< ); } - /** - * @deprecated Use UserKey instead - */ - async getEncryptedCryptoSymmetricKey(options?: StorageOptions): Promise { - return ( - await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskOptions())) - )?.keys.cryptoSymmetricKey.encrypted; - } - async getIsAuthenticated(options?: StorageOptions): Promise { return ( (await this.tokenService.getAccessToken(options?.userId as UserId)) != null &&