Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@scure/bip39
Advanced tools
@scure/bip39 is an npm package that provides functionality for generating and working with BIP-39 mnemonic phrases, which are used in the creation of cryptocurrency wallets. It allows for the generation of mnemonic phrases, conversion between mnemonic phrases and seed values, and validation of mnemonic phrases.
Generate Mnemonic
This feature allows you to generate a new BIP-39 mnemonic phrase using the English wordlist.
const { generateMnemonic } = require('@scure/bip39');
const { wordlist } = require('@scure/bip39/wordlists/english');
const mnemonic = generateMnemonic(wordlist);
console.log(mnemonic);
Mnemonic to Seed
This feature converts a BIP-39 mnemonic phrase to a seed value, which can be used to derive keys for cryptocurrency wallets.
const { mnemonicToSeedSync } = require('@scure/bip39');
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
const seed = mnemonicToSeedSync(mnemonic);
console.log(seed.toString('hex'));
Validate Mnemonic
This feature checks if a given BIP-39 mnemonic phrase is valid according to the specified wordlist.
const { validateMnemonic } = require('@scure/bip39');
const { wordlist } = require('@scure/bip39/wordlists/english');
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
const isValid = validateMnemonic(mnemonic, wordlist);
console.log(isValid);
The 'bip39' package is a popular alternative for working with BIP-39 mnemonic phrases. It provides similar functionality, including generating mnemonics, converting them to seeds, and validating them. It is widely used in the cryptocurrency community.
The 'bitcore-mnemonic' package is part of the Bitcore library and offers functionality for BIP-39 mnemonic phrases. It allows for the generation, validation, and conversion of mnemonics to seeds. It is well-integrated with other Bitcore components for building cryptocurrency applications.
The 'ethers' package is a comprehensive library for interacting with the Ethereum blockchain. It includes functionality for generating and managing BIP-39 mnemonic phrases, among many other features related to Ethereum development. It is a good choice if you need a broader set of tools for Ethereum.
Secure, audited & minimal implementation of BIP39 mnemonic phrases.
Compared to popular bip39
package, scure-bip39:
Check out scure-bip32 if you need hierarchical deterministic wallets ("HD Wallets").
scure — secure audited packages for every use case.
npm install @scure/bip39
Or
yarn add @scure/bip39
import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
// Generate x random words. Uses Cryptographically-Secure Random Number Generator.
const mn = bip39.generateMnemonic(wordlist);
console.log(mn);
// Reversible: Converts mnemonic string to raw entropy in form of byte array.
const ent = bip39.mnemonicToEntropy(mn, wordlist)
// Reversible: Converts raw entropy in form of byte array to mnemonic string.
bip39.entropyToMnemonic(ent, wordlist);
// Validates mnemonic for being 12-24 words contained in `wordlist`.
bip39.validateMnemonic(mn, wordlist);
// Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
await bip39.mnemonicToSeed(mn, 'password');
bip39.mnemonicToSeedSync(mn, 'password');
This submodule contains the word lists defined by BIP39 for Czech, English, French, Italian, Japanese, Korean, Simplified and Traditional Chinese, and Spanish. These are not imported by default, as that would increase bundle sizes too much. Instead, you should import and use them explicitly.
function generateMnemonic(wordlist: string[], strength?: number): string;
function mnemonicToEntropy(mnemonic: string, wordlist: string[]): Uint8Array;
function entropyToMnemonic(entropy: Uint8Array, wordlist: string[]): string;
function validateMnemonic(mnemonic: string, wordlist: string[]): boolean;
function mnemonicToSeed(mnemonic: string, passphrase?: string): Promise<Uint8Array>;
function mnemonicToSeedSync(mnemonic: string, passphrase?: string): Uint8Array;
All wordlists:
import { wordlist } from '@scure/bip39/wordlists/czech';
import { wordlist } from '@scure/bip39/wordlists/english';
import { wordlist } from '@scure/bip39/wordlists/french';
import { wordlist } from '@scure/bip39/wordlists/italian';
import { wordlist } from '@scure/bip39/wordlists/japanese';
import { wordlist } from '@scure/bip39/wordlists/korean';
import { wordlist } from '@scure/bip39/wordlists/simplified-chinese';
import { wordlist } from '@scure/bip39/wordlists/spanish';
import { wordlist } from '@scure/bip39/wordlists/traditional-chinese';
The library has been audited by Cure53 on Jan 5, 2022. Check out the audit PDF & URL. See changes since audit.
micro-bip39
@micro
namespace was taken, we've renamed the package to @scure/bip39
Copyright (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com)
FAQs
Secure, audited & minimal implementation of BIP39 mnemonic phrases
The npm package @scure/bip39 receives a total of 1,151,776 weekly downloads. As such, @scure/bip39 popularity was classified as popular.
We found that @scure/bip39 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.