-
Notifications
You must be signed in to change notification settings - Fork 2
/
mnenonic.js
83 lines (63 loc) · 1.31 KB
/
mnenonic.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use strict";
/**
* 工具类
* 助记词生成
* 公私钥生成
*/
var BMnemonic = require("bitcore-mnemonic");
let hdPrikey;
/**
* 初始化/恢复 助记词、公私钥
* @param words 助记词
* @param passphrase 口令
* @returns {Mnemonic}
*/
function generateMnemonic(words , passphrase) {
var mnemonic;
passphrase = passphrase!=null? passphrase : "";
if(words == null || words == "") {
mnemonic = new BMnemonic();
while(!BMnemonic.isValid(mnemonic.toString())) {
mnemonic = new BMnemonic();
}
}else {
try {
mnemonic = new BMnemonic(words);
}catch (e) {
console.log("recovery mnemonic failed~!");
throw e;
}
}
hdPrikey = mnemonic.toHDPrivateKey(passphrase);
return mnemonic;
}
/**
* 获取主私钥
* @returns {*}
*/
function getHDprikey(){
return hdPrikey;
}
/**
* 获取公钥
* @returns {*}
*/
function getHDpubkey() {
}
/**
* 验证助记词是否合法
* @param words 助记词
* @returns {*|boolean}
*/
function isValid(words) {
return BMnemonic.isValid(words);
}
/**
* 扩展公私钥
*/
function getBIPHDprikey() {
}
exports.generateMnemonic = generateMnemonic;
exports.getHDprikey = getHDprikey;
exports.getHDpubkey = getHDpubkey;
exports.isValid = isValid;