Remove unorm dependency

This commit is contained in:
junderw 2019-04-02 15:53:55 +09:00
parent b6e8f0af2a
commit 91b0efd9fb
No known key found for this signature in database
GPG Key ID: B256185D3A971908
4 changed files with 23 additions and 28 deletions

11
package-lock.json generated
View File

@ -143,12 +143,6 @@
"@types/node": "*"
}
},
"@types/unorm": {
"version": "1.3.27",
"resolved": "https://registry.npmjs.org/@types/unorm/-/unorm-1.3.27.tgz",
"integrity": "sha1-YL2zuy5cnr5tCC3zoTypkjAsyno=",
"dev": true
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
@ -1970,11 +1964,6 @@
"integrity": "sha512-jjOcCZvpkl2+z7JFn0yBOoLQyLoIkNZAs/fYJkUG6VKy6zLPHJGfQJYFHzibB6GJaF/8QrcECtlQ5cpvRHSMEA==",
"dev": true
},
"unorm": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/unorm/-/unorm-1.5.0.tgz",
"integrity": "sha512-sMfSWoiRaXXeDZSXC+YRZ23H4xchQpwxjpw1tmfR+kgbBCaOgln4NI0LXejJIhnBuKINrB3WRn+ZI8IWssirVw=="
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",

View File

@ -38,14 +38,12 @@
"@types/node": "11.11.6",
"create-hash": "^1.1.0",
"pbkdf2": "^3.0.9",
"randombytes": "^2.0.1",
"unorm": "^1.3.3"
"randombytes": "^2.0.1"
},
"devDependencies": {
"@types/create-hash": "1.2.0",
"@types/pbkdf2": "3.0.0",
"@types/randombytes": "2.0.0",
"@types/unorm": "1.3.27",
"node-fetch": "^1.6.3",
"nyc": "^13.1.0",
"prettier": "1.16.4",

View File

@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
const createHash = require("create-hash");
const pbkdf2_1 = require("pbkdf2");
const randomBytes = require("randombytes");
// use unorm until String.prototype.normalize gets better browser support
const unorm = require("unorm");
const _wordlists_1 = require("./_wordlists");
let DEFAULT_WORDLIST = _wordlists_1._default;
const INVALID_MNEMONIC = 'Invalid mnemonic';
@ -35,8 +33,8 @@ function salt(password) {
return 'mnemonic' + (password || '');
}
function mnemonicToSeed(mnemonic, password) {
const mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8');
const saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8');
const mnemonicBuffer = Buffer.from((mnemonic || '').normalize('NFKD'), 'utf8');
const saltBuffer = Buffer.from(salt((password || '').normalize('NFKD')), 'utf8');
return pbkdf2_1.pbkdf2Sync(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512');
}
exports.mnemonicToSeed = mnemonicToSeed;
@ -47,8 +45,8 @@ exports.mnemonicToSeedHex = mnemonicToSeedHex;
function mnemonicToSeedAsync(mnemonic, password) {
return new Promise((resolve, reject) => {
try {
const mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8');
const saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8');
const mnemonicBuffer = Buffer.from((mnemonic || '').normalize('NFKD'), 'utf8');
const saltBuffer = Buffer.from(salt((password || '').normalize('NFKD')), 'utf8');
pbkdf2_1.pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512', (err, data) => {
if (err)
return reject(err);
@ -72,7 +70,7 @@ function mnemonicToEntropy(mnemonic, wordlist) {
if (!wordlist) {
throw new Error(WORDLIST_REQUIRED);
}
const words = unorm.nfkd(mnemonic).split(' ');
const words = (mnemonic || '').normalize('NFKD').split(' ');
if (words.length % 3 !== 0)
throw new Error(INVALID_MNEMONIC);
// convert word indices to 11 bit binary strings

View File

@ -1,8 +1,6 @@
import * as createHash from 'create-hash';
import { pbkdf2 as pbkdf2Async, pbkdf2Sync as pbkdf2 } from 'pbkdf2';
import * as randomBytes from 'randombytes';
// use unorm until String.prototype.normalize gets better browser support
import * as unorm from 'unorm';
import { _default as _DEFAULT_WORDLIST, wordlists } from './_wordlists';
let DEFAULT_WORDLIST: string[] | undefined = _DEFAULT_WORDLIST;
@ -42,8 +40,14 @@ function salt(password?: string): string {
}
export function mnemonicToSeed(mnemonic: string, password: string): Buffer {
const mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8');
const saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8');
const mnemonicBuffer = Buffer.from(
(mnemonic || '').normalize('NFKD'),
'utf8',
);
const saltBuffer = Buffer.from(
salt((password || '').normalize('NFKD')),
'utf8',
);
return pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512');
}
@ -59,8 +63,14 @@ export function mnemonicToSeedAsync(
return new Promise(
(resolve, reject): void => {
try {
const mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8');
const saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8');
const mnemonicBuffer = Buffer.from(
(mnemonic || '').normalize('NFKD'),
'utf8',
);
const saltBuffer = Buffer.from(
salt((password || '').normalize('NFKD')),
'utf8',
);
pbkdf2Async(
mnemonicBuffer,
saltBuffer,
@ -96,7 +106,7 @@ export function mnemonicToEntropy(
throw new Error(WORDLIST_REQUIRED);
}
const words = unorm.nfkd(mnemonic).split(' ');
const words = (mnemonic || '').normalize('NFKD').split(' ');
if (words.length % 3 !== 0) throw new Error(INVALID_MNEMONIC);
// convert word indices to 11 bit binary strings