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

@beshkenadze/react-secret-sharing

v0.2.0

Published

A clean, minimalist implementation of Shamir Secret Sharing with React hooks for easy integration

Readme

@beshkenadze/react-secret-sharing

npm version

A clean, minimalist implementation of Shamir Secret Sharing with React hooks for easy integration.

✨ Features

  • 🔐 Secure: Based on Shamir's Secret Sharing algorithm
  • 📦 Simple: Clean API with full TypeScript support
  • ⚛️ React Ready: Custom hooks for seamless React integration
  • 🎯 Flexible: Three output formats (Base64, Hex, BIP39 Mnemonic)
  • 🔍 Auto-Detection: Automatically detects share formats when combining

📦 Installation

npm install @beshkenadze/react-secret-sharing

🚀 Quick Start

import { useShamir } from "@beshkenadze/react-secret-sharing";

function MyComponent() {
  const { split, combine, shares, isLoading, error, reset } = useShamir();
  
  const handleSplit = async () => {
    await split("my-secret", { totalShares: 3, threshold: 2 });
  };
  
  const handleCombine = async () => {
    const secret = await combine(shares.slice(0, 2));
    console.log('Reconstructed:', secret);
  };
  
  return (
    <div>
      {error && <div>Error: {error}</div>}
      {isLoading && <div>Loading...</div>}
      <button onClick={handleSplit}>Split Secret</button>
      <button onClick={handleCombine}>Combine Shares</button>
      <button onClick={reset}>Reset</button>
    </div>
  );
}

🎨 Share Formats

Base64 (Default)

await split("secret", { totalShares: 3, threshold: 2 });
// Output: "SGVsbG8gV29ybGQ="

Human-Readable Hex

await split("secret", { totalShares: 3, threshold: 2 }, { encoding: 'human' });
// Output: "48-65-6c-6c-6f-20-57-6f-72-6c-64"

BIP39 Mnemonic Words

await split("secret", { totalShares: 3, threshold: 2 }, { encoding: 'mnemonic' });
// Output: "search only exotic way tomato sure despair ship speed beef"

📚 API Reference

useShamir() Hook

The main hook for stateful Shamir operations:

const {
  // State
  isLoading,           // boolean - loading state
  error,               // string | null - error message
  shares,              // TShare[] - generated shares
  reconstructedSecret, // string | null - reconstructed secret
  
  // Actions
  split,               // (secret, config, options?) => Promise<TShare[]>
  combine,             // (shares) => Promise<string>
  reset,               // () => void - reset all state
  clearError           // () => void - clear error only
} = useShamir();

Methods:

  • split(secret, config, options?) - Split a secret into shares

    • secret: string - The secret to split
    • config: TShamirConfig - Configuration for shares
    • options?: TShamirOptions - Optional encoding format
    • Returns: Promise<TShare[]> - Array of generated shares
  • combine(shares) - Combine shares to reconstruct the secret

    • shares: TShare[] - Array of shares to combine
    • Returns: Promise<string> - The reconstructed secret
  • reset() - Reset all state (shares, secret, error)

  • clearError() - Clear only the error state

useShamirOperations() Hook

For one-time operations without state management:

const { splitSecret, combineShares } = useShamirOperations();

// Direct usage
const result = await splitSecret("secret", { totalShares: 3, threshold: 2 });
const reconstructed = await combineShares(result.shares.slice(0, 2));

Core Functions

You can also import the core functions directly:

import { splitSecret, combineShares } from "@beshkenadze/react-secret-sharing";

const { shares } = await splitSecret("secret", { totalShares: 3, threshold: 2 });
const { secret } = await combineShares(shares);

📝 TypeScript Types

interface TShamirConfig {
  totalShares: number;  // 2-255: total number of shares to create
  threshold: number;    // 2-totalShares: minimum shares needed to reconstruct
}

interface TShamirOptions {
  encoding?: 'base64' | 'human' | 'mnemonic'; // output format
}

interface TShare {
  id: number;    // share identifier (1-based)
  data: string;  // encoded share data
}

interface TSplitResult {
  shares: TShare[];
  config: TShamirConfig;
}

interface TCombineResult {
  secret: string;
}

🧩 Auto-Detection Magic

The combine function automatically detects share formats - mix them seamlessly:

const mixedShares = [
  { id: 1, data: "SGVsbG8gV29ybGQ=" },           // Base64
  { id: 2, data: "48-65-6c-6c-6f-20-57-6f-72" }, // Hex  
  { id: 3, data: "search only exotic way tomato" } // Mnemonic
];

const secret = await combine(mixedShares); // ✅ Works perfectly!

🛡️ Security Notes

  • Shares are generated using cryptographically secure random numbers
  • Based on proven Shamir Secret Sharing algorithm
  • No secrets are stored in memory longer than necessary
  • Each share reveals no information about the original secret
  • Threshold security: need exactly K shares to reconstruct

📄 License

MIT © Akira Beshkenadze