hypercore-xsalsa20-onwrite-hook
A write hook to decrypt data using a XSalsa20 cipher into a hypercore storage when replicating from peers
Last updated 10 months ago by werle .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hypercore-xsalsa20-onwrite-hook 
SYNC missed versions from official npm registry.

hypercore-xsalsa20-onwrite-hook

A write hook to decrypt data using a xsalsa20 cipher into a Hypercore storage when replicating from peers.

Installation

$ npm install hypercore-xsalsa20-onwrite-hook

Usage

const onwrite = hook(sharedSecret)

Example

const replicate = require('hypercore-replicate')
const hypercore = require('hypercore')
const crypto = require('hypercore-crypto')
const pump = require('pump')
const hook = require('hypercore-xsalsa20-onwrite-hook')
const ram = require('random-access-memory')

const key = crypto.randomBytes(32)

const { publicKey, secretKey } = crypto.keyPair()

const source = hypercore(ram, publicKey, {
  secretKey,
})

const cipher = hypercore(ram, publicKey, {
  secretKey,
  onwrite: hook(key)
})

const edge = hypercore(ram, publicKey)

const reader = hypercore(ram, publicKey, {
  onwrite: hook(key)
})

source.append(Buffer.from('hello'), (err) => {
  source.head(console.log) // plaintext

  // load cipher hypercore
  pump(source.createReadStream(), cipher.createWriteStream(), (err) => {
    if (err) throw err
    cipher.head(console.log) // ciphertext

    replicate(cipher, edge, (err) => {
      if (err) throw err
      edge.head(console.log) // ciphertext

      replicate(edge, reader, (err) => {
        if (err) throw err
        reader.head(console.log) // plaintext
      })
    })
  })
})

API

const onwrite = hook(nonceStorage, sharedKey)

Creates a onwrite() hook for a Hypercore feed that uses the xsalsa20 cipher to encipher or decipher blocks in a Hypercore feed. Nonces are computed from the Hypercore feed's public key and block index.

License

MIT

Current Tags

  • 2.0.0                                ...           latest (10 months ago)

9 Versions

  • 2.0.0                                ...           10 months ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.3                                ...           a year ago
  • 0.1.2                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           2 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (7)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |