ssi.bitcoin.onPrimaryChanged
Fires when the primary key is changed.
Syntax
browser.ssi.bitcoin.onPrimaryChanged.addListener(listener)
browser.ssi.bitcoin.onPrimaryChanged.removeListener(listener)
browser.ssi.bitcoin.onPrimaryChanged.hasListener(listener)
Events have three functions:
addListener(listener)
Adds a listener to this event.
removeListener(listener)
Stop listening to this event. The listener argument is the listener to remove.
hasListener(listener)
Check whether listener is registered for this event. Returns true
if it is listening, false
otherwise.
addListener syntax
Parameters
None.
Examples
Notifying to the web app, since onPrimaryChanged
is notified when the primary key is changed on the settings page. If the user has account changed notifications turned off then PrimaryChanged
will not fire.
// Callback when primary is changed on the settings page
const onPrimaryChangedCallback = async () => {
// Get the new primary key. If without authorization, it will be executed during running.
const credentials = await browser.ssi.searchCredentials({
protocolName: "bitcoin",
credentialName: "bip39",
primary: true
})
const publicKey = decodeNpub(credentials[0].identifier)
// Send the message to the contents
const tabs = await browser.tabs.query()
for (const tab of tabs) {
browser.tabs
.sendMessage(tab.id, {
action: "accountChanged",
args: { publicKey },
})
}
}
// Listen to the event
browser.ssi.bitcoin.onPrimaryChanged.addListener(onPrimaryChangedCallback)
This documentation is derived from ssi.bitcoin.json in gecko-dev-for-ssi.