Modes

There are two modes of operation for the Threat Detector:

  • local: This mode uses a local database of scam URLs. Use this mode for offline threat detection and testing.
  • cloud: This mode uses ChainPatrol’s cloud service to detect scams.

Local Mode

To use the local mode, you need to instantiate the ThreatDetector class with the mode option set to local.

const detector = new ThreatDetector({
  mode: "local",
});

Cloud Mode

To use the cloud mode, you need to instantiate the ThreatDetector class with the mode option set to cloud and provide your API key.

const detector = new ThreatDetector({
  mode: "cloud",
  apiKey: "YOUR_API_KEY",
});

Parameters

options
object
required
mode
'local' | 'cloud'
required

The mode property controls the mode of operation for the Threat Detector.

The value of this property can be either local or cloud.

apiKey
string

The apiKey property is the API Key for accessing ChainPatrol’s APIs. We recommend using an environment variable to store your API Key.

This property is required when the mode property is set to cloud. If proxyUrl is set, this property is not required as the proxy server will handle the authentication.

proxyUrl
string

The proxyUrl property is an optional property that can be used to specify a proxy URL for accessing ChainPatrol’s APIs.

This property is useful when you are behind a firewall or need to use a proxy to access the internet.

This value is only used when the mode property is set to cloud.

redirectUrl
string | (url: string) => string

The redirectUrl property is an optional property that can be used to specify a redirect URL for when the detector detects a scam.

By default, the detector will return the ChainPatrol warning page URL, but you can override this by specifying your own URL.

If you specify a string, the string will be used as the redirect URL with the scam URL appended as the originUrl query parameter:

const detector = new ThreatDetector({
  redirectUrl: "https://your-warning-page.com/",
});

If you specify a function, the function will be called with the scam URL as the first argument:

const detector = new ThreatDetector({
  redirectUrl: (url) => {
    return `https://your-warning-page.com/?url=${encodeURIComponent(url)}`;
  },
});
storage
Storage

The storage property is an optional property that can be used to specify a custom storage adapter for the detector to cache URL lookups.

By default, the detector will use the Storage.memory() adapter, which stores the cache database in memory. This means that the database will be cleared when the process exits. If you want to persist the database, you can use the Storage.browser() adapter, which stores the database in local storage, or the Storage.extension() adapter, which stores the database in the browser’s extension storage.