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

shamir-secret-sharing-extended

v0.1.2

Published

Zero-dependency TypeScript implementation of Shamir's Secret Sharing (t-of-n threshold scheme) for Node.js and browsers.

Downloads

18

Readme

CI

shamir-secret-sharing-extended

A zero-dependency TypeScript library that implements Shamir’s Secret Sharing (SSS) — a cryptographic scheme that splits a secret into multiple pieces (“shares”) so that only a threshold number of shares can reconstruct it.

  • Threshold security: e.g., split a key into 5 shares, and require any 3 of them to recover the secret.
  • Zero runtime dependencies: relies only on the platform’s built-in Web Crypto API.
  • Lightweight & portable: works in Node.js (≥16) and modern browsers.
  • Encryption option: supports optional AES-256-GCM encryption of shares at rest.
  • Flexible formats: json, string, binary, or base64.
  • Dual distribution: ESM + CJS + TypeScript definitions.

Why this library?

Managing sensitive data like wallet keys, API tokens, or environment secrets is hard. Storing them in one place is risky. Shamir’s Secret Sharing provides information-theoretic security:

  • With fewer than t shares, the secret is impossible to reconstruct.
  • With t or more, the secret is recovered exactly.

This library provides a modern, developer-friendly implementation of SSS with:

  • No dependencies (secure by default, small bundle size).
  • Simple API (split / combine with sane defaults).
  • Encryption support (AES-GCM) for at-rest protection.
  • Cross-platform compatibility (Node & Browser).

How it works (in simple terms)

  1. Splitting (split):

    • The secret (bytes) is encoded as the constant term of a random polynomial over GF(256).
    • Each share is a point (x, y) on that polynomial.
    • At least t points are required to reconstruct the polynomial.
  2. Combining (combine):

    • Given t valid shares, Lagrange interpolation recovers the constant term at x=0.
    • The original secret is restored exactly, without loss.
  3. Formats:

    • Shares can be serialized as JSON, compact strings, binary buffers, or base64 strings.
  4. Optional encryption:

    • Each share’s bytes can be encrypted with AES-256-GCM using a 32-byte key.
    • This ensures both confidentiality and integrity for each share at rest.

Example use cases

  • Cryptocurrency & Fintech

    • Protect wallet private keys by splitting them among multiple parties.
    • Require multiple approvals (e.g., 3-of-5) for transactions.
  • DevOps / Infrastructure

    • Share API tokens, JWT secrets, or database passwords across a team with threshold recovery.
    • Disaster recovery scenarios where multiple people must cooperate.
  • Individuals

    • Backup your recovery seed in multiple forms (QR, paper, USB).
    • Ensure that no single lost share reveals your secret.

Security model

  • Confidentiality: With fewer than t shares, the secret is perfectly hidden (information-theoretic security).
  • Integrity: Basic SSS does not detect tampering.
    • With AES-GCM enabled, tampering is detected (decryption fails).
  • RNG: Polynomials use a cryptographically secure RNG (Web Crypto).
  • Responsibility: Share distribution and storage policies (who holds what) remain an operational concern.

Features at a glance

  • ✅ Shamir’s Secret Sharing (t-of-n) over GF(256).
  • ✅ No runtime dependencies (only built-in crypto).
  • ✅ Optional AES-256-GCM per-share encryption.
  • ✅ Multiple serialization formats.
  • ✅ Works in Node ≥16 & modern browsers.
  • ✅ Distributed as ESM + CJS + TypeScript types.

🚀 Basic Usage

Install the package:

npm i shamir-secret-sharing-extended

Test Code

import { splitString, combineStrings } from "shamir-secret-sharing-extended";

async function main() {
  /**
   * Share format can be one of the following:
   * - "base64"
   * - "string"
   * - "binary"
   * - "json"
   */
  const shareFormat = "base64";

  /**
   * Encryption key is optional:
   * - If not provided → shares are stored in plain format.
   * - If provided → should be a string (e.g. 32 bytes for AES-256-GCM).
   */
  const key = "my-secret-key";

  // Split the secret into 5 shares, with threshold = 3
  const shares = await splitString("hello-world", { shares: 5, threshold: 3, format: shareFormat }, key);
  console.log("Shares:", shares);

  // Combine any 3 shares to recover the original string
  const recovered = await combineStrings([shares[0], shares[1], shares[2]], shareFormat, key);
  console.log("Recovered:", recovered);
}

main();