ssi.bitcoin.generate()

Generates Bitcoin 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.bitcoin.generate(
	options, // object
)

Parameters

options

object. Direction about the key you want the user to generate.

passphrase(optional)

string. The passphrase when generating a mnemonic (and a master key). This is optional when type is "mnemonic".

path(optional)

string. The Hierarchical Deterministic (HD) path: e.g. "m/0'/1/2'". If null (or "m") a master key will be generated. The seed specified by the user as the primary will be used. This is required when type is "derivation".

strength(optional)

number. The strength when generating a mnemonic (and a master key). This is required when type is "mnemonic".

type

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

Return value

A Promise that will be fulfilled with a string of xpub.

Exceptions

Throw error If failed

Examples

Generating mnemonic and master key in BIP-39

const pubkey = await window.ssi.bitcoin.generate({type: "mnemonic", strength: 256})
if (!pubkey) {
  throw new Error("Failed to generate mnemonic")
}

console.log(pubkey)
// "xpub661MyMwAqRbcEhXhghozukZbTsvY5HgocKwMHK2paDXsyVRKRysKfbR1Uvb618DFYUA1ZdrKeQWZ9cjkoPG7xzzs25PRs88EBXHHGiUeLF7"

Note

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