Nostr.Event.Rumor (Nostr Lib v0.2.1) (event) (nip59)

View Source

Unsigned Nostr event (Rumor)

A rumor is the same thing as an unsigned event. Any event kind can be made a rumor by removing the signature. This provides deniability - if a rumor is leaked, it cannot be verified.

Defined in NIP 59 https://github.com/nostr-protocol/nips/blob/master/59.md

Summary

Types

t()

Unsigned Nostr event (rumor)

Functions

Compute the event ID (SHA256 hash of serialized event)

Create a new rumor (unsigned event)

Convert a signed event to a rumor by stripping the signature

Parse a raw map into a rumor struct

Serialize rumor for ID computation (NIP-01 format)

Types

t()

@type t() :: %Nostr.Event.Rumor{
  content: binary(),
  created_at: DateTime.t(),
  id: binary() | nil,
  kind: non_neg_integer(),
  pubkey: binary() | nil,
  tags: [Nostr.Tag.t()]
}

Unsigned Nostr event (rumor)

Functions

compute_id(rumor)

@spec compute_id(t()) :: binary()

Compute the event ID (SHA256 hash of serialized event)

create(kind, opts \\ [])

@spec create(kind :: non_neg_integer(), opts :: Keyword.t()) :: t()

Create a new rumor (unsigned event)

Requires event kind and optionally any other event field:

  • pubkey - public key of the author (required for encryption)
  • tags - default is [] (needs to be list of Nostr.Tag structs)
  • created_at - default is DateTime.utc_now/0
  • content - default is ""

The ID is computed automatically.

Example

iex> rumor = Nostr.Event.Rumor.create(1, pubkey: "abc123", content: "Hello")
iex> rumor.kind
1
iex> rumor.content
"Hello"

from_event(event)

@spec from_event(Nostr.Event.t()) :: t()

Convert a signed event to a rumor by stripping the signature

Example

iex> event = %Nostr.Event{kind: 1, content: "test", tags: [], created_at: ~U[2023-01-01 00:00:00Z], pubkey: "abc", id: "123", sig: "xyz"}
iex> rumor = Nostr.Event.Rumor.from_event(event)
iex> rumor.kind
1
iex> rumor.id
"123"

parse(data)

@spec parse(map()) :: t()

Parse a raw map into a rumor struct

Unlike regular events, rumors have no signature to validate.

serialize(rumor)

@spec serialize(t()) :: String.t()

Serialize rumor for ID computation (NIP-01 format)