Class NDKArticle

Represents a NIP-23 article.

Hierarchy

Constructors

Properties

content: string = ""
created_at?: number
decrypt: ((...args: [sender?: NDKUser, signer?: NDKSigner]) => Promise<void>) = ...

Type declaration

encode: ((...args: []) => `nevent1${string}` | `naddr1${string}` | `note1${string}`) = ...

Type declaration

    • (...args: []): `nevent1${string}` | `naddr1${string}` | `note1${string}`
    • Encodes a bech32 id.

      Parameters

      • Rest ...args: []

      Returns `nevent1${string}` | `naddr1${string}` | `note1${string}`

      • Encoded naddr, note or nevent.
encrypt: ((...args: [recipient?: NDKUser, signer?: NDKSigner]) => Promise<void>) = ...

Type declaration

id: string = ""
isEphemeral: ((...args: []) => boolean) = ...

Type declaration

    • (...args: []): boolean
    • Parameters

      • Rest ...args: []

      Returns boolean

isParamReplaceable: ((...args: []) => boolean) = ...

Type declaration

    • (...args: []): boolean
    • Parameters

      • Rest ...args: []

      Returns boolean

isReplaceable: ((...args: []) => boolean) = ...

Type declaration

    • (...args: []): boolean
    • Parameters

      • Rest ...args: []

      Returns boolean

kind?: number
ndk?: default
onRelays: NDKRelay[] = []

The relays that this event was received from and/or successfully published to.

pubkey: string = ""
relay: undefined | NDKRelay

The relay that this event was first received from.

repost: ((...args: [publish: boolean, signer?: NDKSigner]) => Promise<NDKEvent>) = ...

Type declaration

    • (...args: [publish: boolean, signer?: NDKSigner]): Promise<NDKEvent>
    • NIP-18 reposting event.

      Parameters

      • Rest ...args: [publish: boolean, signer?: NDKSigner]

      Returns Promise<NDKEvent>

      The reposted event

      Function

sig?: string
tags: NDKTag[] = []

Accessors

  • get alt(): undefined | string
  • Gets the NIP-31 "alt" tag of the event.

    Returns undefined | string

  • set alt(alt: undefined | string): void
  • Sets the NIP-31 "alt" tag of the event. Use this to set an alt tag so clients that don't handle a particular event kind can display something useful for users.

    Parameters

    • alt: undefined | string

    Returns void

  • get dTag(): undefined | string
  • Gets the NIP-33 "d" tag of the event.

    Returns undefined | string

  • set dTag(value: undefined | string): void
  • Sets the NIP-33 "d" tag of the event.

    Parameters

    • value: undefined | string

    Returns void

  • get image(): undefined | string
  • Getter for the article image.

    Returns undefined | string

    • The article image if available, otherwise undefined.
  • set image(image: undefined | string): void
  • Setter for the article image.

    Parameters

    • image: undefined | string

      The image to set for the article.

    Returns void

  • get isValid(): boolean
  • Checks whether the event is valid per underlying NIPs.

    This method is meant to be overridden by subclasses that implement specific NIPs to allow the enforcement of NIP-specific validation rules.

    Returns boolean

  • get published_at(): undefined | number
  • Getter for the article's publication timestamp.

    Returns undefined | number

    • The Unix timestamp of when the article was published or undefined.
  • set published_at(timestamp: undefined | number): void
  • Setter for the article's publication timestamp.

    Parameters

    • timestamp: undefined | number

      The Unix timestamp to set for the article's publication date.

    Returns void

  • get title(): undefined | string
  • Getter for the article title.

    Returns undefined | string

    • The article title if available, otherwise undefined.
  • set title(title: undefined | string): void
  • Setter for the article title.

    Parameters

    • title: undefined | string

      The title to set for the article.

    Returns void

  • get url(): undefined | string
  • Getter for the article's URL.

    Returns undefined | string

    • The article's URL if available, otherwise undefined.
  • set url(url: undefined | string): void
  • Setter for the article's URL.

    Parameters

    • url: undefined | string

      The URL to set for the article.

    Returns void

Methods

  • Provides a deduplication key for the event.

    For kinds 0, 3, 10k-20k this will be the event : For kinds 30k-40k this will be the event :: For all other kinds this will be the event id

    Returns string

  • Generates a deletion event of the current event

    Parameters

    • Optional reason: string

      The reason for the deletion

    • publish: boolean = true

      Whether to publish the deletion event automatically

    Returns Promise<NDKEvent>

    The deletion event

  • Provides the filter that will return matching events for this event.

    Returns NDKFilter

    The filter that will return matching events for this event

    Example

    event = new NDKEvent(ndk, { kind: 30000, pubkey: 'pubkey', tags: [ ["d", "d-code"] ] });
    event.filter(); // { "#a": ["30000:pubkey:d-code"] }

    Example

    event = new NDKEvent(ndk, { kind: 1, pubkey: 'pubkey', id: "eventid" });
    event.filter(); // { "#e": ["eventid"] }
  • Generates content tags for the article.

    This method first checks and sets the publication date if not available, and then generates content tags based on the base NDKEvent class.

    Returns Promise<ContentTag>

    • The generated content tags.
  • Attempt to sign and then publish an NDKEvent to a given relaySet. If no relaySet is provided, the relaySet will be calculated by NDK.

    Parameters

    • Optional relaySet: NDKRelaySet

      {NDKRelaySet} The relaySet to publish the even to.

    • Optional timeoutMs: number

    Returns Promise<Set<NDKRelay>>

    A promise that resolves to the relays the event was published to.

  • Get the tags that can be used to reference this event from another event

    Parameters

    • Optional marker: string

      The marker to use in the tag

    • Optional skipAuthorTag: boolean

    Returns NDKTag[]

    The NDKTag object referencing this event

    Example

    event = new NDKEvent(ndk, { kind: 30000, pubkey: 'pubkey', tags: [ ["d", "d-code"] ] });
    event.referenceTags(); // [["a", "30000:pubkey:d-code"], ["e", "parent-id"]]

    event = new NDKEvent(ndk, { kind: 1, pubkey: 'pubkey', id: "eventid" });
    event.referenceTags(); // [["e", "parent-id"]]
  • Remove all tags with the given name (e.g. "d", "a", "p")

    Parameters

    • tagName: string

      Tag name to search for and remove

    Returns void

  • Returns the "d" tag of a parameterized replaceable event or throws an error if the event isn't a parameterized replaceable event.

    Returns string

    the "d" tag of the event.

  • Sign the event if a signer is present.

    It will generate tags. Repleacable events will have their created_at field set to the current time.

    Parameters

    • Optional signer: NDKSigner

      {NDKSigner} The NDKSigner to use to sign the event

    Returns Promise<string>

    A Promise that resolves to the signature of the signed event.

  • Tag a user with an optional marker.

    Parameters

    • user: NDKUser

      The user to tag.

    • Optional marker: string

      The marker to use in the tag.

    Returns void

  • Tag a user with an optional marker.

    Parameters

    • user: NDKUser

      The user to tag.

    • Optional marker: string

      The marker to use in the tag.

    Returns void

  • Tag a user with an optional marker.

    Parameters

    • event: NDKEvent

      The event to tag.

    • Optional marker: string

      The marker to use in the tag.

    • Optional skipAuthorTag: boolean

      Whether to explicitly skip adding the author tag of the event.

    Returns void

    Example

    reply.tag(opEvent, "reply");
    // reply.tags => [["e", <id>, <relay>, "reply"]]
  • Returns the id of the event or, if it's a parameterized event, the generated id of the event using "d" tag, pubkey, and kind.

    Returns string

    The id

  • Get the tag that can be used to reference this event from another event.

    Consider using referenceTags() instead (unless you have a good reason to use this)

    Parameters

    • Optional marker: string

    Returns NDKTag

    The NDKTag object referencing this event

    Example

    event = new NDKEvent(ndk, { kind: 30000, pubkey: 'pubkey', tags: [ ["d", "d-code"] ] });
    event.tagReference(); // ["a", "30000:pubkey:d-code"]

    event = new NDKEvent(ndk, { kind: 1, pubkey: 'pubkey', id: "eventid" });
    event.tagReference(); // ["e", "eventid"]
  • Get the first tag with the given name

    Parameters

    • tagName: string

      Tag name to search for

    Returns undefined | string

    The value of the first tag with the given name, or undefined if no such tag exists

  • Return a NostrEvent object, trying to fill in missing fields when possible, adding tags when necessary.

    Parameters

    • Optional pubkey: string

      {string} The pubkey of the user who the event belongs to.

    Returns Promise<NostrEvent>

    A promise that resolves to a NostrEvent.

  • Create a zap request for an existing event

    Parameters

    • amount: number

      The amount to zap in millisatoshis

    • Optional comment: string

      A comment to add to the zap request

    • Optional extraTags: NDKTag[]

      Extra tags to add to the zap request

    • Optional recipient: NDKUser

      The zap recipient (optional for events)

    • Optional signer: NDKSigner

      The signer to use (will default to the NDK instance's signer)

    Returns Promise<null | string>

Generated using TypeDoc