forked from kadena-io/cardano-crypto.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poc.js
29 lines (23 loc) · 799 Bytes
/
poc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var { mnemonicToRootKeypair } = (lib = require("./index"));
var bip39 = require("bip39");
// console.log(lib);
var mnemonic = bip39.generateMnemonic();
var pwd = "123";
function validateMnemonic(input) {
if (!bip39.validateMnemonic(input)) {
const e = new Error("Invalid or unsupported mnemonic format:");
e.name = "InvalidArgumentException";
throw e;
}
}
function mnemonicToRootKeypairV3(mnemonic, pwd) {
validateMnemonic(mnemonic);
const seed = Buffer.from(bip39.mnemonicToSeedSync(mnemonic), "hex");
console.log(seed);
return lib._seedToKeypairV1(pwd, seed);
}
function kadenaMnemonicToRootKeypair(pwd, mnemonic) {
const pwdBuf = Buffer.from(pwd);
return mnemonicToRootKeypairV3(mnemonic, pwdBuf);
}
var rootKeyPair = kadenaMnemonicToRootKeypair(pwd, mnemonic);