How to use the hypercore.call function in hypercore

To help you get started, we’ve selected a few hypercore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fsteff / hypercore-encrypted / index.js View on Github external
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)

hypercore

Hypercore is a secure, distributed append-only log

MIT
Latest version published 22 hours ago

Package Health Score

84 / 100
Full package analysis