forked from jackliu8722/eos-bip44
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (42 loc) · 1.38 KB
/
index.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
var assert = require("assert")
const ecc = require('eosjs-ecc')
var Mnemonic = require('bitcore-mnemonic');
var EOSBIP44 = function(hdKey) {
this.parts = [
`44'`, // bip 44
`194'`, // coin
`0'`, // wallet
`0` // 0 - public, 1 = private
// index
];
assert(hdKey);
this.key = hdKey;
}
EOSBIP44.fromPublicSeed = function(seed) {
return new EOSBIP44(new HDPublicKey(seed));
}
EOSBIP44.fromPrivateSeed = function(seed) {
return new EOSBIP44(new HDPrivateKey(seed));
}
EOSBIP44.fromMnemonic = function(wordslist) {
var mn = new Mnemonic(str)
var key = mn.toHDPrivateKey()
return new EOSBIP44(key);
}
EOSBIP44.prototype.derive = function(path) {
return this.key.derive(path);
}
EOSBIP44.prototype.getPublickey = function(index) {
let path = this.parts.slice(this.key.depth);
let derived = this.key.derive('m/' + (path.length > 0 ? path.join('/') + '/' : "") + index);
seed = derived.privateKey.toBuffer().toString('hex')
priv = ecc.seedPrivate(seed)
return ecc.privateToPublic(priv)
}
EOSBIP44.prototype.getPrivateKey = function(index) {
let path = this.parts.slice(this.key.depth);
let derived = this.key.derive('m/' + (path.length > 0 ? path.join('/') + '/' : "") + index);
seed = derived.privateKey.toBuffer().toString('hex')
return ecc.seedPrivate(seed)
}
module.exports = EOSBIP44