ssi.nostr.generate()

Generates Nostr key in the specified order. During the execution process, an internal authorization check is performed similar to browser.ssi.askConsent.

Syntax

const promiseValue = await window.ssi.nostr.generate(
	options, // object
)

Parameters

options

object. Direction about generation detail.

type

NostrGenerateType. The type that specifies the secret you want the user to generate: e.g. "single", "mnemonic".

Return value

A Promise that will be fulfilled with a string of hex-format public key.

Exceptions

Throw error If failed

Examples

Generating a single key pair on secp256k1

const pubkey = await window.ssi.nostr.generate(
  {
    type: "single",
  },
)
if (!pubkey) {
  throw new Error("Failed to generate")
}

console.log(pubkey)
// "5793aa60c01dba51b3e8848fa0dfd39062fa8fda77702dc142f815c39bb4c10d"

Note

This documentation is derived from window.ssi.type.ts in gecko-dev-for-ssi.