From 6af1b1dab6f9ca9ed7e75eddd007f01b7c53daf9 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Mar 2014 00:40:59 -0300 Subject: [PATCH] add broken test for sha256ripe160 --- Key.js | 2 -- WalletKey.js | 2 -- examples/example.html | 12 ++++++++++++ test/test.util.js | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Key.js b/Key.js index 0f306165a..550c40f9d 100644 --- a/Key.js +++ b/Key.js @@ -50,8 +50,6 @@ if (process.versions) { }; kSpec.prototype.regenerateSync = function() { - -console.log('[Key.js.53]', this); //TODO if (!this.private) { throw new Error('Key does not have a private key set'); } diff --git a/WalletKey.js b/WalletKey.js index f651159ee..c2311a5a6 100644 --- a/WalletKey.js +++ b/WalletKey.js @@ -21,9 +21,7 @@ WalletKey.prototype.generate = function() { WalletKey.prototype.storeObj = function() { var pubKey = this.privKey.public.toString('hex'); -console.log('[WalletKey.js.23:pubKey:]',pubKey); //TODO var pubKeyHash = coinUtil.sha256ripe160(this.privKey.public); -console.log('[WalletKey.js.25:pubKeyHash:]', buffertools.toHex(pubKeyHash)); //TODO var addr = new Address(this.network.addressPubkey, pubKeyHash); var priv = new PrivateKey(this.network.keySecret, this.privKey.private, this.privKey.compressed); var obj = { diff --git a/examples/example.html b/examples/example.html index 438472f5f..01f317442 100644 --- a/examples/example.html +++ b/examples/example.html @@ -55,7 +55,19 @@ var p = new bitcore.PeerManager(); print('
'); + var coinUtil = bitcore.util; + + var pk = '03d95e184cce34c3cfa58e9a277a09a7c5ed1b2a8134ea1e52887bc66fa3f47071' + var pubKeyHash = coinUtil.sha256(pk); + print(bitcore.buffertools.toHex(pubKeyHash)); + pubKeyHash = coinUtil.sha256ripe160(pk); + print(bitcore.buffertools.toHex(pubKeyHash)); + + pubKeyHash = coinUtil.ripe160(new bitcore.Buffer('hola')); + print(bitcore.buffertools.toHex(pubKeyHash)); + + print('
'); var WalletKey = bitcore.WalletKey; var networks = bitcore.networks; diff --git a/test/test.util.js b/test/test.util.js index e3de356a8..e2245508d 100644 --- a/test/test.util.js +++ b/test/test.util.js @@ -36,6 +36,23 @@ describe('util', function() { }); }); }); + describe('#sha256', function() { + var pk = '03d95e184cce34c3cfa58e9a277a09a7c5ed1b2a8134ea1e52887bc66fa3f47071' + it('should work for ' + pk, function() { + var pubKeyHash = coinUtil.sha256(pk); + var pkh = buffertools.toHex(pubKeyHash); + pkh.should.equal('a5c756101065ac5b8f689139e6d856fa99e54b5000b6428b43729d334cc9277d'); + }); + }); + + describe('#sha256ripe160', function() { + var pk = '03d95e184cce34c3cfa58e9a277a09a7c5ed1b2a8134ea1e52887bc66fa3f47071' + it('should work for ' + pk, function() { + var pubKeyHash = coinUtil.sha256ripe160(pk); + var pkh = buffertools.toHex(pubKeyHash); + pkh.should.equal('d166a41f27fd4b158f70314e5eee8998bf3d97d5'); + }); + }); describe('#ripemd160', function() { var ripemdData = [ ['somemessage123', '12fd01a7ec6b9ba23b3a5c16fbfab3ac19624a88'],