Add support for identities.
This commit is contained in:
parent
f01ebd97d2
commit
5fc9721647
|
@ -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() );
|
||||
|
|
|
@ -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,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…
Reference in New Issue