aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Coleman <ian@iancoleman.io>2021-02-12 23:33:19 +0000
committerIan Coleman <ian@iancoleman.io>2021-02-12 23:33:19 +0000
commita362ff2f626b8dbf0302c1d55a55ccd3ee2da221 (patch)
tree9b135ae5e0e2ee1bf857ab2d91b7927d7eb6c97d
parent9a82f12b915b179c39719af2ea12dace01287575 (diff)
downloadBIP39-a362ff2f626b8dbf0302c1d55a55ccd3ee2da221.tar.gz
BIP39-a362ff2f626b8dbf0302c1d55a55ccd3ee2da221.tar.zst
BIP39-a362ff2f626b8dbf0302c1d55a55ccd3ee2da221.zip
Pad eth private keys correctly
Fixes #469
-rw-r--r--src/js/index.js2
-rw-r--r--tests/spec/tests.js22
2 files changed, 23 insertions, 1 deletions
diff --git a/src/js/index.js b/src/js/index.js
index 96fc451..c502208 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -1238,7 +1238,7 @@
1238 address = libs.ethUtil.addHexPrefix(checksumAddress); 1238 address = libs.ethUtil.addHexPrefix(checksumAddress);
1239 pubkey = libs.ethUtil.addHexPrefix(pubkey); 1239 pubkey = libs.ethUtil.addHexPrefix(pubkey);
1240 if (hasPrivkey) { 1240 if (hasPrivkey) {
1241 privkey = libs.ethUtil.bufferToHex(keyPair.d.toBuffer()); 1241 privkey = libs.ethUtil.bufferToHex(keyPair.d.toBuffer(32));
1242 } 1242 }
1243 } 1243 }
1244 //TRX is different 1244 //TRX is different
diff --git a/tests/spec/tests.js b/tests/spec/tests.js
index 10575ef..d57b753 100644
--- a/tests/spec/tests.js
+++ b/tests/spec/tests.js
@@ -5122,4 +5122,26 @@ it('Generates ethereum addresses from a public key', function(done) {
5122 }); 5122 });
5123}); 5123});
5124 5124
5125// https://github.com/iancoleman/bip39/issues/469
5126fit('Generates ethereum private keys with the correct padding', function(done) {
5127 var phrase = "flip vicious divorce angle toward say derive blue refuse load word creek once expire bounce";
5128 let withoutPadding = "0x53121fc5d193e623d2dbf43b2a96640bbed16bd530947fff8dda12f1aec828";
5129 let withPadding = "0x0053121fc5d193e623d2dbf43b2a96640bbed16bd530947fff8dda12f1aec828";
5130 let skIndex = 15;
5131 driver.findElement(By.css('.phrase'))
5132 .sendKeys(phrase);
5133 selectNetwork('ETH - Ethereum');
5134 driver.sleep(generateDelay).then(function() {
5135 driver.findElements(By.css(".privkey"))
5136 .then(function(els) {
5137 els[skIndex].getText()
5138 .then(function(sk) {
5139 expect(sk).toBe(withPadding);
5140 expect(sk).not.toBe(withoutPadding);
5141 done();
5142 });
5143 })
5144 });
5145});
5146
5125}); 5147});