Skip to content

Commit

Permalink
refactor(DataIntegrityProof): extract merkle proof 2019 to its own co…
Browse files Browse the repository at this point in the history
…nstructor
  • Loading branch information
lemoustachiste committed Feb 13, 2024
1 parent 6df70eb commit 889440b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
11 changes: 3 additions & 8 deletions cert_issuer/merkle_tree_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pycoin.serialize import h2b
from lds_merkle_proof_2019.merkle_proof_2019 import MerkleProof2019
from cert_issuer import helpers
from cert_issuer.proof_suites.merkle_proof_2019 import MerkleProof2019Suite


def hash_byte_array(data):
Expand Down Expand Up @@ -75,14 +76,8 @@ def get_proof_generator(self, tx_id, verification_method, chain=Chain.bitcoin_ma
logging.info('merkle_json: %s', str(merkle_json))

proof_value = mp2019.encode(merkle_json)
merkle_proof = {
"type": "MerkleProof2019",
"created": datetime.now().isoformat(),
"proofValue": proof_value.decode('utf8'),
"proofPurpose": "assertionMethod",
"verificationMethod": verification_method
}
yield merkle_proof
merkle_proof = MerkleProof2019Suite(proof_value, verification_method)
yield merkle_proof.to_json_object()


def to_source_id(txid, chain):
Expand Down
2 changes: 1 addition & 1 deletion cert_issuer/proof_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cert_issuer.chained_proof_2021 import ChainedProof2021
from cert_issuer.proof_suites.chained_proof_2021 import ChainedProof2021
from cert_schema import ContextUrls
from cert_issuer.utils import array_intersect

Expand Down
Empty file.
File renamed without changes.
23 changes: 23 additions & 0 deletions cert_issuer/proof_suites/merkle_proof_2019.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import datetime

MERKLE_PROOF_2019_TYPE = 'MerkleProof2019'
class MerkleProof2019Suite:
type = ''
verificationMethod = ''
created = ''
proofPurpose = ''
previousProof = ''
proofValue = ''

def __init__(self, proof_value, verificationMethod):
self.type = MERKLE_PROOF_2019_TYPE
self.proofPurpose = 'assertionMethod'
self.created = self.get_creation_time()
self.proofValue = proof_value.decode('utf-8')
self.verificationMethod = verificationMethod

def get_creation_time(self):
return datetime.now().isoformat()

def to_json_object(self):
return self.__dict__

0 comments on commit 889440b

Please sign in to comment.