Skip to content

Commit

Permalink
support encrypt option for stateless generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Dec 2, 2024
1 parent 6683144 commit b6bb796
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
}
Expand Down

0 comments on commit b6bb796

Please sign in to comment.