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/keygen

v0.1.4

Published

A simple utility to generate key pairs from a mnemonic seed phrase

Downloads

123

Readme

@fnet/keygen

Introduction

@fnet/keygen is a JavaScript library designed to help users derive cryptographic keys using a mnemonic seed phrase or a private key. It leverages industry-standard cryptographic methods to generate secure keys suitable for blockchain applications, including Bitcoin. The library also supports Shamir's Secret Sharing to provide an additional layer of security.

How It Works

The core functionality of @fnet/keygen revolves around deriving keys using the BIP39 and BIP32 standards. Given a mnemonic seed phrase, the library generates a cryptographic seed, which is then used to create a root key. From this root key, you can derive child keys using a specified hierarchical path. The library can output the private key, public key, and the corresponding public Bitcoin address. It also offers an optional feature to split a private key into multiple shares using Shamir's Secret Sharing, providing an extra security measure.

Key Features

  • Generate cryptographic keys from a mnemonic seed phrase.
  • Standard BIP44 derivation paths for hierarchical key generation.
  • Output includes private key, public key, and Bitcoin address.
  • Supports Shamir's Secret Sharing to divide a private key into shares with a defined threshold for reconstruction.

Conclusion

@fnet/keygen is a practical tool for users looking to implement secure key derivation in blockchain applications. Its straightforward approach to generating and managing keys ensures a robust solution without unnecessary complexity. Whether you need to create a simple wallet or implement an advanced key management solution, this library offers essential features to support your cryptographic needs.

@fnet/keygen Developer Guide

Overview

The @fnet/keygen library provides a utility for generating cryptographic keys using mnemonic seed phrases following the BIP39 standard. Additionally, it supports deriving child keys based on custom derivation paths compatible with BIP32, and offers Shamir Secret Sharing to split private keys into secure shares for enhanced security. This library is ideal for developers looking to manage and secure cryptographic keys for blockchain or other secure applications.

Installation

To install @fnet/keygen in your project, use npm or yarn:

npm install @fnet/keygen

or

yarn add @fnet/keygen

Usage

Key Derivation

You can derive cryptographic keys using a mnemonic phrase and a custom derivation path. Define the necessary parameters such as organization, account, scope, and index to derive specific keys in your application's context.

import keygen from '@fnet/keygen';

const derivedKey = await keygen({
  phrase: 'your mnemonic seed phrase here',
  organization: 0,
  account: 0,
  scope: 0,
  index: 0
});

console.log('Private Key:', derivedKey.private_key);
console.log('Public Key:', derivedKey.public_key);
console.log('Address:', derivedKey.address);
console.log('Path:', derivedKey.path);

Shamir Secret Sharing

If you want to enable Shamir Secret Sharing to split the derived private key into multiple shares, you can specify the shares, shares_total, and shares_threshold parameters.

const secretSharedKey = await keygen({
  phrase: 'your mnemonic seed phrase here',
  organization: 0,
  account: 0,
  scope: 0,
  index: 0,
  shares: true,
  shares_total: 5,
  shares_threshold: 3
});

console.log('Private Key Shares:', secretSharedKey.private_key_shares);
console.log('Total Shares:', secretSharedKey.private_key_shares_total);
console.log('Threshold Needed to Reconstruct:', secretSharedKey.private_key_shares_threshold);

Examples

Basic Key Derivation

import keygen from '@fnet/keygen';

async function deriveKeys() {
  const keys = await keygen({
    phrase: 'correct horse battery staple',
    organization: 1,
    account: 2,
    scope: 3,
    index: 4
  });

  console.log(keys);
}

deriveKeys();

Using Shamir Secret Sharing

import keygen from '@fnet/keygen';

async function secureKeyWithShares() {
  const keys = await keygen({
    phrase: 'correct horse battery staple',
    shares: true,
    shares_total: 7,
    shares_threshold: 4
  });

  console.log('Shares:', keys.private_key_shares);
}

secureKeyWithShares();

Acknowledgement

This guide is based on the library's current functionalities and may evolve as the library is updated. The library utilizes tiny-secp256k1, bip39, bitcoinjs-lib, and @fnet/key-shamir for cryptographic operations and secret sharing.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  phrase:
    type: string
    description: The mnemonic seed phrase (BIP39) used to generate the cryptographic seed.
  organization:
    type: number
    description: The organization number to use in the key derivation path.
    default: 0
  account:
    type: number
    description: The account number to use in the key derivation path.
    default: 0
  scope:
    type: number
    description: The scope for custom key derivation (used to define the coin type
      or specific application context).
    default: 0
  index:
    type: number
    description: The index of the key to derive within the account.
    default: 0
  shares:
    type: boolean
    description: Enabled Shamir Secret Sharing for private key.
    default: false
  shares_threshold:
    type: number
    description: The threshold of Shamir Secret Sharing.
    default: 3
  shares_total:
    type: number
    description: The number of shares for Shamir Secret Sharing.
    default: 5
required:
  - phrase