mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Add littleEndian conversions
This commit is contained in:
parent
ed4eaafcdf
commit
7fe93d9be7
2 changed files with 10 additions and 1 deletions
|
@ -42,7 +42,11 @@ public class CryptoUtil {
|
|||
public static BigInteger l = BigInteger.valueOf(2).pow(252).add(new BigInteger("27742317777372353535851937790883648493"));
|
||||
|
||||
public static String toCanonicalTxKey(String txKey) {
|
||||
return HexEncoder.getString(new BigInteger(HexEncoder.getBytes(txKey)).mod(l).toByteArray());
|
||||
byte[] bytes = HexEncoder.getBytes(txKey);
|
||||
byte[] asLittleEndianBytes = ensure32BytesAndConvertToLittleEndian(bytes);
|
||||
byte[] nonMalleable = new BigInteger(asLittleEndianBytes).mod(l).toByteArray();
|
||||
byte[] nonMalleableAsLittleEndian = ensure32BytesAndConvertToLittleEndian(nonMalleable);
|
||||
return HexEncoder.getString(nonMalleableAsLittleEndian);
|
||||
}
|
||||
|
||||
public static byte[] scReduce32(byte[] a) {
|
||||
|
|
|
@ -20,6 +20,7 @@ package knaccc.monero.address;
|
|||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
|
||||
|
||||
|
@ -31,5 +32,9 @@ public class CryptoUtilTest {
|
|||
String txKey = "6c336e52ed537676968ee319af6983c80b869ca6a732b5962c02748b486f8f0f";
|
||||
assertEquals(txKey, CryptoUtil.toCanonicalTxKey(txKey));
|
||||
assertEquals(txKey, CryptoUtil.toCanonicalTxKey(txKey.toUpperCase()));
|
||||
|
||||
// key with 1 above l value (created with HexEncoder.getString(ensure32BytesAndConvertToLittleEndian(l.add(BigInteger.ONE).toByteArray())))
|
||||
txKey = "eed3f55c1a631258d69cf7a2def9de1400000000000000000000000000000010";
|
||||
assertFalse(txKey.equals(CryptoUtil.toCanonicalTxKey(txKey)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue