implement basic protocol in nip-01

This commit is contained in:
jeffthibault
2022-07-20 14:51:44 -04:00
parent 3964d0fe06
commit 8323b3e948
7 changed files with 259 additions and 0 deletions

20
nostr/key.py Normal file
View File

@@ -0,0 +1,20 @@
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:])