Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hypercore-xsalsa20-onwrite-hook

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hypercore-xsalsa20-onwrite-hook

A write hook to decrypt data using a XSalsa20 cipher into a hypercore storage when replicating from peers

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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 hook = require('hypercore-xsalsa20-onwrite-hook')
const feed = hypercore(storage, key, {
  onwrite: hook({
    nonce: storageNonce,
    key: sharedStorageKey
  })
})

Example

const { keyPair } = require('hypercore-crypto')
const replicate = require('hypercore-replicate')
const hypercore = require('hypercore')
const xsalsa20 = require('xsalsa20-encoding')
const crypto = require('crypto')
const hook = require('hypercore-xsalsa20-onwrite-hook')
const ram = require('random-access-memory')

const key = crypto.randomBytes(32)
const nonce = crypto.randomBytes(32)
const onwrite = hook({ nonce, key })
const { publicKey, secretKey } = keyPair()
const valueEncoding = xsalsa20(nonce, key)

const feed = hypercore(ram, publicKey, { secretKey, valueEncoding })

feed.ready(() => {
  const copy = hypercore(ram, publicKey, { onwrite })
  const other = hypercore(ram, publicKey, { valueEncoding })

  feed.append('hello')

  replicate(feed, copy.replicate({ live: true }), other.replicate({ live: true }), {
    userData: Buffer.from([0xfa, 0xce]),
    live: true
  })

  copy.update(() => {
    copy.head((err, buf) => {
      console.log('%s', buf) // 'hello'
    })
  })

  other.update(() => {
    other.head((err, buf) => {
      console.log('%s', buf) // 'hello'
    })
  })
})

API

hook = require('hypercore-xsalsa20-onwrite-hook')(opts)

where opts can be:

{
  nonce: [Buffer], // An optional 24 byte nonce. If not given, the hypercore's public key is used
  key: Buffer, // A required shared 32 byte shared secret key
}

License

MIT

Keywords

FAQs

Package last updated on 20 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc