From e9fdfecfea6271b6269a15fb55e1d1ea992f576b Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sun, 23 Mar 2014 05:42:04 +1100 Subject: [PATCH 1/3] Changes default EC*Key.toString behaviour to Hex --- src/eckey.js | 4 ++-- test/hdwallet.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/eckey.js b/src/eckey.js index c5a715b..7be1688 100644 --- a/src/eckey.js +++ b/src/eckey.js @@ -96,7 +96,7 @@ ECKey.prototype.toBase64 = function() { return convert.bytesToBase64(this.toBytes()) } -ECKey.prototype.toString = ECKey.prototype.toWif +ECKey.prototype.toString = ECKey.prototype.toHex ECKey.prototype.getAddress = function(version) { return this.getPub().getAddress(version) @@ -170,7 +170,7 @@ ECPubKey.prototype.toWif = function(version) { return base58.checkEncode(this.toBytes(), version) } -ECPubKey.prototype.toString = ECPubKey.prototype.toWif +ECPubKey.prototype.toString = ECPubKey.prototype.toHex ECPubKey.prototype.getAddress = function(version) { var version = version || Network.mainnet.addressVersion; diff --git a/test/hdwallet.js b/test/hdwallet.js index 7d19473..631e46b 100644 --- a/test/hdwallet.js +++ b/test/hdwallet.js @@ -46,7 +46,7 @@ describe('HDWallet', function() { it('creates from binary seed', function() { var hd = new HDWallet(seed) - assert.equal(hd.priv, expectedPrivKey) + assert.equal(hd.priv.toWif(), expectedPrivKey) assert(hd.pub) }) @@ -54,7 +54,7 @@ describe('HDWallet', function() { it('creates from hex seed', function() { var hd = HDWallet.fromSeedHex(b2h(seed)) - assert.equal(hd.priv, expectedPrivKey) + assert.equal(hd.priv.toWif(), expectedPrivKey) assert(hd.pub) }) }) @@ -63,7 +63,7 @@ describe('HDWallet', function() { it('creates from string seed', function() { var hd = HDWallet.fromSeedString(convert.bytesToString(seed)) - assert.equal(hd.priv, expectedPrivKey) + assert.equal(hd.priv.toWif(), expectedPrivKey) assert(hd.pub) }) }) From 2e2932c4104249a1b30af275d4be87f55c078874 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sun, 23 Mar 2014 05:45:43 +1100 Subject: [PATCH 2/3] Renames variables to better reflect their values --- test/hdwallet.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/test/hdwallet.js b/test/hdwallet.js index 631e46b..560a45b 100644 --- a/test/hdwallet.js +++ b/test/hdwallet.js @@ -33,20 +33,16 @@ describe('HDWallet', function() { }) describe('constructor & seed deserialization', function() { - var expectedPrivKey, seed; - - beforeEach(function(){ - expectedPrivKey = 'KwkW62Lzm4a7Eo5nPLezrVjWBGFh2KMfpyf4Swz9NmfsVaLoeXv9' - seed = [ - 99, 114, 97, 122, 121, 32, 104, 111, 114, 115, 101, 32, 98, - 97, 116, 116, 101, 114, 121, 32, 115, 116, 97, 112, 108, 101 - ] - }) + var expectedWif = 'KwkW62Lzm4a7Eo5nPLezrVjWBGFh2KMfpyf4Swz9NmfsVaLoeXv9'; + var seed = [ + 99, 114, 97, 122, 121, 32, 104, 111, 114, 115, 101, 32, 98, + 97, 116, 116, 101, 114, 121, 32, 115, 116, 97, 112, 108, 101 + ]; it('creates from binary seed', function() { var hd = new HDWallet(seed) - assert.equal(hd.priv.toWif(), expectedPrivKey) + assert.equal(hd.priv.toWif(), expectedWif) assert(hd.pub) }) @@ -54,7 +50,7 @@ describe('HDWallet', function() { it('creates from hex seed', function() { var hd = HDWallet.fromSeedHex(b2h(seed)) - assert.equal(hd.priv.toWif(), expectedPrivKey) + assert.equal(hd.priv.toWif(), expectedWif) assert(hd.pub) }) }) @@ -63,7 +59,7 @@ describe('HDWallet', function() { it('creates from string seed', function() { var hd = HDWallet.fromSeedString(convert.bytesToString(seed)) - assert.equal(hd.priv.toWif(), expectedPrivKey) + assert.equal(hd.priv.toWif(), expectedWif) assert(hd.pub) }) }) From 48883dd069e870c9aaa6b6631590921aaee4a7b5 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 24 Mar 2014 05:09:03 +1100 Subject: [PATCH 3/3] Changes expected key output to hex --- test/hdwallet.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/hdwallet.js b/test/hdwallet.js index 560a45b..65b5db0 100644 --- a/test/hdwallet.js +++ b/test/hdwallet.js @@ -33,7 +33,7 @@ describe('HDWallet', function() { }) describe('constructor & seed deserialization', function() { - var expectedWif = 'KwkW62Lzm4a7Eo5nPLezrVjWBGFh2KMfpyf4Swz9NmfsVaLoeXv9'; + var expectedPrivateKey = '0fd71c652e847ba7ea7956e3cf3fc0a0985871846b1b2c23b9c6a29a38cee86001'; var seed = [ 99, 114, 97, 122, 121, 32, 104, 111, 114, 115, 101, 32, 98, 97, 116, 116, 101, 114, 121, 32, 115, 116, 97, 112, 108, 101 @@ -42,7 +42,7 @@ describe('HDWallet', function() { it('creates from binary seed', function() { var hd = new HDWallet(seed) - assert.equal(hd.priv.toWif(), expectedWif) + assert.equal(hd.priv.toHex(), expectedPrivateKey) assert(hd.pub) }) @@ -50,7 +50,7 @@ describe('HDWallet', function() { it('creates from hex seed', function() { var hd = HDWallet.fromSeedHex(b2h(seed)) - assert.equal(hd.priv.toWif(), expectedWif) + assert.equal(hd.priv.toHex(), expectedPrivateKey) assert(hd.pub) }) }) @@ -59,7 +59,7 @@ describe('HDWallet', function() { it('creates from string seed', function() { var hd = HDWallet.fromSeedString(convert.bytesToString(seed)) - assert.equal(hd.priv.toWif(), expectedWif) + assert.equal(hd.priv.toHex(), expectedPrivateKey) assert(hd.pub) }) })