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
3 changes: 3 additions & 0 deletions src/main/java/co/dfns/sdk/DfnsAsyncClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.dfns.sdk;

import co.dfns.sdk.internal.DfnsHttpClient;
import co.dfns.sdk.addresswatches.AddressWatchesAsyncClient;
import co.dfns.sdk.agreements.AgreementsAsyncClient;
import co.dfns.sdk.allocations.AllocationsAsyncClient;
import co.dfns.sdk.auth.AuthAsyncClient;
Expand All @@ -22,6 +23,7 @@
/** Dfns async SDK client. Provides access to all Dfns API domains. */
public class DfnsAsyncClient implements AutoCloseable {
private final DfnsHttpClient httpClient;
public final AddressWatchesAsyncClient addressWatches;
public final AgreementsAsyncClient agreements;
public final AllocationsAsyncClient allocations;
public final AuthAsyncClient auth;
Expand All @@ -42,6 +44,7 @@ public class DfnsAsyncClient implements AutoCloseable {

public DfnsAsyncClient(DfnsClientConfig config) {
this.httpClient = new DfnsHttpClient(config);
this.addressWatches = new AddressWatchesAsyncClient(httpClient);
this.agreements = new AgreementsAsyncClient(httpClient);
this.allocations = new AllocationsAsyncClient(httpClient);
this.auth = new AuthAsyncClient(httpClient);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/co/dfns/sdk/DfnsClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.dfns.sdk;

import co.dfns.sdk.internal.DfnsHttpClient;
import co.dfns.sdk.addresswatches.AddressWatchesClient;
import co.dfns.sdk.agreements.AgreementsClient;
import co.dfns.sdk.allocations.AllocationsClient;
import co.dfns.sdk.auth.AuthClient;
Expand All @@ -22,6 +23,7 @@
/** Dfns SDK client. Provides access to all Dfns API domains. */
public class DfnsClient implements AutoCloseable {
private final DfnsHttpClient httpClient;
public final AddressWatchesClient addressWatches;
public final AgreementsClient agreements;
public final AllocationsClient allocations;
public final AuthClient auth;
Expand All @@ -42,6 +44,7 @@ public class DfnsClient implements AutoCloseable {

public DfnsClient(DfnsClientConfig config) {
this.httpClient = new DfnsHttpClient(config);
this.addressWatches = new AddressWatchesClient(httpClient);
this.agreements = new AgreementsClient(httpClient);
this.allocations = new AllocationsClient(httpClient);
this.auth = new AuthClient(httpClient);
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/co/dfns/sdk/DfnsClientConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.dfns.sdk;

import co.dfns.sdk.auth.Signer;
import java.net.URI;
import java.time.Duration;

/** Configuration for all Dfns SDK clients. Build via {@link #builder()}. */
Expand All @@ -11,7 +12,7 @@ public class DfnsClientConfig {
private final Duration requestTimeout;

private DfnsClientConfig(Builder b) {
this.baseUrl = b.baseUrl;
this.baseUrl = normalizeBaseUrl(b.baseUrl);
this.authToken = b.authToken;
this.signer = b.signer;
this.requestTimeout = b.requestTimeout;
Expand All @@ -22,6 +23,26 @@ private DfnsClientConfig(Builder b) {
public Signer getSigner() { return signer; }
public Duration getRequestTimeout() { return requestTimeout; }

private static String normalizeBaseUrl(String baseUrl) {
if (baseUrl == null || baseUrl.isBlank())
throw new IllegalStateException("baseUrl is required");

URI uri;
try {
uri = URI.create(baseUrl);
} catch (IllegalArgumentException e) {
throw new IllegalStateException("baseUrl must be a valid absolute URL", e);
}
if (!uri.isAbsolute() || uri.getHost() == null)
throw new IllegalStateException("baseUrl must be an absolute URL");
if (uri.getRawQuery() != null)
throw new IllegalStateException("baseUrl must not include a query");
if (uri.getRawFragment() != null)
throw new IllegalStateException("baseUrl must not include a fragment");

return baseUrl.replaceAll("/+$", "");
}

public static Builder builder() { return new Builder(); }

public static class Builder {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/co/dfns/sdk/DfnsDelegatedAsyncClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.dfns.sdk;

import co.dfns.sdk.internal.DfnsHttpClient;
import co.dfns.sdk.addresswatches.DelegatedAddressWatchesAsyncClient;
import co.dfns.sdk.agreements.DelegatedAgreementsAsyncClient;
import co.dfns.sdk.allocations.DelegatedAllocationsAsyncClient;
import co.dfns.sdk.auth.DelegatedAuthAsyncClient;
Expand All @@ -26,6 +27,7 @@
*/
public class DfnsDelegatedAsyncClient implements AutoCloseable {
private final DfnsHttpClient httpClient;
public final DelegatedAddressWatchesAsyncClient addressWatches;
public final DelegatedAgreementsAsyncClient agreements;
public final DelegatedAllocationsAsyncClient allocations;
public final DelegatedAuthAsyncClient auth;
Expand All @@ -46,6 +48,7 @@ public class DfnsDelegatedAsyncClient implements AutoCloseable {

public DfnsDelegatedAsyncClient(DfnsClientConfig config) {
this.httpClient = new DfnsHttpClient(config);
this.addressWatches = new DelegatedAddressWatchesAsyncClient(httpClient);
this.agreements = new DelegatedAgreementsAsyncClient(httpClient);
this.allocations = new DelegatedAllocationsAsyncClient(httpClient);
this.auth = new DelegatedAuthAsyncClient(httpClient);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/co/dfns/sdk/DfnsDelegatedClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.dfns.sdk;

import co.dfns.sdk.internal.DfnsHttpClient;
import co.dfns.sdk.addresswatches.DelegatedAddressWatchesClient;
import co.dfns.sdk.agreements.DelegatedAgreementsClient;
import co.dfns.sdk.allocations.DelegatedAllocationsClient;
import co.dfns.sdk.auth.DelegatedAuthClient;
Expand All @@ -26,6 +27,7 @@
*/
public class DfnsDelegatedClient implements AutoCloseable {
private final DfnsHttpClient httpClient;
public final DelegatedAddressWatchesClient addressWatches;
public final DelegatedAgreementsClient agreements;
public final DelegatedAllocationsClient allocations;
public final DelegatedAuthClient auth;
Expand All @@ -46,6 +48,7 @@ public class DfnsDelegatedClient implements AutoCloseable {

public DfnsDelegatedClient(DfnsClientConfig config) {
this.httpClient = new DfnsHttpClient(config);
this.addressWatches = new DelegatedAddressWatchesClient(httpClient);
this.agreements = new DelegatedAgreementsClient(httpClient);
this.allocations = new DelegatedAllocationsClient(httpClient);
this.auth = new DelegatedAuthClient(httpClient);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package co.dfns.sdk.addresswatches;

import co.dfns.sdk.internal.DfnsHttpClient;
import co.dfns.sdk.addresswatches.model.*;
import java.util.List;
import co.dfns.sdk.PaginatedList;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

public class AddressWatchesAsyncClient {
private final DfnsHttpClient httpClient;

public AddressWatchesAsyncClient(DfnsHttpClient httpClient) {
this.httpClient = httpClient;
}

/** List Address Watches */
public CompletableFuture<PaginatedList<AddressWatch>> listAddressWatches(ListAddressWatchesQuery query) {
return httpClient.getAsync("/address-watches", query.toMap(), new com.fasterxml.jackson.core.type.TypeReference<PaginatedList<AddressWatch>>() {});
}

/** Create Address Watch */
public CompletableFuture<AddressWatch> createAddressWatch(CreateAddressWatchRequest body) {
return httpClient.postAsync("/address-watches", java.util.Map.of(), body, AddressWatch.class, true);
}

/** Get Address Watch */
public CompletableFuture<AddressWatch> getAddressWatch(String addressWatchId) {
return httpClient.getAsync("/address-watches/" + addressWatchId, java.util.Map.of(), AddressWatch.class);
}

/** Get Address Watch Assets */
public CompletableFuture<GetAddressWatchAssetsResponse> getAddressWatchAssets(String addressWatchId, GetAddressWatchAssetsQuery query) {
return httpClient.getAsync("/address-watches/" + addressWatchId + "/assets", query.toMap(), GetAddressWatchAssetsResponse.class);
}

/** Get Address Watch Blockchain Events */
public CompletableFuture<GetAddressWatchBlockchainEventsResponse> getAddressWatchBlockchainEvents(String addressWatchId, GetAddressWatchBlockchainEventsQuery query) {
return httpClient.getAsync("/address-watches/" + addressWatchId + "/blockchain-events", query.toMap(), GetAddressWatchBlockchainEventsResponse.class);
}

/** Get Address Watch History */
public CompletableFuture<GetAddressWatchHistoryResponse> getAddressWatchHistory(String addressWatchId, GetAddressWatchHistoryQuery query) {
return httpClient.getAsync("/address-watches/" + addressWatchId + "/history", query.toMap(), GetAddressWatchHistoryResponse.class);
}
}
45 changes: 45 additions & 0 deletions src/main/java/co/dfns/sdk/addresswatches/AddressWatchesClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package co.dfns.sdk.addresswatches;

import co.dfns.sdk.internal.DfnsHttpClient;
import co.dfns.sdk.addresswatches.model.*;
import java.util.List;
import co.dfns.sdk.PaginatedList;
import java.util.Map;

public class AddressWatchesClient {
private final DfnsHttpClient httpClient;

public AddressWatchesClient(DfnsHttpClient httpClient) {
this.httpClient = httpClient;
}

/** List Address Watches */
public PaginatedList<AddressWatch> listAddressWatches(ListAddressWatchesQuery query) {
return httpClient.get("/address-watches", query.toMap(), new com.fasterxml.jackson.core.type.TypeReference<PaginatedList<AddressWatch>>() {});
}

/** Create Address Watch */
public AddressWatch createAddressWatch(CreateAddressWatchRequest body) {
return httpClient.post("/address-watches", java.util.Map.of(), body, AddressWatch.class, true);
}

/** Get Address Watch */
public AddressWatch getAddressWatch(String addressWatchId) {
return httpClient.get("/address-watches/" + addressWatchId, java.util.Map.of(), AddressWatch.class);
}

/** Get Address Watch Assets */
public GetAddressWatchAssetsResponse getAddressWatchAssets(String addressWatchId, GetAddressWatchAssetsQuery query) {
return httpClient.get("/address-watches/" + addressWatchId + "/assets", query.toMap(), GetAddressWatchAssetsResponse.class);
}

/** Get Address Watch Blockchain Events */
public GetAddressWatchBlockchainEventsResponse getAddressWatchBlockchainEvents(String addressWatchId, GetAddressWatchBlockchainEventsQuery query) {
return httpClient.get("/address-watches/" + addressWatchId + "/blockchain-events", query.toMap(), GetAddressWatchBlockchainEventsResponse.class);
}

/** Get Address Watch History */
public GetAddressWatchHistoryResponse getAddressWatchHistory(String addressWatchId, GetAddressWatchHistoryQuery query) {
return httpClient.get("/address-watches/" + addressWatchId + "/history", query.toMap(), GetAddressWatchHistoryResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package co.dfns.sdk.addresswatches;

import co.dfns.sdk.internal.DfnsHttpClient;
import co.dfns.sdk.addresswatches.model.*;
import java.util.List;
import co.dfns.sdk.PaginatedList;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import co.dfns.sdk.auth.UserActionChallenge;
import co.dfns.sdk.auth.CredentialAssertion;

public class DelegatedAddressWatchesAsyncClient {
private final DfnsHttpClient httpClient;

public DelegatedAddressWatchesAsyncClient(DfnsHttpClient httpClient) {
this.httpClient = httpClient;
}

/** List Address Watches */
public CompletableFuture<PaginatedList<AddressWatch>> listAddressWatches(ListAddressWatchesQuery query) {
return httpClient.getAsync("/address-watches", query.toMap(), new com.fasterxml.jackson.core.type.TypeReference<PaginatedList<AddressWatch>>() {});
}

/** Delegated signing step 1 for Create Address Watch: returns the challenge to sign out-of-band. */
public CompletableFuture<UserActionChallenge> createAddressWatchInit(CreateAddressWatchRequest body) {
return httpClient.createUserActionChallengeAsync("POST", "/address-watches", body);
}

/** Delegated signing step 2 for Create Address Watch: submits the signed challenge and issues the request. */
public CompletableFuture<AddressWatch> createAddressWatchComplete(CreateAddressWatchRequest body, String challengeIdentifier, CredentialAssertion assertion) {
return httpClient.completeUserActionSigningAsync(challengeIdentifier, assertion)
.thenCompose(userAction -> httpClient.executeWithUserActionAsync("POST", "/address-watches", java.util.Map.of(), body, AddressWatch.class, userAction));
}

/** Get Address Watch */
public CompletableFuture<AddressWatch> getAddressWatch(String addressWatchId) {
return httpClient.getAsync("/address-watches/" + addressWatchId, java.util.Map.of(), AddressWatch.class);
}

/** Get Address Watch Assets */
public CompletableFuture<GetAddressWatchAssetsResponse> getAddressWatchAssets(String addressWatchId, GetAddressWatchAssetsQuery query) {
return httpClient.getAsync("/address-watches/" + addressWatchId + "/assets", query.toMap(), GetAddressWatchAssetsResponse.class);
}

/** Get Address Watch Blockchain Events */
public CompletableFuture<GetAddressWatchBlockchainEventsResponse> getAddressWatchBlockchainEvents(String addressWatchId, GetAddressWatchBlockchainEventsQuery query) {
return httpClient.getAsync("/address-watches/" + addressWatchId + "/blockchain-events", query.toMap(), GetAddressWatchBlockchainEventsResponse.class);
}

/** Get Address Watch History */
public CompletableFuture<GetAddressWatchHistoryResponse> getAddressWatchHistory(String addressWatchId, GetAddressWatchHistoryQuery query) {
return httpClient.getAsync("/address-watches/" + addressWatchId + "/history", query.toMap(), GetAddressWatchHistoryResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package co.dfns.sdk.addresswatches;

import co.dfns.sdk.internal.DfnsHttpClient;
import co.dfns.sdk.addresswatches.model.*;
import java.util.List;
import co.dfns.sdk.PaginatedList;
import java.util.Map;
import co.dfns.sdk.auth.UserActionChallenge;
import co.dfns.sdk.auth.CredentialAssertion;

public class DelegatedAddressWatchesClient {
private final DfnsHttpClient httpClient;

public DelegatedAddressWatchesClient(DfnsHttpClient httpClient) {
this.httpClient = httpClient;
}

/** List Address Watches */
public PaginatedList<AddressWatch> listAddressWatches(ListAddressWatchesQuery query) {
return httpClient.get("/address-watches", query.toMap(), new com.fasterxml.jackson.core.type.TypeReference<PaginatedList<AddressWatch>>() {});
}

/** Delegated signing step 1 for Create Address Watch: returns the challenge to sign out-of-band. */
public UserActionChallenge createAddressWatchInit(CreateAddressWatchRequest body) {
return httpClient.createUserActionChallenge("POST", "/address-watches", body);
}

/** Delegated signing step 2 for Create Address Watch: submits the signed challenge and issues the request. */
public AddressWatch createAddressWatchComplete(CreateAddressWatchRequest body, String challengeIdentifier, CredentialAssertion assertion) {
String userAction = httpClient.completeUserActionSigning(challengeIdentifier, assertion);
return httpClient.executeWithUserAction("POST", "/address-watches", java.util.Map.of(), body, AddressWatch.class, userAction);
}

/** Get Address Watch */
public AddressWatch getAddressWatch(String addressWatchId) {
return httpClient.get("/address-watches/" + addressWatchId, java.util.Map.of(), AddressWatch.class);
}

/** Get Address Watch Assets */
public GetAddressWatchAssetsResponse getAddressWatchAssets(String addressWatchId, GetAddressWatchAssetsQuery query) {
return httpClient.get("/address-watches/" + addressWatchId + "/assets", query.toMap(), GetAddressWatchAssetsResponse.class);
}

/** Get Address Watch Blockchain Events */
public GetAddressWatchBlockchainEventsResponse getAddressWatchBlockchainEvents(String addressWatchId, GetAddressWatchBlockchainEventsQuery query) {
return httpClient.get("/address-watches/" + addressWatchId + "/blockchain-events", query.toMap(), GetAddressWatchBlockchainEventsResponse.class);
}

/** Get Address Watch History */
public GetAddressWatchHistoryResponse getAddressWatchHistory(String addressWatchId, GetAddressWatchHistoryQuery query) {
return httpClient.get("/address-watches/" + addressWatchId + "/history", query.toMap(), GetAddressWatchHistoryResponse.class);
}
}
22 changes: 22 additions & 0 deletions src/main/java/co/dfns/sdk/addresswatches/model/AddressWatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package co.dfns.sdk.addresswatches.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public record AddressWatch(
@JsonProperty("id") String id,
@JsonProperty("network") Network network,
@JsonProperty("address") String address,
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty("name") String name,
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty("externalId") String externalId,
@JsonProperty("tags") List<String> tags,
@JsonProperty("status") String status,
@JsonProperty("dateCreated") String dateCreated,
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty("dateDeleted") String dateDeleted
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package co.dfns.sdk.addresswatches.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public record AddressWatchBlockchainEvent(
@JsonProperty("id") String id,
@JsonProperty("addressWatchId") String addressWatchId,
@JsonProperty("network") Network network,
@JsonProperty("name") String name,
@JsonProperty("blockNumber") double blockNumber,
@JsonProperty("txHash") String txHash,
@JsonProperty("index") String index,
@JsonProperty("timestamp") String timestamp,
@JsonProperty("status") String status,
@JsonProperty("data") Map<String, Object> data
) {}
Loading
Loading