From cd992ba328d3395a96e15f5187384d5115859cbf Mon Sep 17 00:00:00 2001 From: QuincySx <772804430@qq.com> Date: Thu, 21 Jun 2018 11:18:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A5=E5=A4=AA=E5=9D=8A=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E9=BB=98=E8=AE=A4=E6=94=AF=E6=8C=81=E6=95=88?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/quincysx/crypto/eip55/EthCheckAddress.java | 4 +++- .../main/java/com/quincysx/crypto/ethereum/EthECKeyPair.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/quincysx/crypto/eip55/EthCheckAddress.java b/library/src/main/java/com/quincysx/crypto/eip55/EthCheckAddress.java index 4002508..b014f5e 100644 --- a/library/src/main/java/com/quincysx/crypto/eip55/EthCheckAddress.java +++ b/library/src/main/java/com/quincysx/crypto/eip55/EthCheckAddress.java @@ -20,7 +20,9 @@ public static String toChecksumAddress(String address) { StringBuilder result = new StringBuilder(lowercaseAddress.length() + 2); - result.append("0x"); + if (containsHexPrefix(address)) { + result.append("0x"); + } for (int i = 0; i < lowercaseAddress.length(); i++) { if (Integer.parseInt(String.valueOf(addressHash.charAt(i)), 16) >= 8) { diff --git a/library/src/main/java/com/quincysx/crypto/ethereum/EthECKeyPair.java b/library/src/main/java/com/quincysx/crypto/ethereum/EthECKeyPair.java index e31705b..d5cc7a3 100644 --- a/library/src/main/java/com/quincysx/crypto/ethereum/EthECKeyPair.java +++ b/library/src/main/java/com/quincysx/crypto/ethereum/EthECKeyPair.java @@ -3,6 +3,7 @@ import com.quincysx.crypto.ECKeyPair; import com.quincysx.crypto.Key; import com.quincysx.crypto.bip32.ValidationException; +import com.quincysx.crypto.eip55.EthCheckAddress; import com.quincysx.crypto.utils.HexUtils; import com.quincysx.crypto.utils.KECCAK256; @@ -70,7 +71,7 @@ public byte[] getRawAddress() { @Override public String getAddress() { - return HexUtils.toHex(getRawAddress()); + return EthCheckAddress.toChecksumAddress(HexUtils.toHex(getRawAddress())); } public ECDSASignature doSign(byte[] input) {