diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index 1e617c22d..85c18af1a 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -26,9 +26,10 @@ import { IHttpOpts, IToDeviceEvent, MatrixClient, MatrixHttpApi } from "../../.. import { mkEvent } from "../../test-utils/test-utils"; import { CryptoBackend } from "../../../src/common-crypto/CryptoBackend"; import { IEventDecryptionResult } from "../../../src/@types/crypto"; -import { OutgoingRequestProcessor } from "../../../src/rust-crypto/OutgoingRequestProcessor"; +import { OutgoingRequest, OutgoingRequestProcessor } from "../../../src/rust-crypto/OutgoingRequestProcessor"; import { ServerSideSecretStorage } from "../../../src/secret-storage"; import { ImportRoomKeysOpts } from "../../../src/crypto-api"; +import * as testData from "../../test-utils/test-data"; afterEach(() => { // reset fake-indexeddb after each test, to make sure we don't leak connections @@ -357,6 +358,35 @@ describe("RustCrypto", () => { }); }); + describe("userHasCrossSigningKeys", () => { + let rustCrypto: RustCrypto; + + beforeEach(async () => { + rustCrypto = await makeTestRustCrypto(undefined, testData.TEST_USER_ID); + }); + + it("returns false if there is no cross-signing identity", async () => { + await expect(rustCrypto.userHasCrossSigningKeys()).resolves.toBe(false); + }); + + it("returns true if OlmMachine has a cross-signing identity", async () => { + // @ts-ignore private field + const olmMachine = rustCrypto.olmMachine; + + const outgoingRequests: OutgoingRequest[] = await olmMachine.outgoingRequests(); + // pick out the KeysQueryRequest, and respond to it with the cross-signing keys + const req = outgoingRequests.find((r) => r instanceof KeysQueryRequest)!; + await olmMachine.markRequestAsSent( + req.id!, + req.type, + JSON.stringify(testData.SIGNED_CROSS_SIGNING_KEYS_DATA), + ); + + // ... and we should now have cross-signing keys. + await expect(rustCrypto.userHasCrossSigningKeys()).resolves.toBe(true); + }); + }); + describe("createRecoveryKeyFromPassphrase", () => { let rustCrypto: RustCrypto; diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index 84a21c548..0405ed429 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -188,9 +188,12 @@ export class RustCrypto implements CryptoBackend { public globalBlacklistUnverifiedDevices = false; + /** + * Implementation of {@link CryptoApi.userHasCrossSigningKeys}. + */ public async userHasCrossSigningKeys(): Promise { - // TODO - return false; + const userIdentity = await this.olmMachine.getIdentity(new RustSdkCryptoJs.UserId(this.userId)); + return userIdentity !== undefined; } public prepareToEncrypt(room: Room): void {