diff --git a/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java b/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java index a44c0992..d42d1bdf 100644 --- a/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java +++ b/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java @@ -366,18 +366,6 @@ public class ECKey implements Serializable { return new ECDSASignature(components[0], components[1]).toCanonicalised(); } - /** - * Signs a text message using the standard Bitcoin messaging signing format and returns the signature as a base64 - * encoded string. - * - * @throws IllegalStateException if this ECKey does not have the private part. - */ - public String signBitcoinMessage(String message) { - byte[] data = ByteUtil.formatForBitcoinSigning(message); - byte[] hash = HashUtil.doubleDigest(data); - return sign(hash).toBase64(); - } - /** * Takes the sha3 hash (32 bytes) of data and returns the ECDSA signature * @@ -401,23 +389,6 @@ public class ECKey implements Serializable { sig.v = (byte) (recId + 27 + (isCompressed() ? 4 : 0)); return sig; } - - /** - * Given a piece of text and a message signature encoded in base64, returns an ECKey - * containing the public key that was used to sign it. This can then be compared to the expected public key to - * determine if the signature was correct. - * - * @param message a piece of human readable text that was signed - * @param signatureBase64 The Bitcoin-format message signature in base64 - * @throws SignatureException If the public key could not be recovered or if there was a signature format error. - */ - public static ECKey signedBitcoinMessageToKey(String message, String signatureBase64) throws SignatureException { - byte[] messageBytes = ByteUtil.formatForBitcoinSigning(message); - // Note that the C++ code doesn't actually seem to specify any character encoding. Presumably it's whatever - // JSON-SPIRIT hands back. Assume UTF-8 for now. - byte[] messageHash = HashUtil.doubleDigest(messageBytes); - return signatureToKey(messageHash, signatureBase64); - } /** * Given a piece of text and a message signature encoded in base64, returns an ECKey @@ -536,16 +507,6 @@ public class ECKey implements Serializable { return true; } - /** - * Convenience wrapper around {@link ECKey#signedBitcoinMessageToKey(String, String)}. If the key derived from the - * signature is not the same as this one, throws a SignatureException. - */ - public void verifyBitcoinMessage(String message, String signatureBase64) throws SignatureException { - ECKey key = ECKey.signedBitcoinMessageToKey(message, signatureBase64); - if (!key.pub.equals(pub)) - throw new SignatureException("Signature did not match for message"); - } - /** *

Given the components of a signature and a selector value, recover and return the public key * that generated the signature according to the algorithm in SEC1v2 section 4.1.6.

diff --git a/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java b/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java index 9d5ef905..c348784f 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java @@ -3,7 +3,6 @@ package org.ethereum.util; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.math.BigInteger; -import java.nio.charset.Charset; import java.util.Arrays; import com.google.common.primitives.UnsignedInteger; @@ -11,10 +10,6 @@ import com.google.common.primitives.UnsignedLongs; public class ByteUtil { - /** The string that prefixes all text messages signed using Bitcoin keys. */ - public static final String BITCOIN_SIGNED_MESSAGE_HEADER = "Bitcoin Signed Message:\n"; - public static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES = BITCOIN_SIGNED_MESSAGE_HEADER.getBytes(); - /** * Creates a copy of bytes and appends b to the end of it */ @@ -24,20 +19,6 @@ public class ByteUtil { return result; } -// /** -// * Returns the given byte array hex encoded. -// */ -// public static String bytesToHexString(byte[] bytes) { -// StringBuffer buf = new StringBuffer(bytes.length * 2); -// for (byte b : bytes) { -// String s = Integer.toString(0xFF & b, 16); -// if (s.length() < 2) -// buf.append('0'); -// buf.append(s); -// } -// return buf.toString(); -// } - /** * The regular {@link java.math.BigInteger#toByteArray()} method isn't quite what we often need: it appends a * leading zero to indicate that the number is positive and may need padding. @@ -57,30 +38,11 @@ public class ByteUtil { System.arraycopy(biBytes, start, bytes, numBytes - length, length); return bytes; } - - /** - *

Given a textual message, returns a byte buffer formatted as follows:

- * - *

[24] "Bitcoin Signed Message:\n" [message.length as a varint] message

- */ - public static byte[] formatForBitcoinSigning(String message) { - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES.length); - bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES); - byte[] messageBytes = message.getBytes(Charset.forName("UTF-8")); - bos.write(encodeInt(messageBytes.length)); - bos.write(messageBytes); - return bos.toByteArray(); - } catch (IOException e) { - throw new RuntimeException(e); // Cannot happen. - } - } /** *

Given a textual message, returns a byte buffer formatted as follows:

*/ - public static byte[] formatForEthereumSigning(byte[] message) { + public static byte[] formatForSigning(byte[] message) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(encodeInt(message.length));