Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@moralisweb3/common-core
Advanced tools
The `@moralisweb3/common-core` should be used in _every_ application that uses Moralis. It is already included if you install the unbrella package `moralis`.
The @moralisweb3/common-core
should be used in every application that uses Moralis. It is already included if you install the unbrella package moralis
.
The core responsibilities of this package are
registerModules()
Note: this is automatically handled when using the moralis
umbrella package
When you import packages from moralis @moralisweb3/xxx
, you need to let this core package know what modules you are using. This is required to enable cross-communication between different modules.
You can do this by using the registerModules()
function. This should be done before calling any Moralis logic. Ideally this should be at the top of your code, just after the imports.
Example when using Moralis with the evm network, evm api and server
import { Core } from '@moralisweb3/common-core';
import { EvmApi } from '@moralisweb3/evm-api';
Core.registerModules([EvmApi]);
start()
You can start every package separately via a start()
function. But easier is to call the start()
function in the core package. This will start (initialise) all registered modules.
You can provide a configuration object (see Config). Some config options are required, depending on what packages you have registered (for example you will need a apiKey
for any api package).
import * as Core from '@moralisweb3/common-core';
Core.start({
apiKey: '<YOUR_API_KEY>',
});
As argument you can provide a partial config object, as described in Config.
You can set the config when you call Core.start
. Possible options and default values are can be found in configOptions
The LoggerController
is used in every package as replacement for console.log, console.warn and console.error. In the config you can specify the logLevel:
enum LogLevel {
VERBOSE = 5,
DEBUG = 4,
INFO = 3,
WARNING = 2,
ERROR = 1,
OFF = 0,
}
By specifying a loglevel, any logs up and until that number will be emitted.
For example, by specifying LogLevel.INFO
, all logs with the level LogLevel.INFO
, LogLevel.WARNING
and LogLevel.ERROR
will be emitted.
Using the LoggerController in a package is as simple as:
const logger = new Logger('moduleName');
logger.warning('this is a warning');
the RequestController is a generalized way to handle any external request.
await RequestController.get(url, params, options, abortSignal);
params
: an object with searchparams. For example:
const params = {
name: 'batman',
};
options
: an object with possible options (See RequestController for possible options)
abortSignal
: a signal from an AbortController, to cancel the request.
await RequestController.post(url, params, body, options, abortSignal);
Accepts the same options as get()
, with the addition of body
, which is an (JSON) object.
Errors within Moralis are an instance of MoralisError
. These are extended into a few different classes:
CoreError
MoralisApiError
Which are used in there respective packages. Creating a new error must accept the following 2 params:
code
: a valid ErrorCodemessage
: a descriptive message for the userAdditionally the following params can be provided for more information
details
: an object with additional datacause
: in case the MoralisError is caused by another Error, you should provide this Error as a causeExample:
throw new MoralisServerError({
code: NetworkErrorCode.GENERIC_SERVER_ERROR,
message: 'Make sure to read the docs',
details: {
name: 'Gandalf',
},
});
Moralis DataTypes are used everywhere to enforce consistency and utilities for devs. The core benefits of them are:
format()
function is used to format the datatype to its requested format. This can globally be configured in the config, or overwritten by giving a paramIf a datatype has a DataType.create()
function, then it should be created via this function rather than using new DataType
. For example EvmChain
accepts an EvmChainish
as input value. This can be a string
, number
or EvmChain
. In case a EvmChain
is provided, no new instance is created, but that instance is returned directly. This makes it possible to make generalized functions where we accept a number
/string
/existing EvmChain
as argument
FAQs
The `@moralisweb3/common-core` should be used in _every_ application that uses Moralis. It is already included if you install the unbrella package `moralis`.
We found that @moralisweb3/common-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.