Ejemplo n.º 1
0
def update_token_uri(app_config, certificate_batch_handler,
                     transaction_handler, token_id, token_uri):
    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)

    issuer.update_token_uri(app_config.chain, app_config, token_id, token_uri)
def issue(app_config, certificate_batch_handler, transaction_handler):
    unsigned_certs_dir = app_config.unsigned_certificates_dir
    signed_certs_dir = app_config.signed_certificates_dir
    blockchain_certificates_dir = app_config.blockchain_certificates_dir
    work_dir = app_config.work_dir

    certificates_metadata = helpers.prepare_issuance_batch(
        unsigned_certs_dir, signed_certs_dir, blockchain_certificates_dir,
        work_dir)
    num_certificates = len(certificates_metadata)
    if num_certificates < 1:
        logging.warning('No certificates to process')
        return None

    logging.info('Processing %d certificates under work path=%s',
                 num_certificates, work_dir)
    certificate_batch_handler.set_certificates_in_batch(certificates_metadata)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    tx_id = issuer.issue(app_config.bitcoin_chain)

    helpers.copy_output(certificates_metadata)

    logging.info('Your Blockchain Certificates are in %s',
                 blockchain_certificates_dir)
    return tx_id
Ejemplo n.º 3
0
def issue(app_config, certificate_batch_handler, transaction_handler):
    certificate_batch_handler.pre_batch_actions(app_config)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    tx_id = issuer.issue(app_config.chain)

    certificate_batch_handler.post_batch_actions(app_config)
    return tx_id
Ejemplo n.º 4
0
def issue(app_config, certificate_batch_handler, transaction_handler):
    certificate_batch_handler.pre_batch_actions(app_config)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    tx_id = issuer.issue(app_config.chain)
    """"Este metodo copia del workingDir al blockchainCertDir"""
    #certificate_batch_handler.post_batch_actions(app_config)
    return tx_id
Ejemplo n.º 5
0
    def post(self):
        json_data = request.get_json(force=True)
        # get recipient from the json_data
        fields = {}
        fields["identity"] = json_data['email']
        fields["name"] = json_data['name']
        recipient = Recipient(fields)

        # get the template from db
        template_col = DAO().get_collection('certificate_template')
        template = template_col.find_one({}, {"_id": 0})

        # get deep copy of the template as cert
        cert = deepcopy(template)

        # get the config
        config = Config().get()

        # call instantiate_assertion and instantiate_recipient
        uid = str(uuid.uuid4())
        issued_on = helpers.create_iso8601_tz()
        instantiate_assertion(cert, uid, issued_on)
        instantiate_recipient(cert, recipient,
                              config.additional_per_recipient_fields,
                              config.hash_emails)

        # get the config
        config = Config().get()

        # post it to blockchain
        # first instantiate handlers
        chain = config.chain
        if chain == Chain.ethereum_mainnet or chain == Chain.ethereum_ropsten:
            from cert_issuer.blockchain_handlers import ethereum
            certificate_batch_handler, transaction_handler, connector = ethereum.instantiate_blockchain_handlers(
                config, False)
        else:
            from cert_issuer.blockchain_handlers import bitcoin
            certificate_batch_handler, transaction_handler, connector = bitcoin.instantiate_blockchain_handlers(
                config, False)

        certificate_batch_handler.certificates_to_issue = [cert]
        issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                        transaction_handler=transaction_handler,
                        max_retry=config.max_retry)
        tx_id = issuer.issue(config.chain)

        issued_cert = certificate_batch_handler.certificates_to_issue[0]
        issued_cert_to_insert = deepcopy(issued_cert)
        cert_col = DAO().get_collection("certificates")
        cert_col.insert_one(issued_cert_to_insert)
        return issued_cert
Ejemplo n.º 6
0
def issue(app_config, certificate_batch_handler, transaction_handler,
          recipient_address, token_uri):
    certificate_batch_handler.pre_batch_actions(app_config)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    (tx_id, token_id) = issuer.issue(app_config.chain, app_config,
                                     recipient_address, token_uri)

    certificate_batch_handler.post_batch_actions(app_config)
    return (tx_id, token_id)
Ejemplo n.º 7
0
def issue(app_config, certificate_batch_handler, transaction_handler,
          recipient_address, uidArray, token_uri):
    # Provide array of uidArrays to generate certificates
    certificate_batch_handler.pre_batch_actions(app_config, uidArray)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    (tx_id, token_id) = issuer.issue(app_config.chain, app_config,
                                     recipient_address, token_uri)

    certificate_batch_handler.post_batch_actions(app_config)
    return (tx_id, token_id)
Ejemplo n.º 8
0
def main(app_config, secure_signer=None):
    unsigned_certs_dir = app_config.unsigned_certificates_dir
    signed_certs_dir = app_config.signed_certificates_dir
    blockchain_certificates_dir = app_config.blockchain_certificates_dir
    work_dir = app_config.work_dir
    v2 = app_config.v2
    issuing_address = app_config.issuing_address
    revocation_address = app_config.revocation_address  # not needed for v2

    certificates, batch_metadata = helpers.prepare_issuance_batch(
        unsigned_certs_dir, signed_certs_dir, blockchain_certificates_dir,
        work_dir)
    logging.info('Processing %d certificates under work path=%s',
                 len(certificates), work_dir)

    logging.info('Signing certificates...')
    if not secure_signer:
        secure_signer = secure_signer_helper.initialize_secure_signer(
            app_config)
    connector = ServiceProviderConnector(app_config.bitcoin_chain)
    tx_constants = TransactionCostConstants(app_config.tx_fee,
                                            app_config.dust_threshold,
                                            app_config.satoshi_per_byte)

    if v2:
        certificate_handler = CertificateV2Handler()
        transaction_handler = TransactionV2Handler(
            tx_cost_constants=tx_constants, issuing_address=issuing_address)
    else:
        certificate_handler = CertificateV1_2Handler()
        transaction_handler = TransactionV1_2Handler(
            tx_cost_constants=tx_constants,
            issuing_address=issuing_address,
            certificates_to_issue=certificates,
            revocation_address=revocation_address)
    certificate_batch_handler = CertificateBatchHandler(
        certificates_to_issue=certificates,
        certificate_handler=certificate_handler)
    issuer = Issuer(issuing_address=issuing_address,
                    connector=connector,
                    secure_signer=secure_signer,
                    certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler)
    transaction_cost = issuer.calculate_cost_for_certificate_batch()
    logging.info('Total cost will be %d satoshis', transaction_cost)

    # ensure the issuing address has sufficient balance
    balance = connector.get_balance(issuing_address)

    if transaction_cost > balance:
        error_message = 'Please add {} satoshis to the address {}'.format(
            transaction_cost - balance, issuing_address)
        logging.error(error_message)
        raise InsufficientFundsError(error_message)

    tx_id = issuer.issue_certificates()

    blockcerts_tmp_dir = os.path.join(work_dir,
                                      helpers.BLOCKCHAIN_CERTIFICATES_DIR)
    if not os.path.exists(blockchain_certificates_dir):
        os.makedirs(blockchain_certificates_dir)
    for item in os.listdir(blockcerts_tmp_dir):
        s = os.path.join(blockcerts_tmp_dir, item)
        d = os.path.join(blockchain_certificates_dir, item)
        shutil.copy2(s, d)

    logging.info('Your Blockchain Certificates are in %s',
                 blockchain_certificates_dir)
    return tx_id