Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!opts) opts = {}
// note: internal encoding (of the unerlying hypercore) is always binary
this.encoding = opts.valueEncoding || 'binary'
// copy to avoid problems with internal changes
opts = Object.assign({}, opts)
const self = this
if (Buffer.isBuffer(key)) {
key = key.toString('hex')
}
let registerBook = findCryptoBook()
hypercore.call(this, createStorage, key, opts)
this._byteLengthOffset = 0
this.on('append', () => {
this._byteLengthOffset = 0
})
if (registerBook) {
this.on('ready', () => {
CryptoLib.getInstance().addBook(self.key.toString('hex'), self.cryptoKeyBook)
})
}
function findCryptoBook () {
let registerBook = false
if (typeof opts.encryptionKeyBook === 'undefined' && (typeof key === 'string' && !opts.secretKey) && !opts.noEncryption) {
self.cryptoKeyBook = CryptoLib.getInstance().getBook(key)