Skip to content

Commit

Permalink
feat(DataIntegrityProof): handle contexts for data integrity proof
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoustachiste committed Feb 15, 2024
1 parent 3dc65ff commit b13182b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
17 changes: 4 additions & 13 deletions cert_issuer/proof_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def add_proof(self, certificate_json, merkle_proof, app_config=None):
certificate_json['proof'].append(merkle_proof)
else:
certificate_json['proof'] = merkle_proof
self.update_context_for_single_proof(certificate_json)
self.update_context_for_proof(certificate_json)
return certificate_json

def add_merkle_proof_2019(self, certificate_json, proof_value, app_config=None):
Expand All @@ -35,25 +35,16 @@ def add_chained_proof(self, certificate_json, merkle_proof):
previous_proof = certificate_json['proof'][-1]
merkle_proof['previousProof'] = previous_proof['id']
certificate_json['proof'].append(merkle_proof)
self.update_context_for_chained_proof(certificate_json)

def update_context_for_chained_proof(self, certificate_json):
def update_context_for_proof(self, certificate_json):
context = certificate_json['@context']
if self.contextUrls.merkle_proof_2019() not in context:
context.append(self.contextUrls.merkle_proof_2019())

if self.contextUrls.chained_proof_2021() not in context:
context.append(self.contextUrls.chained_proof_2021())
if self.contextUrls.data_integrity_proof_v2() not in context:
context.append(self.contextUrls.data_integrity_proof_v2())

if array_intersect(self.contextUrls.v3_all(), context):
for v3_context in self.contextUrls.v3_all():
if v3_context in context:
index = context.index(v3_context)
del context[index]
context.append(self.contextUrls.v3_1_canonical())

def update_context_for_single_proof(self, certificate_json):
context = certificate_json['@context']
if array_intersect(self.contextUrls.v3_1_all(), context):
if self.contextUrls.merkle_proof_2019() not in context:
context.append(self.contextUrls.merkle_proof_2019())
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cert-core>=3.0.0
cert-schema>=3.5.1
cert-schema>=3.6.0
merkletools==1.0.3
configargparse==0.13.0
glob2==0.6
Expand Down
3 changes: 2 additions & 1 deletion tests/test_certificate_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def test_web_add_proof(self):
return_cert = handler.add_proof(certificate_json, proof_value)
self.assertEqual(return_cert, {
'@context': [
'https://www.w3.org/2018/credentials/v1'
'https://www.w3.org/2018/credentials/v1',
'https://w3id.org/security/data-integrity/v2'
],
'kek': 'kek',
'proof': self._proof_helper()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_proof_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_single_signature(self):
output = self.handler.add_proof(fixture_certificate_json, fixture_proof)
self.assertEqual(output['proof'], fixture_proof)

def test_single_signature_3_1_update_context_merkle_proof_2019(self):
def test_single_signature_3_1_update_context_data_integrity_proof(self):
fixture_certificate_json = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
Expand All @@ -44,7 +44,7 @@ def test_single_signature_3_1_update_context_merkle_proof_2019(self):
'verificationMethod': 'did:ion:EiA_Z6LQILbB2zj_eVrqfQ2xDm4HNqeJUw5Kj2Z7bFOOeQ#key-1'
}
output = self.handler.add_proof(fixture_certificate_json, fixture_proof)
self.assertIn(self.contextUrls.merkle_proof_2019(), output['@context'])
self.assertIn(self.contextUrls.data_integrity_proof_v2(), output['@context'])

def test_multiple_non_chained_signature(self):
fixture_initial_proof = {
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_multiple_three_chained_signature(self):
}
])

def test_adds_merkle_proof_context(self):
def test_adds_date_integrity_proof_context(self):
fixture_initial_proof = {
'type': 'Ed25519Signature2020',
'id': 'urn:uuid:1de8149b-fff1-4908-8d69-89b56358fd31',
Expand Down Expand Up @@ -200,9 +200,9 @@ def test_adds_merkle_proof_context(self):
'verificationMethod': 'did:example:ebfeb1f712ebc6f1c276e12ec21#assertion'
}
output = self.handler.add_proof(fixture_certificate_json, fixture_proof)
self.assertIn(self.contextUrls.merkle_proof_2019(), output['@context'])
self.assertIn(self.contextUrls.data_integrity_proof_v2(), output['@context'])

def test_adds_chained_proof_context(self):
def test_adds_data_integrity_proof_context(self):
fixture_initial_proof = {
'type': 'Ed25519Signature2020',
'id': 'urn:uuid:1de8149b-fff1-4908-8d69-89b56358fd31',
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_adds_chained_proof_context(self):
'verificationMethod': 'did:example:ebfeb1f712ebc6f1c276e12ec21#assertion'
}
output = self.handler.add_proof(fixture_certificate_json, fixture_proof)
self.assertIn(self.contextUrls.chained_proof_2021(), output['@context'])
self.assertIn(self.contextUrls.data_integrity_proof_v2(), output['@context'])

def test_updates_blockcerts_context_version(self):
fixture_initial_proof = {
Expand Down

0 comments on commit b13182b

Please sign in to comment.