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 🙏

© 2026 – Pkg Stats / Ryan Hefner

secrets-sharing

v1.0.2

Published

A Typescript implementation of Shamir's Secret Sharing Scheme using buffers.

Readme

Secrets Sharing

A TypeScript library for Shamir's Secret Sharing using Buffers instead of strings.

Inspired by grempe/secrets.js, but operates on Buffer objects for native binary data support.

Features

  • Split secrets into shares using Shamir's threshold scheme
  • Reconstruct secrets from shares
  • Generate new shares from existing ones without knowing the secret
  • Works with arbitrary binary data (Buffers)
  • Configurable bit-width for the finite field (3–20 bits)
  • Pluggable RNG
  • Zero dependencies

Installation

npm install secrets-sharing

Usage

import { share, combine } from 'secrets-sharing';

const secret = Buffer.from('my super secret data');

// Split into 5 shares, requiring any 3 to reconstruct
const shares = share(secret, 5, 3);

// Reconstruct from any 3 shares
const recovered = combine(shares.slice(0, 3));
console.log(recovered.toString()); // 'my super secret data'

API

share(secretBuffer, numShares, threshold, padLength?)

Split a secret Buffer into shares using Shamir's threshold secret sharing.

| Parameter | Type | Description | |---|---|---| | secretBuffer | Buffer | The secret to split. | | numShares | number | Total shares to produce (2 to config.max). | | threshold | number | Minimum shares required to reconstruct (2 to numShares). | | padLength | number | Zero-pad the binary secret to a multiple of this many bits before splitting. Defaults to 128. Must be 0–1024. |

Returns: Buffer[] — an array of share Buffers.

combine(shares, at?)

Reconstruct a secret Buffer from an array of share Buffers.

| Parameter | Type | Description | |---|---|---| | shares | Buffer[] | Array of share Buffers (must meet the threshold count). | | at | number | Evaluates the polynomial at this x value instead of 0. Defaults to 0. Used internally by newShare. |

Returns: Buffer — the reconstructed secret.

newShare(id, shares)

Generate a new share with the given numeric id from existing shares, without reconstructing the secret.

| Parameter | Type | Description | |---|---|---| | id | number | Share id, an integer in [1, config.max]. | | shares | Buffer[] | At least threshold existing share Buffers. |

Returns: Buffer — a new share Buffer for the requested id.

init(bits?)

Initialize (or reinitialize) the finite field used for sharing. Called automatically on import with 8 bits.

| Parameter | Type | Description | |---|---|---| | bits | number | Bit-width for the field (3–20). Defaults to 8. |

setRNG(rng)

Provide a custom random number generator. By default the library uses Math.random.

| Parameter | Type | Description | |---|---|---| | rng | (() => number) \| null | A function returning an integer in [0, config.max], or null to reset to the default. |

getConfig()

Return the current library configuration.

Returns: { bits: number; radix: number; maxShares: number }

extractShareComponents(shareBuffer)

Extract the components of a share Buffer.

| Parameter | Type | Description | |---|---|---| | shareBuffer | Buffer | A share Buffer produced by share() or newShare(). |

Returns: { bits: number; id: number; data: string } — where data is the hex payload.

shareBufferToString(shareBuffer)

Convert a share Buffer to its ASCII string representation.

Returns: string

shareStringToBuffer(shareString)

Convert an ASCII share string back to a Buffer.

Returns: Buffer

utf16beFromString(str)

Encode a JS string into a UTF-16BE Buffer with reversed code-unit ordering (matches the secrets.js str2hex convention).

Returns: Buffer

utf16beToString(buf)

Decode a UTF-16BE Buffer (with reversed code-unit ordering) back into a JS string.

Returns: string

Inspiration

Based on the well-known secrets.js library, adapted to work natively with Buffer objects and binary data.

License

ISC