diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java index e31442a..7a3a755 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java @@ -719,7 +719,7 @@ public class ECKey implements EncryptableItem { */ public String signMessage(String message, ScriptType scriptType, Key aesKey) throws KeyCrypterException { byte[] data = formatMessageForSigning(message); - Sha256Hash hash = Sha256Hash.twiceOf(data); + Sha256Hash hash = Sha256Hash.of(data); ECDSASignature sig = sign(hash, aesKey); byte recId = findRecoveryId(hash, sig); int headerByte = recId + getSigningTypeConstant(scriptType); @@ -785,7 +785,7 @@ public class ECKey implements EncryptableItem { byte[] messageBytes = formatMessageForSigning(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. - Sha256Hash messageHash = Sha256Hash.twiceOf(messageBytes); + Sha256Hash messageHash = Sha256Hash.of(messageBytes); boolean compressed = false; if(header >= 39) { // this is a bech32 signature header -= 12; @@ -1156,7 +1156,7 @@ public class ECKey implements EncryptableItem { } /** The string that prefixes all text messages signed using Bitcoin keys. */ - private static final String BITCOIN_SIGNED_MESSAGE_HEADER = "Bitcoin Signed Message:\n"; + private static final String BITCOIN_SIGNED_MESSAGE_HEADER = "GroestlCoin Signed Message:\n"; private static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES = BITCOIN_SIGNED_MESSAGE_HEADER.getBytes(StandardCharsets.UTF_8); /** diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/Base58.java b/src/main/java/com/sparrowwallet/drongo/protocol/Base58.java index 017b5d6..c000de0 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/Base58.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/Base58.java @@ -17,6 +17,8 @@ package com.sparrowwallet.drongo.protocol; +import com.sparrowwallet.drongo.crypto.Groestl; + import java.math.BigInteger; import java.util.Arrays; @@ -99,7 +101,7 @@ public class Base58 { // data bytes + 4 bytes check code (a truncated hash) byte[] addressBytes = new byte[payload.length + 4]; System.arraycopy(payload, 0, addressBytes, 0, payload.length); - byte[] checksum = Sha256Hash.hashTwice(addressBytes, 0, payload.length); + byte[] checksum = Groestl.digest(addressBytes, 0, payload.length); System.arraycopy(checksum, 0, addressBytes, payload.length, 4); return Base58.encode(addressBytes); } @@ -184,7 +186,7 @@ public class Base58 { throw new ProtocolException("Input too short: " + decoded.length); byte[] data = Arrays.copyOfRange(decoded, 0, decoded.length - 4); byte[] checksum = Arrays.copyOfRange(decoded, decoded.length - 4, decoded.length); - byte[] actualChecksum = Arrays.copyOfRange(Sha256Hash.hashTwice(data), 0, 4); + byte[] actualChecksum = Arrays.copyOfRange(Groestl.digest(data), 0, 4); if (!Arrays.equals(checksum, actualChecksum)) throw new ProtocolException("Invalid checksum"); return data; diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java b/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java index 2dc71e9..7bc9826 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java @@ -129,7 +129,7 @@ public class Transaction extends ChildMessage { } catch (IOException e) { throw new RuntimeException(e); // cannot happen } - return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(stream.toByteArray())); + return Sha256Hash.wrapReversed(Sha256Hash.hash(stream.toByteArray())); } public boolean isSegwit() { @@ -522,7 +522,7 @@ public class Transaction extends ChildMessage { uint32ToByteStreamLE(0x000000ff & sigHashType, bos); // Note that this is NOT reversed to ensure it will be signed correctly. If it were to be printed out // however then we would expect that it is IS reversed. - Sha256Hash hash = Sha256Hash.twiceOf(bos.toByteArray()); + Sha256Hash hash = Sha256Hash.of(bos.toByteArray()); bos.close(); return hash; @@ -562,7 +562,7 @@ public class Transaction extends ChildMessage { bosHashPrevouts.write(this.inputs.get(i).getOutpoint().getHash().getReversedBytes()); uint32ToByteStreamLE(this.inputs.get(i).getOutpoint().getIndex(), bosHashPrevouts); } - hashPrevouts = Sha256Hash.hashTwice(bosHashPrevouts.toByteArray()); + hashPrevouts = Sha256Hash.hash(bosHashPrevouts.toByteArray()); } if(!anyoneCanPay && signAll) { @@ -570,7 +570,7 @@ public class Transaction extends ChildMessage { for(int i = 0; i < this.inputs.size(); ++i) { uint32ToByteStreamLE(this.inputs.get(i).getSequenceNumber(), bosSequence); } - hashSequence = Sha256Hash.hashTwice(bosSequence.toByteArray()); + hashSequence = Sha256Hash.hash(bosSequence.toByteArray()); } if(signAll) { @@ -580,13 +580,13 @@ public class Transaction extends ChildMessage { bosHashOutputs.write(new VarInt(this.outputs.get(i).getScriptBytes().length).encode()); bosHashOutputs.write(this.outputs.get(i).getScriptBytes()); } - hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray()); + hashOutputs = Sha256Hash.hash(bosHashOutputs.toByteArray()); } else if(basicSigHashType == SigHash.SINGLE.value && inputIndex < outputs.size()) { ByteArrayOutputStream bosHashOutputs = new UnsafeByteArrayOutputStream(256); uint64ToByteStreamLE(BigInteger.valueOf(this.outputs.get(inputIndex).getValue()), bosHashOutputs); bosHashOutputs.write(new VarInt(this.outputs.get(inputIndex).getScriptBytes().length).encode()); bosHashOutputs.write(this.outputs.get(inputIndex).getScriptBytes()); - hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray()); + hashOutputs = Sha256Hash.hash(bosHashOutputs.toByteArray()); } uint32ToByteStreamLE(version, bos); @@ -606,6 +606,6 @@ public class Transaction extends ChildMessage { throw new RuntimeException(e); // Cannot happen. } - return Sha256Hash.twiceOf(bos.toByteArray()); + return Sha256Hash.of(bos.toByteArray()); } }