Skip to content

Commit e1803b8

Browse files
committed
Merge branch 'peacekeeper-titanium-json-ld' into master
2 parents b974d05 + 254ea45 commit e1803b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1127
-1471
lines changed

examples-ldp.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,23 @@ Verifiable Credentials with Linked Data Proofs:
4040
LinkedHashMap<String, Object> jsonLdDriversLicense = new LinkedHashMap<String, Object> ();
4141
jsonLdDriversLicense.put("licenseClass", "trucks");
4242
jsonLdCredentialSubject.put("driversLicense", jsonLdDriversLicense);
43-
44-
URI creator = URI.create("did:sov:1yvXbmgPoUm4dl66D7KhyD#keys-1");
45-
String created = "2018-01-01T21:19:10Z";
46-
String domain = null;
47-
String nonce = "c0ae1c8e-c7e7-469f-b252-86e6a0e7387e";
48-
49-
RsaSignature2018LdSigner signer = new RsaSignature2018LdSigner(creator, created, domain, nonce, TestUtil.testRSAPrivateKey);
50-
LdSignature ldSignature = signer.sign(verifiableCredential.getJsonLdObject());
51-
52-
System.out.println(JsonUtils.toString(verifiableCredential.getJsonLdObject()));
43+
44+
byte[] testEd25519PrivateKey = Hex.decodeHex("984b589e121040156838303f107e13150be4a80fc5088ccba0b0bdc9b1d89090de8777a28f8da1a74e7a13090ed974d879bf692d001cddee16e4cc9f84b60580".toCharArray());
45+
46+
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new FileReader("input.jsonld"));
47+
String verificationMethod = "https://example.com/jdoe/keys/1";
48+
String domain = "example.com";
49+
String nonce = null;
50+
51+
Ed25519Signature2018LdSigner signer = new Ed25519Signature2018LdSigner(testEd25519PrivateKey);
52+
signer.setCreated(new Date());
53+
signer.setProofPurpose(LDSecurityKeywords.JSONLD_TERM_ASSERTIONMETHOD);
54+
signer.setVerificationMethod(verificationMethod);
55+
signer.setDomain(domain);
56+
signer.setNonce(nonce);
57+
LdProof ldProof = signer.sign(jsonLdObject);
58+
59+
System.out.println(ldProof.toJson(true));
5360

5461
### Example code (verifying)
5562

pom.xml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,17 @@
123123
<groupId>info.weboftrust</groupId>
124124
<artifactId>ld-signatures-java</artifactId>
125125
<version>0.3-SNAPSHOT</version>
126-
<scope>compile</scope>
127126
</dependency>
128127
<dependency>
129128
<groupId>com.nimbusds</groupId>
130129
<artifactId>nimbus-jose-jwt</artifactId>
131-
<version>8.14.1</version>
132-
<scope>compile</scope>
130+
<version>9.0.1</version>
131+
</dependency>
132+
<dependency>
133+
<groupId>com.fasterxml.jackson.core</groupId>
134+
<artifactId>jackson-databind</artifactId>
135+
<version>2.11.1</version>
133136
</dependency>
134-
<!-- <dependency>
135-
<groupId>org.slf4j</groupId>
136-
<artifactId>slf4j-nop</artifactId>
137-
<version>1.7.25</version>
138-
<scope>compile</scope>
139-
</dependency> -->
140137
</dependencies>
141138

142139
</project>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.danubetech.verifiablecredentials;
2+
3+
4+
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
5+
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
6+
import foundation.identity.jsonld.JsonLDKeywords;
7+
import foundation.identity.jsonld.JsonLDObject;
8+
import foundation.identity.jsonld.JsonLDUtils;
9+
import info.weboftrust.ldsignatures.LdProof;
10+
import info.weboftrust.ldsignatures.jsonld.LDSecurityContexts;
11+
import info.weboftrust.ldsignatures.jsonld.LDSecurityKeywords;
12+
13+
import javax.json.JsonObject;
14+
import javax.json.JsonValue;
15+
import java.io.Reader;
16+
import java.net.URI;
17+
import java.util.HashMap;
18+
import java.util.LinkedHashMap;
19+
import java.util.Map;
20+
21+
public class CredentialSubject extends JsonLDObject {
22+
23+
public static final URI[] DEFAULT_JSONLD_CONTEXTS = { VerifiableCredentialContexts.JSONLD_CONTEXT_W3C_2018_CREDENTIALS_V1 };
24+
public static final String[] DEFAULT_JSONLD_TYPES = { };
25+
public static final String DEFAULT_JSONLD_PREDICATE = VerifiableCredentialKeywords.JSONLD_TERM_CREDENTIALSUBJECT;
26+
27+
private CredentialSubject() {
28+
super(VerifiableCredentialContexts.DOCUMENT_LOADER);
29+
}
30+
31+
public CredentialSubject(JsonObject jsonObject) {
32+
super(VerifiableCredentialContexts.DOCUMENT_LOADER, jsonObject);
33+
}
34+
35+
/*
36+
* Factory methods
37+
*/
38+
39+
public static class Builder extends JsonLDObject.Builder<Builder, CredentialSubject> {
40+
41+
private Map<String, JsonValue> claims;
42+
43+
public Builder(CredentialSubject jsonLDObject) {
44+
super(jsonLDObject);
45+
}
46+
47+
@Override
48+
public CredentialSubject build() {
49+
50+
super.build();
51+
52+
// add JSON-LD properties
53+
if (this.claims != null) JsonLDUtils.jsonLdAddAllJsonValueMap(this.jsonLDObject, this.claims);
54+
55+
return this.jsonLDObject;
56+
}
57+
58+
public Builder claims(Map<String, JsonValue> claims) {
59+
this.claims = claims;
60+
return this;
61+
}
62+
}
63+
64+
public static Builder builder() {
65+
return new Builder(new CredentialSubject());
66+
}
67+
68+
/*
69+
* Reading the JSON-LD object
70+
*/
71+
72+
public static CredentialSubject fromJson(Reader reader) {
73+
return JsonLDObject.fromJson(CredentialSubject.class, reader);
74+
}
75+
76+
public static CredentialSubject fromJson(String json) {
77+
return JsonLDObject.fromJson(CredentialSubject.class, json);
78+
}
79+
80+
/*
81+
* Adding, getting, and removing the JSON-LD object
82+
*/
83+
84+
public static CredentialSubject getFromJsonLDObject(JsonLDObject jsonLdObject) {
85+
return JsonLDObject.getFromJsonLDObject(CredentialSubject.class, jsonLdObject);
86+
}
87+
88+
public static void removeFromJsonLdObject(JsonLDObject jsonLdObject) {
89+
JsonLDObject.removeFromJsonLdObject(CredentialSubject.class, jsonLdObject);
90+
}
91+
92+
/*
93+
* Getters
94+
*/
95+
96+
public Map<String, JsonValue> getClaims() {
97+
Map<String, JsonValue> claims = new LinkedHashMap<>(JsonLDUtils.jsonLdGetAsJsonValueMap(this.getJsonObject()));
98+
claims.remove(JsonLDKeywords.JSONLD_TERM_ID);
99+
return claims;
100+
}
101+
}

0 commit comments

Comments
 (0)