Add support for identities.
This commit is contained in:
parent
f01ebd97d2
commit
5fc9721647
|
@ -1,5 +1,7 @@
|
||||||
var Identity = require('../lib/identity');
|
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() );
|
console.log( identity.toString() );
|
||||||
|
|
|
@ -58,7 +58,10 @@ Identity.prototype.fromHashbuf = function(hashbuf, networkstr, typestr) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.fromPubkey = function(pubkey, networkstr) {
|
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.networkstr = networkstr || 'mainnet';
|
||||||
this.typestr = 'identephem';
|
this.typestr = 'identephem';
|
||||||
return this;
|
return this;
|
||||||
|
@ -88,9 +91,6 @@ Identity.prototype.isValid = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.toBuffer = function() {
|
Identity.prototype.toBuffer = function() {
|
||||||
|
|
||||||
console.log(this.networkstr); process.exit();
|
|
||||||
|
|
||||||
version = new Buffer([constants[this.networkstr][this.typestr]]);
|
version = new Buffer([constants[this.networkstr][this.typestr]]);
|
||||||
var buf = Buffer.concat([version, this.hashbuf]);
|
var buf = Buffer.concat([version, this.hashbuf]);
|
||||||
return buf;
|
return buf;
|
||||||
|
|
|
@ -3,16 +3,22 @@ var Pubkey = require('./pubkey');
|
||||||
var BN = require('./bn');
|
var BN = require('./bn');
|
||||||
var point = require('./point');
|
var point = require('./point');
|
||||||
|
|
||||||
var Keypair = function Keypair(obj) {
|
var Keypair = function Keypair(obj) {
|
||||||
if (!(this instanceof Keypair))
|
if (!(this instanceof Keypair))
|
||||||
return new Keypair(obj);
|
return new Keypair(obj);
|
||||||
|
|
||||||
|
if (!obj) {
|
||||||
|
var privkey = Privkey().fromRandom();
|
||||||
|
var obj = this.fromPrivkey( privkey );
|
||||||
|
}
|
||||||
|
|
||||||
if (obj)
|
if (obj)
|
||||||
this.set(obj);
|
this.set(obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
Keypair.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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue