mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 07:28:06 +01:00
Support for advertising payment addresses on profile
This commit is contained in:
@@ -55,6 +55,7 @@ import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
||||
import org.whispersystems.textsecuregcm.storage.PaymentAddressList;
|
||||
import org.whispersystems.textsecuregcm.storage.PendingAccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.UsernamesManager;
|
||||
import org.whispersystems.textsecuregcm.util.Constants;
|
||||
@@ -514,6 +515,16 @@ public class AccountController {
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@PUT
|
||||
@Path("/payments")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public void setPayments(@Auth Account account, @Valid PaymentAddressList payments) {
|
||||
account.setPayments(payments.getPayments());
|
||||
accounts.update(account);
|
||||
}
|
||||
|
||||
private CaptchaRequirement requiresCaptcha(String number, String transport, String forwardedFor,
|
||||
String requester,
|
||||
Optional<String> captchaToken,
|
||||
@@ -608,6 +619,7 @@ public class AccountController {
|
||||
setAccountRegistrationLockFromAttributes(account, accountAttributes);
|
||||
account.setUnidentifiedAccessKey(accountAttributes.getUnidentifiedAccessKey());
|
||||
account.setUnrestrictedUnidentifiedAccess(accountAttributes.isUnrestrictedUnidentifiedAccess());
|
||||
account.setPayments(accountAttributes.getPayments());
|
||||
|
||||
if (accounts.create(account)) {
|
||||
newUserMeter.mark();
|
||||
|
||||
@@ -200,7 +200,9 @@ public class ProfileController {
|
||||
accountProfile.get().isUnrestrictedUnidentifiedAccess(),
|
||||
new UserCapabilities(accountProfile.get().isUuidAddressingSupported(), accountProfile.get().isGroupsV2Supported()),
|
||||
username.orElse(null),
|
||||
null, credential.orElse(null)));
|
||||
null,
|
||||
credential.orElse(null),
|
||||
accountProfile.get().getPayments()));
|
||||
} catch (InvalidInputException e) {
|
||||
logger.info("Bad profile request", e);
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
@@ -236,7 +238,9 @@ public class ProfileController {
|
||||
accountProfile.get().isUnrestrictedUnidentifiedAccess(),
|
||||
new UserCapabilities(accountProfile.get().isUuidAddressingSupported(), accountProfile.get().isGroupsV2Supported()),
|
||||
username,
|
||||
accountProfile.get().getUuid(), null);
|
||||
accountProfile.get().getUuid(),
|
||||
null,
|
||||
accountProfile.get().getPayments());
|
||||
}
|
||||
|
||||
private Optional<ProfileKeyCredentialResponse> getProfileCredential(Optional<String> encodedProfileCredentialRequest,
|
||||
@@ -307,7 +311,9 @@ public class ProfileController {
|
||||
accountProfile.get().isUnrestrictedUnidentifiedAccess(),
|
||||
new UserCapabilities(accountProfile.get().isUuidAddressingSupported(), accountProfile.get().isGroupsV2Supported()),
|
||||
username.orElse(null),
|
||||
null, null);
|
||||
null,
|
||||
null,
|
||||
accountProfile.get().getPayments());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.Device.DeviceCapabilities;
|
||||
import org.whispersystems.textsecuregcm.storage.PaymentAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AccountAttributes {
|
||||
|
||||
@@ -49,6 +52,9 @@ public class AccountAttributes {
|
||||
@JsonProperty
|
||||
private boolean unrestrictedUnidentifiedAccess;
|
||||
|
||||
@JsonProperty
|
||||
private List<PaymentAddress> payments;
|
||||
|
||||
@JsonProperty
|
||||
private DeviceCapabilities capabilities;
|
||||
|
||||
@@ -56,17 +62,18 @@ public class AccountAttributes {
|
||||
|
||||
@VisibleForTesting
|
||||
public AccountAttributes(String signalingKey, boolean fetchesMessages, int registrationId, String pin) {
|
||||
this(signalingKey, fetchesMessages, registrationId, null, pin, null);
|
||||
this(signalingKey, fetchesMessages, registrationId, null, pin, null, null);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public AccountAttributes(String signalingKey, boolean fetchesMessages, int registrationId, String name, String pin, String registrationLock) {
|
||||
public AccountAttributes(String signalingKey, boolean fetchesMessages, int registrationId, String name, String pin, String registrationLock, List<PaymentAddress> payments) {
|
||||
this.signalingKey = signalingKey;
|
||||
this.fetchesMessages = fetchesMessages;
|
||||
this.registrationId = registrationId;
|
||||
this.name = name;
|
||||
this.pin = pin;
|
||||
this.registrationLock = registrationLock;
|
||||
this.payments = payments;
|
||||
}
|
||||
|
||||
public String getSignalingKey() {
|
||||
@@ -104,4 +111,8 @@ public class AccountAttributes {
|
||||
public DeviceCapabilities getCapabilities() {
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
public List<PaymentAddress> getPayments() {
|
||||
return payments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import org.signal.zkgroup.profiles.ProfileKeyCredentialResponse;
|
||||
import org.whispersystems.textsecuregcm.storage.PaymentAddress;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Profile {
|
||||
@@ -35,6 +37,9 @@ public class Profile {
|
||||
@JsonProperty
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty
|
||||
private List<PaymentAddress> payments;
|
||||
|
||||
@JsonProperty
|
||||
@JsonSerialize(using = ProfileKeyCredentialResponseAdapter.Serializing.class)
|
||||
@JsonDeserialize(using = ProfileKeyCredentialResponseAdapter.Deserializing.class)
|
||||
@@ -45,7 +50,8 @@ public class Profile {
|
||||
public Profile(String name, String avatar, String identityKey,
|
||||
String unidentifiedAccess, boolean unrestrictedUnidentifiedAccess,
|
||||
UserCapabilities capabilities, String username, UUID uuid,
|
||||
ProfileKeyCredentialResponse credential)
|
||||
ProfileKeyCredentialResponse credential,
|
||||
List<PaymentAddress> payments)
|
||||
{
|
||||
this.name = name;
|
||||
this.avatar = avatar;
|
||||
@@ -55,6 +61,7 @@ public class Profile {
|
||||
this.capabilities = capabilities;
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.payments = payments;
|
||||
this.credential = credential;
|
||||
}
|
||||
|
||||
@@ -97,4 +104,9 @@ public class Profile {
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public List<PaymentAddress> getPayments() {
|
||||
return payments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.whispersystems.textsecuregcm.auth.StoredRegistrationLock;
|
||||
import javax.security.auth.Subject;
|
||||
import java.security.Principal;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@@ -52,10 +53,10 @@ public class Account implements Principal {
|
||||
private String avatar;
|
||||
|
||||
@JsonProperty
|
||||
private String avatarDigest;
|
||||
private String pin;
|
||||
|
||||
@JsonProperty
|
||||
private String pin;
|
||||
private List<PaymentAddress> payments;
|
||||
|
||||
@JsonProperty
|
||||
private String registrationLock;
|
||||
@@ -224,14 +225,6 @@ public class Account implements Principal {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getAvatarDigest() {
|
||||
return avatarDigest;
|
||||
}
|
||||
|
||||
public void setAvatarDigest(String avatarDigest) {
|
||||
this.avatarDigest = avatarDigest;
|
||||
}
|
||||
|
||||
public void setPin(String pin) {
|
||||
this.pin = pin;
|
||||
}
|
||||
@@ -261,6 +254,14 @@ public class Account implements Principal {
|
||||
this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess;
|
||||
}
|
||||
|
||||
public List<PaymentAddress> getPayments() {
|
||||
return payments;
|
||||
}
|
||||
|
||||
public void setPayments(List<PaymentAddress> payments) {
|
||||
this.payments = payments;
|
||||
}
|
||||
|
||||
public boolean isFor(AmbiguousIdentifier identifier) {
|
||||
if (identifier.hasUuid()) return identifier.getUuid().equals(uuid);
|
||||
else if (identifier.hasNumber()) return identifier.getNumber().equals(number);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import javax.annotation.RegEx;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PaymentAddress {
|
||||
|
||||
@JsonProperty
|
||||
@NotEmpty
|
||||
@Size(max = 256)
|
||||
private String address;
|
||||
|
||||
@JsonProperty
|
||||
@NotEmpty
|
||||
@Size(min = 88, max = 88)
|
||||
private String signature;
|
||||
|
||||
public PaymentAddress() {}
|
||||
|
||||
public PaymentAddress(String address, String signature) {
|
||||
this.address = address;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PaymentAddress that = (PaymentAddress) o;
|
||||
return Objects.equals(address, that.address) && Objects.equals(signature, that.signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(address, signature);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
public class PaymentAddressList {
|
||||
|
||||
@JsonProperty
|
||||
@NotNull
|
||||
@Valid
|
||||
private List<PaymentAddress> payments;
|
||||
|
||||
public PaymentAddressList() {
|
||||
|
||||
}
|
||||
|
||||
public PaymentAddressList(List<PaymentAddress> payments) {
|
||||
this.payments = payments;
|
||||
}
|
||||
|
||||
public List<PaymentAddress> getPayments() {
|
||||
return payments;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user