Skip to main content

Nostr identity SDK for OpenClaw AI entities — generate keys, sign events, encrypt data

Project description

NostrKey for OpenClaw

Give your AI its own cryptographic identity.

A Python SDK for OpenClaw AI entities to generate Nostr keypairs, sign events, encrypt data, and manage their own identity on the Nostr protocol.

Why?

AI agents need identity. Not a shared API key — their own keypair, their own signature, their own verifiable presence on an open protocol. That's what this SDK gives them.

A few things your bot can do with its own npub:

  • Sign its own work — every post, response, or action is cryptographically signed. Anyone can verify it came from your bot, not an impersonator.
  • Send and receive encrypted messages — private communication between your bot and its human, or between bots, using NIP-44 encryption. No platform middleman.
  • Persist memory across sessions — save encrypted identity files and reload them. Your bot picks up where it left off.
  • Publish to the Nostr network — your bot can post notes, respond to mentions, and interact on any Nostr relay. It's a first-class participant, not a wrapper around someone else's account.
  • Delegate sensitive actions to a human — via NIP-46 bunker, your bot can request its human sponsor to co-sign high-stakes events. The human stays in the loop without holding the bot's keys.

Install

pip install nostrkey

Quick Start

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=[]
)

# Publish to a relay
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 & Load Identity

# 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")

NIP-44 Encryption

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
)

NIP-46 Bunker (Delegated Signing)

When your bot needs its human sponsor to co-sign:

from nostrkey.bunker import BunkerClient

async def delegated_sign():
    bunker = BunkerClient(bot.nsec)
    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")

NIPs Implemented

NIP What Status
NIP-01 Basic protocol (events, signing) Implemented
NIP-04 Encrypted DMs (legacy) Implemented
NIP-19 bech32 encoding (npub/nsec/note) Implemented
NIP-44 Versioned encryption Implemented
NIP-46 Nostr Connect (bunker) Implemented

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nostrkey-0.1.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nostrkey-0.1.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file nostrkey-0.1.1.tar.gz.

File metadata

  • Download URL: nostrkey-0.1.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for nostrkey-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e8f7ae84ed9559195a5a65b7203f6111413099920d54b958691dcc9bcb790459
MD5 f6353e4522c2cb9c4b45465e84963d40
BLAKE2b-256 f3ae8da7849097817b519e0254dd7df81988adccd5be97bc475d1e32ee42ad67

See more details on using hashes here.

File details

Details for the file nostrkey-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nostrkey-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for nostrkey-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30e00564b64b411bee0eb0e7d4683d53a111321d31d1f45df73c0f26f58debd0
MD5 a08380ce30a4fd6efda02b5e27d96b03
BLAKE2b-256 2e38bbc9174fb17b2518841646fb3dff2f3e369950b361c7ce9147dd676332bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page