def create_certificate_template(config):
    certificate = create_certificate_section(config)
    verify = create_verification_section(config)
    assertion = create_assertion_section(config)
    recipient = create_recipient_section(config)

    template_dir = config.template_dir
    if not os.path.isabs(template_dir):
        template_dir = os.path.join(config.abs_data_dir, template_dir)
    template_file_name = config.template_file_name

    raw_json = {
        '@context': 'https://w3id.org/blockcerts/v1',
        'type': 'CertificateDocument',
        'recipient': recipient,
        'assertion': assertion,
        'certificate': certificate,
        'verify': verify
    }

    if config.additional_global_fields:
        for field in config.additional_global_fields:
            raw_json = jsonpath_helpers.set_field(raw_json, field['path'], field['value'])

    if config.additional_per_recipient_fields:
        for field in config.additional_per_recipient_fields:
            raw_json = jsonpath_helpers.set_field(raw_json, field['path'], field['value'])

    template_path = os.path.join(config.abs_data_dir, template_dir, template_file_name)

    with open(template_path, 'w') as cert_template:
        json.dump(raw_json, cert_template)

    return raw_json
def create_certificate_template(config):

    if not config.badge_id:
        badge_uuid = str(uuid.uuid4())
        print('Generated badge id {0}'.format(badge_uuid))
        config.badge_id = badge_uuid

    badge = create_badge_section(config)
    verification = create_verification_section(config)
    assertion = create_assertion_section(config)
    recipient = create_recipient_section(config)
    recipient_profile = create_recipient_profile_section()

    assertion['recipient'] = recipient
    assertion[scope_name('recipientProfile')] = recipient_profile

    assertion['badge'] = badge
    assertion['verification'] = verification

    if config.additional_global_fields:
        for field in config.additional_global_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'], field['value'])

    if config.additional_per_recipient_fields:
        for field in config.additional_per_recipient_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'], field['value'])

    return assertion
def create_certificate_template(config):

    if not config.badge_id:
        badge_uuid = str(uuid.uuid4())
        print('Generated badge id {0}'.format(badge_uuid))
        config.badge_id = badge_uuid

    badge = create_badge_section(config)
    verification = create_verification_section(config)
    assertion = create_assertion_section(config)
    recipient = create_recipient_section(config)
    recipient_profile = create_recipient_profile_section()

    assertion['recipient'] = recipient
    assertion[scope_name('recipientProfile')] = recipient_profile

    assertion['badge'] = badge
    assertion['verification'] = verification

    if config.additional_global_fields:
        for field in config.additional_global_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'],
                                                   field['value'])

    if config.additional_per_recipient_fields:
        for field in config.additional_per_recipient_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'],
                                                   field['value'])

    return assertion
def create_v3_template(config):
    assertion = create_v3_assertion(config)
    credential_subject = create_credential_subject_section(config)

    assertion['credentialSubject'] = credential_subject

    if config.additional_global_fields:
        for field in config.additional_global_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'], field['value'])

    if config.additional_per_recipient_fields:
        for field in config.additional_per_recipient_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'], field['value'])

    return assertion
def instantiate_recipient(config, cert, recipient):

    if config.hash_emails:
        salt = helpers.encode(os.urandom(16))
        cert['recipient']['hashed'] = True
        cert['recipient']['salt'] = salt
        cert['recipient']['identity'] = hash_and_salt_email_address(recipient.identity, salt)
    else:
        cert['recipient']['identity'] = recipient.identity
        cert['recipient']['hashed'] = False

    profile_field = scope_name('recipientProfile')

    cert[profile_field] = {}
    cert[profile_field]['type'] = ['RecipientProfile', 'Extension']
    cert[profile_field]['name'] = recipient.name
    cert[profile_field]['publicKey'] = recipient.pubkey

    if config.additional_per_recipient_fields:
        if not recipient.additional_fields:
            raise Exception('expected additional recipient fields in the csv file but none found')
        for field in config.additional_per_recipient_fields:
            cert = jsonpath_helpers.set_field(cert, field['path'], recipient.additional_fields[field['csv_column']])
    else:
        if recipient.additional_fields:
            # throw an exception on this in case it's a user error. We may decide to remove this if it's a nuisance
            raise Exception(
                'there are fields in the csv file that are not expected by the additional_per_recipient_fields configuration')
def instantiate_recipient(config, cert, recipient):

    if config.hash_emails:
        salt = helpers.encode(os.urandom(16))
        cert['recipient']['hashed'] = True
        cert['recipient']['salt'] = salt
        cert['recipient']['identity'] = hash_and_salt_email_address(
            recipient.identity, salt)
    else:
        cert['recipient']['identity'] = recipient.identity
        cert['recipient']['hashed'] = False

    profile_field = scope_name('recipientProfile')

    cert[profile_field] = {}
    cert[profile_field]['type'] = ['RecipientProfile', 'Extension']
    cert[profile_field]['name'] = recipient.name
    cert[profile_field]['publicKey'] = recipient.pubkey

    if config.additional_per_recipient_fields:
        if not recipient.additional_fields:
            raise Exception(
                'expected additional recipient fields in the csv file but none found'
            )
        for field in config.additional_per_recipient_fields:
            cert = jsonpath_helpers.set_field(
                cert, field['path'],
                recipient.additional_fields[field['csv_column']])
    else:
        if recipient.additional_fields:
            # throw an exception on this in case it's a user error. We may decide to remove this if it's a nuisance
            raise Exception(
                'there are fields in the csv file that are not expected by the additional_per_recipient_fields configuration'
            )
def create_certificate_template(config):

    if not config.badge_id:
        badge_uuid = str(uuid.uuid4())
        print('Generated badge id {0}'.format(badge_uuid))
        config.badge_id = badge_uuid

    badge = create_badge_section(config)
    verification = create_verification_section(config)
    assertion = create_assertion_section(config)
    recipient = create_recipient_section(config)
    recipient_profile = create_recipient_profile_section()

    template_dir = config.template_dir
    if not os.path.isabs(template_dir):
        template_dir = os.path.join(config.abs_data_dir, template_dir)
    template_file_name = config.template_file_name

    assertion['recipient'] = recipient
    assertion[scope_name('recipientProfile')] = recipient_profile

    assertion['badge'] = badge
    assertion['verification'] = verification

    if config.additional_global_fields:
        for field in config.additional_global_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'],
                                                   field['value'])

    if config.additional_per_recipient_fields:
        for field in config.additional_per_recipient_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'],
                                                   field['value'])

    template_path = os.path.join(config.abs_data_dir, template_dir,
                                 template_file_name)

    print('Writing template to ' + template_path)
    with open(template_path, 'w') as cert_template:
        json.dump(assertion, cert_template)

    return assertion
def create_certificate_template(config):

    if not config.badge_id:
        badge_uuid = str(uuid.uuid4())
        print('Generated badge id {0}'.format(badge_uuid))
        config.badge_id = badge_uuid

    badge = create_badge_section(config)
    verification = create_verification_section(config)
    assertion = create_assertion_section(config)
    recipient = create_recipient_section(config)
    recipient_profile = create_recipient_profile_section()

    template_dir = config.template_dir
    if not os.path.isabs(template_dir):
        template_dir = os.path.join(config.abs_data_dir, template_dir)
    template_file_name = config.template_file_name

    assertion['recipient'] = recipient
    assertion[scope_name('recipientProfile')] = recipient_profile

    assertion['badge'] = badge
    assertion['verification'] = verification

    if config.additional_global_fields:
        for field in config.additional_global_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'], field['value'])

    if config.additional_per_recipient_fields:
        for field in config.additional_per_recipient_fields:
            assertion = jsonpath_helpers.set_field(assertion, field['path'], field['value'])

    template_path = os.path.join(config.abs_data_dir, template_dir, template_file_name)

    print('Writing template to ' + template_path)
    with open(template_path, 'w') as cert_template:
        json.dump(assertion, cert_template)

    return assertion
Example #9
0
def instantiate_recipient(cert, recipient, additional_fields, hash_emails):
    if cert['displayHtml']:
        cert[
            'displayHtml'] = """<section class="text" style="margin-top: 24px; width: 100%; display: inline-block;"><span style="display: block; font-family: Helvetica, sans-serif; font-weight: bold; font-size: 2.5em; text-align: left; text-transform: none; color: #4e5f6b; margin: 0 auto; width: 100%;"><img style="display: block; margin-left: auto; margin-right: auto;" src="https://upload.wikimedia.org/wikipedia/commons/3/39/ETS_Logo.svg" alt="" width="120" height="88" /></span></section>
                                <h4 class="text" style="margin-top: 24px; width: 100%; display: inline-block;"><span style="font-size: 2.5em;"><em><span style="display: block; font-family: Helvetica, sans-serif; font-weight: bold; text-align: center; text-transform: none; color: #4e5f6b; margin: 0px auto; width: 100%;">Certificate of Participation</span></em></span></h4>
                                <section class="text" style="margin-top: 24px; width: 100%; display: inline-block;"><span style="display: block; font-family: Helvetica, sans-serif; font-weight: bold; font-size: 2.5em; text-align: center; text-transform: none; color: #4e5f6b; margin: 0 auto; width: 100%;">""" + recipient.name + """</span></section><h3 class="text" style="margin-top: 24px; width: 100%; display: inline-block;"><span style="display: block; font-family: Helvetica, sans-serif; font-size: 1em; text-align: center; text-transform: none; color: #4e5f6b; margin: 0px auto; width: 100%;">Blockchain based ETS Credentials</span></h3>
                                <section class="text" style="margin-top: 24px; width: 100%; display: inline-block;"></section><blockquote><p style="text-align: center;"><em>This certificate describes the use case of blockchain-based ETS credential</em></p><p style="text-align: center;">&nbsp;</p></blockquote>"""

    if hash_emails:
        salt = helpers.encode(os.urandom(16))
        cert['recipient']['hashed'] = True
        cert['recipient']['salt'] = salt
        cert['recipient']['identity'] = hash_and_salt_email_address(
            recipient.identity, salt)
    else:
        cert['recipient']['identity'] = recipient.identity
        cert['recipient']['hashed'] = False

    profile_field = scope_name('recipientProfile')

    cert[profile_field] = {}
    cert[profile_field]['type'] = ['RecipientProfile', 'Extension']
    cert[profile_field]['name'] = recipient.name
    cert[profile_field]['publicKey'] = recipient.pubkey

    if additional_fields:
        if not recipient.additional_fields:
            raise Exception(
                'expected additional recipient fields but none found')
        for field in additional_fields:
            cert = jsonpath_helpers.set_field(
                cert, field['path'],
                recipient.additional_fields[field['csv_column']])
    else:
        if recipient.additional_fields:
            # throw an exception on this in case it's a user error. We may decide to remove this if it's a nuisance
            raise Exception(
                'there are fields that are not expected by the additional_per_recipient_fields configuration'
            )