diff --git a/assets/src/main/java/bisq/asset/CryptoNoteUtils.java b/assets/src/main/java/bisq/asset/CryptoNoteUtils.java index 7540092465..d5150353c6 100644 --- a/assets/src/main/java/bisq/asset/CryptoNoteUtils.java +++ b/assets/src/main/java/bisq/asset/CryptoNoteUtils.java @@ -28,22 +28,38 @@ import java.util.Arrays; import java.util.Map; public class CryptoNoteUtils { - public static String convertToRawHex(String address) { + public static String getRawSpendKeyAndViewKey(String address) throws CryptoNoteUtils.CryptoNoteException { try { - byte[] decoded = MoneroBase58.decode(address); - // omit the type (1st byte) and checksum (last 4 byte) - byte[] slice = Arrays.copyOfRange(decoded, 1, decoded.length - 4); + // See https://monerodocs.org/public-address/standard-address/ + byte[] decoded = CryptoNoteUtils.MoneroBase58.decode(address); + // Standard addresses are of length 69 and addresses with integrated payment ID of length 77. + + if (decoded.length <= 65) { + throw new CryptoNoteUtils.CryptoNoteException("The address we received is too short. address=" + address); + } + + // If the length is not as expected but still can be truncated we log an error and continue. + if (decoded.length != 69 && decoded.length != 77) { + System.out.println("The address we received is not in the expected format. address=" + address); + } + + // We remove the network type byte, the checksum (4 bytes) and optionally the payment ID (8 bytes if present) + // So extract the 64 bytes after the first byte, which are the 32 byte public spend key + the 32 byte public view key + byte[] slice = Arrays.copyOfRange(decoded, 1, 65); return Utils.HEX.encode(slice); - } catch (CryptoNoteException e) { - e.printStackTrace(); + } catch (CryptoNoteUtils.CryptoNoteException e) { + throw new CryptoNoteUtils.CryptoNoteException(e); } - return null; } public static class CryptoNoteException extends Exception { CryptoNoteException(String msg) { super(msg); } + + public CryptoNoteException(CryptoNoteException exception) { + super(exception); + } } static class Keccak { diff --git a/core/src/main/java/bisq/core/trade/txproof/xmr/XmrTxProofParser.java b/core/src/main/java/bisq/core/trade/txproof/xmr/XmrTxProofParser.java index 495ef68a01..cf7b7835cf 100644 --- a/core/src/main/java/bisq/core/trade/txproof/xmr/XmrTxProofParser.java +++ b/core/src/main/java/bisq/core/trade/txproof/xmr/XmrTxProofParser.java @@ -74,7 +74,7 @@ public class XmrTxProofParser implements AssetTxProofParser