mirror of
https://github.com/aljazceru/python-nostr.git
synced 2025-12-19 07:14:23 +01:00
20 lines
691 B
Python
20 lines
691 B
Python
from secp256k1 import PrivateKey
|
|
|
|
def generate_private_key() -> str:
|
|
private_key = PrivateKey()
|
|
public_key = private_key.pubkey.serialize().hex()
|
|
while not public_key.startswith("02"):
|
|
private_key = PrivateKey()
|
|
public_key = private_key.pubkey.serialize().hex()
|
|
return private_key.serialize()
|
|
|
|
def get_public_key(secret: str) -> str:
|
|
private_key = PrivateKey(bytes.fromhex(secret))
|
|
public_key = private_key.pubkey.serialize().hex()
|
|
return public_key[2:] # chop off sign byte
|
|
|
|
def get_key_pair() -> tuple:
|
|
private_key = PrivateKey()
|
|
public_key = private_key.pubkey.serialize().hex()
|
|
return (private_key.serialize(), public_key[2:])
|
|
|