Browse Source

Full suite of working tests for Identities.

patch-2
Eric Martindale 10 years ago
parent
commit
6102374875
  1. 5
      examples/identity.js
  2. 3
      package.json
  3. 13
      test/identity.js

5
examples/identity.js

@ -9,7 +9,12 @@ 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 );
keypair.pubkey.compressed = false;
var identityComp = new Identity().fromPubkey( keypair.pubkey );
console.log( 'identity:' , identity );
console.log( 'identity string:' , identity.toString() );
console.log( 'identity string, compressed:' , identityComp.toString() );

3
package.json

@ -5,7 +5,8 @@
"author": "BitPay <dev@bitpay.com>",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "mocha",
"coverage": "istanbul cover _mocha"
},
"contributors": [
{

13
test/identity.js

@ -5,10 +5,11 @@ var Identity = require('../lib/identity');
describe('Identity', function() {
var knownPrivKey = 'L3qq9TMqq2Wfax48vTsywEtCTCTbr18PuMwkvpLUseCJPBhGhAJj';
var knownPubKey = '03663eadf291f099c7c87cf04dc037c49b4d168ff67a0f86d95fa77e525af4dee6';
var knownPubKeyHash = 'c3f89d708d24c0eaf5953d103b95dfec87ab66f6';
var knownIdent = 'TfFQdYg2BmLVWew1faUytoG3EpZZ8ebTqHr';
var knownPrivKey = 'L3e3ZneXzGw2wyyRoUxKGGrHCBhBE3uPMvQDXPaJTom4d4ogRxvC';
var knownPubKey = '02ff0c643214634691e6f1c5044df79f7002c404407c8db1897484017e1082f182';
var knownPubKeyHash = 'bceb8b52237d7a6c09e9aaedcf26cf387530d23e';
var knownIdent = 'TfEmMAA5PSQRRJgiZka8y6B5x1pABHe6BVv';
var knownIdentComp = 'TfDBCwB4ciatE4Kx3r1TK5kfCTxrrpG1H8J';
var pubkeyhash = new Buffer( knownPubKeyHash , 'hex');
@ -76,11 +77,11 @@ describe('Identity', function() {
it('should make this identity from an uncompressed pubkey', function() {
var pubkey = new PubKey();
pubkey.fromDER(new Buffer( knownPubKeyUncomp , 'hex'));
pubkey.fromDER(new Buffer( knownPubKey , 'hex'));
var identity = new Identity();
pubkey.compressed = false;
identity.fromPubkey(pubkey, 'ephemeral');
identity.toString().should.equal( knownIdent );
identity.toString().should.equal( knownIdentComp );
});
});

Loading…
Cancel
Save