npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hyper-secret-sharing

v0.1.0

Published

Secret sharing over hypercore

Downloads

4

Readme

hyper-secret-sharing

Secret sharing over Hypercore that leverages xsalsa20-encoding to secure shares at rest.

Installation

$ npm install hyper-secret-sharing

Usage

const secrets = require('hyper-secret-sharing')

// split 'secret' into shares appended to 'originFeed'
secrets.share(originFeed, { secret, nonce, threshold, shares }, (err, shares, index) => {
  // shares appened to 'originFeed' starting at 'index'
})

// recover secret from 'recoveryFeed'
secrets.recover(recoveryFeed, { nonce, threshold, shares, secretKey }, (err, secret) => {
  // 'secret' is the result from combined shared
})

Example

const { recover, share } = require('hyper-secret-sharing')
const { keyPair } = require('hypercore-crypto')
const replicate = require('hypercore-replicate')
const hypercore = require('hypercore')
const crypto = require('crypto')
const ram = require('random-access-memory')

const { publicKey, secretKey } = keyPair()
const threshold = 32
const shares = 64
const secret = Buffer.from('a secret message')
const nonce = crypto.randomBytes(32)

const recoverer = hypercore(ram, publicKey, { sparse: true })
const origin = hypercore(ram, publicKey, { secretKey })

const holders = Array(shares).fill(0).map((_, start) => {
  const holder = hypercore(ram, publicKey, { sparse: true })
  process.nextTick(replicate, holder, recoverer, { live: true })
  process.nextTick(download, holder, start)
  return holder
})

share(origin, { secret, nonce, threshold, shares }, onshare)
recover(recoverer, { nonce, secretKey, threshold }, onrecover)
replicate(origin, ...holders)

function onshare(err, shares, start, end, threshold) {
  console.log('shares: count=%d threshold=%d start=%d end=%d',
    shares.length, threshold, start, end)
}

function onrecover(err, secret) {
  console.log('recovered secret: %s', secret);
}

function download(feed, start) {
  feed.download({ start: start, end: start + feed.length })
}

API

secrets.share(feed, opts, callback)

Split opts.secret into opts.shares shares with a recovery threshold specified by opts.threshold appending each share into the feed calling callback(err, shares, start, end, threshold) upon success or error where opts can be:

{
  threshold: Number, // The number of shares need to recover the secret
  shares: Number, // The number of shares to create from the secret,
  secret: Buffer, // The secret to split into shares
  nonce: Buffer, // _Required_ nonce for 'xsalsa20-encoding' encryption
  secretKey: feed.secretKey, // An optional secret key override
}
const crypto = require('crypto')

const secret = Buffer.from('secret message')
const nonce = crypto.randomBytes(32)
const feed = hypercore(ram)

feed.ready(() => {
  const opts = { secret, nonce, shares: 4, threshold: 2 }
  secrets.share(feed, opts, (err, shares) => {
    // handle shares
  })
})

secrets.recover(feed, opts, callback)

Recover secret in feed with at least opts.threshold shares calling callback(err, secret) where opts can be:

{
  threshold: Number, // The number of shares need to recover the secret
  secretKey: Buffer, // _Required_ key for 'xsalsa20-encryption' decryption
  nonce: Buffer, // _Required_ nonce for 'xsalsa20-encoding' decryption
}
const replicate = require('hypercore-replicate')
const crypto = require('crypto')

const secret = Buffer.from('secret message')
const nonce = crypto.randomBytes(32)
const feed = hypercore(ram)
const copy = hypercore(ram)

feed.ready(() => {
  const opts = { secret, nonce, shares: 4, threshold: 2 }
  secrets.share(feed, opts, (err, shares) => {
    replicate(feed, copy, () => {
      const opts = { nonce, threshold: 2, secret: feed.secretKey }
      secrets.recover(copy, opts, (err, secret) => {
        console.log('%s', secret) // 'secret message'
      })
    })
  })
})

License

MIT