ssi.nostr.getPublicKeySync()
Callback type of getPublicKey
.
Syntax
window.ssi.nostr.getPublicKeySync(
options, // object
callback, // object
)
Parameters
options
object
. Not implemented
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 hex-format public key.
error
Error
.publicKey
string
.
Return value
None (undefined).
Examples
Getting public key in NIP-07
const callback = (error, pubkey) => {
if (error) {
throw new Error("Failed to get public key")
}
console.log(pubkey)
}
window.ssi.nostr.getPublicKeySync(null, callback)
// callback result
// "3327e31cfbef92d143c699e1559e207d977639303d81bb132d9541bff99af3b4"
In the WebExtension on Firefox
When you care about security and privacy, combining Sync method with Xray Vision can help prevent eavesdropping via postMessage and prototype chain pollution, with some trade-offs. See also “Share objects with page scripts”.
// In content-script
function getPublicKey() {
return window.wrappedJSObject.ssi.nostr.getPublicKeySync(null, (error, pubkey) => {
if (error) {
throw new Error("Failed to get public key")
}
console.log(pubkey)
})
}
window.wrappedJSObject.nostr.getPublicKey = exportFunction(getPublicKey, window)
// In page-script
const pubkey = await window.nostr.getPublicKey()
This documentation is derived from window.ssi.type.ts in gecko-dev-for-ssi.