mirror of
https://github.com/aljazceru/python-nostr.git
synced 2025-12-19 07:14:23 +01:00
implement basic protocol in nip-01
This commit is contained in:
20
nostr/key.py
Normal file
20
nostr/key.py
Normal 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:])
|
||||
|
||||
Reference in New Issue
Block a user