diff --git a/src/client.js b/src/client.js index 837122c35..0fc3d64ea 100644 --- a/src/client.js +++ b/src/client.js @@ -582,6 +582,28 @@ MatrixClient.prototype.setDehydrationKey = async function( ); }; +/** + * Creates a new dehydrated device (without queuing periodic dehydration) + * @param {Uint8Array} key the dehydration key + * @param {object} [keyInfo] Information about the key. Primarily for + * information about how to generate the key from a passphrase. + * @param {string} [deviceDisplayName] The device display name for the + * dehydrated device. + * @return {Promise} the device id of the newly created dehydrated device + */ +MatrixClient.prototype.createDehydratedDevice = async function( + key, keyInfo = {}, deviceDisplayName = undefined, +) { + if (!(this._crypto)) { + logger.warn('not dehydrating device if crypto is not enabled'); + return; + } + await this._crypto._dehydrationManager.setKey( + key, keyInfo, deviceDisplayName, + ); + return await this._crypto._dehydrationManager.dehydrateDevice(); +}; + MatrixClient.prototype.exportDevice = async function() { if (!(this._crypto)) { logger.warn('not exporting device if crypto is not enabled'); diff --git a/src/crypto/dehydration.ts b/src/crypto/dehydration.ts index e276c140c..07bf04131 100644 --- a/src/crypto/dehydration.ts +++ b/src/crypto/dehydration.ts @@ -132,7 +132,9 @@ export class DehydrationManager { } return matches; } - private async dehydrateDevice(): Promise { + + /** returns the device id of the newly created dehydrated device */ + async dehydrateDevice(): Promise { if (this.inProgress) { logger.log("Dehydration already in progress -- not starting new dehydration"); return; @@ -270,6 +272,8 @@ export class DehydrationManager { this.timeoutId = global.setTimeout( this.dehydrateDevice.bind(this), oneweek, ); + + return deviceId; } finally { this.inProgress = false; }