Merge pull request #6 from ethereumjs/feature/less-strict-icap

Accept the true range of addresses for ICAP direct
This commit is contained in:
Alex Beregszaszi 2018-02-03 22:41:30 +00:00 committed by GitHub
commit 02599c6018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -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)
}
}

View File

@ -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)
})
})