Skip to content

Commit

Permalink
feat(MultiSign): allow n amount of proofs to be chained
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoustachiste committed May 9, 2022
1 parent 4866a3b commit 1c6e3b4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 13 deletions.
33 changes: 23 additions & 10 deletions cert_issuer/chained_proof_2021.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json
CHAINED_PROOF_TYPE = 'ChainedProof2021'

class ChainedProof2021:
type = ''
Expand All @@ -9,14 +9,27 @@ class ChainedProof2021:
previousProof = ''
proofValue = ''

def __init__ (self, previousProof, currentProof):
self.type = 'ChainedProof2021'
self.verificationMethod = currentProof['verificationMethod']
self.chainedProofType = currentProof['type']
self.created = currentProof['created']
self.proofPurpose = currentProof['proofPurpose']
self.previousProof = previousProof
self.proofValue = currentProof['proofValue']
def __init__(self, previous_proof, current_proof):
self.type = CHAINED_PROOF_TYPE
self.create_proof_object(current_proof)
self.set_previous_proof(previous_proof)

def toJsonObject(self):
def create_proof_object(self, current_proof):
self.verificationMethod = current_proof['verificationMethod']
self.chainedProofType = current_proof['type']
self.created = current_proof['created']
self.proofPurpose = current_proof['proofPurpose']
self.proofValue = current_proof['proofValue']

def set_previous_proof(self, previous_proof):
if previous_proof['type'] == CHAINED_PROOF_TYPE:
previous_proof_to_store = previous_proof
previous_proof_to_store['type'] = previous_proof['chainedProofType']
del previous_proof_to_store['chainedProofType']
del previous_proof_to_store['previousProof']
self.previousProof = previous_proof_to_store
else:
self.previousProof = previous_proof

def to_json_object(self):
return self.__dict__
8 changes: 6 additions & 2 deletions cert_issuer/proof_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
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()]
if not isinstance(certificate_json['proof'], list):
# convert proof to list
initial_proof = certificate_json['proof']
certificate_json['proof'] = [initial_proof]
previous_proof = certificate_json['proof'][-1]
certificate_json['proof'].append(ChainedProof2021(previous_proof, merkle_proof).to_json_object())
else:
certificate_json['proof'] = merkle_proof
return certificate_json
59 changes: 58 additions & 1 deletion tests/test_proof_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from cert_issuer.proof_handler import ProofHandler

class TestProofHandler(unittest.TestCase):
def multiple_two_chained_signature(self):
def test_multiple_two_chained_signature(self):
handler = ProofHandler()
fixture_initial_proof = {
'type': 'Ed25519Signature2020',
Expand Down Expand Up @@ -38,3 +38,60 @@ def multiple_two_chained_signature(self):
}
]
})

def test_multiple_three_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_second_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'
}
fixture_certificate_json = {
'kek': 'kek',
'proof': [
fixture_initial_proof,
fixture_second_proof
]
}
fixture_proof = {
'type': 'MerkleProof2019',
'created': '2022-05-06T20:31:54',
'proofValue': 'mockProofValueForUnitTestPurpose',
'proofPurpose': 'assertionMethod',
'verificationMethod': 'did:example:ebfeb1f712ebc6f1c276e12ec21#assertion'
}
output = handler.add_proof(fixture_certificate_json, fixture_proof)
self.maxDiff = None
self.assertEqual(output, {
'kek': 'kek',
'proof': [
fixture_initial_proof,
fixture_second_proof,
{
'type': 'ChainedProof2021',
'chainedProofType': 'MerkleProof2019',
'created': '2022-05-06T20:31:54',
'previousProof': {
'type': 'MerkleProof2019',
'created': '2022-05-05T08:05:14.912828',
'proofValue': 'zMcm4LfQFUZkWZyLJp1bqtXF8vkZZwp79x7Nvt5BmN2XV4usLLtDoeqiq3et923mcWfXde4a3m4f57yUZcATCbBXV1byb5AXbV8EzT6E8B9JKf3scvxxZCBVePtV4SrhYysAiLNJ9N2R8LgnpJ47wnQHkaTB1AMxrcLEHUTxm4zJTtQqf9orDLf3L4VoLzmST7ZzsDjuX9cw2hZ3Aazhhjy7swG44xfF1PC73SyCv77pDnJ6BSHm3azmbVG6BXv1EPtwF4J1YRqwojBEWk9nDgduACR7b9qNhQ46ND4B5vL8p3LkqTh',
'proofPurpose': 'assertionMethod',
'verificationMethod': 'did:ion:EiA_Z6LQILbB2zj_eVrqfQ2xDm4HNqeJUw5Kj2Z7bFOOeQ#key-1'
},
'proofValue': 'mockProofValueForUnitTestPurpose',
'proofPurpose': 'assertionMethod',
'verificationMethod': 'did:example:ebfeb1f712ebc6f1c276e12ec21#assertion'
}
]
})

0 comments on commit 1c6e3b4

Please sign in to comment.