#!/usr/bin/env python3
"""Generate Nostr keypairs for Timmy Time team agents."""

import json
import os
import stat
from nostr_sdk import Keys

AGENTS = ["timmy", "claude", "gemini", "groq", "grok", "hermes", "alexander"]
OUTPUT_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "agent_keys.json")


def main():
    all_keys = {}

    for agent in AGENTS:
        keys = Keys.generate()
        all_keys[agent] = {
            "npub": keys.public_key().to_bech32(),
            "nsec": keys.secret_key().to_bech32(),
            "hex_pub": keys.public_key().to_hex(),
            "hex_sec": keys.secret_key().to_hex(),
        }

    # Write keys to JSON file
    with open(OUTPUT_FILE, "w") as f:
        json.dump(all_keys, f, indent=2)

    # Set file permissions to 600 (owner read/write only)
    os.chmod(OUTPUT_FILE, stat.S_IRUSR | stat.S_IWUSR)

    # Print summary (public keys only)
    print("=" * 60)
    print("  Nostr Keypairs Generated for Timmy Time Team")
    print("=" * 60)
    for agent, data in all_keys.items():
        print(f"  {agent:12s} -> {data['npub']}")
    print("=" * 60)
    print(f"\nKeys saved to: {OUTPUT_FILE}")
    print(f"File permissions set to 600 (owner read/write only)")
    print(f"Total keypairs generated: {len(all_keys)}")


if __name__ == "__main__":
    main()
