Extension API Reference
This guide will get you all set up and ready to use the Block-Auth Extension API. We'll cover how to get started using one of our API clients and how to make your first API event request. We'll also look at where to go next to find all the information you need to take full advantage of our powerful Events API.
Sending events from website to extension
The blockAuth extension communication model allow to send some events from website to extension. The extension will receive the event and will send it to the different parts of the extension.
The events are sent using the postMessage
function and add different customs events listeners to document when loaded.
Open Popup : ext:initial
Start communication with the extension. This event is used to check if the extension is installed, if user exist, if the user is active, if the user have locked up their OTP and if the extension is connected to the website.
function extensionStart() {
if(!document) throw new Error('This function can only be called from a browser context');
if(!document.hasEventListener('ext:initial:response')) {
document.addEventListener('ext:initial:response', (event) => {
const { data } = event;
console.log(data);
});
}
const e = new CustomEvent('ext:initial', { data: {} });
document.dispatchEvent(e)
}
Open Popup : ext:open
Opens the extension popup with default navigation
function openPopup() {
if(!document) throw new Error('This function can only be called from a browser context');
if(!document.hasEventListener('ext:open:response')) {
document.addEventListener('ext:open:response', (event) => {
const { data } = event;
console.log(data);
});
}
const e = new CustomEvent('ext:open', { data: {} });
document.dispatchEvent(e)
}
Open Popup : ext:txn
Opens the extension popup in the transaction view
function openPopupTxnView() {
if(!document) throw new Error('This function can only be called from a browser context');
if(!document.hasEventListener('ext:txn:response')) {
document.addEventListener('ext:txn:response', (event) => {
const { data } = event;
console.log(data);
});
}
const e = new CustomEvent('ext:txn', { data: {} });
document.dispatchEvent(e)
}