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

@code-wallet/mnemonic

v1.0.6

Published

[![npm][npm-image]][npm-url] [![npm-downloads][npm-downloads-image]][npm-url]

Downloads

71

Readme

npm npm-downloads

@code-wallet/mnemonic

A TypeScript library to generate and manage cryptographic keys using mnemonics and HD (hierarchical deterministic) paths for the ED25519 curve based on the SLIP-0010 specification.

Learn more about Code at https://getcode.com. See the docs for more information.

Introduction

Cryptographic keys are essential for maintaining security in digital systems, especially in blockchain and cryptographic applications. This library offers a deterministic approach to key derivation, allowing users to generate a Keypair from a mnemonic phrase, which is a human-readable list of words, following the principles of the SLIP-0010 specification.

Features

  • Clean, simple, low-dependency library. Passes standard set of tests for SLIP-0010.

  • Mnemonic Generation: Create mnemonic phrases of either 12 or 24 words.

  • Mnemonic to Keypair: Derive cryptographic key pairs directly from mnemonic phrases.

  • Path Parsing: Convert string representations of HD paths into structured formats.

  • Child Key Derivation: Create child keys based on provided parent keys.

  • Key Offset: Manage individual indexes in the HD path, including hardened keys.

Quick Start

npm install @code-wallet/mnemonic

Examples

Generating a Mnemonic and Keypair

import { MnemonicPhrase, MnemonicType } from '@code-wallet/mnemonic';

const mnemonic = MnemonicPhrase.generate(MnemonicType.Long);
console.log("Mnemonic:", mnemonic.getPhrase());

const keypair = mnemonic.toKeypair();
console.log("Public Key:", keypair.publicKey);
console.log("Private Key:", keypair.privateKey);

Phrase to Keypair

import { MnemonicPhrase } from '@code-wallet/mnemonic';

const mnemonic = new MnemonicPhrase("install assume ketchup talk giant bone foster flight situate math hurt border deputy grab mesh hope update dream evolve caught erupt win danger thought");

const keypair = mnemonic.toKeypair(); // Uses default Solana path unless specified
console.log("Public Key:", keypair.publicKey);
console.log("Private Key:", keypair.privateKey);

Parsing a Path

import { Path } from '@code-wallet/mnemonic';

const path = new Path("m/44'/180'/0'/0'");
console.log(path.toString());

Mnemonic Generation

To generate a mnemonic:

import { MnemonicPhrase, MnemonicType } from '@code-wallet/mnemonic';

const mnemonic = MnemonicPhrase.generate(MnemonicType.Short);
console.log(mnemonic.getPhrase());

Deriving a Keypair

Once you have a mnemonic, you can derive a keypair:

const keypair = mnemonic.toKeypair();

Using a Custom HD Path

By default, the library uses a standard path for Solana (m/44'/501'/0'/0'). However, you can specify a custom path:

import { Path } from '@code-wallet/mnemonic';

const customPath = new Path("m/44'/180'/0'/0'");
const keypair = mnemonic.toKeypair(customPath);

Contribution

Feel free to contribute to the library by submitting pull requests or reporting issues.

License

This library is licensed under the MIT License.