@keplr-wallet/crypto
Advanced tools
Comparing version 0.10.1 to 0.10.2-rc.0
@@ -10,2 +10,4 @@ export declare type RNG = <T extends Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | null>(array: T) => Promise<T>; | ||
static generateWalletFromMnemonic(mnemonic: string, path?: string, password?: string): Uint8Array; | ||
static generateMasterSeedFromMnemonic(mnemonic: string, password?: string): Uint8Array; | ||
static generatePrivateKeyFromMasterSeed(seed: Uint8Array, path?: string): Uint8Array; | ||
} |
@@ -17,2 +17,4 @@ "use strict"; | ||
const bip32 = require("bip32"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const bs58check = require("bs58check"); | ||
const buffer_1 = require("buffer/"); | ||
@@ -45,4 +47,18 @@ class Mnemonic { | ||
const seed = bip39.mnemonicToSeedSync(mnemonic, password); | ||
const masterSeed = bip32.fromSeed(seed); | ||
const hd = masterSeed.derivePath(path); | ||
const privateKey = hd.privateKey; | ||
if (!privateKey) { | ||
throw new Error("null hd key"); | ||
} | ||
return privateKey; | ||
} | ||
static generateMasterSeedFromMnemonic(mnemonic, password = "") { | ||
const seed = bip39.mnemonicToSeedSync(mnemonic, password); | ||
const masterKey = bip32.fromSeed(seed); | ||
const hd = masterKey.derivePath(path); | ||
return buffer_1.Buffer.from(bs58check.decode(masterKey.toBase58())); | ||
} | ||
static generatePrivateKeyFromMasterSeed(seed, path = `m/44'/118'/0'/0/0`) { | ||
const masterSeed = bip32.fromBase58(bs58check.encode(seed)); | ||
const hd = masterSeed.derivePath(path); | ||
const privateKey = hd.privateKey; | ||
@@ -49,0 +65,0 @@ if (!privateKey) { |
{ | ||
"name": "@keplr-wallet/crypto", | ||
"version": "0.10.1", | ||
"version": "0.10.2-rc.0", | ||
"main": "build/index.js", | ||
@@ -27,2 +27,3 @@ "author": "chainapsis", | ||
"bip39": "^3.0.3", | ||
"bs58check": "^2.1.2", | ||
"buffer": "^6.0.3", | ||
@@ -33,3 +34,3 @@ "crypto-js": "^4.0.0", | ||
}, | ||
"gitHead": "fe8b77605d5158bdb50ec8233dd698ad6e2e4f57" | ||
"gitHead": "feba531bd2241b6c1ffc7c8cad3c6496a84960ee" | ||
} |
@@ -5,2 +5,4 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const bip32 = require("bip32"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const bs58check = require("bs58check"); | ||
@@ -65,5 +67,29 @@ import { Buffer } from "buffer/"; | ||
const seed = bip39.mnemonicToSeedSync(mnemonic, password); | ||
const masterSeed = bip32.fromSeed(seed); | ||
const hd = masterSeed.derivePath(path); | ||
const privateKey = hd.privateKey; | ||
if (!privateKey) { | ||
throw new Error("null hd key"); | ||
} | ||
return privateKey; | ||
} | ||
static generateMasterSeedFromMnemonic( | ||
mnemonic: string, | ||
password: string = "" | ||
): Uint8Array { | ||
const seed = bip39.mnemonicToSeedSync(mnemonic, password); | ||
const masterKey = bip32.fromSeed(seed); | ||
const hd = masterKey.derivePath(path); | ||
return Buffer.from(bs58check.decode(masterKey.toBase58())); | ||
} | ||
static generatePrivateKeyFromMasterSeed( | ||
seed: Uint8Array, | ||
path: string = `m/44'/118'/0'/0/0` | ||
): Uint8Array { | ||
const masterSeed = bip32.fromBase58(bs58check.encode(seed)); | ||
const hd = masterSeed.derivePath(path); | ||
const privateKey = hd.privateKey; | ||
@@ -70,0 +96,0 @@ if (!privateKey) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41257
30
587
7
+ Addedbs58check@^2.1.2