Skip to content

Commit

Permalink
refactor(JSONLD): centralize jsonld handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoustachiste committed Jun 22, 2022
1 parent cd80945 commit f8022b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cert_issuer/certificate_handlers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import json
import logging

from cert_schema import normalize_jsonld
from cert_issuer import helpers
from cert_issuer.proof_handler import ProofHandler
from pycoin.serialize import b2h
from cert_issuer.normalization_handler import JSONLDHandler
from cert_issuer.models import CertificateHandler, BatchHandler

from cert_issuer.signer import FinalizableSigner


class CertificateV3Handler(CertificateHandler):
def get_byte_array_to_issue(self, certificate_metadata):
certificate_json = self._get_certificate_to_issue(certificate_metadata)
normalized = normalize_jsonld(certificate_json, detect_unmapped_fields=False)
return normalized.encode('utf-8')
return JSONLDHandler.normalize_to_utf8(certificate_json)

def add_proof(self, certificate_metadata, merkle_proof):
"""
Expand All @@ -34,8 +34,7 @@ def _get_certificate_to_issue(self, certificate_metadata):

class CertificateWebV3Handler(CertificateHandler):
def get_byte_array_to_issue(self, certificate_json):
normalized = normalize_jsonld(certificate_json, detect_unmapped_fields=False)
return normalized.encode('utf-8')
return JSONLDHandler.normalize_to_utf8(certificate_json)

def add_proof(self, certificate_json, merkle_proof):
certificate_json = ProofHandler().add_proof(certificate_json, merkle_proof)
Expand Down
8 changes: 8 additions & 0 deletions cert_issuer/normalization_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from cert_schema import normalize_jsonld


class JSONLDHandler:
@staticmethod
def normalize_to_utf8(certificate_json):
normalized = normalize_jsonld(certificate_json, detect_unmapped_fields=False)
return normalized.encode('utf-8')

0 comments on commit f8022b0

Please sign in to comment.