Skip to content

Commit

Permalink
Merge pull request #8 from torusresearch/fix_decoded_r_conversion
Browse files Browse the repository at this point in the history
fix: decoded R conversion for RecoveryParam
  • Loading branch information
metalurgical authored Dec 31, 2023
2 parents 13a311b + 72458d9 commit db09c07
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,19 +309,19 @@ public Triple<BigInteger, BigInteger, Byte> sign(String message, boolean hashOnl
String sighex = ByteUtils.convertByteToHexadecimal(decoded);
BigInteger r = new BigInteger(sighex.substring(0, 64), 16);
BigInteger s = new BigInteger(sighex.substring(64), 16);
byte recoveryParam = (byte) (decoded_r[decoded_r.length - 1] % 2);
int recoveryParam = Math.floorMod(decoded_r[decoded_r.length - 1], 2);

// boolean _sLessThanHalf = true;
// if (_sLessThanHalf) {
BigInteger halfOfSecp256k1n = Secp256k1.HALF_CURVE_ORDER;
if (s.compareTo(halfOfSecp256k1n) > 0) {
s = Secp256k1.CURVE.getN().subtract(s);
recoveryParam = (byte) ((recoveryParam + 1) % 2);
recoveryParam = Math.floorMod((recoveryParam+1),2);
}
// }

consumed = true;
return new Triple<>(s, r, recoveryParam);
return new Triple<>(s, r, (byte) recoveryParam);
} catch (Exception | DKLSError e) {
throw new TSSClientError(e.getMessage());
}
Expand Down

0 comments on commit db09c07

Please sign in to comment.