diff --git a/core/src/main/java/com/google/bitcoin/core/ECKey.java b/core/src/main/java/com/google/bitcoin/core/ECKey.java index ec11280d..337853c6 100644 --- a/core/src/main/java/com/google/bitcoin/core/ECKey.java +++ b/core/src/main/java/com/google/bitcoin/core/ECKey.java @@ -560,7 +560,8 @@ public class ECKey implements EncryptableItem, Serializable { * EC maths on them. * * @param aesKey The AES key to use for decryption of the private key. If null then no decryption is required. - * @throws KeyCrypterException if this ECKey doesn't have a private part. + * @throws KeyCrypterException if there's something wrong with aesKey. + * @throws ECKey.MissingPrivateKeyException if this key cannot sign because it's pubkey only. */ public ECDSASignature sign(Sha256Hash input, @Nullable KeyParameter aesKey) throws KeyCrypterException { KeyCrypter crypter = getKeyCrypter(); @@ -721,8 +722,6 @@ public class ECKey implements EncryptableItem, Serializable { * @throws KeyCrypterException if this ECKey is encrypted and no AESKey is provided or it does not decrypt the ECKey. */ public String signMessage(String message, @Nullable KeyParameter aesKey) throws KeyCrypterException { - if (priv == null) - throw new MissingPrivateKeyException(); byte[] data = Utils.formatMessageForSigning(message); Sha256Hash hash = Sha256Hash.createDouble(data); ECDSASignature sig = sign(hash, aesKey); diff --git a/core/src/test/java/com/google/bitcoin/wallet/DeterministicKeyChainTest.java b/core/src/test/java/com/google/bitcoin/wallet/DeterministicKeyChainTest.java index 95adface..a703d4e4 100644 --- a/core/src/test/java/com/google/bitcoin/wallet/DeterministicKeyChainTest.java +++ b/core/src/test/java/com/google/bitcoin/wallet/DeterministicKeyChainTest.java @@ -71,6 +71,12 @@ public class DeterministicKeyChainTest { key3.sign(Sha256Hash.ZERO_HASH); } + @Test + public void signMessage() throws Exception { + ECKey key = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); + key.verifyMessage("test", key.signMessage("test")); + } + @Test public void events() throws Exception { // Check that we get the right events at the right time.