Nostr.Event.Metadata (Nostr Lib v0.2.1) (event) (nip01) (nip24) (nip30) (nip39)

View Source

User metadata (Kind 0)

Implements NIP-01 (basic metadata), NIP-24 (extra metadata fields), NIP-30 (custom emoji), and NIP-39 (external identities).

NIP-01 Fields

  • name - username
  • about - bio/description
  • picture - avatar URL
  • nip05 - NIP-05 identifier

NIP-24 Extra Fields

  • display_name - alternative, richer display name
  • website - web URL related to the user
  • banner - wide background picture URL (~1024x768)
  • bot - boolean indicating automated content
  • birthday - birth date with optional year/month/day

NIP-30 Custom Emoji

  • emojis - map of shortcode => URL for custom emoji in name and about

NIP-39 External Identities

  • identities - list of external identity verifications (github, twitter, mastodon, telegram)

Examples

# Create basic metadata
Metadata.create("alice", "About me", "https://pic.com/a.jpg", "alice@example.com")

# Create with NIP-24 fields
Metadata.create("alice", "About me", "https://pic.com/a.jpg", "alice@example.com",
  display_name: "Alice Wonderland",
  website: "https://alice.example.com",
  banner: "https://pic.com/banner.jpg",
  bot: false,
  birthday: %{year: 1990, month: 1, day: 15}
)

# Create with custom emoji (NIP-30)
Metadata.create("Alice :verified:", "About me", nil, nil,
  emojis: %{"verified" => "https://example.com/verified.png"}
)

# Create with external identities (NIP-39)
Metadata.create("alice", "About me", nil, nil,
  identities: [
    %{platform: "github", identity: "alice", proof: "gist_id"},
    %{platform: "twitter", identity: "alice_btc", proof: "tweet_id"}
  ]
)

See:

Summary

Types

Birthday with optional year/month/day

t()

Types

birthday()

@type birthday() ::
  %{year: non_neg_integer() | nil, month: 1..12 | nil, day: 1..31 | nil} | nil

Birthday with optional year/month/day

t()

@type t() :: %Nostr.Event.Metadata{
  about: String.t() | nil,
  banner: URI.t() | nil,
  birthday: birthday(),
  bot: boolean() | nil,
  display_name: String.t() | nil,
  emojis: %{required(binary()) => binary()},
  event: Nostr.Event.t(),
  identities: [Nostr.NIP39.identity()],
  name: String.t() | nil,
  nip05: String.t() | nil,
  other: map(),
  picture: URI.t() | nil,
  user: binary(),
  website: URI.t() | nil
}

Functions

create(name, about, picture, nip05, opts \\ [])

@spec create(
  name :: String.t() | nil,
  about :: String.t() | nil,
  picture :: URI.t() | String.t() | nil,
  nip05 :: String.t() | nil,
  opts :: Keyword.t()
) :: t()

Create new Nostr.Event.Metadata struct.

Arguments

  • name - username
  • about - bio/description
  • picture - avatar URL (URI struct or String)
  • nip05 - NIP-05 identifier
  • opts - keyword list of options

Options

Event options:

  • :pubkey - author pubkey
  • :created_at - timestamp
  • :tags - additional tags

NIP-24 fields:

  • :display_name - alternative, richer display name
  • :website - web URL (String or URI)
  • :banner - background picture URL (String or URI)
  • :bot - boolean indicating automated content
  • :birthday - map with optional :year, :month, :day keys

NIP-30 fields:

  • :emojis - map of shortcode => URL for custom emoji in name and about

NIP-39 fields:

  • :identities - list of identity maps with :platform, :identity, :proof keys

Examples

Metadata.create("alice", "About me", "https://pic.com/a.jpg", "alice@example.com")

Metadata.create("alice", "About me", "https://pic.com/a.jpg", "alice@example.com",
  display_name: "Alice Wonderland",
  website: "https://alice.example.com",
  banner: "https://pic.com/banner.jpg",
  bot: false,
  birthday: %{year: 1990, month: 1, day: 15}
)

parse(event)

@spec parse(event :: Nostr.Event.t()) :: t() | {:error, String.t(), Nostr.Event.t()}

Parse generic Nostr.Event to Nostr.Event.Metadata struct.

Handles deprecated field normalization:

  • displayNamedisplay_name
  • usernamename