forked from bitpay/bitcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WalletKey.js
43 lines (35 loc) · 1.06 KB
/
WalletKey.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
require('classtool');
function ClassSpec(b) {
var coinUtil = require('./util/util');
var timeUtil = require('./util/time');
var KeyModule = require('./Key');
var Address = require('./Address').class();
function WalletKey(cfg) {
this.network = cfg.network; // required
this.created = cfg.created;
this.privKey = cfg.privKey;
};
WalletKey.prototype.generate = function() {
this.privKey = KeyModule.Key.generateSync();
this.created = timeUtil.curtime();
};
WalletKey.prototype.storeObj = function() {
var pubKey = this.privKey.public.toString('hex');
var pubKeyHash = coinUtil.sha256ripe160(this.privKey.public);
var addr = new Address(this.network.addressPubkey, pubKeyHash);
var obj = {
created: this.created,
priv: this.privKey.private.toString('hex'),
pub: pubKey,
addr: addr.toString(),
};
return obj;
};
WalletKey.prototype.fromObj = function(obj) {
this.created = obj.created;
this.privKey = new KeyModule.Key();
this.privKey.private = new Buffer(obj.priv, 'hex');
};
return WalletKey;
};
module.defineClass(ClassSpec);