1 package org
.asamk
.signal
.manager
.util
;
3 import com
.google
.protobuf
.ByteString
;
5 import org
.signal
.libsignal
.protocol
.IdentityKey
;
6 import org
.signal
.libsignal
.protocol
.IdentityKeyPair
;
7 import org
.signal
.libsignal
.protocol
.ecc
.ECPrivateKey
;
8 import org
.signal
.libsignal
.protocol
.ecc
.ECPublicKey
;
9 import org
.whispersystems
.signalservice
.internal
.push
.SignalServiceProtos
;
11 public class PaymentUtils
{
13 private PaymentUtils() {
17 * Signs the supplied address bytes with the {@link IdentityKeyPair}'s private key and returns a proto that includes it, and it's signature.
19 public static SignalServiceProtos
.PaymentAddress
signPaymentsAddress(
20 byte[] publicAddressBytes
, ECPrivateKey privateKey
22 byte[] signature
= privateKey
.calculateSignature(publicAddressBytes
);
24 return SignalServiceProtos
.PaymentAddress
.newBuilder()
25 .setMobileCoinAddress(SignalServiceProtos
.PaymentAddress
.MobileCoinAddress
.newBuilder()
26 .setAddress(ByteString
.copyFrom(publicAddressBytes
))
27 .setSignature(ByteString
.copyFrom(signature
)))
32 * Verifies that the payments address is signed with the supplied {@link IdentityKey}.
34 * Returns the validated bytes if so, otherwise returns null.
36 public static byte[] verifyPaymentsAddress(
37 SignalServiceProtos
.PaymentAddress paymentAddress
, ECPublicKey publicKey
39 if (!paymentAddress
.hasMobileCoinAddress()) {
43 byte[] bytes
= paymentAddress
.getMobileCoinAddress().getAddress().toByteArray();
44 byte[] signature
= paymentAddress
.getMobileCoinAddress().getSignature().toByteArray();
46 if (signature
.length
!= 64 || !publicKey
.verifySignature(bytes
, signature
)) {