diff --git a/src/main/java/io/bitsquare/crypto/CryptoModule.java b/src/main/java/io/bitsquare/crypto/CryptoModule.java index 22738e55e1..7d47530dde 100644 --- a/src/main/java/io/bitsquare/crypto/CryptoModule.java +++ b/src/main/java/io/bitsquare/crypto/CryptoModule.java @@ -30,5 +30,6 @@ public class CryptoModule extends BitsquareModule { @Override protected void configure() { bind(SignatureService.class).asEagerSingleton(); + bind(HashService.class).asEagerSingleton(); } } diff --git a/src/main/java/io/bitsquare/crypto/HashService.java b/src/main/java/io/bitsquare/crypto/HashService.java new file mode 100644 index 0000000000..6567bea455 --- /dev/null +++ b/src/main/java/io/bitsquare/crypto/HashService.java @@ -0,0 +1,29 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.crypto; + +import org.bitcoinj.core.Sha256Hash; +import org.bitcoinj.core.Utils; + +public class HashService { + + public Sha256Hash hash(String message) { + byte[] data = Utils.formatMessageForSigning(message); + return Sha256Hash.createDouble(data); + } +} diff --git a/src/main/java/io/bitsquare/crypto/SignatureService.java b/src/main/java/io/bitsquare/crypto/SignatureService.java index 7f45662894..68fc7d1ac5 100644 --- a/src/main/java/io/bitsquare/crypto/SignatureService.java +++ b/src/main/java/io/bitsquare/crypto/SignatureService.java @@ -30,6 +30,10 @@ public class SignatureService { public String signMessage(ECKey key, String message) { byte[] data = Utils.formatMessageForSigning(message); Sha256Hash hash = Sha256Hash.createDouble(data); + return signMessage(key, hash); + } + + public String signMessage(ECKey key, Sha256Hash hash) { ECKey.ECDSASignature sig = key.sign(hash, null); // Now we have to work backwards to figure out the recId needed to recover the signature. int recId = -1; @@ -54,4 +58,8 @@ public class SignatureService { String signedMessage = signMessage(key, message); return Utils.sha256hash160(message.concat(signedMessage).getBytes(Charsets.UTF_8)); } + + public boolean verify(ECKey key, Sha256Hash hash, ECKey.ECDSASignature signature) { + return key.verify(hash, signature); + } }