ssi.bitcoin.shareWithSync()

Callback type of shareWith.

Syntax

 window.ssi.bitcoin.shareWithSync(
	pubkey, // string
	options, // object
	callback, // object
)

Parameters

pubkey

string. Your Nostr public key for encrypting the shared secret. Either npub or hex format.

options

object. Direction about the secret you want the user to share. "mnemonic" and "derivation" use the seed specified by the user as the primary.

path(optional)

string. The Hierarchical Deterministic (HD) path that specifies the secret you want the user to share: e.g. "m/0'/1/2'". The return value is encrypted xprv key. The seed specified by the user as the primary will be used. This is required when type is "derivation".

type

BitcoinShareType. The type that specifies the secret you want the user to share: e.g. "mnemonic", "derivation", "xprv".

xpub(optional)

string. The Bitcoin public key that specifies the secret you want the user to share: e.g. "xpub123...". The return value is encrypted xprv key. This is required when type is "xprv".

callback

object. A reference to a function that should be called in the near future, when the result is returned. The callback function is passed two arguments — 1. Error object if failed otherwise null, 2. The resulting ssi.bitcoin.SharedSecret object.

error

Error.

sharedSecret

BitcoinSharedSecret.

Return value

None (undefined).

Examples

Sharing BIP-39 mnemonic

Combined with the Nostr protocol, it allows users to securely share their Bitcoin secrets.

// Generate a random mnemonic inside the browser
window.ssi.bitcoin.generateSync({type: "mnemonic", strength: 256}, someCallback)

// Ask the user to share the mnemonic encrypted with Nostr NIP-44.
// The mnemonic currently set as the primary for the user will be the one that is shared.
// Additionally, the nostr key used to pair with the yourNpubKey will also be the one currently set as the primary.
// During execution, authentication is performed to request user consent.
function callback(error, encryptedSecret) {
  if (error) {
    // The user declined, or some error occured.
    return
  }

  passSomewhere(encryptedSecret)
}
window.ssi.bitcoin.shareWithSync(yourNpubKey, {type: "mnemonic"}, callback)


// Decryption. Follow NIP-44 spec.
const userNpubkey = await window.ssi.nostr.getPublicKey()
const sharedKey = nip44.getConversationKey(yourNsecKey, userNpubkey)
const mnemonic = nip44.decrypt(encryptedSecret, sharedKey)

Note

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