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

seeded-keypair

v1.0.6

Published

Library for generating RSA keypair using a seed.

Downloads

1

Readme

Seeded-Keypair

Library for generating RSA keypair using a seed.

Installing

Install this package using NPM:

npm install seeded-keypair

Usage

Generating a seeded key

Generating a keypair using the seeded generator requires passing a bigint as the seed. This could be a key derived from using something like PBKDF2.

import { SeededRSA } from "seeded-keypair";

// length of key, e (default 65537)
let generator = new SeededRSA(2048);

// Seed to be used for key generation
let keypair = await generator.generateSeeded(14318751325n);

Using the keypair is described below.

Generating a cryptographic key

For completeness’s sake, the library also includes a method for generating a keypair using the browser's crypto API.

import { CryptoRSA } from "seeded-keypair";

// length of key, e (default 65537)
let generator = new CryptoRSA(2048);

// Seed to be used for key generation
let keypair = await generator.generateKeypair();

Using keypair

A keypair is an object that inherits from PublicComponent and contains the private components of the key. This can be used to decrypt messages and sign messages that the public component can encrypt and verify.

Encrypt

Encrypts the message and returns the encrypted string. Long messages are split into chunks based on the length of the key. Each chunk is encoded in base64 and separated by $ characters.

let encrypted = keypair.encrypt("Hello world!");

Decrypt

Pass an encrypted message (base64 format) generated using the encrypt method described above, and it returns the original message.

let decrypted = keypair.decrypt(encrypted);

Sign

Returns a base64 encoded string that can be used to verify the message passed in.

Note Be sure to also include a seed as part of the message. Here it's missing for demonstration purposes.

let signature = keypair.sign("Hello world!");

Verify signature

Pass a message and a signature and the method returns whether the signature matches the message.

// message, signature
let signatureValid = keypair.checkSignature("Hello world!", signature);

To string representation

Returns a string containing the private components of the keypair. This can be used to store the key in a cache. To get a string that represents the public components, first extract the PublicComponent and use toString() on that.

let string = keypair.toString();

From string representation

Create a keypair object using a string generated using the toString() method described above.

let keypair = KeyPair.fromString(string);

Extract public component

Returns a PublicComponent object that only contains the public components of the keypair. This can be sent others to encrypt messages or verify signatures.

let publicComponent = keypair.extractPublicComponent();

Public component

The public component only contains the parts of the keypair that are safe to share. These can be used by others to encrypt messages to send to you or verify messages that you created using the keypair using a signature.

Encrypt

Works the exact same way as the encrypt() method present on a keypair object.

let encrypted = publicComponent.encrypt("Hello world!");

Verify signature

Works the exact same way as the checkSignature() method present on a keypair object.

// message, signature
let signatureValid = publicComponent.checkSignature("Hello world!", signature);

To string representation

Returns a string containing the public components of the keypair. This can then be used to send the public component to a server or share it some other way.

let string = publicComponent.toString();

From string representation

Creates a PublicComponent object from a string that was created using the toString() method described above.

let publicComponent = PublicComponent.fromString(string);