From b6bb796a6fe6374b880a0fa0410da38c9b0c68b5 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Mon, 2 Dec 2024 10:31:44 +0100 Subject: [PATCH] support encrypt option for stateless generation --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) 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') }