forked from nbd-wtf/bitcoin_signet
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathkeygen.py
More file actions
executable file
·35 lines (28 loc) · 922 Bytes
/
keygen.py
File metadata and controls
executable file
·35 lines (28 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
import sys
import secrets
from ecdsa import SigningKey, SECP256k1
def generate_keypair():
# Generate random private key
private_key = SigningKey.generate(curve=SECP256k1)
# Get private key as hex
private_hex = private_key.to_string().hex()
# Get public key point
public_key = private_key.get_verifying_key()
public_point = public_key.pubkey.point
# Format as compressed public key
x = public_point.x()
y = public_point.y()
if y % 2 == 0:
compressed = f"02{x:064x}"
else:
compressed = f"03{x:064x}"
return private_hex, compressed
if __name__ == "__main__":
try:
private_hex, public_hex = generate_keypair()
print(f"PRIVATE:{private_hex}")
print(f"PUBLIC:{public_hex}")
except ImportError:
print("ERROR: ecdsa library not available", file=sys.stderr)
exit(1)