Constructor
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
.
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.
Parameters
The mode
property controls the mode of operation for the Threat Detector.
The value of this property can be either local
or cloud
.
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.
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
.
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:
If you specify a function, the function will be called with the scam URL as the first argument:
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.