The Relay class is a utility for receiving messages from the ChainPatrol warning page in your browser extension-based wallet/security app. You may already have a message passing system in place in your browser extension, but this class is provided as a convenience for those who do not, or if you want to keep your message passing system separate from the ChainPatrol SDK.

Usage

import { Relay, Events } from "@chainpatrol/sdk";

// Send a message to the extension
Relay.send(Events.ContinueAtOwnRisk, { domain: "example.com" });

How it works

In order for events from the warning page to be received by your browser extension, the messages have to be relayed from the warning page to the content script, and then from the content script to the background script.

Under the hood, the Relay class sets up the appropriate message listeners depending on the scripting context (ie. window.postMessage in the warning page, chrome.runtime.sendMessage in the content and background scripts), and makes sure that all messages are passed along to all subscribers.


Static Methods

send()

Sends an event to listeners.

run()

Sets up listeners for events and forwards events to all other listeners.

on()

Adds a listener for an event.