2026-07-21 10:26:42 +02:00
|
|
|
"""One-time ops bootstrap: generate and encrypt the server's master xprv.
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
|
2026-10-18 00:54:23 +02:00
|
|
|
# write it to the file XPRV_ENCRYPTION_KEY_FILE (.env) points at, then:
|
2026-07-21 10:26:42 +02:00
|
|
|
python scripts/generate_master_key.py
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from app.config import settings
|
|
|
|
|
from app.wallet.hd import generate_master_key
|
2026-10-18 00:38:26 +02:00
|
|
|
from app.wallet.verify import load_sample
|
2026-07-21 10:26:42 +02:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
if not settings.xprv_encryption_key:
|
2026-10-18 00:54:23 +02:00
|
|
|
raise SystemExit("XPRV_ENCRYPTION_KEY_FILE is not set, or its file is missing or empty")
|
2026-10-18 00:38:26 +02:00
|
|
|
sample = load_sample()
|
|
|
|
|
if sample.users or sample.rounds or sample.seeds:
|
|
|
|
|
# SEC-50: a new key cannot reproduce the addresses the database already holds.
|
|
|
|
|
raise SystemExit("the database already has users or rounds: a new key would not reproduce their addresses")
|
2026-07-21 10:26:42 +02:00
|
|
|
generate_master_key()
|
|
|
|
|
print(f"Master key written (encrypted) to {settings.master_key_path}")
|