Awesome
nmostr
Library for working with Nostr.
Contained modules:
- Events
- Messages
- Bech32
- Proof of work
Stability: Early days. Functional.
Usage
Compile with -d:ssl
for wss://
connections
Example uses guzba's whisky i.e. nimble install whisky
import pkg/[nmostr, whisky]
let keypair = random Keypair
echo "New secret key: " & keypair.seckey.toBech32
echo "The public key: " & keypair.pubkey.toBech32
# Post a note
let socket = newWebSocket("wss://nostr.bongbong.com") # Remember to build with -d:ssl
socket.send CMEvent(event: note(keypair, "Hello world from nmostr!")).toJson
let response = socket.receiveMessage().get.data
echo response
# Read the note back
unpack fromMessage(response), msg:
when msg is SMOk:
socket.send CMRequest(id: randomID(), filter: Filter(ids: @[msg.id.hex])).toJson
echo socket.receiveMessage().get.data
For more, see the reference client niomo and tests.
What is Nostr?
Nostr is a simple decentralized protocol. It defines a standard for sending and receiving messages between users identified by their public keys using generic servers or "relays" that handle storage and logic.
Its popularity grew with the goal of creating a decentralized alternative to Twitter and an alternative to the Fediverse (Mastodon/Pleroma) that doesn't constrain users to one server that can be shut down or blocked.