Add support for identities.

This commit is contained in:
Eric Martindale 2014-10-02 15:08:44 -04:00
parent f01ebd97d2
commit 5fc9721647
3 changed files with 15 additions and 7 deletions

View File

@ -1,5 +1,7 @@
var Identity = require('../lib/identity');
var Keypair = require('../lib/keypair');
var identity = new Identity( 0x02 );
var keypair = new Keypair();
var identity = new Identity().fromPubkey( keypair.pubkey );
console.log( identity.toString() );

View File

@ -58,7 +58,10 @@ Identity.prototype.fromHashbuf = function(hashbuf, networkstr, typestr) {
};
Identity.prototype.fromPubkey = function(pubkey, networkstr) {
this.hashbuf = Hash.sha256ripemd160(pubkey.toBuffer());
var p = new Buffer( 0x01 );
var b = pubkey.toBuffer();
this.hashbuf = Hash.sha256ripemd160( Buffer.concat([ p , b ]) );
this.networkstr = networkstr || 'mainnet';
this.typestr = 'identephem';
return this;
@ -88,9 +91,6 @@ Identity.prototype.isValid = function() {
};
Identity.prototype.toBuffer = function() {
console.log(this.networkstr); process.exit();
version = new Buffer([constants[this.networkstr][this.typestr]]);
var buf = Buffer.concat([version, this.hashbuf]);
return buf;

View File

@ -3,16 +3,22 @@ var Pubkey = require('./pubkey');
var BN = require('./bn');
var point = require('./point');
var Keypair = function Keypair(obj) {
var Keypair = function Keypair(obj) {
if (!(this instanceof Keypair))
return new Keypair(obj);
if (!obj) {
var privkey = Privkey().fromRandom();
var obj = this.fromPrivkey( privkey );
}
if (obj)
this.set(obj);
};
Keypair.prototype.set = function(obj) {
this.privkey = obj.privkey || this.privkey || undefined;
this.pubkey = obj.pubkey || this.pubkey || undefined;
this.pubkey = obj.pubkey || this.pubkey || undefined;
return this;
};