Pad eth private keys correctly

Fixes #469
This commit is contained in:
Ian Coleman
2021-02-12 23:33:19 +00:00
parent 9a82f12b91
commit a362ff2f62
2 changed files with 23 additions and 1 deletions

View File

@@ -1238,7 +1238,7 @@
address = libs.ethUtil.addHexPrefix(checksumAddress);
pubkey = libs.ethUtil.addHexPrefix(pubkey);
if (hasPrivkey) {
privkey = libs.ethUtil.bufferToHex(keyPair.d.toBuffer());
privkey = libs.ethUtil.bufferToHex(keyPair.d.toBuffer(32));
}
}
//TRX is different

View File

@@ -5122,4 +5122,26 @@ it('Generates ethereum addresses from a public key', function(done) {
});
});
// https://github.com/iancoleman/bip39/issues/469
fit('Generates ethereum private keys with the correct padding', function(done) {
var phrase = "flip vicious divorce angle toward say derive blue refuse load word creek once expire bounce";
let withoutPadding = "0x53121fc5d193e623d2dbf43b2a96640bbed16bd530947fff8dda12f1aec828";
let withPadding = "0x0053121fc5d193e623d2dbf43b2a96640bbed16bd530947fff8dda12f1aec828";
let skIndex = 15;
driver.findElement(By.css('.phrase'))
.sendKeys(phrase);
selectNetwork('ETH - Ethereum');
driver.sleep(generateDelay).then(function() {
driver.findElements(By.css(".privkey"))
.then(function(els) {
els[skIndex].getText()
.then(function(sk) {
expect(sk).toBe(withPadding);
expect(sk).not.toBe(withoutPadding);
done();
});
})
});
});
});