Class default

The NDK class is the main entry point to the library.

Emits

signer:ready when a signer is ready

Hierarchy

  • EventEmitter
    • default

Constructors

Properties

cacheAdapter?: NDKCacheAdapter
clientName?: string
clientNip89?: string
debug: Debugger
devWriteRelaySet?: NDKRelaySet
explicitRelayUrls?: string[]
httpFetch: undefined | ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>)

Fetch function to use for HTTP requests.

Type declaration

    • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
    • Parameters

      • input: RequestInfo | URL
      • Optional init: RequestInit

      Returns Promise<Response>

Example

import fetch from "node-fetch";

ndk.httpFetch = fetch;
mutedIds: Map<string, string>
outboxPool?: NDKPool
outboxTracker?: OutboxTracker
pool: NDKPool
relayAuthDefaultPolicy?: NDKAuthPolicy

Default relay-auth policy that will be used when a relay requests authentication, if no other policy is specified for that relay.

Example

Disconnect from relays that request authentication:

ndk.relayAuthDefaultPolicy = NDKAuthPolicies.disconnect(ndk.pool);

Example

Sign in to relays that request authentication:

ndk.relayAuthDefaultPolicy = NDKAuthPolicies.signIn({ndk})

Example

Sign in to relays that request authentication, asking the user for confirmation:

ndk.relayAuthDefaultPolicy = (relay: NDKRelay) => {
const signIn = NDKAuthPolicies.signIn({ndk});
if (confirm(`Relay ${relay.url} is requesting authentication, do you want to sign in?`)) {
signIn(relay);
}
}

Accessors

  • get activeUser(): undefined | NDKUser
  • Returns undefined | NDKUser

  • set activeUser(user: undefined | NDKUser): void
  • Sets the active user for this NDK instance, typically this will be called when assigning a signer to the NDK instance.

    This function will automatically connect to the user's relays if autoConnectUserRelays is set to true.

    It will also fetch the user's mutelist if autoFetchUserMutelist is set to true.

    Parameters

    Returns void

Methods

  • Ensures that a signer is available to sign an event.

    Returns void

  • Connect to relays with optional timeout. If the timeout is reached, the connection will be continued to be established in the background.

    Parameters

    • Optional timeoutMs: number

    Returns Promise<void>

  • Creates a new Nip96 instance for the given domain.

    Parameters

    • domain: string

      Domain to use for nip96 uploads

    Returns Nip96

    Example

    Upload a file to a NIP-96 enabled domain:

    const blob = new Blob(["Hello, world!"], { type: "text/plain" });
    const nip96 = ndk.getNip96("nostrcheck.me");
    await nip96.upload(blob);
  • Get a NDKUser from a NIP05

    Parameters

    • nip05: string

      NIP-05 ID

    • skipCache: boolean = false

      Skip cache

    Returns Promise<undefined | NDKUser>

  • Publish an event to a relay

    Parameters

    • event: NDKEvent

      event to publish

    • Optional relaySet: NDKRelaySet

      explicit relay set to use

    • Optional timeoutMs: number

      timeout in milliseconds to wait for the event to be published

    Returns Promise<Set<NDKRelay>>

    The relays the event was published to

    Deprecated

    Use event.publish() instead

Generated using TypeDoc