]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Pad eth private keys correctly
authorIan Coleman <ian@iancoleman.io>
Fri, 12 Feb 2021 23:33:19 +0000 (23:33 +0000)
committerIan Coleman <ian@iancoleman.io>
Fri, 12 Feb 2021 23:33:19 +0000 (23:33 +0000)
Fixes #469

src/js/index.js
tests/spec/tests.js

index 96fc4510c80c796a985fed943c92ff22671e003f..c502208d3b468737c3cc1f86d059434e5ba9de1d 100644 (file)
                     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
index 10575efb9f97da948facae8246c9d55ffe7df71d..d57b7536ddf68d22f96bf963e663194297ada03d 100644 (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();
+                    });
+            })
+    });
+});
+
 });