Browse Source

Add support for identities.

patch-2
Eric Martindale 11 years ago
parent
commit
5fc9721647
  1. 4
      examples/identity.js
  2. 8
      lib/identity.js
  3. 6
      lib/keypair.js

4
examples/identity.js

@ -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() );

8
lib/identity.js

@ -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;

6
lib/keypair.js

@ -6,6 +6,12 @@ var point = require('./point');
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);
};

Loading…
Cancel
Save