Skip to content

Commit a60feac

Browse files
committed
Add more ecdsa tests
1 parent 662fa2c commit a60feac

6 files changed

+72
-9
lines changed

src/test/java/com/danubetech/dataintegrity/JsonLdSignDataIntegrityProof_bip340_jcs_2025_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void before() {
4141

4242
@Test
4343
@SuppressWarnings("unchecked")
44-
public void testSign() throws Throwable {
44+
public void testSignSecp256k1() throws Throwable {
4545

4646
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(JsonLdSignDataIntegrityProof_bip340_jcs_2025_Test.class.getResourceAsStream("input.jsonld"))));
4747
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);

src/test/java/com/danubetech/dataintegrity/JsonLdSignDataIntegrityProof_bip340_rdfc_2025_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void before() {
4141

4242
@Test
4343
@SuppressWarnings("unchecked")
44-
public void testSign() throws Throwable {
44+
public void testSignSecp256k1() throws Throwable {
4545

4646
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(JsonLdSignDataIntegrityProof_bip340_rdfc_2025_Test.class.getResourceAsStream("input.jsonld"))));
4747
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);

src/test/java/com/danubetech/dataintegrity/JsonLdSignDataIntegrityProof_ecdsa_jcs_2019_Test.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.danubetech.dataintegrity.signer.DataIntegrityProofLdSigner;
55
import com.danubetech.dataintegrity.suites.DataIntegritySuites;
66
import com.danubetech.dataintegrity.util.TestKeys;
7-
import com.danubetech.dataintegrity.util.TestUtil;
87
import com.danubetech.dataintegrity.verifier.DataIntegrityProofLdVerifier;
98
import com.danubetech.keyformats.crypto.PrivateKeySigner;
109
import com.danubetech.keyformats.crypto.PrivateKeySignerFactory;
@@ -42,7 +41,7 @@ public void before() {
4241

4342
@Test
4443
@SuppressWarnings("unchecked")
45-
public void testSign() throws Throwable {
44+
public void testSignSecp256k1() throws Throwable {
4645

4746
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(JsonLdSignDataIntegrityProof_ecdsa_jcs_2019_Test.class.getResourceAsStream("input.jsonld"))));
4847
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);
@@ -73,4 +72,37 @@ public void testSign() throws Throwable {
7372
boolean verify = verifier.verify(jsonLdObject, dataIntegrityProof);
7473
assertTrue(verify);
7574
}
75+
76+
@Test
77+
@SuppressWarnings("unchecked")
78+
public void testSignP256() throws Throwable {
79+
80+
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(JsonLdSignDataIntegrityProof_ecdsa_jcs_2019_Test.class.getResourceAsStream("input.jsonld"))));
81+
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);
82+
83+
Date created = JsonLDUtils.DATE_FORMAT.parse("2017-10-24T05:33:31Z");
84+
Date expires = JsonLDUtils.DATE_FORMAT.parse("2027-10-24T05:33:31Z");
85+
String domain = "example.com";
86+
String nonce = null;
87+
88+
PrivateKeySigner<?> privateKeySigner = PrivateKeySignerFactory.privateKeySignerForKey(KeyTypeName.P_256, JWSAlgorithm.ES256, TestKeys.testP256PrivateKey);
89+
DataIntegrityProofLdSigner signer = new DataIntegrityProofLdSigner(privateKeySigner);
90+
signer.setCryptosuite("ecdsa-jcs-2019");
91+
signer.setCreated(created);
92+
signer.setExpires(expires);
93+
signer.setDomain(domain);
94+
signer.setNonce(nonce);
95+
DataIntegrityProof dataIntegrityProof = signer.sign(jsonLdObject);
96+
97+
assertEquals(DataIntegritySuites.DATA_INTEGRITY_SUITE_DATAINTEGRITYPROOF.getTerm(), dataIntegrityProof.getType());
98+
assertEquals(created, dataIntegrityProof.getCreated());
99+
assertEquals(expires, dataIntegrityProof.getExpires());
100+
assertEquals(domain, dataIntegrityProof.getDomain());
101+
assertEquals(nonce, dataIntegrityProof.getNonce());
102+
103+
PublicKeyVerifier<?> publicKeyVerifier = PublicKeyVerifierFactory.publicKeyVerifierForKey(KeyTypeName.P_256, JWSAlgorithm.ES256, TestKeys.testP256PublicKey);
104+
DataIntegrityProofLdVerifier verifier = new DataIntegrityProofLdVerifier(publicKeyVerifier);
105+
boolean verify = verifier.verify(jsonLdObject, dataIntegrityProof);
106+
assertTrue(verify);
107+
}
76108
}

src/test/java/com/danubetech/dataintegrity/JsonLdSignDataIntegrityProof_ecdsa_rdfc_2019_Test.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void before() {
4141

4242
@Test
4343
@SuppressWarnings("unchecked")
44-
public void testSign() throws Throwable {
44+
public void testSignSecp256k1() throws Throwable {
4545

4646
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(JsonLdSignDataIntegrityProof_ecdsa_rdfc_2019_Test.class.getResourceAsStream("input.jsonld"))));
4747
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);
@@ -72,4 +72,37 @@ public void testSign() throws Throwable {
7272
boolean verify = verifier.verify(jsonLdObject, dataIntegrityProof);
7373
assertTrue(verify);
7474
}
75+
76+
@Test
77+
@SuppressWarnings("unchecked")
78+
public void testSignP256() throws Throwable {
79+
80+
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(JsonLdSignDataIntegrityProof_ecdsa_rdfc_2019_Test.class.getResourceAsStream("input.jsonld"))));
81+
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);
82+
83+
Date created = JsonLDUtils.DATE_FORMAT.parse("2017-10-24T05:33:31Z");
84+
Date expires = JsonLDUtils.DATE_FORMAT.parse("2027-10-24T05:33:31Z");
85+
String domain = "example.com";
86+
String nonce = null;
87+
88+
PrivateKeySigner<?> privateKeySigner = PrivateKeySignerFactory.privateKeySignerForKey(KeyTypeName.P_256, JWSAlgorithm.ES256, TestKeys.testP256PrivateKey);
89+
DataIntegrityProofLdSigner signer = new DataIntegrityProofLdSigner(privateKeySigner);
90+
signer.setCryptosuite("ecdsa-rdfc-2019");
91+
signer.setCreated(created);
92+
signer.setExpires(expires);
93+
signer.setDomain(domain);
94+
signer.setNonce(nonce);
95+
DataIntegrityProof dataIntegrityProof = signer.sign(jsonLdObject);
96+
97+
assertEquals(DataIntegritySuites.DATA_INTEGRITY_SUITE_DATAINTEGRITYPROOF.getTerm(), dataIntegrityProof.getType());
98+
assertEquals(created, dataIntegrityProof.getCreated());
99+
assertEquals(expires, dataIntegrityProof.getExpires());
100+
assertEquals(domain, dataIntegrityProof.getDomain());
101+
assertEquals(nonce, dataIntegrityProof.getNonce());
102+
103+
PublicKeyVerifier<?> publicKeyVerifier = PublicKeyVerifierFactory.publicKeyVerifierForKey(KeyTypeName.P_256, JWSAlgorithm.ES256, TestKeys.testP256PublicKey);
104+
DataIntegrityProofLdVerifier verifier = new DataIntegrityProofLdVerifier(publicKeyVerifier);
105+
boolean verify = verifier.verify(jsonLdObject, dataIntegrityProof);
106+
assertTrue(verify);
107+
}
75108
}

src/test/java/com/danubetech/dataintegrity/JsonLdSignDataIntegrityProof_eddsa_jcs_2022_Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.danubetech.dataintegrity.signer.DataIntegrityProofLdSigner;
55
import com.danubetech.dataintegrity.suites.DataIntegritySuites;
66
import com.danubetech.dataintegrity.util.TestKeys;
7-
import com.danubetech.dataintegrity.util.TestUtil;
87
import com.danubetech.dataintegrity.verifier.DataIntegrityProofLdVerifier;
98
import com.danubetech.keyformats.crypto.PrivateKeySigner;
109
import com.danubetech.keyformats.crypto.PrivateKeySignerFactory;
@@ -42,7 +41,7 @@ public void before() {
4241

4342
@Test
4443
@SuppressWarnings("unchecked")
45-
public void testSign() throws Throwable {
44+
public void testSignEd25519() throws Throwable {
4645

4746
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(JsonLdSignDataIntegrityProof_eddsa_jcs_2022_Test.class.getResourceAsStream("input.jsonld"))));
4847
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);

src/test/java/com/danubetech/dataintegrity/JsonLdSignDataIntegrityProof_eddsa_rdfc_2022_Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.danubetech.dataintegrity.signer.DataIntegrityProofLdSigner;
55
import com.danubetech.dataintegrity.suites.DataIntegritySuites;
66
import com.danubetech.dataintegrity.util.TestKeys;
7-
import com.danubetech.dataintegrity.util.TestUtil;
87
import com.danubetech.dataintegrity.verifier.DataIntegrityProofLdVerifier;
98
import com.danubetech.keyformats.crypto.PrivateKeySigner;
109
import com.danubetech.keyformats.crypto.PrivateKeySignerFactory;
@@ -42,7 +41,7 @@ public void before() {
4241

4342
@Test
4443
@SuppressWarnings("unchecked")
45-
public void testSign() throws Throwable {
44+
public void testSignEd25519() throws Throwable {
4645

4746
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(JsonLdSignDataIntegrityProof_eddsa_rdfc_2022_Test.class.getResourceAsStream("input.jsonld"))));
4847
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);

0 commit comments

Comments
 (0)