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

Java Vaccine Walkthrough Fixes #686

Merged
merged 9 commits into from
May 27, 2022
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
8 changes: 4 additions & 4 deletions docs/reference/services/credential-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Then you can supply it to SDK:
=== "Java"
<!--codeinclude-->
```java
[CreateProof](../../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:issueCredentialSample
[CreateProof](../../../java/src/test/java/trinsic/CredentialsDemo.java) inside_block:issueCredentialSample
```
<!--/codeinclude-->

Expand Down Expand Up @@ -281,7 +281,7 @@ Then you can supply it to SDK:
=== "Java"
<!--codeinclude-->
```java
[CreateProof](../../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:createProof
[CreateProof](../../../java/src/test/java/trinsic/CredentialsDemo.java) inside_block:createProof
```
<!--/codeinclude-->

Expand Down Expand Up @@ -336,7 +336,7 @@ Then you can supply it to SDK:
=== "Java"
<!--codeinclude-->
```java
[VerifyProof](../../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:verifyProof
[VerifyProof](../../../java/src/test/java/trinsic/CredentialsDemo.java) inside_block:verifyProof
```
<!--/codeinclude-->

Expand Down Expand Up @@ -406,7 +406,7 @@ Then you can supply it to SDK:
=== "Java"
<!--codeinclude-->
```java
[SendRequest](../../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:sendCredential
[SendRequest](../../../java/src/test/java/trinsic/CredentialsDemo.java) inside_block:sendCredential
```
<!--/codeinclude-->

Expand Down
2 changes: 0 additions & 2 deletions docs/reference/services/template-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ The response model is of type [Get Credential Template Response](../proto/index.
Querying template data in our SDK is enabled through the use of familiar SQL syntax. All data is stored in JSON-LD format, so it can be easily searched.
This approach allows us to give developers full control over how data is retrieved. In addition to customizable sorting, paging and filtering, developers have the ability to construct projections, combine result sets, and even run user-defined functions over their queries.

> This endpoint will support querying using [Verifiable Presentation Request Spec <small>:material-open-in-new:</small>](https://w3c-ccg.github.io/vp-request-spec/){target=_blank}. This feature is still in development.

Template searching works very similarly to Wallet searching. Please refer to [Wallet Service > Search / Query](./wallet-service.md#search--query) for more information.

### Basic Search
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/services/wallet-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Then you can supply it to the SDKs:
=== "Java"
<!--codeinclude-->
```java
[RegisterIssuer](../../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:insertItemWallet
[RegisterIssuer](../../../java/src/test/java/trinsic/WalletsDemo.java) inside_block:insertItemWallet
```
<!--/codeinclude-->

Expand Down Expand Up @@ -115,7 +115,7 @@ The default query used in the commands below returns the first 100 items in the
=== "Java"
<!--codeinclude-->
```java
[RegisterIssuer](../../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:searchWalletBasic
[RegisterIssuer](../../../java/src/test/java/trinsic/WalletsDemo.java) inside_block:searchWalletBasic
```
<!--/codeinclude-->

Expand Down Expand Up @@ -167,7 +167,7 @@ To pass custom query to the search function, use the query parameter or the avai
=== "Java"
<!--codeinclude-->
```java
[RegisterIssuer](../../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:searchWalletSQL
[RegisterIssuer](../../../java/src/test/java/trinsic/WalletsDemo.java) inside_block:searchWalletSQL
```
<!--/codeinclude-->

Expand Down
7 changes: 2 additions & 5 deletions docs/walkthroughs/vaccination.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ This tutorial is meant to share the concepts of verifiable credentials, so feel
=== "Java"
- <a href="/java/" target="_blank">Installation instructions</a> for Java.

In this project, we'll be following along the [`java/src/test/java/trinsic/VaccineDemo.java`](https://github.com/trinsic-id/sdk/blob/main/java/src/test/java/trinsic/VaccineDemo.java) in our [SDK repository](https://github.com/trinsic-id/sdk)


=== "Go"
- [Install Instructions](../go/index.md)

Expand Down Expand Up @@ -117,7 +114,7 @@ The first step is to create an [ecosystem](/learn/ecosystems/), within which eve
=== "Java"
<!--codeinclude-->
```java
[Create Ecosystem](../../java/src/test/java/trinsic/EcosystemsDemo.java) inside_block:createEcosystem
[Create Ecosystem](../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:createEcosystem
```
<!--/codeinclude-->

Expand Down Expand Up @@ -356,7 +353,7 @@ Templates are simply a list of the fields that a credential can have.
=== "Java"
<!--codeinclude-->
```java
[Create Template](../../java/src/test/java/trinsic/TemplatesDemo.java) inside_block:createTemplate
[Create Template](../../java/src/test/java/trinsic/VaccineDemo.java) inside_block:createTemplate
```
<!--/codeinclude-->

Expand Down
4 changes: 4 additions & 0 deletions java/src/main/java/trinsic/services/ServiceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public void setProfile(String base64ProfileToken) {
this.options = Options.ServiceOptions.newBuilder().mergeFrom(this.options).setAuthToken(base64ProfileToken).build();
}

public void setDefaultEcosystem(String ecosystemId) {
this.options = Options.ServiceOptions.newBuilder().mergeFrom(this.options).setDefaultEcosystem(ecosystemId).build();
}

public Options.ServiceOptions getOptions() {
return this.options;
}
Expand Down
4 changes: 4 additions & 0 deletions java/src/main/java/trinsic/services/WalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public WalletService(Options.ServiceOptions options) {
this.stub = UniversalWalletGrpc.newFutureStub(this.getChannel());
}

public ListenableFuture<UniversalWalletOuterClass.SearchResponse> search() throws InvalidProtocolBufferException, DidException {
return search(UniversalWalletOuterClass.SearchRequest.getDefaultInstance());
}

public ListenableFuture<UniversalWalletOuterClass.SearchResponse> search(UniversalWalletOuterClass.SearchRequest request) throws InvalidProtocolBufferException, DidException {
if (request.getQuery().isBlank()) request = UniversalWalletOuterClass.SearchRequest.newBuilder(request).setQuery("SELECT c.id, c.type, c.data FROM c OFFSET 0 LIMIT 100").build();

Expand Down
121 changes: 121 additions & 0 deletions java/src/test/java/trinsic/CredentialsDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package trinsic;

import org.junit.jupiter.api.Assertions;
import trinsic.okapi.DidException;
import trinsic.services.AccountService;
import trinsic.services.CredentialService;
import trinsic.services.ProviderService;
import trinsic.services.WalletService;
import trinsic.services.common.v1.ProviderOuterClass;
import trinsic.services.universalwallet.v1.UniversalWalletOuterClass;
import trinsic.services.verifiablecredentials.v1.VerifiableCredentials;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.ExecutionException;

public class CredentialsDemo {
public static void main(String[] args) throws IOException, DidException, ExecutionException, InterruptedException {
run();
}

public static void run() throws IOException, DidException, ExecutionException, InterruptedException {
var unsignedCredential = Files.readString(vaccineCertUnsignedPath());
var proofRequestJson = Files.readString(vaccineCertFramePath());
var recipientEmail = "example@trinsic.id";

var serverConfig = TrinsicUtilities.getTrinsicServiceOptions();

var providerService = new ProviderService(serverConfig);
var ecosystemId = providerService
.createEcosystem(ProviderOuterClass.CreateEcosystemRequest.getDefaultInstance())
.get().getEcosystem().getId();

serverConfig = serverConfig.toBuilder().setDefaultEcosystem(ecosystemId).build();

var accountService = new AccountService(serverConfig);

var issuerVerifier = accountService.signIn().get(); //Both issues and verifies
var holder = accountService.signIn().get();

var walletService = new WalletService(TrinsicUtilities.getTrinsicServiceOptions());
var credentialService = new CredentialService(TrinsicUtilities.getTrinsicServiceOptions());

credentialService.setProfile(issuerVerifier);

// issueCredentialSample() {
var issueResult = credentialService.issueCredential(
VerifiableCredentials.IssueRequest
.newBuilder()
.setDocumentJson(unsignedCredential)
.build()
).get();

var signedCredentialJson = issueResult.getSignedDocumentJson();
// }

System.out.println("Credential: " + signedCredentialJson);

credentialService.setProfile(holder);
// createProof() {
var createProofResponse = credentialService.createProof(
VerifiableCredentials.CreateProofRequest
.newBuilder()
.setDocumentJson(signedCredentialJson)
.setRevealDocumentJson(proofRequestJson)
.build()
).get();

var credentialProof = createProofResponse.getProofDocumentJson();
// }

System.out.println("Proof: " + credentialProof);

try {
// sendCredential() {
credentialService.send(
VerifiableCredentials.SendRequest
.newBuilder()
.setDocumentJson(signedCredentialJson)
.setEmail(recipientEmail)
.build()
);
// }
} catch (ExecutionException re) {
// This is okay, we don't expect that account to exist.
}

credentialService.setProfile(issuerVerifier);
// verifyProof() {
var verifyProofResponse = credentialService.verifyProof(
VerifiableCredentials.VerifyProofRequest
.newBuilder()
.setProofDocumentJson(credentialProof)
.build()
).get();

boolean isValid = verifyProofResponse.getIsValid();
// }

System.out.println("Verification result: " + isValid);
assert isValid;

providerService.shutdown();
accountService.shutdown();
credentialService.shutdown();
walletService.shutdown();
}

public static String baseTestPath() {
return Path.of(new File("").getAbsolutePath(), "..", "devops", "testdata").toAbsolutePath().toString();
}

public static Path vaccineCertUnsignedPath() {
return Path.of(baseTestPath(), "vaccination-certificate-unsigned.jsonld");
}

public static Path vaccineCertFramePath() {
return Path.of(baseTestPath(), "vaccination-certificate-frame.jsonld");
}
}
10 changes: 10 additions & 0 deletions java/src/test/java/trinsic/TrinsicServicesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public void testTemplatesDemo() throws IOException, ExecutionException, Interrup
TemplatesDemo.run();
}

@Test
public void testWalletDemo() throws IOException, ExecutionException, InterruptedException, DidException {
WalletsDemo.run();
}

@Test
public void testCredentialsDemo() throws IOException, ExecutionException, InterruptedException, DidException {
CredentialsDemo.run();
}

@Test
public void testProviderServiceInputValidation() {
var providerService = new ProviderService(TrinsicUtilities.getTrinsicServiceOptions());
Expand Down
Loading