Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@scure/bip39

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scure/bip39 - npm Package Compare versions

Comparing version
1.5.0
to
1.5.1
+28
-0
esm/index.d.ts
/**
* Audited & minimal JS implementation of
* [BIP39 mnemonic phrases](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).
* @example
import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
const mn = bip39.generateMnemonic(wordlist);
console.log(mn);
const ent = bip39.mnemonicToEntropy(mn, wordlist)
bip39.entropyToMnemonic(ent, wordlist);
bip39.validateMnemonic(mn, wordlist);
await bip39.mnemonicToSeed(mn, 'password');
bip39.mnemonicToSeedSync(mn, 'password');
// Wordlists
import { wordlist as czech } from '@scure/bip39/wordlists/czech';
import { wordlist as english } from '@scure/bip39/wordlists/english';
import { wordlist as french } from '@scure/bip39/wordlists/french';
import { wordlist as italian } from '@scure/bip39/wordlists/italian';
import { wordlist as japanese } from '@scure/bip39/wordlists/japanese';
import { wordlist as korean } from '@scure/bip39/wordlists/korean';
import { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese';
import { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese';
import { wordlist as spanish } from '@scure/bip39/wordlists/spanish';
import { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese';
* @module
*/
/**
* Generate x random words. Uses Cryptographically-Secure Random Number Generator.

@@ -3,0 +31,0 @@ * @param wordlist imported wordlist for specific language

+35
-7

@@ -0,1 +1,29 @@

/**
* Audited & minimal JS implementation of
* [BIP39 mnemonic phrases](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).
* @example
import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
const mn = bip39.generateMnemonic(wordlist);
console.log(mn);
const ent = bip39.mnemonicToEntropy(mn, wordlist)
bip39.entropyToMnemonic(ent, wordlist);
bip39.validateMnemonic(mn, wordlist);
await bip39.mnemonicToSeed(mn, 'password');
bip39.mnemonicToSeedSync(mn, 'password');
// Wordlists
import { wordlist as czech } from '@scure/bip39/wordlists/czech';
import { wordlist as english } from '@scure/bip39/wordlists/english';
import { wordlist as french } from '@scure/bip39/wordlists/french';
import { wordlist as italian } from '@scure/bip39/wordlists/italian';
import { wordlist as japanese } from '@scure/bip39/wordlists/japanese';
import { wordlist as korean } from '@scure/bip39/wordlists/korean';
import { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese';
import { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese';
import { wordlist as spanish } from '@scure/bip39/wordlists/spanish';
import { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese';
* @module
*/
/*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */

@@ -26,4 +54,4 @@ import { abytes, anumber } from '@noble/hashes/_assert';

}
function assertEntropy(entropy) {
abytes(entropy, 16, 20, 24, 28, 32);
function aentropy(ent) {
abytes(ent, 16, 20, 24, 28, 32);
}

@@ -76,3 +104,3 @@ /**

const entropy = getCoder(wordlist).decode(words);
assertEntropy(entropy);
aentropy(entropy);
return entropy;

@@ -94,3 +122,3 @@ }

export function entropyToMnemonic(entropy, wordlist) {
assertEntropy(entropy);
aentropy(entropy);
const words = getCoder(wordlist).encode(entropy);

@@ -111,3 +139,3 @@ return words.join(isJapanese(wordlist) ? '\u3000' : ' ');

}
const salt = (passphrase) => nfkd('mnemonic' + passphrase);
const psalt = (passphrase) => nfkd('mnemonic' + passphrase);
/**

@@ -124,3 +152,3 @@ * Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.

export function mnemonicToSeed(mnemonic, passphrase = '') {
return pbkdf2Async(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
return pbkdf2Async(sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
}

@@ -138,3 +166,3 @@ /**

export function mnemonicToSeedSync(mnemonic, passphrase = '') {
return pbkdf2(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
return pbkdf2(sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
}
/**
* Audited & minimal JS implementation of
* [BIP39 mnemonic phrases](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).
* @example
import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
const mn = bip39.generateMnemonic(wordlist);
console.log(mn);
const ent = bip39.mnemonicToEntropy(mn, wordlist)
bip39.entropyToMnemonic(ent, wordlist);
bip39.validateMnemonic(mn, wordlist);
await bip39.mnemonicToSeed(mn, 'password');
bip39.mnemonicToSeedSync(mn, 'password');
// Wordlists
import { wordlist as czech } from '@scure/bip39/wordlists/czech';
import { wordlist as english } from '@scure/bip39/wordlists/english';
import { wordlist as french } from '@scure/bip39/wordlists/french';
import { wordlist as italian } from '@scure/bip39/wordlists/italian';
import { wordlist as japanese } from '@scure/bip39/wordlists/japanese';
import { wordlist as korean } from '@scure/bip39/wordlists/korean';
import { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese';
import { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese';
import { wordlist as spanish } from '@scure/bip39/wordlists/spanish';
import { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese';
* @module
*/
/**
* Generate x random words. Uses Cryptographically-Secure Random Number Generator.

@@ -3,0 +31,0 @@ * @param wordlist imported wordlist for specific language

"use strict";
/**
* Audited & minimal JS implementation of
* [BIP39 mnemonic phrases](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).
* @example
import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
const mn = bip39.generateMnemonic(wordlist);
console.log(mn);
const ent = bip39.mnemonicToEntropy(mn, wordlist)
bip39.entropyToMnemonic(ent, wordlist);
bip39.validateMnemonic(mn, wordlist);
await bip39.mnemonicToSeed(mn, 'password');
bip39.mnemonicToSeedSync(mn, 'password');
// Wordlists
import { wordlist as czech } from '@scure/bip39/wordlists/czech';
import { wordlist as english } from '@scure/bip39/wordlists/english';
import { wordlist as french } from '@scure/bip39/wordlists/french';
import { wordlist as italian } from '@scure/bip39/wordlists/italian';
import { wordlist as japanese } from '@scure/bip39/wordlists/japanese';
import { wordlist as korean } from '@scure/bip39/wordlists/korean';
import { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese';
import { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese';
import { wordlist as spanish } from '@scure/bip39/wordlists/spanish';
import { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese';
* @module
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -34,4 +62,4 @@ exports.generateMnemonic = generateMnemonic;

}
function assertEntropy(entropy) {
(0, _assert_1.abytes)(entropy, 16, 20, 24, 28, 32);
function aentropy(ent) {
(0, _assert_1.abytes)(ent, 16, 20, 24, 28, 32);
}

@@ -84,3 +112,3 @@ /**

const entropy = getCoder(wordlist).decode(words);
assertEntropy(entropy);
aentropy(entropy);
return entropy;

@@ -102,3 +130,3 @@ }

function entropyToMnemonic(entropy, wordlist) {
assertEntropy(entropy);
aentropy(entropy);
const words = getCoder(wordlist).encode(entropy);

@@ -119,3 +147,3 @@ return words.join(isJapanese(wordlist) ? '\u3000' : ' ');

}
const salt = (passphrase) => nfkd('mnemonic' + passphrase);
const psalt = (passphrase) => nfkd('mnemonic' + passphrase);
/**

@@ -132,3 +160,3 @@ * Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.

function mnemonicToSeed(mnemonic, passphrase = '') {
return (0, pbkdf2_1.pbkdf2Async)(sha512_1.sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
return (0, pbkdf2_1.pbkdf2Async)(sha512_1.sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
}

@@ -146,3 +174,3 @@ /**

function mnemonicToSeedSync(mnemonic, passphrase = '') {
return (0, pbkdf2_1.pbkdf2)(sha512_1.sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
return (0, pbkdf2_1.pbkdf2)(sha512_1.sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
}
+2
-2
{
"name": "@scure/bip39",
"version": "1.5.0",
"version": "1.5.1",
"description": "Secure, audited & minimal implementation of BIP39 mnemonic phrases",

@@ -14,3 +14,3 @@ "files": [

"dependencies": {
"@noble/hashes": "~1.6.0",
"@noble/hashes": "~1.7.0",
"@scure/base": "~1.2.1"

@@ -17,0 +17,0 @@ },

@@ -0,1 +1,30 @@

/**
* Audited & minimal JS implementation of
* [BIP39 mnemonic phrases](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).
* @example
import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
const mn = bip39.generateMnemonic(wordlist);
console.log(mn);
const ent = bip39.mnemonicToEntropy(mn, wordlist)
bip39.entropyToMnemonic(ent, wordlist);
bip39.validateMnemonic(mn, wordlist);
await bip39.mnemonicToSeed(mn, 'password');
bip39.mnemonicToSeedSync(mn, 'password');
// Wordlists
import { wordlist as czech } from '@scure/bip39/wordlists/czech';
import { wordlist as english } from '@scure/bip39/wordlists/english';
import { wordlist as french } from '@scure/bip39/wordlists/french';
import { wordlist as italian } from '@scure/bip39/wordlists/italian';
import { wordlist as japanese } from '@scure/bip39/wordlists/japanese';
import { wordlist as korean } from '@scure/bip39/wordlists/korean';
import { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese';
import { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese';
import { wordlist as spanish } from '@scure/bip39/wordlists/spanish';
import { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese';
* @module
*/
/*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */

@@ -28,4 +57,4 @@ import { abytes, anumber } from '@noble/hashes/_assert';

function assertEntropy(entropy: Uint8Array) {
abytes(entropy, 16, 20, 24, 28, 32);
function aentropy(ent: Uint8Array) {
abytes(ent, 16, 20, 24, 28, 32);
}

@@ -84,3 +113,3 @@

const entropy = getCoder(wordlist).decode(words);
assertEntropy(entropy);
aentropy(entropy);
return entropy;

@@ -103,3 +132,3 @@ }

export function entropyToMnemonic(entropy: Uint8Array, wordlist: string[]): string {
assertEntropy(entropy);
aentropy(entropy);
const words = getCoder(wordlist).encode(entropy);

@@ -121,3 +150,3 @@ return words.join(isJapanese(wordlist) ? '\u3000' : ' ');

const salt = (passphrase: string) => nfkd('mnemonic' + passphrase);
const psalt = (passphrase: string) => nfkd('mnemonic' + passphrase);

@@ -134,4 +163,4 @@ /**

*/
export function mnemonicToSeed(mnemonic: string, passphrase = '') {
return pbkdf2Async(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
export function mnemonicToSeed(mnemonic: string, passphrase = ''): Promise<Uint8Array> {
return pbkdf2Async(sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
}

@@ -149,4 +178,4 @@

*/
export function mnemonicToSeedSync(mnemonic: string, passphrase = '') {
return pbkdf2(sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
export function mnemonicToSeedSync(mnemonic: string, passphrase = ''): Uint8Array {
return pbkdf2(sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
}