Skip to content

Commit cd883df

Browse files
committed
doc: Add example for VP with LD proof.
1 parent e2f661a commit cd883df

File tree

4 files changed

+110
-39
lines changed

4 files changed

+110
-39
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Dependency:
2626
## Examples
2727

2828
* [examples-ldp.md](examples-ldp.md) - Examples of Verifiable Credentials with Linked Data Proofs
29+
* [examples-ldp-vp.md](examples-ldp-vp.md) - Examples of Verifiable Presentations with Linked Data Proofs
2930
* [examples-jwt.md](examples-jwt.md) - Examples of Verifiable Credentials with JSON Web Tokens
3031
* [examples-jwt-vp.md](examples-jwt-vp.md) - Examples of Verifiable Presentations with JSON Web Tokens
3132

examples-jwt-vp.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,41 @@ JWT Payload:
2424

2525
### Example code (signing)
2626

27-
Map<String, Object> claims = new LinkedHashMap<>();
28-
Map<String, Object> degree = new LinkedHashMap<String, Object>();
29-
degree.put("name", "Bachelor of Science and Arts");
30-
degree.put("type", "BachelorDegree");
31-
claims.put("college", "Test University");
32-
claims.put("degree", degree);
33-
34-
CredentialSubject credentialSubject = CredentialSubject.builder()
35-
.id(URI.create("did:example:ebfeb1f712ebc6f1c276e12ec21"))
36-
.claims(claims)
37-
.build();
38-
39-
VerifiableCredential verifiableCredential = VerifiableCredential.builder()
40-
.context(VerifiableCredentialContexts.JSONLD_CONTEXT_W3C_2018_CREDENTIALS_EXAMPLES_V1)
41-
.type("UniversityDegreeCredential")
42-
.id(URI.create("http://example.edu/credentials/3732"))
43-
.issuer(URI.create("did:example:76e12ec712ebc6f1c221ebfeb1f"))
44-
.issuanceDate(JsonLDUtils.stringToDate("2019-06-16T18:56:59Z"))
45-
.expirationDate(JsonLDUtils.stringToDate("2019-06-17T18:56:59Z"))
46-
.credentialSubject(credentialSubject)
47-
.build();
48-
49-
byte[] testEd25519PrivateKey = Hex.decodeHex("984b589e121040156838303f107e13150be4a80fc5088ccba0b0bdc9b1d89090de8777a28f8da1a74e7a13090ed974d879bf692d001cddee16e4cc9f84b60580".toCharArray());
50-
51-
JwtVerifiableCredential jwtVerifiableCredential = ToJwtConverter.toJwtVerifiableCredential(verifiableCredential);
52-
53-
String jwtPayload = jwtVerifiableCredential.getPayload().toString();
54-
System.out.println(jwtPayload);
55-
56-
String jwtString = jwtVerifiableCredential.sign_Ed25519_EdDSA(testEd25519PrivateKey);
57-
System.out.println(jwtString);
58-
59-
JwtVerifiablePresentation jwtVerifiablePresentation = JwtVerifiablePresentation.fromJwtVerifiableCredential(jwtVerifiableCredential);
60-
String jwtPayload2 = jwtVerifiablePresentation.getPayload().toString();
61-
System.out.println(jwtPayload2);
62-
63-
String jwtString2 = jwtVerifiablePresentation.sign_Ed25519_EdDSA(testEd25519PrivateKey);
64-
System.out.println(jwtString2);
27+
Map<String, Object> claims = new LinkedHashMap<>();
28+
Map<String, Object> degree = new LinkedHashMap<String, Object>();
29+
degree.put("name", "Bachelor of Science and Arts");
30+
degree.put("type", "BachelorDegree");
31+
claims.put("college", "Test University");
32+
claims.put("degree", degree);
33+
34+
CredentialSubject credentialSubject = CredentialSubject.builder()
35+
.id(URI.create("did:example:ebfeb1f712ebc6f1c276e12ec21"))
36+
.claims(claims)
37+
.build();
38+
39+
VerifiableCredential verifiableCredential = VerifiableCredential.builder()
40+
.context(VerifiableCredentialContexts.JSONLD_CONTEXT_W3C_2018_CREDENTIALS_EXAMPLES_V1)
41+
.type("UniversityDegreeCredential")
42+
.id(URI.create("http://example.edu/credentials/3732"))
43+
.issuer(URI.create("did:example:76e12ec712ebc6f1c221ebfeb1f"))
44+
.issuanceDate(JsonLDUtils.stringToDate("2019-06-16T18:56:59Z"))
45+
.expirationDate(JsonLDUtils.stringToDate("2019-06-17T18:56:59Z"))
46+
.credentialSubject(credentialSubject)
47+
.build();
48+
49+
byte[] testEd25519PrivateKey = Hex.decodeHex("984b589e121040156838303f107e13150be4a80fc5088ccba0b0bdc9b1d89090de8777a28f8da1a74e7a13090ed974d879bf692d001cddee16e4cc9f84b60580".toCharArray());
50+
51+
JwtVerifiableCredential jwtVerifiableCredential = ToJwtConverter.toJwtVerifiableCredential(verifiableCredential);
52+
53+
String jwtPayload = jwtVerifiableCredential.getPayload().toString();
54+
System.out.println(jwtPayload);
55+
56+
String jwtString = jwtVerifiableCredential.sign_Ed25519_EdDSA(testEd25519PrivateKey);
57+
System.out.println(jwtString);
58+
59+
JwtVerifiablePresentation jwtVerifiablePresentation = JwtVerifiablePresentation.fromJwtVerifiableCredential(jwtVerifiableCredential);
60+
String jwtPayload2 = jwtVerifiablePresentation.getPayload().toString();
61+
System.out.println(jwtPayload2);
62+
63+
String jwtString2 = jwtVerifiablePresentation.sign_Ed25519_EdDSA(testEd25519PrivateKey);
64+
System.out.println(jwtString2);

examples-ldp-vp.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## Examples
2+
3+
Verifiable Presentations with Linked Data Proofs:
4+
5+
### Example Verifiable Presentation
6+
7+
{
8+
"@context" : [ "https://www.w3.org/2018/credentials/v1" ],
9+
"type" : [ "VerifiablePresentation" ],
10+
"holder" : "did:key:z6MkwBZ6oiJ71ovCohPfdsgBrQinMXnFn6wJxVZHpZEpSh8x",
11+
"verifiableCredential" : {
12+
"@context" : [ "https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1" ],
13+
"type" : [ "VerifiableCredential", "UniversityDegreeCredential" ],
14+
"id" : "http://example.edu/credentials/3732",
15+
"issuer" : "did:example:76e12ec712ebc6f1c221ebfeb1f",
16+
"issuanceDate" : "2019-06-16T18:56:59Z",
17+
"expirationDate" : "2019-06-17T18:56:59Z",
18+
"credentialSubject" : {
19+
"id" : "did:example:ebfeb1f712ebc6f1c276e12ec21",
20+
"college" : "Test University",
21+
"degree" : {
22+
"name" : "Bachelor of Science and Arts",
23+
"type" : "BachelorDegree"
24+
}
25+
},
26+
"proof" : {
27+
"type" : "Ed25519Signature2018",
28+
"created" : "2021-11-17T22:43:04Z",
29+
"proofPurpose" : "assertionMethod",
30+
"verificationMethod" : "did:example:76e12ec712ebc6f1c221ebfeb1f#keys-1",
31+
"jws" : "eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJhbGciOiJFZERTQSJ9..jbhZsH1jylvuZLov502qhTRkYvgbepU8ds8Mbgf4X7dhVp8F1P89Ql5WMA2DQEJxMGsVlaT8plfSY0JUw6XmDg"
32+
}
33+
},
34+
"proof" : {
35+
"type" : "Ed25519Signature2018",
36+
"created" : "2021-11-17T22:43:05Z",
37+
"domain" : "example.com",
38+
"nonce" : "343s$FSFDa-",
39+
"proofPurpose" : "assertionMethod",
40+
"verificationMethod" : "did:key:z6MkwBZ6oiJ71ovCohPfdsgBrQinMXnFn6wJxVZHpZEpSh8x#z6MkwBZ6oiJ71ovCohPfdsgBrQinMXnFn6wJxVZHpZEpSh8x",
41+
"jws" : "eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJhbGciOiJFZERTQSJ9..D9T1iZ6bF_do_xFhYWjb3HVicP0NvpaKrBrE6K8ZpReEE1UUj5iV6prkj81bilovcRZ9FZpVmq_Gq3mDfIfnBg"
42+
}
43+
}
44+
45+
### Example code (signing)
46+
47+
VerifiablePresentation verifiablePresentation = VerifiablePresentation.builder()
48+
.verifiableCredential(verifiableCredential)
49+
.build();
50+
51+
byte[] testEd25519PrivateKey2 = Hex.decodeHex("984b589e121040156838303f107e13150be4a80fc5088ccba0b0bdc9b1d89090de8777a28f8da1a74e7a13090ed974d879bf692d001cddee16e4cc9f84b60580".toCharArray());
52+
53+
Ed25519Signature2018LdSigner signer2 = new Ed25519Signature2018LdSigner(testEd25519PrivateKey2);
54+
signer2.setCreated(new Date());
55+
signer2.setProofPurpose(LDSecurityKeywords.JSONLD_TERM_ASSERTIONMETHOD);
56+
signer2.setVerificationMethod(URI.create("did:example:45678#keys-1"));
57+
signer2.setDomain("example.com");
58+
signer2.setNonce("343s$FSFDa-");
59+
LdProof ldProof2 = signer2.sign(verifiablePresentation);
60+
61+
System.out.println(verifiablePresentation.toJson(true));
62+
63+
### Example code (verifying)
64+
65+
byte[] testEd25519PublicKey = Hex.decodeHex("f890ab605908a65b89b926fba3b540c0132ce147e3dc5da9fbe7f1445d7279e5".toCharArray());
66+
67+
VerifiablePresentation verifiablePresentation = VerifiablePresentation.fromJson(new FileReader("input.jsonld"));
68+
Ed25519Signature2018LdVerifier verifier = new Ed25519Signature2018LdVerifier(testEd25519PublicKey);
69+
System.out.println(verifier.verify(verifiablePresentation));

examples-ldp.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Verifiable Credentials with Linked Data Proofs:
44

55
### Example Verifiable Credential
6+
67
{
78
"@context" : [ "https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1" ],
89
"type" : [ "VerifiableCredential", "UniversityDegreeCredential" ],
@@ -66,7 +67,7 @@ Process finished with exit code 0
6667
### Example code (verifying)
6768

6869
byte[] testEd25519PublicKey = Hex.decodeHex("de8777a28f8da1a74e7a13090ed974d879bf692d001cddee16e4cc9f84b60580".toCharArray());
69-
70+
7071
VerifiableCredential verifiableCredential = VerifiableCredential.fromJson(new FileReader("input.jsonld"));
7172
Ed25519Signature2018LdVerifier verifier = new Ed25519Signature2018LdVerifier(testEd25519PublicKey);
7273
System.out.println(verifier.verify(verifiableCredential));

0 commit comments

Comments
 (0)