Use namedtuple for key pair

This commit is contained in:
Sylvain Bellemare 2017-03-14 11:47:44 +01:00 committed by Sylvain Bellemare
parent 3627978e16
commit 7b0e758bc1

View File

@ -1,18 +1,31 @@
# Separate all crypto code so that we can easily test several implementations
from collections import namedtuple
import sha3
from cryptoconditions import crypto
CryptoKeypair = namedtuple('CryptoKeypair', ('private_key', 'public_key'))
def hash_data(data):
"""Hash the provided data using SHA3-256"""
return sha3.sha3_256(data.encode()).hexdigest()
def generate_key_pair():
"""Generates a cryptographic key pair.
Returns:
:class:`~bigchaindb.common.crypto.CryptoKeypair`: A
:obj:`collections.namedtuple` with named fields
:attr:`~bigchaindb.common.crypto.CryptoKeypair.private_key` and
:attr:`~bigchaindb.common.crypto.CryptoKeypair.public_key`.
"""
# TODO FOR CC: Adjust interface so that this function becomes unnecessary
private_key, public_key = crypto.ed25519_generate_key_pair()
return private_key.decode(), public_key.decode()
return CryptoKeypair(
*(k.decode() for k in crypto.ed25519_generate_key_pair()))
PrivateKey = crypto.Ed25519SigningKey