diff --git a/src/client.js b/src/client.js index c8e903577..0f3abc92c 100644 --- a/src/client.js +++ b/src/client.js @@ -1151,6 +1151,7 @@ wrapCryptoFuncs(MatrixClient, [ "checkCrossSigningPrivateKey", "legacyDeviceVerification", "prepareToEncrypt", + "isCrossSigningReady", ]); /** diff --git a/src/crypto/index.js b/src/crypto/index.js index 46c48e9a1..40a529bf1 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -352,6 +352,37 @@ Crypto.prototype.createRecoveryKeyFromPassphrase = async function(password) { } }; +/** + * Checks whether cross signing: + * - is enabled on this account + * - is trusted by this device + * - has private keys stored in secret storage + * and that the account has a secret storage key + * + * If this function returns false, bootstrapSecretStorage() can be used + * to fix things such that it returns true. That is to say, after + * bootstrapSecretStorage() completes sucessfully, this function should + * return true. + * + * The cross-signing API is currently UNSTABLE and may change without notice. + * + * @return {bool} True if cross-signing is ready to be used on this device + */ +Crypto.prototype.isCrossSigningReady = async function() { + const publicKeysOnDevice = this._crossSigningInfo.getId(); + const privateKeysInStorage = await this._crossSigningInfo.isStoredInSecretStorage( + this._secretStorage, + ); + const secretStorageKeyInAccount = await this._secretStorage.hasKey(); + + return ( + publicKeysOnDevice && + privateKeysInStorage && + secretStorageKeyInAccount + ); +}; + + /** * Bootstrap Secure Secret Storage if needed by creating a default key and * signing it with the cross-signing master key. If everything is already set