Skip to content

Commit

Permalink
Merge pull request #116 from EdjoLabs/master
Browse files Browse the repository at this point in the history
Added support for seed in generating key pair
  • Loading branch information
ttmc authored Oct 20, 2018
2 parents 1762f81 + d3c254a commit 819d312
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cryptoconditions/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def encode(self, encoding='base58'):
@classmethod
def generate(cls):
return cls(nacl.signing.SigningKey.generate().encode(encoder=Base58Encoder))

@classmethod
def generate_with_seed(cls, seed):
return cls(nacl.signing.SigningKey(seed).encode(encoder=Base58Encoder))


class Ed25519VerifyingKey(nacl.signing.VerifyKey):
Expand Down Expand Up @@ -143,14 +147,19 @@ def encode(self, encoding='base58'):
return super().encode(encoder=_get_nacl_encoder(encoding))


def ed25519_generate_key_pair():
def ed25519_generate_key_pair(seed=None):
"""
Generate a new key pair.
Args:
seed (bytes): 32-byte seed for deterministic generation.
Returns:
A tuple of (private_key, public_key) encoded in base58.
"""
sk = Ed25519SigningKey.generate()
if seed:
sk = Ed25519SigningKey.generate_with_seed(seed)
else:
sk = Ed25519SigningKey.generate()
# Private key
private_value_base58 = sk.encode(encoding='base58')

Expand Down

0 comments on commit 819d312

Please sign in to comment.