def revoke_certificates(conf, interactive=False): certificates = conf.p # for all certificates remove chainpoint receipt and get original hash txid_to_revoke = None hashes_to_revoke = [] for cert in certificates: pdf_hash, txid = remove_chainpoint_proof_and_hash(cert) if not txid_to_revoke: txid_to_revoke = txid elif txid_to_revoke != txid: if interactive: sys.exit("Certificates to revoke are not all part of the same transaction!") else: raise TypeError("Certificates to revoke are not all part of the same transaction!") if pdf_hash: hashes_to_revoke.append(pdf_hash) else: if interactive: print('Certificate {} is invalid (possible tampered)! -- Skipping!'.format(cert)) else: # note that if the hash is different from original after # removing the chainpoint_proof then fail completely in # non-interactive mode raise RuntimeError('Certificate {} is invalid (possible tampered)! -- Skipping!'.format(cert)) # get last certificate if number of certificates is even final_odd_hash_to_revoke = None if len(hashes_to_revoke) % 2 != 0: final_odd_hash_to_revoke = hashes_to_revoke[-1] # iterate every two certificates revoke_tx_hashes = [] for hash1, hash2 in zip(hashes_to_revoke[0::2], hashes_to_revoke[1::2]): op_return_bstring = cred_protocol.revoke_creds_cmd(txid, hash1, hash2) revoked_txid = publish_hash.issue_op_return(conf, op_return_bstring) if interactive: print('\nTx hash: {}'.format(revoked_txid)) input('Take a note of the revoke txid and press ENTER to continue...') else: revoke_tx_hashes.append( { "txid": revoked_txid } ) if final_odd_hash_to_revoke: # issue a final revoke cmd with the last certificate hash op_return_bstring = cred_protocol.revoke_creds_cmd(txid, final_odd_hash_to_revoke) print(conf) revoked_txid = publish_hash.issue_op_return(conf, op_return_bstring, interactive) if interactive: print('\nTx hash: {}'.format(revoked_txid)) input('Take a note of the revoke txid and press ENTER to continue...') else: revoke_tx_hashes.append( { "txid": revoked_txid } ) if not interactive: return { "results": revoke_tx_hashes }
def issue_certificates(conf, interactive=False): # check if issuance address has not been revoked! # TODO: REVOKE ADDRESS CMD pdf_utils.add_metadata_only_to_pdf_certificates(conf, interactive) # get certificate file list here (to ensure it is identical to both # 'hash_certificates' and 'insert_proof_to_certificates') certificates_directory = os.path.join(conf.working_directory, conf.certificates_directory) cert_files = glob.glob(certificates_directory + os.path.sep + "*.[pP][dD][fF]") cert_hashes = pdf_utils.hash_certificates(cert_files) cp = prepare_chainpoint_tree(cert_hashes) # create OP_RETURN in bytes if conf.expiry_date: op_return_bstring = cred_protocol.issue_abs_expiry_cmd( conf.issuer_identifier, cp.get_merkle_root(), conf.expiry_date) else: op_return_bstring = cred_protocol.issue_cmd(conf.issuer_identifier, cp.get_merkle_root()) txid = publish_hash.issue_op_return(conf, op_return_bstring, interactive) insert_proof_to_certificates(conf, cp, txid, cert_files, interactive) return txid
def main(): if sys.version_info.major < 3: sys.stderr.write('Python 3 is required!') sys.exit(1) conf = load_config() # check if issuance address has not been revoked! # TODO: REVOKE ADDRESS CMD pdf_utils.populate_pdf_certificates(conf) # get certificate file list here (to ensure it is identical to both # 'hash_certificates' and 'insert_proof_to_certificates' certificates_directory = os.path.join(conf.working_directory, conf.certificates_directory) cert_files = glob.glob(certificates_directory + os.path.sep + "*.pdf") cert_hashes = pdf_utils.hash_certificates(cert_files) cp = prepare_chainpoint_tree(cert_hashes) # create OP_RETURN in hex op_return_hex = cred_protocol.issue_cmd(conf.issuer_identifier, cp.get_merkle_root()) txid = publish_hash.issue_op_return(conf, op_return_hex) insert_proof_to_certificates(conf, cp, txid, cert_files) print('\nTx hash: {}'.format(txid))
def revoke_address(conf, interactive=False): if(conf.blockchain == 'litecoin'): from litecoinutils.setup import setup from litecoinutils.keys import P2pkhAddress, P2wpkhAddress from litecoinutils.utils import is_address_bech32 else: from bitcoinutils.setup import setup from bitcoinutils.keys import P2pkhAddress, P2wpkhAddress from bitcoinutils.utils import is_address_bech32 # initialize full node connection if(conf.testnet): setup('testnet') else: setup('mainnet') if(is_address_bech32(conf.issuing_address)): address = P2wpkhAddress(conf.issuing_address).to_hash160() else: address = P2pkhAddress(conf.issuing_address).to_hash160() op_return_bstring = cred_protocol.revoke_address_cmd(address) revoked_txid = publish_hash.issue_op_return(conf, op_return_bstring) if interactive: print('\nTx hash: {}'.format(revoked_txid)) else: return revoked_txid
def revoke_batch(conf, interactive=False): txid = conf.batch op_return_bstring = cred_protocol.revoke_batch_cmd(txid) revoked_txid = publish_hash.issue_op_return(conf, op_return_bstring) if interactive: print('\nTx hash: {}'.format(revoked_txid)) else: return revoked_txid
def revoke_certificates(conf): certificates = conf.p # for all certificates remove chainpoint receipt and get original hash txid_to_revoke = None hashes_to_revoke = [] for cert in certificates: pdf_hash, txid = remove_chainpoint_proof_and_hash(cert) if not txid_to_revoke: txid_to_revoke = txid elif txid_to_revoke != txid: sys.exit( "Certificates to revoke are not all part of the same transaction!" ) if pdf_hash: hashes_to_revoke.append(pdf_hash) else: print('Certificate {} is invalid! -- Skipping!'.format(cert)) # get last certificate if number of certificates is even final_odd_hash_to_revoke = None if len(hashes_to_revoke) % 2 != 0: final_odd_hash_to_revoke = hashes_to_revoke[-1] # iterate every two certificates for hash1, hash2 in zip(hashes_to_revoke[0::2], hashes_to_revoke[1::2]): op_return_bstring = cred_protocol.revoke_creds_cmd(txid, hash1, hash2) revoked_txid = publish_hash.issue_op_return(conf, op_return_bstring) print('\nTx hash: {}'.format(revoked_txid)) input('Take a note of the revoke txid and press ENTER to continue...') if final_odd_hash_to_revoke: # issue a final revoke cmd with the last certificate hash op_return_bstring = cred_protocol.revoke_creds_cmd( txid, final_odd_hash_to_revoke) revoked_txid = publish_hash.issue_op_return(conf, op_return_bstring) print('\nTx hash: {}'.format(revoked_txid)) input('Take a note of the revoke txid and press ENTER to continue...')
def revoke_address(conf, interactive=False): # initialize full node connection if(conf.testnet): setup('testnet') else: setup('mainnet') address = P2pkhAddress(conf.issuing_address).to_hash160() op_return_bstring = cred_protocol.revoke_address_cmd(address) revoked_txid = publish_hash.issue_op_return(conf, op_return_bstring) if interactive: print('\nTx hash: {}'.format(revoked_txid)) else: return revoked_txid
def revoke_batch(conf): txid = conf.batch op_return_bstring = cred_protocol.revoke_batch_cmd(txid) revoked_txid = publish_hash.issue_op_return(conf, op_return_bstring) print('\nTx hash: {}'.format(revoked_txid))