Class NDKNip46Signer

This NDKSigner implements NIP-46, which allows remote signing of events. This class is meant to be used client-side, paired with the NDKNip46Backend or a NIP-46 backend (like Nostr-Connect)

Emits

authUrl -- Emitted when the user should take an action in certain URL. When a client receives this event, it should direct the user to go to that URL to authorize the application.

Example

const ndk = new NDK()
const nip05 = await prompt("enter your nip-05") // Get a NIP-05 the user wants to login with
const privateKey = localStorage.getItem("nip46-local-key") // If we have a private key previously saved, use it
const signer = new NDKNip46Signer(ndk, nip05, privateKey) // Create a signer with (or without) a private key

// Save generated private key for future use
localStorage.setItem("nip46-local-key", signer.localSigner.privateKey)

// If the backend sends an auth_url event, open that URL as a popup so the user can authorize the app
signer.on("authUrl", (url) => { window.open(url, "auth", "width=600,height=600") })

// wait until the signer is ready
const loggedinUser = await signer.blockUntilReady()

alert("You are now logged in as " + loggedinUser.npub)

Hierarchy

  • EventEmitter
    • NDKNip46Signer

Implements

Constructors

Properties

localSigner: NDKSigner
relayUrls: undefined | string[]
remotePubkey: undefined | string
remoteUser: NDKUser
token: undefined | string

Methods

  • Allows creating a new account on the remote server.

    Parameters

    • Optional username: string

      Desired username for the NIP-05

    • Optional domain: string

      Desired domain for the NIP-05

    • Optional email: string

      Email address to associate with this account -- Remote servers may use this for recovery

    Returns Promise<string>

    The public key of the newly created account

  • Encrypts the given Nostr event for the given recipient.

    Parameters

    • recipient: NDKUser

      The recipient of the encrypted value.

    • value: string

      The value to be encrypted.

    Returns Promise<string>

Generated using TypeDoc