diff --git a/src/client.js b/src/client.js index ec1c7f7b9..43701ee91 100644 --- a/src/client.js +++ b/src/client.js @@ -1073,6 +1073,16 @@ MatrixClient.prototype.checkEventSenderTrust = async function(event) { * @return {string} the name of the key */ +/** + * Check whether we have a key with a given ID. + * The Secure Secret Storage API is currently UNSTABLE and may change without notice. + * + * @function module:client~MatrixClient#hasSecretStorageKey + * @param {string} [keyId = default key's ID] The ID of the key to check + * for. Defaults to the default key ID if not provided. + * @return {boolean} Whether we have the key. + */ + /** * Store an encrypted secret on the server * The Secure Secret Storage API is currently UNSTABLE and may change without notice. @@ -1137,6 +1147,7 @@ MatrixClient.prototype.checkEventSenderTrust = async function(event) { wrapCryptoFuncs(MatrixClient, [ "bootstrapSecretStorage", "addSecretStorageKey", + "hasSecretStorageKey", "storeSecret", "getSecret", "isSecretStored", @@ -1401,7 +1412,7 @@ MatrixClient.prototype.prepareKeyBackupVersion = async function( logger.log("Preparing key backup version with Secure Secret Storage"); // Ensure Secure Secret Storage is ready for use - if (!this._secretStorage.hasKey()) { + if (!this.hasSecretStorageKey()) { throw new Error("Secure Secret Storage has no keys, needs bootstrapping"); } } diff --git a/src/crypto/index.js b/src/crypto/index.js index 41f6098ea..ae2c4633e 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -369,7 +369,7 @@ Crypto.prototype.bootstrapSecretStorage = async function({ // Check if Secure Secret Storage has a default key. If we don't have one, create the // default key (which will also be signed by the cross-signing master key). - if (!this._secretStorage.hasKey()) { + if (!this.hasSecretStorageKey()) { logger.log("Secret storage default key not found, creating new key"); const keyOptions = await createSecretStorageKey(); const newKeyId = await this.addSecretStorageKey( @@ -400,6 +400,10 @@ Crypto.prototype.addSecretStorageKey = function(algorithm, opts, keyID) { return this._secretStorage.addKey(algorithm, opts, keyID); }; +Crypto.prototype.hasSecretStorageKey = function(keyID) { + return this._secretStorage.hasKey(keyID); +}; + Crypto.prototype.storeSecret = function(name, secret, keys) { return this._secretStorage.store(name, secret, keys); };