def create_tumbler_checker(inputs, reference_inputs, parameters, outputs, returns, dependencies): try: # retrieve ID list spent_list = loads(outputs[1]) # retrieve vvk & sig packed_vvk = spent_list['vvk'] sig = pet_unpack(parameters[0]) # check format if len(inputs) != 1 or len(reference_inputs) != 0 or len(outputs) != 2 or len(returns) != 0: return False # check types if loads(inputs[0])['type'] != 'TToken' or loads(outputs[0])['type'] != 'TToken': return False if spent_list['type'] != 'TList': return False # verify that the spent list is empty if spent_list['list']: return False # verify signature bp_params = bp_setup() hasher = sha256() hasher.update(outputs[1].encode('utf8')) m = Bn.from_binary(hasher.digest()) vvk = (unpackG2(bp_params,packed_vvk[0]), unpackG2(bp_params,packed_vvk[1]), unpackG2(bp_params,packed_vvk[2])) if not verify(bp_params, vvk, m, sig): return False # otherwise return True except (KeyError, Exception): return False
def sign(inputs, reference_inputs, parameters, priv_signer, sig, vvk): # ini petition, list and parameters old_petition = loads(inputs[0]) new_petition = loads(inputs[0]) old_list = loads(inputs[1]) new_list = loads(inputs[1]) new_values = loads(parameters[0]) # update petition values for i in range(0, len(new_values)): new_petition['scores'][i] = old_petition['scores'][i] + new_values[i] # prepare showing of credentials UUID = pet_unpack(old_petition['UUID']) bp_params = bp_setup() (kappa, nu, proof_v) = show_coconut_petition(bp_params, vvk, priv_signer, UUID) #print(coconut_petition_verify(bp_params, vvk, kappa, sig, proof_v, UUID, nu)) # update spent list new_list['list'].append(pack(nu)) # pack sig packed_sig = (pack(sig[0]), pack(sig[1])) # return return { 'outputs': (dumps(new_petition), dumps(new_list)), 'extra_parameters': (packed_sig, pack(kappa), pack(nu), pet_pack(proof_v)) }
def redeem_checker(inputs, reference_inputs, parameters, outputs, returns, dependencies): try: # retrieve ID list old_list = loads(inputs[0]) new_list = loads(outputs[0]) # retrieve parameters bp_params = bp_setup() ID = loads(parameters[0]) merchant_addr = loads(parameters[1]) packed_sig = parameters[2] sig = (unpackG1(bp_params, packed_sig[0]), unpackG1(bp_params, packed_sig[1])) # check format if len(inputs) != 1 or len(reference_inputs) != 0 or len(outputs) != 1 or len(returns) != 0: return False # check types if new_list['type'] != 'TList': return False # check format & consistency with old object packed_vvk = new_list['vvk'] if new_list['vvk'] != new_list['vvk']: return False # check spent list if (ID in old_list['list']) or (new_list['list'] != old_list['list'] + [ID]): return False # verify signature and nu's correctness vvk = (unpackG2(bp_params,packed_vvk[0]), unpackG2(bp_params,packed_vvk[1]), unpackG2(bp_params,packed_vvk[2])) hasher = sha256() hasher.update(parameters[0].encode('utf8')) hasher.update(parameters[1].encode('utf8')) m = Bn.from_binary(hasher.digest()) if not verify(bp_params, vvk, m, sig): return False # otherwise return True except (KeyError, Exception): return False
start_tx = datetime.now() response = client.process_transaction(tx) client_latency = (datetime.now() - start_tx) print response.text json_response = json.loads(response.text) results.append((json_response['success'], response.url, str(client_latency), tx['transaction']['methodID'])) start_time = datetime.now() client = ChainspaceClient() # crypto parameters t, n = 4, 5 # threshold and total number of authorities bp_params = bp_setup() # bp system's parameters (sk, vk, vvk) = ttp_th_keygen(bp_params, t, n) # signers keys # petition parameters UUID = Bn(1234) options = ['YES', 'NO'] pet_params = pet_setup() (priv_owner, pub_owner) = pet_keygen(pet_params) tx_init = petition.init() # pp_object(tx_init) post_transaction(tx_init) # pp_object(init_transaction)
def sign_checker(inputs, reference_inputs, parameters, outputs, returns, dependencies): try: # retrieve petition old_petition = loads(inputs[0]) new_petition = loads(outputs[0]) # retrieve ID list old_list = loads(inputs[1]) new_list = loads(outputs[1]) # retrieve parameters bp_params = bp_setup() new_values = loads(parameters[0]) packed_sig = parameters[1] sig = (unpackG1(bp_params, packed_sig[0]), unpackG1(bp_params, packed_sig[1])) kappa = unpackG2(bp_params, parameters[2]) nu = unpackG1(bp_params, parameters[3]) proof_v = pet_unpack(parameters[4]) # check format if len(inputs) != 2 or len(reference_inputs) != 0 or len( outputs) != 2 or len(returns) != 0: return False # check types if new_petition['type'] != 'PObject' or new_list['type'] != 'PList': return False # check format & consistency with old object UUID = pet_unpack(new_petition['UUID']) options = new_petition['options'] packed_vvk = new_petition['verifier'] scores = new_petition['scores'] if old_petition['UUID'] != new_petition['UUID']: return False if len(old_petition['owner']) != len(new_petition['owner']): return False if len(old_petition['options']) != len(new_petition['options']): return False if old_petition['verifier'] != new_petition['verifier']: return False # check new values if sum(new_values) != 1: return False for i in range(len(scores)): if scores[i] != old_petition['scores'][i] + new_values[i]: return False if new_values[i] != 0 and new_values[i] != 1: return False # check spent list packed_nu = parameters[3] if (packed_nu in old_list['list']) or (new_list['list'] != old_list['list'] + [packed_nu]): return False # verify signature and nu's correctness vvk = (unpackG2(bp_params, packed_vvk[0]), unpackG2(bp_params, packed_vvk[1]), unpackG2(bp_params, packed_vvk[2])) if not coconut_petition_verify(bp_params, vvk, kappa, sig, proof_v, UUID, nu): return False # otherwise return True except (KeyError, Exception): return False