Skip to content

Commit 833098c

Browse files
committed
fix: Don't preserve contexts when constructing proof options
1 parent 58ec1e6 commit 833098c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/main/java/com/danubetech/dataintegrity/signer/LdSigner.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,17 @@ public DataIntegrityProof sign(JsonLDObject jsonLdObject, boolean addToJsonLdObj
104104

105105
this.loadMissingContext(jsonLdObject);
106106

107-
// add LD contexts to LD proof options if missing
107+
// construct LD proof options
108108

109-
if (dataIntegrityProof.getContexts() == null || dataIntegrityProof.getContexts().isEmpty()) {
110-
JsonLDUtils.jsonLdAdd(dataIntegrityProof, Keywords.CONTEXT, jsonLdObject.getContexts().stream().map(JsonLDUtils::uriToString).filter(Objects::nonNull).toList());
109+
DataIntegrityProof ldProofOptions = DataIntegrityProof.fromJson(dataIntegrityProof.toJson());
110+
if (ldProofOptions.getContexts() == null || ldProofOptions.getContexts().isEmpty()) {
111+
JsonLDUtils.jsonLdAdd(ldProofOptions, Keywords.CONTEXT, jsonLdObject.getContexts().stream().map(JsonLDUtils::uriToString).filter(Objects::nonNull).toList());
111112
}
112113

113114
// obtain the canonicalized document
114115

115-
Canonicalizer canonicalizer = this.getCanonicalizer(dataIntegrityProof);
116-
byte[] canonicalizationResult = canonicalizer.canonicalize(dataIntegrityProof, jsonLdObject);
116+
Canonicalizer canonicalizer = this.getCanonicalizer(ldProofOptions);
117+
byte[] canonicalizationResult = canonicalizer.canonicalize(ldProofOptions, jsonLdObject);
117118
if (log.isDebugEnabled()) log.debug("Canonicalization result with {}: {}", canonicalizer.getClass().getSimpleName(), Hex.encodeHexString(canonicalizationResult));
118119

119120
// sign

src/main/java/com/danubetech/dataintegrity/verifier/LdVerifier.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,22 @@ public boolean verify(JsonLDObject jsonLdObject, DataIntegrityProof dataIntegrit
5858

5959
this.initialize(dataIntegrityProof);
6060

61-
// add LD contexts to LD proof options if missing
61+
// construct LD proof options
6262

63-
if (dataIntegrityProof.getContexts() == null || dataIntegrityProof.getContexts().isEmpty()) {
64-
JsonLDUtils.jsonLdAdd(dataIntegrityProof, Keywords.CONTEXT, jsonLdObject.getContexts().stream().map(JsonLDUtils::uriToString).filter(Objects::nonNull).toList());
63+
DataIntegrityProof ldProofOptions = DataIntegrityProof.fromJson(dataIntegrityProof.toJson());
64+
if (ldProofOptions.getContexts() == null || ldProofOptions.getContexts().isEmpty()) {
65+
JsonLDUtils.jsonLdAdd(ldProofOptions, Keywords.CONTEXT, jsonLdObject.getContexts().stream().map(JsonLDUtils::uriToString).filter(Objects::nonNull).toList());
6566
}
6667

6768
// obtain the canonicalized document
6869

69-
Canonicalizer canonicalizer = this.getCanonicalizer(dataIntegrityProof);
70-
byte[] canonicalizationResult = canonicalizer.canonicalize(dataIntegrityProof, jsonLdObject);
70+
Canonicalizer canonicalizer = this.getCanonicalizer(ldProofOptions);
71+
byte[] canonicalizationResult = canonicalizer.canonicalize(ldProofOptions, jsonLdObject);
7172
if (log.isDebugEnabled()) log.debug("Canonicalization result with {}: {}", canonicalizer.getClass().getSimpleName(), Hex.encodeHexString(canonicalizationResult));
7273

7374
// verify
7475

75-
boolean verify = this.verify(canonicalizationResult, dataIntegrityProof);
76+
boolean verify = this.verify(canonicalizationResult, ldProofOptions);
7677
if (log.isDebugEnabled()) log.debug("Verified data integrity proof: {} --> {}", dataIntegrityProof, verify);
7778

7879
// done

0 commit comments

Comments
 (0)