Allow usage of signMessage for deterministic keys.

This commit is contained in:
Mike Hearn 2014-08-06 16:26:48 +02:00
parent c3cef3b917
commit e41e0c4a1d
2 changed files with 8 additions and 3 deletions

View File

@ -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);

View File

@ -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.