Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Oct 2, 2024
1 parent 1b32620 commit e912ebf
Show file tree
Hide file tree
Showing 14 changed files with 339 additions and 253 deletions.
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,11 @@ It is generated from the latest version of the OpenAPI specifications of the Nut

Find all versions on [Maven central](https://search.maven.org/artifact/nl.reinkrul.nuts/java-client).

# Usage
The example below instantiates the API client for VDR and calls `getDID` for `subjectDID`:
```java
var apiClient = new nl.reinkrul.nuts.Configuration.getDefaultApiClient();

var didApi = new nl.reinkrul.nuts.vdr.DidApi(apiClient);
var didDocument = didApi.getDID(subjectDID, null, null);

// do something with the resolved DID Document
```

# Usage and examples
Since each module in the Nuts Node has its own OpenAPI specification, there is a client API generated for each of them.
You can find in their own subpackage in `nl.reinkrul.nuts` (e.g. `nl.reinkrul.nuts.vdr`).

# Examples

See [src/test/java/v6.CredentialExamples.java](src/test/java/v6.CredentialExamples.java)
for how to issue `NutsOrganizationCredential`, `NutsAuthenticationCredential` and `NutsEmployeeCredential`.
See [src/test/java/nl/reinkrul/nuts/IntegrationTest.java](src/test/java/nl/reinkrul/nuts/IntegrationTest.java) for an example of how to use the client.

# Versioning

Expand Down
1 change: 1 addition & 0 deletions nutsnode/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ services:
NUTS_DISCOVERY_SERVER_IDS: test
NUTS_POLICY_DIRECTORY: /opt/nuts/policy
NUTS_AUTH_CONTRACTVALIDATORS: dummy
NUTS_VDR_DIDMETHODS: web
65 changes: 62 additions & 3 deletions nutsnode/policy/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
{
"id": "organization_name",
"path": [
"$.credentialSubject.organization.name"
"$.credentialSubject.organization.name",
"$.credentialSubject[0].organization.name"
],
"filter": {
"type": "string"
Expand All @@ -54,7 +55,8 @@
{
"id": "organization_ura",
"path": [
"$.credentialSubject.organization.ura"
"$.credentialSubject.organization.ura",
"$.credentialSubject[0].organization.ura"
],
"filter": {
"type": "string"
Expand All @@ -63,7 +65,64 @@
{
"id": "organization_city",
"path": [
"$.credentialSubject.organization.city"
"$.credentialSubject.organization.city",
"$.credentialSubject[0].organization.city"
],
"filter": {
"type": "string"
}
}
]
}
},
{
"id": "id_employee_credential_cred",
"constraints": {
"fields": [
{
"path": [
"$.type"
],
"filter": {
"type": "string",
"const": "NutsEmployeeCredential"
}
},
{
"id": "employee_identifier",
"path": [
"$.credentialSubject.member.identifier",
"$.credentialSubject[0].member.identifier"
],
"filter": {
"type": "string"
}
},
{
"id": "employee_name",
"path": [
"$.credentialSubject.member.member.familyName",
"$.credentialSubject[0].member.member.familyName"
],
"filter": {
"type": "string"
}
},
{
"id": "employee_initials",
"path": [
"$.credentialSubject.member.member.initials",
"$.credentialSubject[0].member.member.initials"
],
"filter": {
"type": "string"
}
},
{
"id": "employee_role",
"path": [
"$.credentialSubject.member.roleName",
"$.credentialSubject[0].member.roleName"
],
"filter": {
"type": "string"
Expand Down
34 changes: 19 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
dest="${openapi.spec.dir}/didman/v1.yaml"/>
<!-- Discovery -->
<mkdir dir="${openapi.spec.dir}/discovery/"/>
<get src="https://raw.githubusercontent.com/nuts-foundation/nuts-node/attempt-openapi-vcr2-fix/docs/_static/discovery/v1.yaml"
<get src="${openapi.spec.baseurl}/discovery/v1.yaml"
dest="${openapi.spec.dir}/discovery/v1.yaml"/>
<!-- Network -->
<mkdir dir="${openapi.spec.dir}/network/"/>
Expand All @@ -238,6 +238,24 @@
</target>
</configuration>
</execution>
<execution>
<!--
We have our own DiscoveryApi class, so change the tag of discovery services to cause the
original generated class to have a base class name, so we can extend it as DiscoveryApi.
-->
<id>replace-discovery-tag</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<replace file="${openapi.spec.dir}/discovery/v1.yaml">
<replacefilter token="- discovery" value="- baseDiscovery" />
</replace>
</target>
</configuration>
</execution>
<execution>
<!-- We have our own Configuration class to provide ApiClient instances, since we need custom deserializers -->
<id>remove-generated-configuration-class</id>
Expand Down Expand Up @@ -302,20 +320,6 @@
</configuration>
<executions>
<!-- Model-only OpenAPI specs need to be generated first, otherwise the ApiClient will be missing authentication schemes -->
<execution>
<id>generate-additions</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>specs/credentials.yaml</inputSpec>
<generateApis>false</generateApis>
<configOptions>
<apiPackage>nl.reinkrul.nuts.extra</apiPackage>
<modelPackage>nl.reinkrul.nuts.extra</modelPackage>
</configOptions>
</configuration>
</execution>
<execution>
<id>generate-common-ssi-types</id>
<goals>
Expand Down
143 changes: 0 additions & 143 deletions specs/credentials.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/nl/reinkrul/nuts/common/VerifiableCredential.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ public VerifiableCredential(Map<String, Object> jsonObject, String source) {
this.source = source;
}

/**
* Constructor for VerifiableCredential for an unsigned credential; it will marshal to JSON-LD.
* @param employeeCredential
*/
public VerifiableCredential(com.danubetech.verifiablecredentials.VerifiableCredential employeeCredential) {
super(employeeCredential.getJsonObject());
try {
source = new ObjectMapper().writeValueAsString(employeeCredential);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

/**
* The raw source of the credential, as it was deserialized.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ public VerifiablePresentationDeserializer() {

@Override
public VerifiablePresentation deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
var token = jsonParser.nextValue();
String valueAsString = jsonParser.getValueAsString();
if (token == JsonToken.START_OBJECT) {
// Parse as JSON-LD
return new VerifiablePresentation(com.danubetech.verifiablecredentials.VerifiablePresentation.fromJson(valueAsString).getJsonObject(), valueAsString);
} else if (token == JsonToken.VALUE_STRING) {
if (jsonParser.getCurrentToken().isScalarValue()) {
var valueAsString = jsonParser.getValueAsString();
try {
return new VerifiablePresentation(JwtVerifiablePresentation.fromCompactSerialization(token.asString()).getPayloadObject().getJsonObject(), valueAsString);
return new VerifiablePresentation(JwtVerifiablePresentation.fromCompactSerialization(valueAsString).getPayloadObject().getJsonObject(), valueAsString);
} catch (ParseException e) {
throw new IOException(e);
}
}
throw new IOException("Unexpected token: " + token);
if (jsonParser.getCurrentToken().isStructStart()) {
// Parse as JSON-LD
var valueAsString = jsonParser.readValueAsTree().toString();
return new VerifiablePresentation(com.danubetech.verifiablecredentials.VerifiablePresentation.fromJson(valueAsString).getJsonObject(), valueAsString);

}
throw new IOException("Unexpected token: " + jsonParser.getCurrentToken().id());
}
}
9 changes: 9 additions & 0 deletions src/main/java/nl/reinkrul/nuts/credentials/Context.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nl.reinkrul.nuts.credentials;

import java.net.URI;

public final class Context {
public static URI VerifiableCredentialV1 = URI.create("https://www.w3.org/2018/credentials/v1");
public static URI NutsV1 = URI.create("https://nuts.nl/credentials/v1");
public static URI Nuts2024 = URI.create("https://nuts.nl/credentials/2024");
}
Loading

0 comments on commit e912ebf

Please sign in to comment.