Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- feat: sort `ScMap` entries by key in `Scv.toMap` following Soroban runtime ordering rules, as the network requires ScMap keys to be in ascending order. `Scv.toMap` now accepts `Map<SCVal, SCVal>`; the previous `toMap(LinkedHashMap<SCVal, SCVal>)` overload is deprecated.
- feat: add `closeTime`, `headerXdr`, and `metadataXdr` to `GetLatestLedgerResponse`.
- chore: bump [stellar-xdr](https://github.com/stellar/stellar-xdr) to v25.0.
- refactor!: remove deprecated `StrKey` helpers `encodeEd25519PublicKey(AccountID)`, `encodeMuxedAccount(MuxedAccount)`, `decodeMuxedAccount(String)`, `encodeToXDRAccountId(String)`, and `encodeToXDRMuxedAccount(String)`; use `StrKey.encodeEd25519PublicKey(byte[])`, `org.stellar.sdk.MuxedAccount`, and `KeyPair#getXdrAccountId()` instead.

## 2.2.3

Expand Down
141 changes: 0 additions & 141 deletions src/main/java/org/stellar/sdk/StrKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
import lombok.NonNull;
import lombok.Value;
import org.stellar.sdk.exception.UnexpectedException;
import org.stellar.sdk.xdr.AccountID;
import org.stellar.sdk.xdr.CryptoKeyType;
import org.stellar.sdk.xdr.MuxedAccount;
import org.stellar.sdk.xdr.PublicKey;
import org.stellar.sdk.xdr.PublicKeyType;
import org.stellar.sdk.xdr.Uint256;
import org.stellar.sdk.xdr.Uint64;
import org.stellar.sdk.xdr.XdrUnsignedHyperInteger;
Expand Down Expand Up @@ -351,127 +346,6 @@ public static boolean isValidMed25519PublicKey(String med25519PublicKey) {
}
}

/**
* Encodes raw data to strkey Stellar account ID (G...)
*
* <p>This method is deprecated and will be removed in future versions, use {@link
* #encodeEd25519PublicKey(byte[])} instead.
*
* @param accountID data to encode
* @return "G..." representation of the key
*/
@Deprecated
public static String encodeEd25519PublicKey(AccountID accountID) {
char[] encoded =
encodeCheck(VersionByte.ACCOUNT_ID, accountID.getAccountID().getEd25519().getUint256());
return String.valueOf(encoded);
}

/**
* Encodes raw data to strkey Stellar muxed account ID (M... or G...)
*
* <p>This method is deprecated and will be removed in future versions, use {@link
* org.stellar.sdk.MuxedAccount} instead.
*
* @param muxedAccount the muxed account to encode
* @return "M..." or "G..." representation of the key
*/
@Deprecated
public static String encodeMuxedAccount(MuxedAccount muxedAccount) {
switch (muxedAccount.getDiscriminant()) {
case KEY_TYPE_MUXED_ED25519:
return String.valueOf(
encodeCheck(
VersionByte.MED25519_PUBLIC_KEY, getMuxedEd25519AccountBytes(muxedAccount)));
case KEY_TYPE_ED25519:
return String.valueOf(
encodeCheck(VersionByte.ACCOUNT_ID, muxedAccount.getEd25519().getUint256()));
default:
throw new IllegalArgumentException("invalid discriminant");
}
}

/**
* Decodes strkey Stellar account ID (G...) or muxed account ID (M...) to {@link MuxedAccount}.
*
* <p>This method is deprecated and will be removed in future versions, use {@link
* org.stellar.sdk.MuxedAccount} instead.
*
* @param address the address to decode
* @return {@link MuxedAccount} representation of the key
*/
@Deprecated
public static MuxedAccount decodeMuxedAccount(String address) {
return encodeToXDRMuxedAccount(address);
}

/**
* Encodes strkey Stellar account ID (G...) to {@link AccountID}.
*
* <p>This method is deprecated and will be removed in future versions, use {@link
* KeyPair#getXdrAccountId()} instead.
*
* @param data the data to encode
* @return {@link AccountID} representation of the key
*/
@Deprecated
public static AccountID encodeToXDRAccountId(String data) {
AccountID accountID = new AccountID();
PublicKey publicKey = new PublicKey();
publicKey.setDiscriminant(PublicKeyType.PUBLIC_KEY_TYPE_ED25519);
try {
publicKey.setEd25519(Uint256.fromXdrByteArray(decodeEd25519PublicKey(data)));
} catch (IOException e) {
throw new IllegalArgumentException("invalid address: " + data, e);
}
accountID.setAccountID(publicKey);
return accountID;
}

/**
* Encodes strkey Stellar account ID (G...) or muxed account ID (M...) to {@link MuxedAccount}.
*
* <p>This method is deprecated and will be removed in future versions, use {@link
* org.stellar.sdk.MuxedAccount} instead.
*
* @param data the data to encode
* @return {@link MuxedAccount} representation of the key
*/
@Deprecated
public static MuxedAccount encodeToXDRMuxedAccount(String data) {
MuxedAccount muxed = new MuxedAccount();

if (data.isEmpty()) {
throw new IllegalArgumentException("address is empty");
}
switch (decodeVersionByte(data)) {
case ACCOUNT_ID:
muxed.setDiscriminant(CryptoKeyType.KEY_TYPE_ED25519);
byte[] rawEd25519PublicKey = decodeEd25519PublicKey(data);
try {
muxed.setEd25519(Uint256.fromXdrByteArray(rawEd25519PublicKey));
} catch (IOException e) {
throw new IllegalArgumentException("invalid address: " + data, e);
}
break;
case MED25519_PUBLIC_KEY:
byte[] input = decodeCheck(VersionByte.MED25519_PUBLIC_KEY, data.toCharArray());
muxed.setDiscriminant(CryptoKeyType.KEY_TYPE_MUXED_ED25519);
MuxedAccount.MuxedAccountMed25519 med = new MuxedAccount.MuxedAccountMed25519();
try {
med.setEd25519(Uint256.fromXdrByteArray(Arrays.copyOfRange(input, 0, 32)));
med.setId(Uint64.fromXdrByteArray(Arrays.copyOfRange(input, 32, 40)));
} catch (IOException e) {
throw new IllegalArgumentException("invalid address: " + data, e);
}
muxed.setMed25519(med);
break;
default:
throw new IllegalArgumentException("Version byte is invalid");
}
return muxed;
}

static VersionByte decodeVersionByte(String data) {
byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
byte[] decoded = base32decode(dataBytes);
Expand Down Expand Up @@ -671,21 +545,6 @@ private static byte[] decodingTable() {
return table;
}

@Deprecated
private static byte[] getMuxedEd25519AccountBytes(MuxedAccount muxedAccount) {
byte[] accountBytes = muxedAccount.getMed25519().getEd25519().getUint256();
byte[] idBytes = muxedAccount.getMed25519().getId().getUint64().getNumber().toByteArray();
byte[] idPaddedBytes = new byte[8];
int idNumBytesToCopy = Math.min(idBytes.length, 8);
int idCopyStartIndex = idBytes.length - idNumBytesToCopy;
System.arraycopy(
idBytes, idCopyStartIndex, idPaddedBytes, 8 - idNumBytesToCopy, idNumBytesToCopy);
byte[] result = new byte[accountBytes.length + idPaddedBytes.length];
System.arraycopy(accountBytes, 0, result, 0, accountBytes.length);
System.arraycopy(idPaddedBytes, 0, result, accountBytes.length, idPaddedBytes.length);
return result;
}

private static byte[] removeBase32Padding(byte[] data) {
// Calculate the length of unpadded data
int unpaddedLength = data.length;
Expand Down
142 changes: 0 additions & 142 deletions src/test/java/org/stellar/sdk/DeprecatedStrKeyTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -15,16 +16,12 @@
import org.stellar.sdk.AssetTypeNative;
import org.stellar.sdk.Claimant;
import org.stellar.sdk.KeyPair;
import org.stellar.sdk.MuxedAccount;
import org.stellar.sdk.Network;
import org.stellar.sdk.Predicate;
import org.stellar.sdk.StrKey;
import org.stellar.sdk.Transaction;
import org.stellar.sdk.TransactionBuilder;
import org.stellar.sdk.TransactionPreconditions;
import org.stellar.sdk.xdr.CryptoKeyType;
import org.stellar.sdk.xdr.MuxedAccount;
import org.stellar.sdk.xdr.Uint64;
import org.stellar.sdk.xdr.XdrUnsignedHyperInteger;

// TODO: refactor the test
public class CreateClaimableBalanceOperationTest {
Expand Down Expand Up @@ -136,17 +133,10 @@ public void testClaimableBalanceIds() throws IOException {
// different sequence number changes the claimable balance id
assertEquals(expectedIdSeq124, transaction.getClaimableBalanceId(0));

// MuxedAccount muxedAccount = ;
MuxedAccount muxedAccount = new MuxedAccount();
muxedAccount.setDiscriminant(CryptoKeyType.KEY_TYPE_MUXED_ED25519);
MuxedAccount.MuxedAccountMed25519 med = new MuxedAccount.MuxedAccountMed25519();
med.setEd25519(StrKey.encodeToXDRMuxedAccount(sourceAccount).getEd25519());
med.setId(new Uint64(new XdrUnsignedHyperInteger(41l)));
muxedAccount.setMed25519(med);
MuxedAccount muxedAccount = new MuxedAccount(sourceAccount, BigInteger.valueOf(41L));

transaction =
new TransactionBuilder(
new Account(StrKey.encodeMuxedAccount(muxedAccount), 123l), Network.TESTNET)
new TransactionBuilder(new Account(muxedAccount.getAddress(), 123l), Network.TESTNET)
.addOperation(op0)
.addOperation(BumpSequenceOperation.builder().bumpTo(2).build())
.setTimeout(TransactionPreconditions.TIMEOUT_INFINITE)
Expand Down
Loading