Skip to content

Commit

Permalink
fix: PublicKey.verifyTransaction() should use the right field in th…
Browse files Browse the repository at this point in the history
…e protobufs

Signed-off-by: Daniel Akhterov <[email protected]>
  • Loading branch information
janaakhterov committed Dec 21, 2021
1 parent 54bc66a commit 1b8ccd6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ static PublicKey fromAliasBytes(ByteString aliasBytes) {
*/
public abstract boolean verify(byte[] message, byte[] signature);

abstract ByteString extractSignatureFromProtobuf(SignaturePair pair);

public boolean verifyTransaction(Transaction<?> transaction) {
if (!transaction.isFrozen()) {
transaction.freeze();
Expand All @@ -95,7 +97,7 @@ public boolean verifyTransaction(Transaction<?> transaction) {
if (sigPair.getPubKeyPrefix().equals(ByteString.copyFrom(toBytes()))) {
found = true;

if (!verify(signedTransaction.getBodyBytes().toByteArray(), sigPair.getEd25519().toByteArray())) {
if (!verify(signedTransaction.getBodyBytes().toByteArray(), extractSignatureFromProtobuf(sigPair).toByteArray())) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ static PublicKeyECDSA fromSubjectKeyInfoInternal(SubjectPublicKeyInfo subjectPub
return new PublicKeyECDSA(subjectPublicKeyInfo.getPublicKeyData().getBytes());
}

@Override
ByteString extractSignatureFromProtobuf(SignaturePair pair) {
return pair.getECDSA384();
}

@Override
public boolean verify(byte[] message, byte[] signature) {
var hash = Crypto.calcKeccak256(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ static PublicKeyED25519 fromSubjectKeyInfoInternal(SubjectPublicKeyInfo subjectP
return new PublicKeyED25519(subjectPublicKeyInfo.getPublicKeyData().getBytes());
}

@Override
ByteString extractSignatureFromProtobuf(SignaturePair pair) {
return pair.getEd25519();
}

@Override
public boolean verify(byte[] message, byte[] signature) {
return Ed25519.verify(signature, 0, keyData, 0, message, 0, message.length);
Expand Down

0 comments on commit 1b8ccd6

Please sign in to comment.