diff --git a/index.js b/index.js index 6bdf2d47..7f81a059 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,7 @@ module.exports = class Autobase extends ReadyResource { this.store = store this.globalCache = store.globalCache || null this.encrypted = handlers.encrypted || !!handlers.encryptionKey + this.encrypt = !!handlers.encrypt this.encryptionKey = handlers.encryptionKey || null this._tryLoadingLocal = true @@ -272,6 +273,11 @@ module.exports = class Autobase extends ReadyResource { } } + if (this.encrypt && this.encryptionKey === null) { + this.encryptionKey = (await this.store.createKeyPair('autobase/encryption')).secretKey.subarray(0, 32) + await this.local.setUserData('autobase/encryption', this.encryptionKey) + } + if (this.encrypted) { assert(this.encryptionKey !== null, 'Encryption key is expected') }