Skip to content

Commit 944a88f

Browse files
committed
Add more json-ld-patch tests
1 parent 7159410 commit 944a88f

File tree

7 files changed

+122
-3
lines changed

7 files changed

+122
-3
lines changed

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,48 @@
2424
public class DidBtc1PatchTest {
2525

2626
@Test
27-
public void testPatch() throws JsonLDException, GeneralSecurityException, IOException {
27+
public void testPatch1() throws JsonLDException, GeneralSecurityException, IOException {
2828

29-
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(DidBtc1PatchTest.class.getResourceAsStream("did-btc1-patch.jsonld"))));
29+
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(DidBtc1PatchTest.class.getResourceAsStream("did-btc1-patch.1.jsonld"))));
3030
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);
3131

32-
JsonLDObject verificationMethod = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(DidBtc1PatchTest.class.getResourceAsStream("did-btc1-patch.verification-method.jsonld"))));
32+
JsonLDObject verificationMethod = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(DidBtc1PatchTest.class.getResourceAsStream("did-btc1-patch.verification-method.1.jsonld"))));
33+
String publicKeyMultibase = (String) verificationMethod.getJsonObject().get("publicKeyMultibase");
34+
byte[] publicKeyBytes = Arrays.copyOfRange(Multibase.decode(publicKeyMultibase), 2, 35);
35+
ECKey publicKey = PublicKeyBytes.bytes_to_secp256k1PublicKey(publicKeyBytes);
36+
37+
PublicKeyVerifier<?> publicKeyVerifier = PublicKeyVerifierFactory.publicKeyVerifierForKey(KeyTypeName.secp256k1, JWSAlgorithm.ES256KS, publicKey);
38+
DataIntegrityProofLdVerifier verifier = new DataIntegrityProofLdVerifier(publicKeyVerifier);
39+
boolean verify = verifier.verify(jsonLdObject);
40+
41+
assertTrue(verify);
42+
}
43+
44+
@Test
45+
public void testPatch2() throws JsonLDException, GeneralSecurityException, IOException {
46+
47+
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(DidBtc1PatchTest.class.getResourceAsStream("did-btc1-patch.2.jsonld"))));
48+
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);
49+
50+
JsonLDObject verificationMethod = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(DidBtc1PatchTest.class.getResourceAsStream("did-btc1-patch.verification-method.2.jsonld"))));
51+
String publicKeyMultibase = (String) verificationMethod.getJsonObject().get("publicKeyMultibase");
52+
byte[] publicKeyBytes = Arrays.copyOfRange(Multibase.decode(publicKeyMultibase), 2, 35);
53+
ECKey publicKey = PublicKeyBytes.bytes_to_secp256k1PublicKey(publicKeyBytes);
54+
55+
PublicKeyVerifier<?> publicKeyVerifier = PublicKeyVerifierFactory.publicKeyVerifierForKey(KeyTypeName.secp256k1, JWSAlgorithm.ES256KS, publicKey);
56+
DataIntegrityProofLdVerifier verifier = new DataIntegrityProofLdVerifier(publicKeyVerifier);
57+
boolean verify = verifier.verify(jsonLdObject);
58+
59+
assertTrue(verify);
60+
}
61+
62+
@Test
63+
public void testPatch3() throws JsonLDException, GeneralSecurityException, IOException {
64+
65+
JsonLDObject jsonLdObject = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(DidBtc1PatchTest.class.getResourceAsStream("did-btc1-patch.3.jsonld"))));
66+
jsonLdObject.setDocumentLoader(DataIntegrityContexts.DOCUMENT_LOADER);
67+
68+
JsonLDObject verificationMethod = JsonLDObject.fromJson(new InputStreamReader(Objects.requireNonNull(DidBtc1PatchTest.class.getResourceAsStream("did-btc1-patch.verification-method.3.jsonld"))));
3369
String publicKeyMultibase = (String) verificationMethod.getJsonObject().get("publicKeyMultibase");
3470
byte[] publicKeyBytes = Arrays.copyOfRange(Multibase.decode(publicKeyMultibase), 2, 35);
3571
ECKey publicKey = PublicKeyBytes.bytes_to_secp256k1PublicKey(publicKeyBytes);

src/test/resources/com/danubetech/dataintegrity/did-btc1-patch.jsonld renamed to src/test/resources/com/danubetech/dataintegrity/did-btc1-patch.1.jsonld

File renamed without changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"@context": [
3+
"https://w3id.org/security/v2",
4+
"https://w3id.org/zcap/v1",
5+
"https://w3id.org/json-ld-patch/v1"
6+
],
7+
"patch": [
8+
{
9+
"op": "add",
10+
"path": "/service/3",
11+
"value": {
12+
"id": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54#service-3",
13+
"type": "SingletonBeacon",
14+
"serviceEndpoint": "bitcoin:bcrt1qmj7rad0en0tjsvtgdry4nmgyu98wkvne5ecw0e"
15+
}
16+
}
17+
],
18+
"sourceHash": "6QWx7ozFnaQT9Ho66MqsJG9BF6snseYXRGNQNv44BxcW",
19+
"targetHash": "4zLUMPm47vrp5DZ42gN2QcQr4pprFA3uswx3zns5iBuc",
20+
"targetVersionId": 2,
21+
"proof": {
22+
"type": "DataIntegrityProof",
23+
"cryptosuite": "bip340-jcs-2025",
24+
"verificationMethod": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54#initialKey",
25+
"proofPurpose": "capabilityInvocation",
26+
"capability": "urn:zcap:root:did%3Abtc1%3Ak1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54",
27+
"capabilityAction": "Write",
28+
"@context": [
29+
"https://w3id.org/security/v2",
30+
"https://w3id.org/zcap/v1",
31+
"https://w3id.org/json-ld-patch/v1"
32+
],
33+
"proofValue": "z2nWY2KijLu1hfaGSSjwNFtMV256myt2etfXUpB6Wgt7UKepgmCMSuUxGunV1Rir2xAVcLxfkfmSt6rGm5zTMTy3w"
34+
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"@context": [
3+
"https://w3id.org/security/v2",
4+
"https://w3id.org/zcap/v1",
5+
"https://w3id.org/json-ld-patch/v1"
6+
],
7+
"patch": [
8+
{
9+
"op": "add",
10+
"path": "/verificationMethod/1",
11+
"value": {
12+
"id": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54#key-1",
13+
"type": "Multikey",
14+
"controller": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54",
15+
"publicKeyMultibase": "zQ3shoxRij8DaCaAn2hfuZrkKgrWKAL8dC8yvUJY1tjDp5HL5"
16+
}
17+
}
18+
],
19+
"sourceHash": "4zLUMPm47vrp5DZ42gN2QcQr4pprFA3uswx3zns5iBuc",
20+
"targetHash": "EoJa8o4VJzybm68pYesiTuBMarwaLkYoT1fTSWiZedtX",
21+
"targetVersionId": 3,
22+
"proof": {
23+
"type": "DataIntegrityProof",
24+
"cryptosuite": "bip340-jcs-2025",
25+
"verificationMethod": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54#initialKey",
26+
"proofPurpose": "capabilityInvocation",
27+
"capability": "urn:zcap:root:did%3Abtc1%3Ak1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54",
28+
"capabilityAction": "Write",
29+
"@context": [
30+
"https://w3id.org/security/v2",
31+
"https://w3id.org/zcap/v1",
32+
"https://w3id.org/json-ld-patch/v1"
33+
],
34+
"proofValue": "z5iSt7bBZscy8BZ2LNU6Jm4DwAQArXksFroQwxX8vFKdkgeEYTW4BQR7WWEZX8Q7wE15D3m8GXQr7jEE7LYqmgoty"
35+
}
36+
}

src/test/resources/com/danubetech/dataintegrity/did-btc1-patch.verification-method.jsonld renamed to src/test/resources/com/danubetech/dataintegrity/did-btc1-patch.verification-method.1.jsonld

File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54#initialKey",
3+
"type": "Multikey",
4+
"controller": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54",
5+
"publicKeyMultibase": "zQ3shf8sfBZB9DWwG2Qkc5vhmruKMWbQsS8gRhezr5axytxv6"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54#initialKey",
3+
"type": "Multikey",
4+
"controller": "did:btc1:k1qgpswh5adnhrvk9vpppgcx08k4eek75c52dr9pcvu2zt5zgakartekc4uzg54",
5+
"publicKeyMultibase": "zQ3shf8sfBZB9DWwG2Qkc5vhmruKMWbQsS8gRhezr5axytxv6"
6+
}

0 commit comments

Comments
 (0)