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

View Source

Seal event (kind 13)

A seal is a kind 13 event that wraps a rumor with the sender's regular key. The seal is always encrypted to a receiver's pubkey but there is no p tag pointing to the receiver. There is no way to know who the rumor is for without the receiver's or the sender's private key.

The only public information in this event is who is signing it.

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

Summary

Types

t()

Seal event wrapping an encrypted rumor

Functions

Parse a kind 13 event into a Seal struct

Unwrap a seal to extract the rumor

Types

t()

@type t() :: %Nostr.Event.Seal{
  encrypted_rumor: binary(),
  event: Nostr.Event.t(),
  sender: binary()
}

Seal event wrapping an encrypted rumor

Functions

create(rumor, sender_seckey, recipient_pubkey, opts \\ [])

@spec create(Nostr.Event.Rumor.t(), binary(), binary(), Keyword.t()) :: t()

Create a seal from a rumor

Encrypts the rumor using NIP-44 with the sender's secret key and recipient's public key. The seal is signed by the sender.

Tags are always empty per NIP-59 spec. The created_at timestamp is randomized within the past 2 days to thwart timing analysis.

Parameters

  • rumor: The rumor to seal (must have pubkey set)
  • sender_seckey: Sender's secret key (hex-encoded)
  • recipient_pubkey: Recipient's public key (hex-encoded)
  • opts: Optional keyword list with :created_at to override random timestamp

Example

rumor = Rumor.create(1, pubkey: sender_pubkey, content: "Hello")
seal = Seal.create(rumor, sender_seckey, recipient_pubkey)

parse(event)

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

Parse a kind 13 event into a Seal struct

Note: This only extracts the encrypted content. Use unwrap/2 to decrypt the rumor.

unwrap(seal, recipient_seckey)

@spec unwrap(t(), binary()) :: {:ok, Nostr.Event.Rumor.t()} | {:error, atom()}

Unwrap a seal to extract the rumor

Decrypts the seal's content using the recipient's secret key. The sender's public key is obtained from the seal event.

Parameters

  • seal: The seal to unwrap
  • recipient_seckey: Recipient's secret key (hex-encoded)

Returns

  • {:ok, rumor} on success
  • {:error, reason} on failure