View Source Nostr.Event (Nostr Lib v0.1.1)
Nostr Event
Summary
Functions
Compute event ID from Nostr.Event
struct
Create new Nostr event struct
Parse raw event map to Nostr.Event
struct and validate ID and signature
Parse raw event map to specific event struct (also validates ID and signature)
Serialize event from Nostr.Event
struct
Sign the event with seckey
Types
@type t() :: %Nostr.Event{ content: binary(), created_at: DateTime.t(), id: <<_::32, _::_*8>>, kind: non_neg_integer(), pubkey: <<_::32, _::_*8>>, sig: <<_::64, _::_*8>>, tags: [Nostr.Tag.t()] }
Nostr event
Functions
Compute event ID from Nostr.Event
struct
Create new Nostr event struct
Requires event kind and optionally any other event field:
pubkey
- default isnil
(derived later during event signing)tags
- default is[]
(needs to be list ofNostr.Tag
structs)created_at
- default isDateTime.utc_now/0
content
- default is""
id
ignored (computed later during event signing)sig
ignored, if you want to signed event useNostr.Event.sign/2
Example
iex> Nostr.Event.create(1, content: "My note", created_at: ~U[2023-06-09 11:07:59.031962Z])
%Nostr.Event{
kind: 1,
pubkey: nil,
tags: [],
created_at: ~U[2023-06-09 11:07:59.031962Z],
content: "My note"
}
iex> tags = [Nostr.Tag.create(:e, "event-id")]
iex> Nostr.Event.create(1, created_at: ~U[2023-06-09 11:07:59.031962Z], tags: tags)
%Nostr.Event{
kind: 1,
pubkey: nil,
tags: [%Nostr.Tag{type: :e, data: "event-id", info: []}],
created_at: ~U[2023-06-09 11:07:59.031962Z],
content: ""
}
Parse raw event map to Nostr.Event
struct and validate ID and signature
Parse raw event map to specific event struct (also validates ID and signature)
Serialize event from Nostr.Event
struct
Sign the event with seckey
It auto-populates pubkey from seckey if event doesn't contain one or check it matches the seckey if there is an pubkey
It auto-populates event ID or check the ID is correct before signing