Skip to content

Instantly share code, notes, and snippets.

@luisschwab
Last active March 15, 2023 20:52
Show Gist options
  • Save luisschwab/9e96c71ad66fc32e3797b374789ed521 to your computer and use it in GitHub Desktop.
Save luisschwab/9e96c71ad66fc32e3797b374789ed521 to your computer and use it in GitHub Desktop.
nostr key generator
#!/usr/bin/python3
'''
usage:
trusted:
./nostr-keygen.py (will generate a private key)
trustless:
./nostr-keygen.py <32 byte hex privkey> (will derive the pubkey)
./nostr-keygen.py "$(openssl rand -hex 32)"
'''
import sys
from nostr.key import PrivateKey
if len(sys.argv) > 1:
private_key = PrivateKey(bytes.fromhex(sys.argv[1]))
else:
private_key = PrivateKey()
public_key = private_key.public_key
print(f"PRIV:\n{private_key.bech32()}\n{private_key.hex()}\n")
print(f"PUB:\n{public_key.bech32()}\n{public_key.hex()}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment