View Source nostr

nostr Elixir

Communicate with any participant, be it relays or clients, with elixir

disclamer

DISCLAMER

This library is in the process of being built in the wild. It should at the moment be considered alpha quality. Function names and what they return will most probably be improved in the near future, so don't expect to write production code on top of it just yet. This is for education purposes only.

The current goal is to get feature complete with the most common NIPs, and will then be refined so it's as easy to use as can be.

installation

Installation

def deps do
  [
    {:nostr, "~> 0.1.3"}
  ]
end

create-a-private-key

Create a private key

iex -S mix
Nostr.Keys.PrivateKey.create()

use-the-example-app

Use the example app

In the lib/examples, there is a NostrApp ready to be used. It connects to a relay and retrieves your own notes and stuff. The easiest way to use it is to create a .iex.local.exs file and paste that in

relays = [
  "wss://relay.nostr.bg",
  "wss://relay.nostr.pro"
]

private_key = Nostr.Keys.PrivateKey.create

NostrApp.start_link(relays, private_key)

and start iex

iex -S mix

now-what

Now what?

edit-your-profile

Edit your profile

profile = %Nostr.Models.Profile{
  about: "Instance of https://github.com/RooSoft/nostr being tested in the wild",
  name: "roosoft_test_bot",
  picture: "https://nostr.build/i/p/5158p.jpg"
}
|> NostrApp.update_profile()

subscribe-to-your-profile-will-send-the-current-version-and-any-subsequent-changes

Subscribe to your profile... will send the current version and any subsequent changes

NostrApp.profile

subscribe-to-a-timeline

Subscribe to a timeline

Nostr.Keys.PublicKey.from_private(private_key)
|> NostrApp.timeline()

You'll receive past and live events from all your followed contacts into the console, and are now able to send messages with that identity.

send-a-message

Send a message

NostrApp.send("aren't you entertained?")

repost-a-message

Repost a message

"note14n5txr742qzq4awx0mmd2x36tul9lrlrgfjvjpr6ev8h82z6yzqs5msdq7"
|> Nostr.Models.Note.Id.from_bech32()
|> NostrApp.repost()

delete-a-message

Delete a message

"note14n5txr742qzq4awx0mmd2x36tul9lrlrgfjvjpr6ev8h82z6yzqs5msdq7"
|> Nostr.Models.Note.Id.from_bech32()
|> NostrApp.delete()

follow-someone

Follow someone

This is a bit rough around the edges still, but will be simplified soon

"npub1s5yq6wadwrxde4lhfs56gn64hwzuhnfa6r9mj476r5s4hkunzgzqrs6q7z"
|> Nostr.Keys.PublicKey.from_npub!()
|> NostrApp.follow()

unfollow-someone

Unfollow someone

"npub1s5yq6wadwrxde4lhfs56gn64hwzuhnfa6r9mj476r5s4hkunzgzqrs6q7z"
|> Nostr.Keys.PublicKey.from_npub!()
|> NostrApp.unfollow()

see-who-someone-is-currently-following

See who someone is currently following

Could be yourself or anybody...

"npub1s5yq6wadwrxde4lhfs56gn64hwzuhnfa6r9mj476r5s4hkunzgzqrs6q7z"
|> Nostr.Keys.PublicKey.from_npub!()
|> NostrApp.contacts 

subscribe-to-incoming-encrypted-direct-messages

Subscribe to incoming encrypted direct messages

NostrApp.encrypted_direct_messages

send-an-encrypted-direct-message-to-someone

Send an encrypted direct message to someone

"npub1s5yq6wadwrxde4lhfs56gn64hwzuhnfa6r9mj476r5s4hkunzgzqrs6q7z"
|> Nostr.Keys.PublicKey.from_npub!()
|> NostrApp.send_encrypted_direct_messages "Howdy?"