Update IronTests.java
This commit is contained in:
parent
7c7d283530
commit
ef74f679fc
@ -1,13 +1,17 @@
|
|||||||
package org.oneedtech.inspect.vc;
|
package org.oneedtech.inspect.vc;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.apicatalog.did.key.DidKey;
|
||||||
import com.apicatalog.ld.signature.ed25519.Ed25519Proof2020Adapter;
|
import com.apicatalog.ld.signature.ed25519.Ed25519Proof2020Adapter;
|
||||||
import com.apicatalog.ld.signature.key.KeyPair;
|
import com.apicatalog.ld.signature.key.KeyPair;
|
||||||
import com.apicatalog.ld.signature.proof.ProofOptions;
|
import com.apicatalog.ld.signature.proof.ProofOptions;
|
||||||
@ -15,7 +19,11 @@ import com.apicatalog.ld.signature.proof.VerificationMethod;
|
|||||||
import com.apicatalog.vc.Vc;
|
import com.apicatalog.vc.Vc;
|
||||||
import com.apicatalog.vc.processor.Issuer;
|
import com.apicatalog.vc.processor.Issuer;
|
||||||
|
|
||||||
|
import jakarta.json.Json;
|
||||||
import jakarta.json.JsonObject;
|
import jakarta.json.JsonObject;
|
||||||
|
import jakarta.json.JsonWriter;
|
||||||
|
import jakarta.json.JsonWriterFactory;
|
||||||
|
import jakarta.json.stream.JsonGenerator;
|
||||||
|
|
||||||
public class IronTests {
|
public class IronTests {
|
||||||
|
|
||||||
@ -23,25 +31,30 @@ public class IronTests {
|
|||||||
@Test
|
@Test
|
||||||
void testOb_01() {
|
void testOb_01() {
|
||||||
Assertions.assertDoesNotThrow(()->{
|
Assertions.assertDoesNotThrow(()->{
|
||||||
|
|
||||||
|
|
||||||
|
final DidKey didKey = DidKey.from(URI.create("did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH"));
|
||||||
|
|
||||||
|
//https://w3id.org/security#Ed25519KeyPair2020
|
||||||
|
//https://w3id.org/security#Ed25519Signature2020
|
||||||
URI unsigned = Samples.OB30.JSON.SIMPLE_JSON_NOPROOF.asURL().toURI();
|
URI unsigned = Samples.OB30.JSON.SIMPLE_JSON_NOPROOF.asURL().toURI();
|
||||||
KeyPair kp = Vc.generateKeys("https://w3id.org/security#Ed25519Signature2020").get(URI.create("urn:1"), 256);
|
KeyPair kp = Vc.generateKeys("https://w3id.org/security#Ed25519Signature2020").get(URI.create("urn:1"), 256);
|
||||||
ProofOptions options = ProofOptions.create(
|
ProofOptions options = ProofOptions.create(
|
||||||
Ed25519Proof2020Adapter.TYPE,
|
Ed25519Proof2020Adapter.TYPE,
|
||||||
new VerificationMethod(URI.create("did:key:z6MkkUD3J14nkYzn46QeuaVSnp7dF85QJKwKvJvfsjx79aXj")),
|
//new VerificationMethod(URI.create("did:key:z6MkkUD3J14nkYzn46QeuaVSnp7dF85QJKwKvJvfsjx79aXj")),
|
||||||
|
new VerificationMethod(didKey.toUri()),
|
||||||
URI.create("https://w3id.org/security#assertionMethod")).created(Instant.now().truncatedTo(ChronoUnit.SECONDS));
|
URI.create("https://w3id.org/security#assertionMethod")).created(Instant.now().truncatedTo(ChronoUnit.SECONDS));
|
||||||
|
|
||||||
Issuer issuer = Vc.sign(unsigned, kp, options);
|
Issuer issuer = Vc.sign(unsigned, kp, options);
|
||||||
JsonObject signed = issuer.getCompacted();
|
System.err.println(pretty(issuer.getCompacted()));
|
||||||
JsonObject proof = signed.getJsonObject("sec:proof");
|
JsonObject signed = issuer.getCompacted();
|
||||||
|
JsonObject proof = signed.getJsonObject("sec:proof");
|
||||||
Assertions.assertNotNull(proof);
|
Assertions.assertNotNull(proof);
|
||||||
|
|
||||||
System.err.println (issuer.getCompacted().toString());
|
|
||||||
|
|
||||||
Vc.verify(issuer.getCompacted()).isValid();
|
Vc.verify(issuer.getCompacted()).isValid();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
void testClr_01() {
|
void testClr_01() {
|
||||||
@ -56,9 +69,20 @@ public class IronTests {
|
|||||||
Issuer issuer = Vc.sign(unsigned, kp, options);
|
Issuer issuer = Vc.sign(unsigned, kp, options);
|
||||||
JsonObject job = issuer.getCompacted().getJsonObject("sec:proof");
|
JsonObject job = issuer.getCompacted().getJsonObject("sec:proof");
|
||||||
|
|
||||||
//System.err.println (issuer.getCompacted().toString());
|
//System.err.println (pretty(issuer.getCompacted().toString()));
|
||||||
Assertions.assertNotNull(job);
|
Assertions.assertNotNull(job);
|
||||||
Vc.verify(issuer.getCompacted()).isValid();
|
Vc.verify(issuer.getCompacted()).isValid();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String pretty(JsonObject jobj) {
|
||||||
|
Map<String, Object> properties = new HashMap<>(1);
|
||||||
|
properties.put(JsonGenerator.PRETTY_PRINTING, true);
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
JsonWriterFactory writerFactory = Json.createWriterFactory(properties);
|
||||||
|
JsonWriter jsonWriter = writerFactory.createWriter(sw);
|
||||||
|
jsonWriter.writeObject(jobj);
|
||||||
|
jsonWriter.close();
|
||||||
|
return sw.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user