Nostr.Event.Bookmarks (Nostr Lib v0.2.1) (event) (nip51)

View Source

Bookmarks (Kind 10003)

An uncategorized, "global" list of things a user wants to save. Can include notes (kind:1) via e tags and articles (kind:30023) via a tags.

Supports both public bookmarks (in tags) and private bookmarks (encrypted in content using NIP-44).

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

Summary

Functions

Creates a new bookmarks event (kind 10003).

Decrypts the private bookmarks using your secret key.

Parses a kind 10003 event into a Bookmarks struct.

Types

t()

@type t() :: %Nostr.Event.Bookmarks{
  articles: [binary()],
  event: Nostr.Event.t(),
  notes: [binary()],
  private_articles: :not_loaded | [binary()],
  private_notes: :not_loaded | [binary()]
}

Functions

create(items, opts \\ [])

@spec create(map() | Keyword.t(), Keyword.t()) :: t()

Creates a new bookmarks event (kind 10003).

Arguments

  • items - Map or keyword list with bookmark items
  • opts - Event options including :seckey for encrypting private items

Item Keys

  • :notes - List of note event IDs to bookmark publicly
  • :articles - List of article addresses (kind:30023) to bookmark publicly
  • :private_notes - List of note event IDs to bookmark privately
  • :private_articles - List of article addresses to bookmark privately

Options

  • :seckey - Required if any private items are specified
  • :pubkey - Event author pubkey
  • :created_at - Event timestamp

Example

Bookmarks.create(%{
  notes: ["abc123"],
  articles: ["30023:pubkey:identifier"],
  private_notes: ["secret_note_id"]
}, seckey: my_secret_key)

decrypt_private(bookmarks, seckey)

@spec decrypt_private(t(), binary()) :: t()

Decrypts the private bookmarks using your secret key.

The secret key must match the event's pubkey (you can only decrypt your own bookmarks). Automatically detects NIP-44 vs legacy NIP-04 encryption.

parse(event)

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

Parses a kind 10003 event into a Bookmarks struct.

Public bookmarks are parsed from tags. Private bookmarks remain encrypted until decrypt_private/2 is called.