Jeff Garzik
12 years ago
2 changed files with 44 additions and 0 deletions
@ -0,0 +1,37 @@ |
|||
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; |
|||
}; |
|||
|
|||
return WalletKey; |
|||
}; |
|||
module.defineClass(ClassSpec); |
|||
|
@ -0,0 +1,7 @@ |
|||
|
|||
// current time, in seconds
|
|||
exports.curtime = function curtime() |
|||
{ |
|||
return Math.round(Date.now() / 1000); |
|||
} |
|||
|
Loading…
Reference in new issue