Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electrum-mnemonic

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electrum-mnemonic - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

package.json
{
"name": "electrum-mnemonic",
"version": "1.0.1",
"version": "1.0.2",
"description": "Electrum Mnemonics (electrum v2 and greater)",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -5,1 +5,2 @@ /// <reference types="node" />

export declare function bitlen(num: number): number;
export declare function normalizeText(str: string): string;

@@ -44,2 +44,15 @@ "use strict";

exports.bitlen = bitlen;
function normalizeText(str) {
// 1. normalize
str = str.normalize('NFKD');
// 2. lower
str = str.toLowerCase();
// 3. remove accents NOT DONE
// TODO: find way to remove accents like python3 unicodedata.combining
// without adding a large dependency
// 4. normalize whitespaces DONE by NFKD normalize
// 5. remove whitespaces between CJK
return removeCJKSpaces(str);
}
exports.normalizeText = normalizeText;
function bufferToBin(data) {

@@ -53,1 +66,51 @@ return Array.from(data)

}
const CJKINTERVALS = [
[0x4e00, 0x9fff, 'CJK Unified Ideographs'],
[0x3400, 0x4dbf, 'CJK Unified Ideographs Extension A'],
[0x20000, 0x2a6df, 'CJK Unified Ideographs Extension B'],
[0x2a700, 0x2b73f, 'CJK Unified Ideographs Extension C'],
[0x2b740, 0x2b81f, 'CJK Unified Ideographs Extension D'],
[0xf900, 0xfaff, 'CJK Compatibility Ideographs'],
[0x2f800, 0x2fa1d, 'CJK Compatibility Ideographs Supplement'],
[0x3190, 0x319f, 'Kanbun'],
[0x2e80, 0x2eff, 'CJK Radicals Supplement'],
[0x2f00, 0x2fdf, 'CJK Radicals'],
[0x31c0, 0x31ef, 'CJK Strokes'],
[0x2ff0, 0x2fff, 'Ideographic Description Characters'],
[0xe0100, 0xe01ef, 'Variation Selectors Supplement'],
[0x3100, 0x312f, 'Bopomofo'],
[0x31a0, 0x31bf, 'Bopomofo Extended'],
[0xff00, 0xffef, 'Halfwidth and Fullwidth Forms'],
[0x3040, 0x309f, 'Hiragana'],
[0x30a0, 0x30ff, 'Katakana'],
[0x31f0, 0x31ff, 'Katakana Phonetic Extensions'],
[0x1b000, 0x1b0ff, 'Kana Supplement'],
[0xac00, 0xd7af, 'Hangul Syllables'],
[0x1100, 0x11ff, 'Hangul Jamo'],
[0xa960, 0xa97f, 'Hangul Jamo Extended A'],
[0xd7b0, 0xd7ff, 'Hangul Jamo Extended B'],
[0x3130, 0x318f, 'Hangul Compatibility Jamo'],
[0xa4d0, 0xa4ff, 'Lisu'],
[0x16f00, 0x16f9f, 'Miao'],
[0xa000, 0xa48f, 'Yi Syllables'],
[0xa490, 0xa4cf, 'Yi Radicals'],
];
function isCJK(c) {
const n = c.charCodeAt(0);
for (const [imin, imax] of CJKINTERVALS) {
if (n >= imin && n <= imax)
return true;
}
return false;
}
function removeCJKSpaces(str) {
return str
.split('')
.filter((char, i, arr) => {
const isSpace = char.trim() === '';
const prevIsCJK = i !== 0 && isCJK(arr[i - 1]);
const nextIsCJK = i !== arr.length - 1 && isCJK(arr[i + 1]);
return !(isSpace && prevIsCJK && nextIsCJK);
})
.join('');
}

@@ -35,3 +35,3 @@ "use strict";

checkPrefix(mnemonic, validPrefixes);
return pbkdf2.pbkdf2Sync(mnemonic.normalize('NFKD'), 'electrum' + passphrase.normalize('NFKD'), 2048, 64, 'sha512');
return pbkdf2.pbkdf2Sync(encoding_1.normalizeText(mnemonic), 'electrum' + encoding_1.normalizeText(passphrase), 2048, 64, 'sha512');
}

@@ -44,3 +44,3 @@ exports.mnemonicToSeedSync = mnemonicToSeedSync;

return new Promise((resolve, reject) => {
pbkdf2.pbkdf2(mnemonic.normalize('NFKD'), 'electrum' + passphrase.normalize('NFKD'), 2048, 64, 'sha512', (err, res) => {
pbkdf2.pbkdf2(encoding_1.normalizeText(mnemonic), 'electrum' + encoding_1.normalizeText(passphrase), 2048, 64, 'sha512', (err, res) => {
/* istanbul ignore next */

@@ -64,4 +64,4 @@ if (err)

const hmac = createHmac('sha512', 'Seed version');
hmac.update(phrase.normalize('NFKD'));
hmac.update(encoding_1.normalizeText(phrase));
return hmac.digest('hex').startsWith(prefix);
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc