ssi.nostr.encrypt()
Pass in the plain text and get back the cipher 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
.
This is an asynchronous function that returns a Promise.
Syntax
const stringValue = await browser.ssi.nostr.encrypt(
tabId, // integer
plaintext, // string
options, // object
dialogOption, // optional object
)
Parameters
tabId
integer
. This is tabs.Tab.id
. See also MDN Reference.
plaintext
string
. The plain text to encrypt. If it’s not a string it must be stringified.
options
object
. Direction about encryption detail.
type
string
. The encryption spec. e.g.,"nip04"
,"nip44"
.pubkey (optional)
string
. The conversation partner’s public key. If type is"nip04"
or"nip44"
, then this is required.version (optional)
string
. The version to define encryption algorithms if the type is"nip44"
.
dialogOption
(optional)
ssi.DialogInfo
. Parameters to build Auth dialog.
Return value
A Promise that will be fulfilled with a string
of the encrypted cipher text. Returns Promise<undefined>
if error.
Examples
Encryption in NIP-44
See also the spec.
const ciphertext = await browser.ssi.nostr.encrypt(
1,
"The computer can be used as a tool to liberate and protect people, rather than to control them.",
{
type: "nip44",
pubkey: "3327e31cfbef92d143c699e1559e207d977639303d81bb132d9541bff99af3b4"
}
)
if (!ciphertext) {
throw new Error("Failed to encrypt")
}
console.log(ciphertext)
// "AkeXqSWNnU7VrlEUHnnGIs9rqXwHLFVxCsfQTRLbERVWh6fWJqfaRw/BC+cFgtfzPSle1csyfdJ+qf/xaCVmVQ2tXPQg6jw9EHwZxNUwz1EJYZStRo6uCXRnvXraMrPfd4Gx046tHyJ+KJIKUGXOFlWtyni+H+Kr151jvxt0PW5O48AMTxfos3/GxY/EF0yWwsJ8JG82JBEDrmzAz4ph8iXbJg=="
This documentation is derived from ssi.nostr.json in gecko-dev-for-ssi.