Give your AI its own cryptographic identity
AI agents need identity. Not a shared API key — their own keypair, their own signature, their own verifiable presence on an open protocol.
pip install nostrkey
Requires Python 3.10 – 3.14. Dependencies: cryptography, websockets, bech32. No C compiler needed.
from nostrkey import Identity
# Create a new AI identity
bot = Identity.generate()
print(f"npub: {bot.npub}")
print(f"nsec: {bot.nsec}")
# Sign a Nostr event
event = bot.sign_event(
kind=1,
content="Hello from an OpenClaw bot!",
tags=[]
)
import asyncio
from nostrkey.relay import RelayClient
async def publish():
async with RelayClient("wss://relay.damus.io") as relay:
await relay.publish(event)
asyncio.run(publish())
# Save identity to file (encrypted)
bot.save("my-bot.nostrkey", passphrase="strong-passphrase")
# Load it back
bot = Identity.load("my-bot.nostrkey", passphrase="strong-passphrase")
from nostrkey.crypto import encrypt, decrypt
# Encrypt a message to another npub
ciphertext = encrypt(
sender_nsec=bot.nsec,
recipient_npub="npub1abc...",
plaintext="secret message"
)
# Decrypt a message
plaintext = decrypt(
recipient_nsec=bot.nsec,
sender_npub="npub1abc...",
ciphertext=ciphertext
)
When your bot needs its human sponsor to co-sign:
from nostrkey.bunker import BunkerClient
async def delegated_sign():
bunker = BunkerClient(bot.private_key_hex)
await bunker.connect("bunker://npub1human...?relay=wss://relay.damus.io")
# Request the human to sign an event
signed = await bunker.sign_event(kind=1, content="Human-approved message")
High-level identity management. Generate, import, sign, save, and load identities.
Keypair generation, bech32 encoding (npub/nsec), and hex conversion.
Create, serialize, hash, and sign Nostr events (NIP-01).
NIP-44 versioned encryption and decryption for private data.
NIP-46 bunker client for delegated signing to a human sponsor.
Async WebSocket relay client. Publish events, subscribe to filters.
| NIP | What |
|---|---|
| NIP-01 | Basic protocol — events, signing, verification |
| NIP-04 | Encrypted DMs (legacy, for compatibility) |
| NIP-19 | Bech32 encoding — npub, nsec, note |
| NIP-44 | Versioned encryption (ECDH + HKDF + ChaCha20) |
| NIP-46 | Nostr Connect — bunker / delegated signing |
NostrKey is available as an OpenClaw skill on ClawHub so AI agents can discover and use it automatically.
clawhub install nostrkey
The skill teaches OpenClaw agents how to generate identities, sign events, encrypt messages, and persist keys — all using the nostrkey pip package under the hood.
Part of the OpenClaw ecosystem. NostrKey is the identity pillar — the foundation that the other OpenClaw skills build on. Learn more about OpenClaw.