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

@fnet/key-shamir

v0.1.4

Published

Shamir's Secret Sharing Scheme

Downloads

350

Readme

@fnet/key-shamir

This project provides a straightforward implementation of Shamir's Secret Sharing scheme for securely splitting and recovering private keys. Users can distribute sensitive keys into multiple parts, known as shares, and set a threshold for how many shares are needed to reconstruct the original key. This facilitates secure key management and sharing in a collaborative setting.

How It Works

The project operates by using Shamir's Secret Sharing algorithm to split a hexadecimal private key into several shares. These shares can be distributed among different parties. To recover the original key, a specified number of shares (set by the threshold) must be combined. Additional functionality allows creating new shares from existing ones without compromising security.

Key Features

  • Split Key: Break down a private key into multiple shares, ensuring the security of the key through distribution.
  • Add Share: Generate new shares from existing shares, increasing flexibility in share management.
  • Recover Key: Combine the minimum required shares to reconstruct the original private key.

Conclusion

The @fnet/key-shamir project is a useful tool for safely managing private keys through Shamir's Secret Sharing. It offers reliable functionality for splitting, distributing, and recovering private keys, helping users enhance their security practices in a simple and effective manner.

@fnet/key-shamir Developer Guide

Overview

The @fnet/key-shamir library provides functionalities to securely split and recover private keys using Shamir's Secret Sharing scheme. It is designed to enhance the security of key management by dividing a single private key into multiple 'shares', such that only a designated subset of these shares can reconstruct the original key. This library is particularly useful for developers needing to securely distribute parts of a key among different parties or systems.

Installation

You can install the @fnet/key-shamir library using npm or yarn. Here are the commands:

npm install @fnet/key-shamir

or

yarn add @fnet/key-shamir

Usage

@fnet/key-shamir provides a straightforward API with three main functions: splitKey, addShare, and recoverKey. These functions allow you to split a private key into shares, generate a new share from existing ones, and recover the original key from shares, respectively.

Example: Splitting a Key

Suppose you have a private key and want to split it into shares:

import splitKey from '@fnet/key-shamir';

const privateKey = 'your_private_key_here_in_hex_format';
const totalShares = 5;
const threshold = 3;

const shares = splitKey({ private_key: privateKey, total_shares: totalShares, threshold: threshold });

console.log('Shares:', shares);

This splits the private key into 5 shares, requiring at least 3 to recover the original key.

Example: Adding a New Share

If you need to add a new share based on the existing ones, use addShare:

import { addShare } from '@fnet/key-shamir';

const existingShares = ['share1', 'share2', 'share3'];
const newShare = addShare(existingShares);

console.log('New Share:', newShare);

Example: Recovering a Key

Once you have enough shares, you can recover the original key using recoverKey:

import { recoverKey } from '@fnet/key-shamir';

const sharesToCombine = ['share1', 'share2', 'share3'];
const originalPrivateKey = recoverKey(sharesToCombine);

console.log('Recovered Private Key:', originalPrivateKey);

Acknowledgement

This library uses the secrets.js-grempe library internally to manage the Shamir's Secret Sharing logic.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  private_key:
    type: string
    description: Hexadecimal private key to split
  total_shares:
    type: integer
    description: Total number of shares to generate
    default: 5
  threshold:
    type: integer
    description: Minimum number of shares required to recover the key
    default: 3
required:
  - private_key