Nostr. Event
(Nostr Lib v0.2.1)
View Source
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)
Parse raw event map to Nostr.Event struct without validating ID or 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
@spec create(non_neg_integer(), Keyword.t()) :: t()
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.Tagstructs)created_at- default isDateTime.utc_now/0content- default is""idignored (computed later during event signing)sigignored, 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)
Parse raw event map to Nostr.Event struct without validating ID or signature.
Useful for relays that need to preserve the event struct (including the claimed ID)
even when validation fails, so they can produce NIP-01 compliant OK error responses.
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