mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Use namedtuple for key pair
This commit is contained in:
parent
3627978e16
commit
7b0e758bc1
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user