From: Ian Coleman Date: Mon, 15 Jan 2018 22:01:10 +0000 (+1100) Subject: LeftPad ethereum private keys with zeros if needed X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git;a=commitdiff_plain;h=78db37f6636f195753a59a61901f850880177c50 LeftPad ethereum private keys with zeros if needed --- diff --git a/src/js/index.js b/src/js/index.js index ec73628..5a1037b 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -799,7 +799,7 @@ } // Ethereum values are different if (networks[DOM.network.val()].name == "ETH - Ethereum") { - var privKeyBuffer = key.keyPair.d.toBuffer(); + var privKeyBuffer = key.keyPair.d.toBuffer(32); privkey = privKeyBuffer.toString('hex'); var addressBuffer = ethUtil.privateToAddress(privKeyBuffer); var hexAddress = addressBuffer.toString('hex'); diff --git a/tests/spec/tests.js b/tests/spec/tests.js index a4863b0..9a1e543 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -2850,4 +2850,29 @@ it('Can display the table as csv', function(done) { }); }); +it('LeftPads ethereum keys that are less than 32 bytes', function(done) { + // see https://github.com/iancoleman/bip39/issues/155 + selectNetwork("ETH - Ethereum"); + driver.findElement(By.css('#bip32-tab a')) + .click() + driver.findElement(By.css('#bip32-path')) + .clear(); + driver.findElement(By.css('#bip32-path')) + .sendKeys("m/44'/60'/0'"); + driver.findElement(By.css('.phrase')) + .sendKeys('scout sort custom elite radar rare vivid thing trophy gesture cover snake change narrow kite list nation sustain buffalo erode open balance system young'); + driver.sleep(generateDelay).then(function() { + driver.findElement(By.css(".address")) + .getText() + .then(function(address) { + expect(address).toBe("0x8943E785B4a5714FC87a3aFAad1eB1FeB602B118"); + done(); + }); + //getFirstAddress(function(address) { + // expect(address).toBe("0x8943E785B4a5714FC87a3aFAad1eB1FeB602B118"); + // done(); + //}); + }); +}); + });