forked from reinkrul/java-nuts-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CredentialExamples.java
79 lines (71 loc) · 3.94 KB
/
CredentialExamples.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import nl.reinkrul.nuts.ApiException;
import nl.reinkrul.nuts.common.VerifiableCredential;
import nl.reinkrul.nuts.extra.FHIRResource;
import nl.reinkrul.nuts.extra.NutsAuthorizationCredential;
import nl.reinkrul.nuts.extra.NutsOrganizationCredential;
import nl.reinkrul.nuts.vcr.*;
import java.util.List;
public class CredentialExamples {
public void searchNutsOrganizationCredential() throws ApiException {
var client = new CredentialApi();
var issuedVC = client.searchVCs(new SearchVCRequest()
// Search options
.searchOptions(new SearchOptions().allowUntrustedIssuer(false))
// VC to match
.query(new VerifiableCredential()
.type(List.of("VerifiableCredential", "NutsOrganizationCredential"))
.atContext(List.of("https://nuts.nl/credentials/v1", "https://www.w3.org/2018/credentials/v1"))
.issuer("did:nuts:some-did") // the DID of the issuer of the credential (DID of software vendor)
.credentialSubject(
new NutsOrganizationCredential()
.organization(new nl.reinkrul.nuts.extra.Organization()
.name("Extra Careful B.V.")
.city("Zorgdorp")
))
));
for (SearchVCResult result : issuedVC.getVerifiableCredentials()) {
System.out.println(result.getVerifiableCredential().getId());
}
}
public void issueNutsOrganizationCredential() throws ApiException {
var client = new CredentialApi();
var issuedVC = client.issueVC(new IssueVCRequest()
// General VC properties
.type("NutsOrganizationCredential")
.issuer("did:nuts:some-did") // the DID of the issuer of the credential (DID of software vendor)
.visibility(IssueVCRequest.VisibilityEnum.PUBLIC) // publish on network, anyone can read it
// Subject of the credential
.credentialSubject(
new NutsOrganizationCredential()
.id("did:nuts:some-other-did") // the DID of the receiver of the credential
.organization(new nl.reinkrul.nuts.extra.Organization()
.name("Extra Careful B.V.")
.city("Zorgdorp")
)
)
);
System.out.println("VC has been issued, ID: " + issuedVC.getId());
}
public void issueNutsAuthorizationCredential() throws ApiException {
var client = new CredentialApi();
var issuedVC = client.issueVC(new IssueVCRequest()
// General VC properties
.type("NutsAuthenticationCredential")
.issuer("did:nuts:some-did") // the DID of the issuer of the credential
.visibility(IssueVCRequest.VisibilityEnum.PRIVATE) // publish on network, but keep it private
// Subject of the credential
.credentialSubject(
new NutsAuthorizationCredential()
.id("did:nuts:some-other-did") // the DID of the receiver of the credential
.subject("1234567890") // social security number of the patient
.addResourcesItem(
// The FHIR resources that can be accessed using the credential
new FHIRResource()
.path("/Task/1")
.addOperationsItem("read")
)
)
);
System.out.println("VC has been issued, ID: " + issuedVC.getId());
}
}