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

shamir-tss-gf256

v0.5.0

Published

Uses Shamir's secret sharing method to allows space-effecient secret sharing (splitting) that requires a minimum threshold of shares in order to unlock the orignal secret.

Downloads

49

Readme

Shamir Threshold Secret Sharing using Galois Field 2^8

Uses Shamir's secret sharing method to allows space-efficient secret sharing (splitting) requiring a minimum threshold of shares in order to unlock the original secret.

Example

import * as shamir_tss from 'shamir-tss-gf256'
// or const shamir_tss = require('shamir-tss-gf256')
// or <script src='https://unpkg.com/[email protected]/umd/shamir-tss-gf256.min.js' ></script>

const secret = shamir_tss.randomBytes(16) // or any Uint8Array/Buffer

// split into 10 shares, allowing any 3 to unlock the secret
const shares = shamir_tss.generateShares_b64(secret, 3, 10)
// shares = [
//   'AwH9nHA-35qs4JvF8qkfngTK',
//   'AwI3E71t-b3c2odZ_2pNcT-3',
//   'AwO1ZJY6wtOKODOfme1m1wP0',
//   'AwSoWHr_aQSotSWu6Pl60tEj',
//   'AwUqL1GoUmr-V5Fojn5RdO1g',
//   'AwbgoJz7dE2ObY30g70Dm9Yd',
//   'Awdi17esTyPYjzky5TooPepe',
//   'AwjN7ewQD5wmByQm8vxuDECz',
//   'AwlPmsdHNPJw5ZDglHtFqnzw',
//   'AwqFFQoUEtUA34x8mbgXRUeN' ]


const res_under_a = shamir_tss.unlockShares([shares[2], shares[7]], false)
// res_under_a = false

try {
  const res_under = shamir_tss.unlockShares([shares[2], shares[7]])
} catch (err) {
  // Number of shares did not meet threshold to unlock shared secret. (2 of 3, 0 duplicates)
}


const res_min = shamir_tss.unlockShares([shares[2], shares[7], shares[4]])
// res_min = Uint8Array [ 127, 235, 91, 105, 228, 244, 250, 2, 47, 3, 148, 46, 52, 56, 56, 137 ]

const res_over = shamir_tss.unlockShares([shares[2], shares[7], shares[4], shares[9], shares[1]])
// res_over = Uint8Array [ 127, 235, 91, 105, 228, 244, 250, 2, 47, 3, 148, 46, 52, 56, 56, 137 ]

API

Primary

generateShares(secret, thresholdShares, totalShares)

Transforms secret into a Galois Field polynomial according to Shamir's secret sharing method, returning the specified number of totalShares where any unique subset of thresholdShare shares will unlock the original secret.

Returns the shares as array of Uint8Array.

generatorShares(secret, thresholdShares, [totalShares])

generateShares() returning an iterator of Uint8Array shares.

unlockShares(shares, [valueIfUnderThreshold])

Computes and returns the secret using provided shares array, given sufficient number of shares. Otherwise, valueIfUnderThreshold is returned.

Cautionary Note: There are no self-consistency checks built into Shamir Threshold Secret Shares -- combining shares from different source will result in unlocking some undefined "secret".

generateShares_b64(secret, thresholdShares, totalShares)

generateShares() returning an array of Base64 encoded shares.

generatorShares_b64(secret, thresholdShares, [totalShares])

generateShares() returning an iterator of Base64 encoded shares.

unlockShares_b64(shares, [valueIfUnderThreshold])

unlockShares() with result Base64 encoded.

Utilities

isBinarySecret(arg)

True if arg is a Buffer or Uint8Array, false otherwise.

randomBytes(n_bytes)

In Browser environments, generates a Uint8Array of specified byte length using crypto.getRandomValues().

In NodeJS, generates a Uint8Array of specified byte length using crypto.randomBytes().

u8_to_base64(u8)

Converts a Uint8Array or Buffer to a Base64 (URL safe) encoded string.

base64_to_u8(string_b64)

Converts a Base64 encoded string to a Uint8Array or Buffer.

Internal API

The internal class ShamirSecretShare (alias ShamirTSS) is exposed. Please read the source for understanding and details.

Galois Field 256 (2^8) math primitives

function compute_poly(x, poly_coeff) {}
function lagrange_basis_poly_at_zero(u) {}
function lagrange_interpolate(u, v_iterable) {}

function add(x, y) {}
function mul(x, y) {}
function div(x, y) {}

To use:

const gf256 = require('shamir-tss-gf256/cjs/gf256')
// or import * as gf256 from 'shamir-tss-gf256/esm/gf256'
// or <script src='https://unpkg.com/[email protected]/umd/gf256.js' ></script>

License

ISC