def add_encrypted_bulletins_to_sum_handler(): data = get_post_data(request) encryptedBulletins = list(str_to_int(data.get('encryptedBulletins'))) mainKey = str_to_int(data.get('mainKey')) prevSums = data.get('prevSums') sum_A, sum_B = add_encrypted_bulletins_to_sum(encryptedBulletins, mainKey, prevSums) return jsonify({"sum_A": int_to_str(sum_A), "sum_B": int_to_str(sum_B)})
def generate_key_pair_handler(): data = get_post_data(request) privateKey, publicKey = generate_key_pair() if data.get('format') == 'hex': publicKey = [format(publicKey.x, 'x'), format(publicKey.y, 'x')] else: publicKey = int_to_str([publicKey.x, publicKey.y]) return jsonify({ "privateKey": int_to_str(privateKey), "publicKey": publicKey })
def subtract_encrypted_bulletins_from_sum_handler(): data = get_post_data(request) encryptedBulletins = list( map(lambda v: [str_to_int(v[0]), str_to_int(v[1])], data.get('encryptedBulletins'))) mainKey = str_to_int(data.get('mainKey')) prevSums = data.get('prevSums') sum_A, sum_B = subtract_encrypted_bulletins_from_sum( encryptedBulletins, mainKey, prevSums) return jsonify({"sum_A": int_to_str(sum_A), "sum_B": int_to_str(sum_B)})
def generate_keys_handler(): privateKey, publicKey = generate_pair() secretKeyOfCommit = gen_random_from_scalar_field() publicKeyCommit = pedersen_commit(privateKey, secretKeyOfCommit) return jsonify({ "privateKey": int_to_str(privateKey), "publicKey": int_to_str([publicKey.x, publicKey.y]), "secretKeyOfCommit": int_to_str(secretKeyOfCommit), # r (steps 1,2) "publicKeyCommit": int_to_str([publicKeyCommit.x, publicKeyCommit.y]), # C (step 1) })
def calculate_main_key_hanlder(): data = get_post_data(request) publicKeysCommits = list( map(lambda publicKeyCommit: str_to_int(publicKeyCommit), data.get('publicKeysCommits'))) secretKeysOfCommits = str_to_int(data.get('secretKeysOfCommits')) mainKey = calculate_main_key(publicKeysCommits, secretKeysOfCommits) return jsonify({"mainKey": int_to_str(mainKey)})
def add_commission_key_handler(): data = get_post_data(request) decryptKey = str_to_int(data.get('decryptKey')) commissionPubKey = str_to_hex(data.get('commissionPubKey')) result, data = add_commission_key(decryptKey, commissionPubKey) if not result: return jsonify(data), 400 else: return jsonify({"mainKey": int_to_str(data)})
def calculate_encrypted_shadows_handler(): data = get_post_data(request) coefficients = str_to_int(data.get('polynomialCoefficients')) unblindedPublicKeys = list( map(lambda publicKey: str_to_int(publicKey), data.get('unblindedPublicKeys'))) encryptedShadows = calculate_encrypted_shadows(coefficients, unblindedPublicKeys) return jsonify({ "encryptedShadows": list( map( lambda encryptedShadow: { "privateKey": int_to_str(encryptedShadow[0]), "publicKey": int_to_str([encryptedShadow[1].x, encryptedShadow[1].y]) }, encryptedShadows)) })
def calculate_polynomial_coefficients_exponents_handler(): data = get_post_data(request) coefficients = str_to_int(data.get('polynomialCoefficients')) polynomialCoefficientsExponents = calculate_polynomial_coefficients_exponents( coefficients) return jsonify({ "polynomialCoefficientsExponents": list( map(lambda exponent: int_to_str([exponent.x, exponent.y]), polynomialCoefficientsExponents)) })
def unblind_public_keys_hanlder(): data = get_post_data(request) publicKeysCommits = list( map(lambda publicKeyCommit: str_to_int(publicKeyCommit), data.get('publicKeysCommits'))) secretKeysOfCommits = str_to_int(data.get('secretKeysOfCommits')) unblindedPublicKeys = unblind_public_keys(publicKeysCommits, secretKeysOfCommits) return jsonify({ "unblindedPublicKeys": list( map(lambda publicKey: int_to_str([publicKey.x, publicKey.y]), unblindedPublicKeys)) })
def _cache(cls, id=None, deep=True): key_prefix = "%s_" % (cls.__name__) if not id: all_ids = helper.int_to_str(cls.all_ids()) if deep: entities = dict([(int(_id), cls.cache(int(_id))) for _id in all_ids]) else: entities = memcache.get_multi(keys=all_ids, key_prefix=key_prefix) return entities else: props = None if id: key = "%s%s" % (key_prefix, id) props = memcache.get(key) if not props: entity = cls.lookup(id) props = entity and entity.props() or None memcache.set(key, props) return props
def get_paramset_handler(): pedersenBase = create_point(pedersen_seed) return jsonify({ "a": int_to_str(a), "b": int_to_str(b), "p": int_to_str(p), "q": int_to_str(q), "base_point": int_to_str([x_base, y_base]), "pedersen_base": int_to_str([pedersenBase.x, pedersenBase.y]), "hash_length": int_to_str(hash_length) })
def get_base_point_handler(): return jsonify(int_to_str(get_base_point()))
def partially_decrypt_sum_a_handler(): data = get_post_data(request) sum_A = str_to_int(data.get('sum_A')) decryptedShadowsSum = str_to_int(data.get('decryptedShadowsSum')) partiallyDecrypted = partially_decrypt_sum_a(sum_A, decryptedShadowsSum) return jsonify({"partiallyDecrypted": int_to_str(partiallyDecrypted)})
def generate_polynomial_coefficients_handler(): data = get_post_data(request) privateKey = str_to_int(data.get('privateKey')) k = str_to_int(data.get('k')) coefficients = generate_polynomial_coefficients(privateKey, k) return jsonify({"polynomialCoefficients": int_to_str(coefficients)})
def restore_common_secret_handler(): data = get_post_data(request) indexes = str_to_int(data.get('indexes')) decryptedShadowsSums = str_to_int(data.get('decryptedShadowsSums')) commonSecret = restore_common_secret(indexes, decryptedShadowsSums) return jsonify({"commonSecret": int_to_str(commonSecret)})
def make_encrypted_bulletin_handler(): data = get_post_data(request) bulletin = str_to_int(data.get('bulletin')) mainKey = str_to_int(data.get('mainKey')) encrypted_bulletin, proof = make_encrypted_bulletin(bulletin, mainKey) return jsonify([list(int_to_str(encrypted_bulletin)), int_to_str(proof)])
def verify_encrypted_bulletins_handler(): data = get_post_data(request) encryptedBulletins = str_to_int(data.get('encryptedBulletins')) mainKey = str_to_int(data.get('mainKey')) verified = verify_encrypted_bulletins(encryptedBulletins, mainKey) return jsonify({"verified": int_to_str(verified)})