Nostr. Event. DraftWrap
(Nostr Lib v0.2.1)
(event)
(nip37)
View Source
Draft Wraps (Kind 31234)
Encrypted storage for unsigned draft events. The draft is JSON-stringified, NIP-44 encrypted to the signer's own public key, and stored in content.
Examples
# Create a draft wrap for a note
draft = %{kind: 1, content: "My draft note", tags: []}
{:ok, wrap} = DraftWrap.create(draft, seckey, identifier: "my-draft")
# Decrypt a draft wrap
{:ok, decrypted} = DraftWrap.decrypt(wrap, seckey)
decrypted.draft # => %{kind: 1, content: "My draft note", tags: []}
# Create a deletion (blanked content)
{:ok, deletion} = DraftWrap.delete("my-draft", pubkey: pubkey)See: https://github.com/nostr-protocol/nips/blob/master/37.md
Summary
Functions
Creates a draft wrap event.
Decrypts a draft wrap and returns it with the draft field populated.
Creates a draft deletion event (blanked content).
Checks if this draft wrap represents a deletion (blanked content).
Parses a kind 31234 event into a DraftWrap struct.
Types
@type t() :: %Nostr.Event.DraftWrap{ draft: map() | nil, draft_kind: non_neg_integer() | nil, event: Nostr.Event.t(), expiration: non_neg_integer() | nil, identifier: binary() }
Functions
@spec create( draft :: map() | Nostr.Event.t(), seckey :: binary(), opts :: Keyword.t() ) :: {:ok, t()}
Creates a draft wrap event.
The draft is JSON-stringified and NIP-44 encrypted to the signer's public key.
Arguments
draft- Map or Event struct representing the unsigned draft eventseckey- Hex-encoded secret key for signing and encryptionopts- Options
Options
:identifier- The d tag identifier (default: random UUID):expiration- Unix timestamp when the draft expires:pubkey- Override pubkey (derived from seckey if not provided):created_at- Override created_at timestamp
Returns
{:ok, draft_wrap}- The created draft wrap (with draft field populated)
Decrypts a draft wrap and returns it with the draft field populated.
Arguments
wrap- The DraftWrap struct to decryptseckey- Hex-encoded secret key for decryption
Returns
{:ok, draft_wrap}- The wrap with draft field populated{:error, reason}- On decryption failure
Creates a draft deletion event (blanked content).
A blanked content field signals that the draft has been deleted.
Arguments
identifier- The d tag identifier of the draft to deleteopts- Options (requires :pubkey or :seckey)
Options
:pubkey- Author's public key (required if seckey not provided):seckey- Secret key to derive pubkey and sign:draft_kind- Optional kind of the original draft:created_at- Override created_at timestamp
Returns
{:ok, draft_wrap}- The deletion wrap (unsigned unless seckey provided)
Checks if this draft wrap represents a deletion (blanked content).
@spec parse(Nostr.Event.t()) :: t()
Parses a kind 31234 event into a DraftWrap struct.
The draft field will be nil until decrypt/2 is called.