From b47c87f909552a4ccb91ffe881d5c8e9cd81fb93 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Mon, 12 Jun 2023 16:00:31 +0200 Subject: [PATCH] Add `rust-crypto#isCrossSigningReady` implementation (#3462) --- spec/integ/crypto/cross-signing.spec.ts | 19 +++++++++++++++++++ spec/unit/rust-crypto/rust-crypto.spec.ts | 5 ----- src/rust-crypto/rust-crypto.ts | 10 +++++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/spec/integ/crypto/cross-signing.spec.ts b/spec/integ/crypto/cross-signing.spec.ts index d86658df8..16ba6df1d 100644 --- a/spec/integ/crypto/cross-signing.spec.ts +++ b/spec/integ/crypto/cross-signing.spec.ts @@ -168,4 +168,23 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s }); }); }); + + describe("isCrossSigningReady()", () => { + it("should return false if cross-signing is not bootstrapped", async () => { + mockSetupCrossSigningRequests(); + + const isCrossSigningReady = await aliceClient.getCrypto()!.isCrossSigningReady(); + + expect(isCrossSigningReady).toBeFalsy(); + }); + + it("should return true after bootstrapping cross-signing", async () => { + mockSetupCrossSigningRequests(); + await bootstrapCrossSigning({ type: "test" }); + + const isCrossSigningReady = await aliceClient.getCrypto()!.isCrossSigningReady(); + + expect(isCrossSigningReady).toBeTruthy(); + }); + }); }); diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index 71df210ad..9ba37a33b 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -93,11 +93,6 @@ describe("RustCrypto", () => { }); }); - it("isCrossSigningReady", async () => { - const rustCrypto = await makeTestRustCrypto(); - await expect(rustCrypto.isCrossSigningReady()).resolves.toBe(false); - }); - it("getCrossSigningKeyId", async () => { const rustCrypto = await makeTestRustCrypto(); await expect(rustCrypto.getCrossSigningKeyId()).resolves.toBe(null); diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index c2a660e61..9ca76c6f6 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -326,7 +326,15 @@ export class RustCrypto implements CryptoBackend { * Implementation of {@link CryptoApi#isCrossSigningReady} */ public async isCrossSigningReady(): Promise { - return false; + const { publicKeysOnDevice, privateKeysInSecretStorage, privateKeysCachedLocally } = + await this.getCrossSigningStatus(); + const hasKeysInCache = + Boolean(privateKeysCachedLocally.masterKey) && + Boolean(privateKeysCachedLocally.selfSigningKey) && + Boolean(privateKeysCachedLocally.userSigningKey); + + // The cross signing is ready if the public and private keys are available + return publicKeysOnDevice && (hasKeysInCache || privateKeysInSecretStorage); } /**