Make more tests pass with Identity().

This commit is contained in:
Eric Martindale 2014-10-06 17:54:20 -04:00
parent 2216fd3f96
commit 14748ae2b5
3 changed files with 20 additions and 16 deletions

View File

@ -1,10 +1,13 @@
var Identity = require('../lib/identity');
var KeyPair = require('../lib/keypair');
var Hash = require('../lib/hash');
var keypair = new KeyPair().fromRandom();
console.log( 'keypair:' , keypair );
console.log( 'public key:' , keypair.pubkey.toString() );
console.log( 'private key:' , keypair.privkey.toString('hex') );
console.log( 'public key:' , keypair.pubkey.toString('hex') );
console.log( 'public hash:' , Hash.sha256ripemd160( keypair.pubkey.toBuffer() ).toString('hex') );
var identity = new Identity().fromPubkey( keypair.pubkey );

View File

@ -6,11 +6,13 @@ var point = require('./point');
var Keypair = function Keypair(obj) {
if (!(this instanceof Keypair))
return new Keypair(obj);
if (!obj) {
// breaks some tests
// TODO: allow keys to be created with simply `new Keypair()` (random gen.)
/*if (!obj) {
var privkey = Privkey().fromRandom();
var obj = this.fromPrivkey( privkey );
}
}*/
if (obj)
this.set(obj);

View File

@ -5,19 +5,18 @@ var Identity = require('../lib/identity');
describe('Identity', function() {
var knownPrivKey = 'L1KL3xHiuBF9YuBKTZMorW6TVDG2QW9UHWdSFEzcVFpLuGxTe9bQ';
var knownPubKey = '026006aa5fd6e800e6b529258dbb73b531da735a863c87e6673bf96def1372a59e';
var knownIdent = 'Tf8vkF9HPCDbNcLoFHk8ENAwJLQMVmWRz5P';
var knownPrivKey = 'L3qq9TMqq2Wfax48vTsywEtCTCTbr18PuMwkvpLUseCJPBhGhAJj';
var knownPubKey = '03663eadf291f099c7c87cf04dc037c49b4d168ff67a0f86d95fa77e525af4dee6';
var knownPubKeyHash = 'c3f89d708d24c0eaf5953d103b95dfec87ab66f6';
var knownIdent = 'TfFQdYg2BmLVWew1faUytoG3EpZZ8ebTqHr';
//var pubkeyhash = new Buffer('3c3fa3d4adcaf8f52d5b1843975e122548269937', 'hex');
var pubkey = '0348dc031a1499c455eeb593407e0505dfbd95a88411fa78e8cab9cbe89d064048';
var key = new PubKey();
key.fromString( pubkey );
var pubkeyhash = new Buffer( knownPubKeyHash , 'hex');
//var buf = Buffer.concat([ new Buffer([0]), new Buffer([0]), pubkeyhash ]);
// note: key is wrong string until I figure out how to duplicate the generation of short keys
var buf = Buffer.concat([ new Buffer( 0x0f ) , new Buffer( 0x02 ) , new Buffer('3c3fa3d4adcaf8f52d5b1843975e122548269937', 'hex') ])
var str = 'Tf3sWHK314o6hpeUDHpqu8RAxPypoAinbDg';
//var buf = Buffer.concat([ new Buffer( 0x0f ) , new Buffer( 0x02 ) , pubkeyhash ])
var buf = Buffer.concat([ new Buffer([0x0f]) , new Buffer([0x02]) , pubkeyhash ])
var str = knownIdent;
it('should create a new identity object', function() {
var identity = new Identity();
@ -77,7 +76,7 @@ describe('Identity', function() {
it('should make this identity from an uncompressed pubkey', function() {
var pubkey = new PubKey();
pubkey.fromDER(new Buffer( knownPubKey , 'hex'));
pubkey.fromDER(new Buffer( knownPubKeyUncomp , 'hex'));
var identity = new Identity();
pubkey.compressed = false;
identity.fromPubkey(pubkey, 'ephemeral');
@ -91,7 +90,7 @@ describe('Identity', function() {
it('should derive from this known ephemeral identity string', function() {
var identity = new Identity();
identity.fromString( str );
identity.toBuffer().slice(1).toString('hex').should.equal(pubkeyhash.toString('hex'));
identity.toBuffer().slice(2).toString('hex').should.equal(pubkeyhash.toString('hex'));
});
});
@ -125,7 +124,7 @@ describe('Identity', function() {
it('should output this known hash', function() {
var identity = new Identity();
identity.fromString(str);
identity.toBuffer().slice(1).toString('hex').should.equal(pubkeyhash.toString('hex'));
identity.toBuffer().slice(2).toString('hex').should.equal(pubkeyhash.toString('hex'));
});
});