]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Ethereum addresses include checksum
authorIan Coleman <coleman.ian@gmail.com>
Wed, 15 Feb 2017 08:45:03 +0000 (19:45 +1100)
committerIan Coleman <coleman.ian@gmail.com>
Wed, 15 Feb 2017 08:45:03 +0000 (19:45 +1100)
bip39-standalone.html
src/js/index.js
tests.js

index 0d1d24434a4fe0f770f722f0cf9aedcf12039db5..de74d8001dce3fddd4df181ea8e5b334b7287b5f 100644 (file)
@@ -41770,7 +41770,9 @@ window.Entropy = new (function() {
                     var privKeyBuffer = key.privKey.d.toBuffer();
                     privkey = privKeyBuffer.toString('hex');
                     var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
-                    address = "0x" + addressBuffer.toString('hex');
+                    var hexAddress = addressBuffer.toString('hex');
+                    var checksumAddress = ethUtil.toChecksumAddress(hexAddress);
+                    address = ethUtil.addHexPrefix(checksumAddress);
                 }
                 addAddressToList(indexText, address, pubkey, privkey);
             }, 50)
index 41f826053cd76e3f9cd94023edc61803e1f533a5..4c947a4e215703704d7830956be7d6ad075b8ebd 100644 (file)
                     var privKeyBuffer = key.privKey.d.toBuffer();
                     privkey = privKeyBuffer.toString('hex');
                     var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
-                    address = "0x" + addressBuffer.toString('hex');
+                    var hexAddress = addressBuffer.toString('hex');
+                    var checksumAddress = ethUtil.toChecksumAddress(hexAddress);
+                    address = ethUtil.addHexPrefix(checksumAddress);
                 }
                 addAddressToList(indexText, address, pubkey, privkey);
             }, 50)
index 677f3e2894111a31dd3aa882a1ba70ed2d460fc7..89f4ce367462fdf27dcff025ebebcec295ddc887 100644 (file)
--- a/tests.js
+++ b/tests.js
@@ -624,12 +624,12 @@ page.open(url, function(status) {
         // check the address is generated correctly
         // this value comes from
         // https://www.myetherwallet.com/#view-wallet-info
-        // I do not understand the capitalization scheme for this hex encoding
+        // Unusual capitalization is due to checksum
         var expected = "0xe5815d5902Ad612d49283DEdEc02100Bd44C2772";
         var actual = page.evaluate(function() {
             return $(".address:first").text();
         });
-        if (actual != expected.toLowerCase()) {
+        if (actual != expected) {
             console.log("Ethereum address is incorrect");
             console.log("Expected: " + expected);
             console.log("Actual: " + actual);