0.1.4 • Published 9 months ago

@fnet/key-shamir v0.1.4

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
9 months ago

@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
0.1.4

9 months ago

0.1.3

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago