-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Proof): abstract proof handler to centralize proof logic
- Loading branch information
1 parent
1d2e678
commit 4866a3b
Showing
4 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from cert_issuer.chained_proof_2021 import ChainedProof2021 | ||
|
||
class ProofHandler: | ||
def add_proof (self, certificate_json, merkle_proof): | ||
if 'proof' in certificate_json: | ||
initial_proof = certificate_json['proof'] | ||
certificate_json['proof'] = [initial_proof, ChainedProof2021(initial_proof, merkle_proof).toJsonObject()] | ||
else: | ||
certificate_json['proof'] = merkle_proof | ||
return certificate_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import unittest | ||
from cert_issuer.proof_handler import ProofHandler | ||
|
||
class TestProofHandler(unittest.TestCase): | ||
def multiple_two_chained_signature(self): | ||
handler = ProofHandler() | ||
fixture_initial_proof = { | ||
'type': 'Ed25519Signature2020', | ||
'created': '2022-05-02T16:36:22.933Z', | ||
'verificationMethod': 'did:key:z6MkjHnntGvtLjwfAMHWTAXXGJHhVL3DPtaT9BHmyTjWpjqs#z6MkjHnntGvtLjwfAMHWTAXXGJHhVL3DPtaT9BHmyTjWpjqs', | ||
'proofPurpose': 'assertionMethod', | ||
'proofValue': 'zAvFt59599JweBZ4zPP6Ge8LhKgECtBvDRmjG5VQbgEkPCiyMcM9QAPanJgSCs6RRGcKu96qNpfmpe9eTygpFZP6' | ||
} | ||
fixture_certificate_json = { | ||
'kek': 'kek', | ||
'proof': fixture_initial_proof | ||
} | ||
fixture_proof = { | ||
'type': 'MerkleProof2019', | ||
'created': '2022-05-05T08:05:14.912828', | ||
'proofValue': 'zMcm4LfQFUZkWZyLJp1bqtXF8vkZZwp79x7Nvt5BmN2XV4usLLtDoeqiq3et923mcWfXde4a3m4f57yUZcATCbBXV1byb5AXbV8EzT6E8B9JKf3scvxxZCBVePtV4SrhYysAiLNJ9N2R8LgnpJ47wnQHkaTB1AMxrcLEHUTxm4zJTtQqf9orDLf3L4VoLzmST7ZzsDjuX9cw2hZ3Aazhhjy7swG44xfF1PC73SyCv77pDnJ6BSHm3azmbVG6BXv1EPtwF4J1YRqwojBEWk9nDgduACR7b9qNhQ46ND4B5vL8p3LkqTh', | ||
'proofPurpose': 'assertionMethod', | ||
'verificationMethod': 'did:ion:EiA_Z6LQILbB2zj_eVrqfQ2xDm4HNqeJUw5Kj2Z7bFOOeQ#key-1' | ||
} | ||
output = handler.add_proof(fixture_certificate_json, fixture_proof) | ||
self.assertEqual(output, { | ||
'kek': 'kek', | ||
'proof': [ | ||
fixture_initial_proof, | ||
{ | ||
'type': 'ChainedProof2021', | ||
'chainedProofType': 'MerkleProof2019', | ||
'created': '2022-05-05T08:05:14.912828', | ||
'previousProof': fixture_initial_proof, | ||
'proofValue': 'zMcm4LfQFUZkWZyLJp1bqtXF8vkZZwp79x7Nvt5BmN2XV4usLLtDoeqiq3et923mcWfXde4a3m4f57yUZcATCbBXV1byb5AXbV8EzT6E8B9JKf3scvxxZCBVePtV4SrhYysAiLNJ9N2R8LgnpJ47wnQHkaTB1AMxrcLEHUTxm4zJTtQqf9orDLf3L4VoLzmST7ZzsDjuX9cw2hZ3Aazhhjy7swG44xfF1PC73SyCv77pDnJ6BSHm3azmbVG6BXv1EPtwF4J1YRqwojBEWk9nDgduACR7b9qNhQ46ND4B5vL8p3LkqTh', | ||
'proofPurpose': 'assertionMethod', | ||
'verificationMethod': 'did:ion:EiA_Z6LQILbB2zj_eVrqfQ2xDm4HNqeJUw5Kj2Z7bFOOeQ#key-1' | ||
} | ||
] | ||
}) |