Skip to content
Open
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
50 changes: 25 additions & 25 deletions src/main/java/org/unicitylabs/sdk/StateTransitionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import org.unicitylabs.sdk.api.AggregatorClient;
import org.unicitylabs.sdk.api.CertificationResponse;
import org.unicitylabs.sdk.api.InclusionProofResponse;
import org.unicitylabs.sdk.api.StateId;
import org.unicitylabs.sdk.api.CertificationResponse;
import org.unicitylabs.sdk.bft.RootTrustBase;
import org.unicitylabs.sdk.predicate.Predicate;
import org.unicitylabs.sdk.predicate.PredicateEngineService;
Expand All @@ -17,7 +17,7 @@
import org.unicitylabs.sdk.token.TokenState;
import org.unicitylabs.sdk.transaction.InclusionProofVerificationStatus;
import org.unicitylabs.sdk.transaction.MintCommitment;
import org.unicitylabs.sdk.transaction.MintTransactionReason;
import org.unicitylabs.sdk.transaction.MintReasonFactory;
import org.unicitylabs.sdk.transaction.MintTransactionState;
import org.unicitylabs.sdk.transaction.TransferCommitment;
import org.unicitylabs.sdk.transaction.TransferTransaction;
Expand Down Expand Up @@ -46,11 +46,9 @@ public StateTransitionClient(AggregatorClient client) {
* Submits a mint commitment to the aggregator.
*
* @param commitment The mint commitment to submit.
* @param <R> The type of mint transaction data.
* @return A CompletableFuture that resolves to the response from the aggregator.
*/
public <R extends MintTransactionReason>
CompletableFuture<CertificationResponse> submitCommitment(MintCommitment<R> commitment) {
public CompletableFuture<CertificationResponse> submitCommitment(MintCommitment commitment) {
return this.client.submitCertificationRequest(commitment.getCertificationData(), false);
}

Expand All @@ -77,45 +75,47 @@ public CompletableFuture<CertificationResponse> submitCommitment(TransferCommitm
/**
* Finalizes a transaction by updating the token state based on the provided transaction data without nametags.
*
* @param trustBase The root trust base for inclusion proof verification.
* @param token The token to be updated.
* @param state The current state of the token.
* @param transaction The transaction containing transfer data.
* @param <R> The type of mint transaction data.
* @param trustBase The root trust base for inclusion proof verification.
* @param mintReasonFactory factory to create mint transaction reasons
* @param token The token to be updated.
* @param state The current state of the token.
* @param transaction The transaction containing transfer data.
* @return The updated token after applying the transaction.
* @throws VerificationException if verification fails during the update process.
*/
public <R extends MintTransactionReason> Token<R> finalizeTransaction(
public Token finalizeTransaction(
RootTrustBase trustBase,
Token<R> token,
MintReasonFactory mintReasonFactory,
Token token,
TokenState state,
TransferTransaction transaction
) throws VerificationException {
return this.finalizeTransaction(trustBase, token, state, transaction, List.of());
return this.finalizeTransaction(trustBase, mintReasonFactory, token, state, transaction, List.of());
}

/**
* Finalizes a transaction by updating the token state based on the provided transaction data and nametags.
*
* @param trustBase The root trust base for inclusion proof verification.
* @param token The token to be updated.
* @param state The current state of the token.
* @param transaction The transaction containing transfer data.
* @param nametags A list of tokens used as nametags in the transaction.
* @param <R> The type of mint transaction data of token.
* @param trustBase The root trust base for inclusion proof verification.
* @param mintReasonFactory factory to create mint transaction reasons
* @param token The token to be updated.
* @param state The current state of the token.
* @param transaction The transaction containing transfer data.
* @param nametags A list of tokens used as nametags in the transaction.
* @return The updated token after applying the transaction.
* @throws VerificationException if verification fails during the update process.
*/
public <R extends MintTransactionReason> Token<R> finalizeTransaction(
public Token finalizeTransaction(
RootTrustBase trustBase,
Token<R> token,
MintReasonFactory mintReasonFactory,
Token token,
TokenState state,
TransferTransaction transaction,
List<Token<?>> nametags
List<Token> nametags
) throws VerificationException {
Objects.requireNonNull(token, "Token is null");

return token.update(trustBase, state, transaction, nametags);
return token.update(trustBase, mintReasonFactory, state, transaction, nametags);
}

/**
Expand All @@ -131,7 +131,7 @@ public CompletableFuture<InclusionProofResponse> getInclusionProof(StateId state
/**
* Check if state is already spent for given state id.
*
* @param stateId state id
* @param stateId state id
* @param trustBase root trust base
* @return A CompletableFuture that resolves to true if state is spent, false otherwise.
*/
Expand Down Expand Up @@ -162,7 +162,7 @@ public CompletableFuture<Boolean> isStateSpent(StateId stateId, RootTrustBase tr
* @return A CompletableFuture that resolves to the inclusion proof response from the aggregator.
*/
public CompletableFuture<Boolean> isStateSpent(
Token<?> token,
Token token,
byte[] publicKey,
RootTrustBase trustBase
) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/unicitylabs/sdk/address/ProxyAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public String getAddress() {
* @throws IllegalArgumentException if the nametags list contains null elements or duplicate
* addresses
*/
public static Address resolve(Address inputAddress, List<Token<?>> nametags) {
Map<Address, Token<?>> nametagMap = new HashMap<>();
for (Token<?> token : nametags) {
public static Address resolve(Address inputAddress, List<Token> nametags) {
Map<Address, Token> nametagMap = new HashMap<>();
for (Token token : nametags) {
if (token == null) {
throw new IllegalArgumentException("Nametag tokens list cannot contain null elements");
}
Expand All @@ -84,7 +84,7 @@ public static Address resolve(Address inputAddress, List<Token<?>> nametags) {

Address targetAddress = inputAddress;
while (targetAddress.getScheme() != AddressScheme.DIRECT) {
Token<?> nametag = nametagMap.get(targetAddress);
Token nametag = nametagMap.get(targetAddress);
if (nametag == null || !nametag.getData().isPresent()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ public JsonRpcAggregatorClient(String url, String apiKey) {
this.apiKey = apiKey;
}

/**
* Submit certification request.
*
* @param certificationData certification data
* @param receipt whether to request a receipt
* @return certification response
*/
public CompletableFuture<CertificationResponse> submitCertificationRequest(
CertificationData certificationData,
boolean receipt
) {
CertificationRequest request = CertificationRequest.create(certificationData,receipt);
CertificationRequest request = CertificationRequest.create(certificationData, receipt);

Map<String, List<String>> headers = this.apiKey == null
? Map.of()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/unicitylabs/sdk/predicate/Predicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public interface Predicate extends SerializablePredicate {
* @param trustBase trust base to verify against.
* @return true if successful
*/
boolean verify(Token<?> token, TransferTransaction transaction, RootTrustBase trustBase);
boolean verify(Token token, TransferTransaction transaction, RootTrustBase trustBase);
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public boolean isOwner(byte[] publicKey) {
}

@Override
public boolean verify(Token<?> token, TransferTransaction transaction, RootTrustBase trustBase) {
public boolean verify(Token token, TransferTransaction transaction, RootTrustBase trustBase) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public boolean isOwner(byte[] publicKey) {
}

@Override
public boolean verify(Token<?> token, TransferTransaction transaction, RootTrustBase trustBase) {
public boolean verify(Token token, TransferTransaction transaction, RootTrustBase trustBase) {
if (!this.tokenId.equals(token.getId()) || !this.tokenType.equals(token.getType())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class MaskedPredicate extends DefaultPredicate {
* @param hashAlgorithm hash algorithm
* @param nonce predicate nonce
*/
public MaskedPredicate(
MaskedPredicate(
TokenId tokenId,
TokenType tokenType,
byte[] publicKey,
Expand All @@ -41,7 +41,7 @@ public MaskedPredicate(
}

/**
* Create masked predicate from signing service.
* Create masked predicate from mint transaction and signing service.
*
* @param tokenId token id
* @param tokenType token type
Expand All @@ -55,7 +55,8 @@ public static MaskedPredicate create(
TokenType tokenType,
SigningService signingService,
HashAlgorithm hashAlgorithm,
byte[] nonce) {
byte[] nonce
) {
return new MaskedPredicate(tokenId, tokenType, signingService.getPublicKey(),
signingService.getAlgorithm(), hashAlgorithm, nonce);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.unicitylabs.sdk.token.Token;
import org.unicitylabs.sdk.token.TokenId;
import org.unicitylabs.sdk.token.TokenType;
import org.unicitylabs.sdk.transaction.Transaction;
import org.unicitylabs.sdk.transaction.TransferTransaction;

/**
Expand All @@ -31,32 +32,34 @@ public class UnmaskedPredicate extends DefaultPredicate {
}

/**
* Create unmasked predicate.
* Create masked predicate from transaction and signing service.
*
* @param tokenId token id
* @param tokenType token type
* @param transaction received transaction
* @param signingService signing service
* @param hashAlgorithm hash algorithm
* @param salt received transaction salt
* @return unmasked predicate
* @return predicate
*/
public static UnmaskedPredicate create(
TokenId tokenId,
TokenType tokenType,
Transaction<?> transaction,
SigningService signingService,
HashAlgorithm hashAlgorithm,
byte[] salt
HashAlgorithm hashAlgorithm
) {
Signature nonce = signingService.sign(
new DataHasher(HashAlgorithm.SHA256).update(salt).digest());
Signature signature = signingService.sign(
new DataHasher(HashAlgorithm.SHA256).update(transaction.getData().getSalt()).digest()
);

return new UnmaskedPredicate(
tokenId,
tokenType,
signingService.getPublicKey(),
signingService.getAlgorithm(),
hashAlgorithm,
nonce.getBytes());
signature.getBytes()
);
}

/**
Expand All @@ -69,19 +72,15 @@ public static UnmaskedPredicate create(
*/
@Override
public boolean verify(
Token<?> token,
Token token,
TransferTransaction transaction,
RootTrustBase trustBase
) {
List<TransferTransaction> transactions = token.getTransactions();

return super.verify(token, transaction, trustBase) && SigningService.verifyWithPublicKey(
new DataHasher(HashAlgorithm.SHA256)
.update(
transactions.isEmpty()
? token.getGenesis().getData().getSalt()
: transactions.get(transactions.size() - 1).getData().getSalt()
)
.update(token.getLatestTransaction().getData().getSalt())
.digest(),
this.getNonce(),
this.getPublicKey()
Expand Down
Loading
Loading