New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@code-wallet/mnemonic

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
12
-29.41%
Maintainers
2
Weekly downloads
 
Created
Source

@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);

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.

FAQs

Package last updated on 22 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts