Merge pull request #22 from jgarzik/wallet-key
Add new modules: WalletKey (a key, as found in a Wallet) and time utils
This commit is contained in:
commit
71a63c5899
|
@ -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