diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index 1297003b74f..a0c9a47763f 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -98,6 +98,11 @@ describe("RustCrypto", () => { await expect(rustCrypto.isCrossSigningReady()).resolves.toBe(false); }); + it("getCrossSigningKeyId", async () => { + const rustCrypto = await makeTestRustCrypto(); + await expect(rustCrypto.getCrossSigningKeyId()).resolves.toBe(null); + }); + it("bootstrapCrossSigning", async () => { const rustCrypto = await makeTestRustCrypto(); await rustCrypto.bootstrapCrossSigning({}); diff --git a/src/client.ts b/src/client.ts index a037a5e4f55..defd1aa9f9e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2567,14 +2567,13 @@ export class MatrixClient extends TypedEventEmitter; + /** + * Get the ID of one of the user's cross-signing keys. + * + * @param type - The type of key to get the ID of. One of `CrossSigningKey.Master`, `CrossSigngingKey.SelfSigning`, + * or `CrossSigningKey.UserSigning`. Defaults to `CrossSigningKey.Master`. + * + * @returns If cross-signing has been initialised on this device, the ID of the given key. Otherwise, null + */ + getCrossSigningKeyId(type?: CrossSigningKey): Promise; + /** * Bootstrap cross-signing by creating keys if needed. * diff --git a/src/crypto/api.ts b/src/crypto/api.ts index 571c3df78d3..97ead425dab 100644 --- a/src/crypto/api.ts +++ b/src/crypto/api.ts @@ -19,6 +19,7 @@ import { IKeyBackupInfo } from "./keybackup"; import type { AddSecretStorageKeyOpts } from "../secret-storage"; /* re-exports for backwards compatibility. */ +export { CrossSigningKey } from "../crypto-api"; export type { AddSecretStorageKeyOpts as IAddSecretStorageKeyOpts, PassphraseInfo as IPassphraseInfo, @@ -27,12 +28,6 @@ export type { // TODO: Merge this with crypto.js once converted -export enum CrossSigningKey { - Master = "master", - SelfSigning = "self_signing", - UserSigning = "user_signing", -} - export interface IEncryptedEventInfo { /** * whether the event is encrypted (if not encrypted, some of the other properties may not be set) diff --git a/src/crypto/index.ts b/src/crypto/index.ts index 234bb2737ab..1e847152b14 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -35,7 +35,13 @@ import * as algorithms from "./algorithms"; import { createCryptoStoreCacheCallbacks, CrossSigningInfo, DeviceTrustLevel, UserTrustLevel } from "./CrossSigning"; import { EncryptionSetupBuilder } from "./EncryptionSetup"; import { SecretStorage as LegacySecretStorage } from "./SecretStorage"; -import { ICreateSecretStorageOpts, IEncryptedEventInfo, IImportRoomKeysOpts, IRecoveryKey } from "./api"; +import { + CrossSigningKey, + ICreateSecretStorageOpts, + IEncryptedEventInfo, + IImportRoomKeysOpts, + IRecoveryKey, +} from "./api"; import { OutgoingRoomKeyRequestManager } from "./OutgoingRoomKeyRequestManager"; import { IndexedDBCryptoStore } from "./store/indexeddb-crypto-store"; import { VerificationBase } from "./verification/Base"; @@ -45,7 +51,7 @@ import { keyFromPassphrase } from "./key_passphrase"; import { decodeRecoveryKey, encodeRecoveryKey } from "./recoverykey"; import { VerificationRequest } from "./verification/request/VerificationRequest"; import { InRoomChannel, InRoomRequests } from "./verification/request/InRoomChannel"; -import { ToDeviceChannel, ToDeviceRequests, Request } from "./verification/request/ToDeviceChannel"; +import { Request, ToDeviceChannel, ToDeviceRequests } from "./verification/request/ToDeviceChannel"; import { IllegalMethod } from "./verification/IllegalMethod"; import { KeySignatureUploadError } from "../errors"; import { calculateKeyCheck, decryptAES, encryptAES } from "./aes"; @@ -54,7 +60,7 @@ import { BackupManager } from "./backup"; import { IStore } from "../store"; import { Room, RoomEvent } from "../models/room"; import { RoomMember, RoomMemberEvent } from "../models/room-member"; -import { EventStatus, IEvent, MatrixEvent, MatrixEventEvent } from "../models/event"; +import { EventStatus, IContent, IEvent, MatrixEvent, MatrixEventEvent } from "../models/event"; import { ToDeviceBatch } from "../models/ToDeviceMessage"; import { ClientEvent, @@ -70,7 +76,6 @@ import { ISyncStateData } from "../sync"; import { CryptoStore } from "./store/base"; import { IVerificationChannel } from "./verification/request/Channel"; import { TypedEventEmitter } from "../models/typed-event-emitter"; -import { IContent } from "../models/event"; import { IDeviceLists, ISyncResponse, IToDeviceEvent } from "../sync-accumulator"; import { ISignatures } from "../@types/signed"; import { IMessage } from "./algorithms/olm"; @@ -80,11 +85,11 @@ import { MapWithDefault, recursiveMapToObject } from "../utils"; import { AccountDataClient, AddSecretStorageKeyOpts, + SECRET_STORAGE_ALGORITHM_V1_AES, + SecretStorageCallbacks, SecretStorageKeyDescription, SecretStorageKeyObject, SecretStorageKeyTuple, - SECRET_STORAGE_ALGORITHM_V1_AES, - SecretStorageCallbacks, ServerSideSecretStorageImpl, } from "../secret-storage"; import { ISecretRequest } from "./SecretSharing"; @@ -1415,6 +1420,11 @@ export class Crypto extends TypedEventEmitter { + return Promise.resolve(this.getCrossSigningId(type)); + } + + // old name, for backwards compatibility public getCrossSigningId(type: string): string | null { return this.crossSigningInfo.getId(type); } diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index d92b7a9ca74..d96c916e477 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -35,6 +35,7 @@ import { deviceKeysToDeviceMap, rustDeviceToJsDevice } from "./device-converter" import { IDownloadKeyResult, IQueryKeysRequest } from "../client"; import { Device, DeviceMap } from "../models/device"; import { ServerSideSecretStorage } from "../secret-storage"; +import { CrossSigningKey } from "../crypto/api"; /** * An implementation of {@link CryptoBackend} using the Rust matrix-sdk-crypto. @@ -324,6 +325,14 @@ export class RustCrypto implements CryptoBackend { return false; } + /** + * Implementation of {@link CryptoApi#getCrossSigningKeyId} + */ + public async getCrossSigningKeyId(type: CrossSigningKey = CrossSigningKey.Master): Promise { + // TODO + return null; + } + /** * Implementation of {@link CryptoApi#boostrapCrossSigning} */