Browse Source

Key -> Keypair

...that is what is called everywhere else.
patch-2
Ryan X. Charles 11 years ago
parent
commit
f3614e4a90
  1. 20
      lib/keypair.js

20
lib/keypair.js

@ -3,32 +3,32 @@ var Pubkey = require('./pubkey');
var BN = require('./bn'); var BN = require('./bn');
var point = require('./point'); var point = require('./point');
var Key = function Key(obj) { var Keypair = function Keypair(obj) {
if (!(this instanceof Key)) if (!(this instanceof Keypair))
return new Key(obj); return new Keypair(obj);
if (obj) if (obj)
this.set(obj); this.set(obj);
}; };
Key.prototype.set = function(obj) { Keypair.prototype.set = function(obj) {
this.privkey = obj.privkey || this.privkey || undefined; this.privkey = obj.privkey || this.privkey || undefined;
this.pubkey = obj.pubkey || this.pubkey || undefined; this.pubkey = obj.pubkey || this.pubkey || undefined;
return this; return this;
}; };
Key.prototype.fromPrivkey = function(privkey) { Keypair.prototype.fromPrivkey = function(privkey) {
this.privkey = privkey; this.privkey = privkey;
this.privkey2pubkey(); this.privkey2pubkey();
return this; return this;
}; };
Key.prototype.fromRandom = function() { Keypair.prototype.fromRandom = function() {
this.privkey = Privkey().fromRandom(); this.privkey = Privkey().fromRandom();
this.privkey2pubkey(); this.privkey2pubkey();
return this; return this;
}; };
Key.prototype.fromString = function(str) { Keypair.prototype.fromString = function(str) {
var obj = JSON.parse(str); var obj = JSON.parse(str);
if (obj.privkey) { if (obj.privkey) {
this.privkey = new Privkey(); this.privkey = new Privkey();
@ -40,11 +40,11 @@ Key.prototype.fromString = function(str) {
} }
}; };
Key.prototype.privkey2pubkey = function() { Keypair.prototype.privkey2pubkey = function() {
this.pubkey = Pubkey().fromPrivkey(this.privkey); this.pubkey = Pubkey().fromPrivkey(this.privkey);
}; };
Key.prototype.toString = function() { Keypair.prototype.toString = function() {
var obj = {}; var obj = {};
if (this.privkey) if (this.privkey)
obj.privkey = this.privkey.toString(); obj.privkey = this.privkey.toString();
@ -53,4 +53,4 @@ Key.prototype.toString = function() {
return JSON.stringify(obj); return JSON.stringify(obj);
}; };
module.exports = Key; module.exports = Keypair;

Loading…
Cancel
Save