-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathaddrs.js
46 lines (43 loc) · 1.47 KB
/
addrs.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
var zcore = require('bitcore-lib-zcash');
var Mnemonic = require('bitcore-mnemonic');
var crypto = require('crypto');
'use strict';
module.exports = {
genPrivKey: function(password, network){
//console.log("In genprivkey")
var code = new Mnemonic(Mnemonic.Words.ENGLISH);
var hdPrivateKey = code.toHDPrivateKey(password, network);
// do we want to store the hdPrivateKey in localstorage?
return {
"code": code.toString(),
"privkey": hdPrivateKey.toString()
};
},
recoverPrivKey: function(code, password, network){
var hdPrivateKey = new Mnemonic(code).toHDPrivateKey(password, network);
return hdPrivateKey;
},
// for per-trade public keys. Necessary?
newPubKey: function(hdPrivateKey, tradeId){
if(typeof(hdPrivateKey) === 'string'){
hdPrivateKey = new zcore.HDPrivateKey(hdPrivateKey)
}
var derived = hdPrivateKey.derive(tradeId)
var hdPublicKey = hdPrivateKey.hdPublicKey;
var address = derived.privateKey.toAddress();
return {
"pubkey": hdPublicKey,
"address": address
};
},
encrypt: function(data,password){
var cipher = crypto.createCipher('aes256',password);
var encrypted = cipher.update(data,'utf-8','hex');
return encrypted + cipher.final('hex');
},
decrypt: function(ciphertext,password){
var decipher = crypto.createDecipher('aes256', password);
var decrypted = decipher.update(ciphertext,'hex','utf-8');
return decrypted + decipher.final('utf-8');
}
};