ssi.nostr.decrypt()

Pass in the cipher text and get back the plain text by Nostr secret key. You should always read the public key without using cache just before signing/encrypting/decrypting, as the user may change their primary key without notifying you. During the execution process, an internal authorization check is performed similar to browser.ssi.askConsent.

Syntax

const promiseValue = await window.ssi.nostr.decrypt(
	ciphertext, // string
	options, // object
)

Parameters

ciphertext

string. The cipher text to decrypt.

options

object. Direction about decryption detail.

pubkey(optional)

string. The conversation partner’s public key. If type is "nip04" or "nip44", then this is required.

type

NostrDecryptType. The encryption spec. e.g., "nip04", "nip44".

version(optional)

string. The version to define encryption algorithms if the type is "nip44".

Return value

A Promise that will be fulfilled with a string of the decrypted plain text.

Exceptions

Throw error If failed

Examples

Decryption in NIP-44

See also the spec.

const plaintext = await window.ssi.nostr.decrypt(
  "AkeXqSWNnU7VrlEUHnnGIs9rqXwHLFVxCsfQTRLbERVWh6fWJqfaRw/BC+cFgtfzPSle1csyfdJ+qf/xaCVmVQ2tXPQg6jw9EHwZxNUwz1EJYZStRo6uCXRnvXraMrPfd4Gx046tHyJ+KJIKUGXOFlWtyni+H+Kr151jvxt0PW5O48AMTxfos3/GxY/EF0yWwsJ8JG82JBEDrmzAz4ph8iXbJg==",
  {
    type: "nip44",
    pubkey: "3327e31cfbef92d143c699e1559e207d977639303d81bb132d9541bff99af3b4"
  }
)
if (!plaintext) {
  throw new Error("Failed to decrypt")
}

console.log(plaintext)
// "The computer can be used as a tool to liberate and protect people, rather than to control them."

Note

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