From 61023748758488323454f80173b7053e75460be6 Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Mon, 6 Oct 2014 18:03:20 -0400 Subject: [PATCH] Full suite of working tests for Identities. --- examples/identity.js | 5 +++++ package.json | 3 ++- test/identity.js | 13 +++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/identity.js b/examples/identity.js index 7990fd9..c17bc21 100644 --- a/examples/identity.js +++ b/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() ); diff --git a/package.json b/package.json index 463bf21..91feea9 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "author": "BitPay ", "main": "index.js", "scripts": { - "test": "mocha" + "test": "mocha", + "coverage": "istanbul cover _mocha" }, "contributors": [ { diff --git a/test/identity.js b/test/identity.js index 8246df0..4e2f75b 100644 --- a/test/identity.js +++ b/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 ); }); });