From f5de70eb31e42c0b4b39f2c5d0213c969b338434 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 Mar 2016 13:55:50 +0000 Subject: [PATCH] Accept the true range of addresses for ICAP direct (slower at the same time) --- index.js | 3 ++- test/index.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7aa41a3..56e32b4 100644 --- a/index.js +++ b/index.js @@ -49,9 +49,10 @@ Object.defineProperty(Wallet.prototype, 'pubKey', { Wallet.generate = function (icapDirect) { if (icapDirect) { + var max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16) while (true) { var privKey = crypto.randomBytes(32) - if (ethUtil.privateToAddress(privKey)[0] === 0) { + if (new ethUtil.BN(ethUtil.privateToAddress(privKey)).lte(max)) { return new Wallet(privKey) } } diff --git a/test/index.js b/test/index.js index 4f38a7c..d9185c0 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,7 @@ var assert = require('assert') var Wallet = require('../') var Thirdparty = require('../thirdparty.js') +var ethUtil = require('ethereumjs-util') var fixturekey = new Buffer('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex') var fixturewallet = Wallet.fromPrivateKey(fixturekey) @@ -102,9 +103,10 @@ describe('.generate()', function () { assert.equal(Wallet.generate().getPrivateKey().length, 32) }) it('should generate an account compatible with ICAP Direct', function () { + var max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16) var wallet = Wallet.generate(true) assert.equal(wallet.getPrivateKey().length, 32) - assert.equal(wallet.getAddress()[0], 0) + assert.equal(new ethUtil.BN(wallet.getAddress()).lte(max), true) }) })