Comamoca/nosnos
Nosnos is a Elixir library implementing NIP-01 cryptographic operations using Zig NIFs.
🔐 High-performance Nostr cryptographic operations library for Elixir
Nosnos is a Elixir library implementing BIP-340 Schnorr signatures and Nostr protocol (NIP-01) cryptographic operations using Zig NIFs for performance.
# Generate a random secret key (32 bytes)
secret_key = :crypto.strong_rand_bytes(32)
# Derive the public key
public_key = Nosnos.get_public_key(secret_key)
# Sign a message
message = "Hello Nostr!"
message_hash = :crypto.hash(:sha256, message)
signature = Nosnos.sign(secret_key, message_hash)
# Verify the signature
is_valid = Nosnos.verify(public_key, message_hash, signature)
# Sign a Nostr event
secret_key = :crypto.strong_rand_bytes(32)
timestamp = :os.system_time(:second)
content = "Hello from Elixir!"
tags = "[]" # JSON string
event = Nosnos.sign_event(secret_key, timestamp, 1, tags, content)
# => %{
# id: "356faddb...",
# pubkey: "132fc0db...",
# created_at: 1700000000,
# kind: 1,
# tags: "[]",
# content: "Hello from Elixir!",
# sig: "fb8f88a9..."
# }
# Verify a Nostr event
is_valid = Nosnos.verify_event(event)
Add nosnos to your list of dependencies in mix.exs:
def deps do
[
{:nosnos, "~> 0.1.0"}
]
end
Then run:
mix deps.get
mix compile
git clone https://github.com/Comamoca/nosnos.git
cd nosnos
mix deps.get
mix test
This project uses Nix flakes for reproducible development environments:
# Enter the development shell
nix develop
# Or use direnv (if .envrc is configured)
direnv allow
The Nix environment includes:
# Install dependencies
mix deps.get
# Run tests
mix test
# Format code
mix format
MIT License