Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[CHORE] Merge release/3.0.1 to main" #1614

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ subprojects {

allprojects {
group = "org.stellar.anchor-sdk"
version = "3.0.1"
version = "3.0.0"

tasks.jar {
manifest {
Expand Down
1 change: 0 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies {

implementation(libs.apache.commons.lang3)
implementation(libs.bcastle)
implementation(libs.bcutil)
implementation(libs.commons.beanutils)
implementation(libs.commons.codec)
implementation(libs.commons.io)
Expand Down
14 changes: 9 additions & 5 deletions core/src/main/java/org/stellar/anchor/auth/Sep10Jwt.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.stellar.sdk.MuxedAccount;
import org.stellar.sdk.AccountConverter;
import org.stellar.sdk.KeyPair;
import org.stellar.sdk.xdr.MuxedAccount;

@Getter
@Setter
Expand Down Expand Up @@ -109,11 +111,13 @@ void updateAccountAndMemo() {
this.accountMemo = null;

try {
MuxedAccount maybeMuxedAccount = new MuxedAccount(sub);
if (maybeMuxedAccount.getMuxedId() != null) {
MuxedAccount maybeMuxedAccount = AccountConverter.enableMuxed().encode(sub);
MuxedAccount.MuxedAccountMed25519 muxedAccount = maybeMuxedAccount.getMed25519();
if (muxedAccount != null) {
this.muxedAccount = sub;
this.account = maybeMuxedAccount.getAccountId();
this.muxedAccountId = maybeMuxedAccount.getMuxedId().longValue();
byte[] pubKeyBytes = muxedAccount.getEd25519().getUint256();
this.account = KeyPair.fromPublicKey(pubKeyBytes).getAccountId();
this.muxedAccountId = muxedAccount.getId().getUint64().getNumber().longValue();
}
} catch (Exception ignored) {
}
Expand Down
27 changes: 8 additions & 19 deletions core/src/main/java/org/stellar/anchor/horizon/Horizon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import static org.stellar.anchor.api.asset.AssetInfo.NATIVE_ASSET_CODE;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import lombok.Getter;
import org.stellar.anchor.config.AppConfig;
import org.stellar.anchor.util.AssetHelper;
import org.stellar.sdk.AssetTypeCreditAlphaNum;
import org.stellar.sdk.Server;
import org.stellar.sdk.TrustLineAsset;
import org.stellar.sdk.exception.NetworkException;
import org.stellar.sdk.requests.PaymentsRequestBuilder;
import org.stellar.sdk.responses.AccountResponse;
import org.stellar.sdk.responses.operations.OperationResponse;
import org.stellar.sdk.xdr.AssetType;

/** The horizon-server. */
public class Horizon {
Expand All @@ -32,38 +30,29 @@ public Server getServer() {
return this.horizonServer;
}

public boolean isTrustlineConfigured(String account, String asset) throws NetworkException {
public boolean isTrustlineConfigured(String account, String asset) throws IOException {
String assetCode = AssetHelper.getAssetCode(asset);
if (NATIVE_ASSET_CODE.equals(assetCode)) {
return true;
}
String assetIssuer = AssetHelper.getAssetIssuer(asset);

AccountResponse accountResponse = getServer().accounts().account(account);
return accountResponse.getBalances().stream()
return Arrays.stream(accountResponse.getBalances())
.anyMatch(
balance -> {
TrustLineAsset trustLineAsset = balance.getTrustLineAsset();
if (trustLineAsset.getAssetType() == AssetType.ASSET_TYPE_CREDIT_ALPHANUM4
|| trustLineAsset.getAssetType() == AssetType.ASSET_TYPE_CREDIT_ALPHANUM12) {
if (balance.getAssetType().equals("credit_alphanum4")
|| balance.getAssetType().equals("credit_alphanum12")) {
AssetTypeCreditAlphaNum creditAsset =
(AssetTypeCreditAlphaNum) trustLineAsset.getAsset();
assert creditAsset != null;
(AssetTypeCreditAlphaNum) balance.getAsset().get();
return creditAsset.getCode().equals(assetCode)
&& creditAsset.getIssuer().equals(assetIssuer);
}
return false;
});
}

/**
* Get payment operations for a transaction.
*
* @param stellarTxnId the transaction id
* @return the operations
* @throws NetworkException request failed, see {@link PaymentsRequestBuilder#execute()}
*/
public List<OperationResponse> getStellarTxnOperations(String stellarTxnId) {
public List<OperationResponse> getStellarTxnOperations(String stellarTxnId) throws IOException {
return getServer()
.payments()
.includeTransactions(true)
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/stellar/anchor/sep10/Sep10Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.stellar.anchor.api.exception.InvalidConfigException;
import org.stellar.anchor.api.exception.SepException;
import org.stellar.anchor.util.Sep1Helper;
import org.stellar.sdk.FormatException;
import org.stellar.sdk.KeyPair;

public class Sep10Helper {
Expand Down Expand Up @@ -38,7 +39,7 @@ public static String fetchSigningKeyFromClientDomain(String clientDomain, boolea
debugF("Validating client_domain signing key: {}", clientSigningKey);
KeyPair.fromAccountId(clientSigningKey);
return clientSigningKey;
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | FormatException e) {
infoF("SIGNING_KEY {} is not a valid Stellar account Id.", clientSigningKey);
throw new SepException(
String.format("SIGNING_KEY %s is not a valid Stellar account Id.", clientSigningKey));
Expand Down
48 changes: 24 additions & 24 deletions core/src/main/java/org/stellar/anchor/sep10/Sep10Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.jsonwebtoken.Jws;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Metrics;
import java.io.IOException;
import java.time.Instant;
import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -35,10 +36,7 @@
import org.stellar.anchor.util.Log;
import org.stellar.sdk.*;
import org.stellar.sdk.Sep10Challenge.ChallengeTransaction;
import org.stellar.sdk.exception.InvalidSep10ChallengeException;
import org.stellar.sdk.exception.NetworkException;
import org.stellar.sdk.operations.ManageDataOperation;
import org.stellar.sdk.operations.Operation;
import org.stellar.sdk.requests.ErrorResponse;
import org.stellar.sdk.responses.AccountResponse;

/** The Sep-10 protocol service. */
Expand Down Expand Up @@ -116,7 +114,7 @@ public ChallengeResponse createChallenge(
}

public ValidationResponse validateChallenge(ValidationRequest request)
throws SepValidationException {
throws IOException, InvalidSep10ChallengeException, SepValidationException {
info("Validating SEP-10 challenge.");

ChallengeTransaction challenge = parseChallenge(request);
Expand Down Expand Up @@ -178,7 +176,8 @@ public ChallengeResponse createChallengeResponse(
}
}

Transaction newChallenge(ChallengeRequest request, String clientSigningKey, Memo memo) {
Transaction newChallenge(ChallengeRequest request, String clientSigningKey, Memo memo)
throws InvalidSep10ChallengeException {

KeyPair signer = KeyPair.fromSecretSeed(secretConfig.getSep10SigningSeed());
long now = Instant.now().getEpochSecond();
Expand Down Expand Up @@ -381,15 +380,15 @@ void validateAccountFormat(ChallengeRequest request) throws SepException {
// Validate account
try {
KeyPair.fromAccountId(request.getAccount());
} catch (IllegalArgumentException ex) {
} catch (Exception ex) {
infoF("client wallet account ({}) is invalid", request.getAccount());
throw new SepValidationException("Invalid account.");
}
}

void validateChallengeRequest(
ValidationRequest request, AccountResponse account, String clientDomain)
throws SepValidationException {
throws InvalidSep10ChallengeException, IOException, SepValidationException {
// fetch the signers from the transaction
Set<Sep10Challenge.Signer> signers = fetchSigners(account);
// the signatures must be greater than the medium threshold of the account.
Expand All @@ -416,15 +415,15 @@ void validateChallengeRequest(

Set<Sep10Challenge.Signer> fetchSigners(AccountResponse account) {
// Find the signers of the client account.
return account.getSigners().stream()
return Arrays.stream(account.getSigners())
.filter(as -> as.getType().equals("ed25519_public_key"))
.map(as -> new Sep10Challenge.Signer(as.getKey(), as.getWeight()))
.collect(Collectors.toSet());
}

AccountResponse fetchAccount(
ValidationRequest request, ChallengeTransaction challenge, String clientDomain)
throws SepValidationException {
throws InvalidSep10ChallengeException, IOException, SepValidationException {
// Check the client's account
AccountResponse account;
try {
Expand All @@ -433,7 +432,7 @@ AccountResponse fetchAccount(
traceF("challenge account: {}", account);
sep10ChallengeValidatedCounter.increment();
return account;
} catch (NetworkException ex) {
} catch (ErrorResponse | IOException ex) {
infoF("Account {} does not exist in the Stellar Network");
// account not found
// The client account does not exist, using the client's master key to verify.
Expand Down Expand Up @@ -495,7 +494,8 @@ String fetchClientDomain(ChallengeTransaction challenge) {
return clientDomain;
}

ChallengeTransaction parseChallenge(ValidationRequest request) throws SepValidationException {
ChallengeTransaction parseChallenge(ValidationRequest request)
throws IOException, InvalidSep10ChallengeException, SepValidationException {

if (request == null || request.getTransaction() == null) {
throw new SepValidationException("{transaction} is required.");
Expand Down Expand Up @@ -554,17 +554,13 @@ private String authUrl() {
* @param network The network to connect to for verifying and retrieving.
* @return The extracted home domain from the Manage Data operation within the SEP-10 challenge
* transaction.
* @throws IOException If read XDR string fails, the exception will be thrown.
* @throws SepValidationException If the transaction is not a valid SEP-10 challenge transaction.
*/
String extractHomeDomainFromChallengeXdr(String challengeXdr, Network network)
throws SepValidationException {
AbstractTransaction parsed;
try {
parsed = Transaction.fromEnvelopeXdr(challengeXdr, network);
} catch (IllegalArgumentException e) {
throw new SepValidationException("Invalid challenge transaction.");
}

throws IOException, SepValidationException {
AbstractTransaction parsed =
Transaction.fromEnvelopeXdr(AccountConverter.enableMuxed(), challengeXdr, network);
if (!(parsed instanceof Transaction)) {
throw new SepValidationException("Transaction cannot be a fee bump transaction");
}
Expand Down Expand Up @@ -607,7 +603,8 @@ public synchronized Transaction newChallenge(
TimeBounds timebounds,
String clientDomain,
String clientSigningKey,
Memo memo) {
Memo memo)
throws InvalidSep10ChallengeException {
return Sep10Challenge.newChallenge(
signer,
network,
Expand All @@ -625,7 +622,8 @@ public synchronized ChallengeTransaction readChallengeTransaction(
String serverAccountId,
Network network,
String domainName,
String webAuthDomain) {
String webAuthDomain)
throws InvalidSep10ChallengeException, IOException {
return Sep10Challenge.readChallengeTransaction(
challengeXdr, serverAccountId, network, domainName, webAuthDomain);
}
Expand All @@ -636,7 +634,8 @@ public synchronized void verifyChallengeTransactionSigners(
Network network,
String domainName,
String webAuthDomain,
Set<String> signers) {
Set<String> signers)
throws InvalidSep10ChallengeException, IOException {
Sep10Challenge.verifyChallengeTransactionSigners(
challengeXdr, serverAccountId, network, domainName, webAuthDomain, signers);
}
Expand All @@ -648,7 +647,8 @@ public synchronized void verifyChallengeTransactionThreshold(
String domainName,
String webAuthDomain,
int threshold,
Set<Sep10Challenge.Signer> signers) {
Set<Sep10Challenge.Signer> signers)
throws InvalidSep10ChallengeException, IOException {
Sep10Challenge.verifyChallengeTransactionThreshold(
challengeXdr, serverAccountId, network, domainName, webAuthDomain, threshold, signers);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/stellar/anchor/sep24/Sep24Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public InteractiveTransactionResponse withdraw(
try {
debugF("checking if withdraw source account:{} is valid", sourceAccount);
KeyPair.fromAccountId(sourceAccount);
} catch (IllegalArgumentException ex) {
} catch (Exception ex) {
infoF("invalid account format: {}", sourceAccount);
throw new SepValidationException(String.format("invalid account: %s", sourceAccount), ex);
}
Expand Down Expand Up @@ -382,7 +382,7 @@ public InteractiveTransactionResponse deposit(Sep10Jwt token, Map<String, String
try {
debugF("checking if deposit destination account:{} is valid", destinationAccount);
KeyPair.fromAccountId(destinationAccount);
} catch (IllegalArgumentException ex) {
} catch (Exception ex) {
infoF("invalid account format: {}", destinationAccount);
throw new SepValidationException(
String.format("invalid account: %s", destinationAccount), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void validateTypes(String requestType, String assetCode, List<String> val
public void validateAccount(String account) throws AnchorException {
try {
KeyPair.fromAccountId(account);
} catch (IllegalArgumentException ex) {
} catch (RuntimeException ex) {
throw new SepValidationException(String.format("invalid account %s", account));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static boolean isNonNativeAsset(String assetCode, String assetIssuer) {
try {
KeyPair.fromAccountId(assetIssuer);
return true;
} catch (IllegalArgumentException ex) {
} catch (Exception ex) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,17 @@ static void validateSep38(AssetService assetService, Sep38Info sep38Info, String
}
}

// Validate country codes
// TODO: Enable validate country codes in version 3.x because 2.x does not conform to the ISO
// country code
/*
if (sep38Info.getCountryCodes() != null) {
for (String country : sep38Info.getCountryCodes()) {
if (!isCountryCodeValid(country))
throw new InvalidConfigException(
String.format("Invalid country code %s defined for asset %s.", country, assetId));
}
}

*/
if (sep38Info.getBuyDeliveryMethods() != null) {
// Validate methods
for (DeliveryMethod method : sep38Info.getBuyDeliveryMethods()) {
Expand Down
14 changes: 9 additions & 5 deletions core/src/main/java/org/stellar/anchor/util/SepHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.stellar.anchor.api.exception.BadRequestException;
import org.stellar.anchor.api.exception.InvalidStellarAccountException;
import org.stellar.anchor.api.sep.SepTransactionStatus;
import org.stellar.sdk.AccountConverter;
import org.stellar.sdk.KeyPair;
import org.stellar.sdk.MuxedAccount;
import org.stellar.sdk.xdr.MemoType;
import org.stellar.sdk.xdr.*;

public class SepHelper {
/**
Expand Down Expand Up @@ -59,11 +59,15 @@ public static String memoTypeString(MemoType memoType) {
public static String getAccountMemo(String strAccount) throws InvalidStellarAccountException {
String[] tokens = strAccount.split(":");
switch (tokens.length) {
// TODO: Should we add a catch here to throw an InvalidStellarAccountException exception in
// case of invalid address?
case 1:
AccountConverter accountConverter;
if (tokens[0].startsWith("G")) {
accountConverter = AccountConverter.disableMuxed();
} else {
accountConverter = AccountConverter.enableMuxed();
}
// Check if the account is a valid G... or M...
new MuxedAccount(tokens[0]);
accountConverter.encode(tokens[0]);
return null;
case 2:
KeyPair.fromAccountId(tokens[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ items:
# - stellar:USDC:GBN4NNCDGJO4XW4KQU3CBIESUJWFVBUZPOKUZHT7W7WRB7CWOA7BXVQF
exchangeable_assets:

# The list of the ISO 3166-1 alpha-2 country codes that the asset is available in.
# The list of the country codes that the asset is available in.
# Example:
# - US
# - CA
# - USA
# - CAN
country_codes:

# An array of objects describing the methods a client can use to sell/deliver funds to the anchor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ internal class DefaultAssetServiceTest {
"stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP"
],
"country_codes": [
"US"
"USA"
],
"sell_delivery_methods": [
{
Expand Down
Loading
Loading