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)

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.

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

bunkerPubkey: undefined | string

The pubkey of the bunker that will be providing signatures

localSigner: NDKSigner
relayUrls: undefined | string[]
secret?: null | string

An optional secret value provided to connect to the bunker

userPubkey?: null | string

The pubkey of the user that events will be published as

Accessors

Methods

  • Allows creating a new account on the remote server.

    Parameters

    • Optionalusername: string

      Desired username for the NIP-05

    • Optionaldomain: string

      Desired domain for the NIP-05

    • Optionalemail: 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>