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

  • 1.0.1
  • 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 nonces = ram() // or any `random-access-storage` compliant object
const onwrite = hook(nonces, sharedSecret)

Example

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

const key = crypto.randomBytes(32)

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

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

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

feed.append(Buffer.from('hello'), (err) => {
  feed.head(console.log) // ciphertext
})

replicate(feed, copy, (err) => {
  copy.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. Blocks that are written to a Hypercore feed are encrypted detached from the nonce used for encryption. Nonces are written to a user supplied "nonce storage" which can be reused for deciphering blocks appended to a Hypercore feed.

This function preserves block sizes but requires an external storage for nonces (nonceStorage). Users should provide a random-access-storage compliant instance or a factory function that returns one.

License

MIT

Keywords

FAQs

Package last updated on 07 Jan 2020

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