]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/util/PaymentUtils.java
Reformat files
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / util / PaymentUtils.java
index 1471d8fed0bd153a1c3c8e87105c1cd3f2d9d09e..36275d8f0168db11aae13fe2da050680b8835f06 100644 (file)
@@ -1,18 +1,18 @@
 package org.asamk.signal.manager.util;
 
-import com.google.protobuf.ByteString;
-
 import org.signal.libsignal.protocol.IdentityKey;
 import org.signal.libsignal.protocol.IdentityKeyPair;
 import org.signal.libsignal.protocol.ecc.ECPrivateKey;
 import org.signal.libsignal.protocol.ecc.ECPublicKey;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
+import org.whispersystems.signalservice.internal.push.PaymentAddress;
+
+import okio.ByteString;
 
 public class PaymentUtils {
 
-    private final static Logger logger = LoggerFactory.getLogger(PaymentUtils.class);
+    private static final Logger logger = LoggerFactory.getLogger(PaymentUtils.class);
 
     private PaymentUtils() {
     }
@@ -20,16 +20,11 @@ public class PaymentUtils {
     /**
      * Signs the supplied address bytes with the {@link IdentityKeyPair}'s private key and returns a proto that includes it, and it's signature.
      */
-    public static SignalServiceProtos.PaymentAddress signPaymentsAddress(
-            byte[] publicAddressBytes, ECPrivateKey privateKey
-    ) {
+    public static PaymentAddress signPaymentsAddress(byte[] publicAddressBytes, ECPrivateKey privateKey) {
         byte[] signature = privateKey.calculateSignature(publicAddressBytes);
 
-        return SignalServiceProtos.PaymentAddress.newBuilder()
-                .setMobileCoinAddress(SignalServiceProtos.PaymentAddress.MobileCoinAddress.newBuilder()
-                        .setAddress(ByteString.copyFrom(publicAddressBytes))
-                        .setSignature(ByteString.copyFrom(signature)))
-                .build();
+        return new PaymentAddress.Builder().mobileCoinAddress(new PaymentAddress.MobileCoinAddress.Builder().address(
+                ByteString.of(publicAddressBytes)).signature(ByteString.of(signature)).build()).build();
     }
 
     /**
@@ -37,16 +32,15 @@ public class PaymentUtils {
      * <p>
      * Returns the validated bytes if so, otherwise returns null.
      */
-    public static byte[] verifyPaymentsAddress(
-            SignalServiceProtos.PaymentAddress paymentAddress, ECPublicKey publicKey
-    ) {
-        if (!paymentAddress.hasMobileCoinAddress()) {
+    public static byte[] verifyPaymentsAddress(PaymentAddress paymentAddress, ECPublicKey publicKey) {
+        final var mobileCoinAddress = paymentAddress.mobileCoinAddress;
+        if (mobileCoinAddress == null || mobileCoinAddress.address == null || mobileCoinAddress.signature == null) {
             logger.debug("Got payment address without mobile coin address, ignoring.");
             return null;
         }
 
-        byte[] bytes = paymentAddress.getMobileCoinAddress().getAddress().toByteArray();
-        byte[] signature = paymentAddress.getMobileCoinAddress().getSignature().toByteArray();
+        byte[] bytes = mobileCoinAddress.address.toByteArray();
+        byte[] signature = mobileCoinAddress.signature.toByteArray();
 
         if (signature.length != 64 || !publicKey.verifySignature(bytes, signature)) {
             logger.debug("Got mobile coin address with invalid signature, ignoring.");