Merge pull request #305 from CosmWasm/219-pbkdf2-uint8array
Use pbkdf2 Uint8Array support
This commit is contained in:
commit
1ae9ac2e4c
@ -51,7 +51,7 @@
|
||||
"elliptic": "^6.4.0",
|
||||
"js-sha3": "^0.8.0",
|
||||
"libsodium-wrappers": "^0.7.6",
|
||||
"pbkdf2": "^3.0.16",
|
||||
"pbkdf2": "^3.1.1",
|
||||
"ripemd160": "^2.0.2",
|
||||
"sha.js": "^2.4.11",
|
||||
"type-tagger": "^1.0.0",
|
||||
@ -61,7 +61,7 @@
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"@types/elliptic": "^6.4.12",
|
||||
"@types/libsodium-wrappers": "^0.7.7",
|
||||
"@types/pbkdf2": "^3.0.0",
|
||||
"@types/pbkdf2": "^3.1.0",
|
||||
"@types/ripemd160": "^2.0.0",
|
||||
"@types/sha.js": "^2.4.0",
|
||||
"@types/unorm": "^1.3.27"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { fromHex, toHex } from "@cosmjs/encoding";
|
||||
import { fromHex, toHex, toUtf8 } from "@cosmjs/encoding";
|
||||
import * as bip39 from "bip39";
|
||||
import { pbkdf2 } from "pbkdf2";
|
||||
import * as unorm from "unorm";
|
||||
@ -23,13 +23,13 @@ export class Bip39 {
|
||||
public static async mnemonicToSeed(mnemonic: EnglishMnemonic, password?: string): Promise<Uint8Array> {
|
||||
// reimplementation of bip39.mnemonicToSeed using the asynchronous
|
||||
// interface of https://www.npmjs.com/package/pbkdf2
|
||||
const mnemonicBytes = Buffer.from(unorm.nfkd(mnemonic.toString()), "utf8");
|
||||
const mnemonicBytes = toUtf8(unorm.nfkd(mnemonic.toString()));
|
||||
const salt = "mnemonic" + (password ? unorm.nfkd(password) : "");
|
||||
const saltBytes = Buffer.from(salt, "utf8");
|
||||
const saltBytes = toUtf8(salt);
|
||||
return this.pbkdf2(mnemonicBytes, saltBytes, 2048, 64, "sha512");
|
||||
}
|
||||
|
||||
// convert pbkdf2's calllback interface to Promise interface
|
||||
// convert pbkdf2's callback interface to Promise interface
|
||||
private static async pbkdf2(
|
||||
secret: Uint8Array,
|
||||
salt: Uint8Array,
|
||||
@ -38,8 +38,7 @@ export class Bip39 {
|
||||
digest: string,
|
||||
): Promise<Uint8Array> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
// TODO: Patch @types/pbkdf2 to allow Uint8Array as secret and salt argument
|
||||
pbkdf2(Buffer.from(secret), Buffer.from(salt), iterations, keylen, digest, (err, derivedKey) => {
|
||||
pbkdf2(secret, salt, iterations, keylen, digest, (err, derivedKey) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
|
||||
16
yarn.lock
16
yarn.lock
@ -1327,10 +1327,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/pako/-/pako-1.0.1.tgz#33b237f3c9aff44d0f82fe63acffa4a365ef4a61"
|
||||
integrity sha512-GdZbRSJ3Cv5fiwT6I0SQ3ckeN2PWNqxd26W9Z2fCK1tGrrasGy4puvNFtnddqH9UJFMQYXxEuuB7B8UK+LLwSg==
|
||||
|
||||
"@types/pbkdf2@^3.0.0":
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/pbkdf2/-/pbkdf2-3.0.0.tgz#5d9ca5f12a78a08cc89ad72883ad4a30af359229"
|
||||
integrity sha512-6J6MHaAlBJC/eVMy9jOwj9oHaprfutukfW/Dyt0NEnpQ/6HN6YQrpvLwzWdWDeWZIdenjGHlbYDzyEODO5Z+2Q==
|
||||
"@types/pbkdf2@^3.1.0":
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/pbkdf2/-/pbkdf2-3.1.0.tgz#039a0e9b67da0cdc4ee5dab865caa6b267bb66b1"
|
||||
integrity sha512-Cf63Rv7jCQ0LaL8tNXmEyqTHuIJxRdlS5vMh1mj5voN4+QFhVZnlZruezqpWYDiJ8UTzhP0VmeLXCmBk66YrMQ==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
@ -6560,10 +6560,10 @@ path-type@^3.0.0:
|
||||
dependencies:
|
||||
pify "^3.0.0"
|
||||
|
||||
pbkdf2@^3.0.16, pbkdf2@^3.0.3, pbkdf2@^3.0.9:
|
||||
version "3.0.17"
|
||||
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.17.tgz#976c206530617b14ebb32114239f7b09336e93a6"
|
||||
integrity sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==
|
||||
pbkdf2@^3.0.3, pbkdf2@^3.0.9, pbkdf2@^3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.1.1.tgz#cb8724b0fada984596856d1a6ebafd3584654b94"
|
||||
integrity sha512-4Ejy1OPxi9f2tt1rRV7Go7zmfDQ+ZectEQz3VGUQhgq62HtIRPDyG/JtnwIxs6x3uNMwo2V7q1fMvKjb+Tnpqg==
|
||||
dependencies:
|
||||
create-hash "^1.1.2"
|
||||
create-hmac "^1.1.4"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user