Socket
Socket
Sign inDemoInstall

web3-core

Package Overview
Dependencies
Maintainers
4
Versions
449
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-core - npm Package Compare versions

Comparing version 4.3.3-dev.5afcb54.0 to 4.3.3-dev.5d2f2aa.0

10

lib/commonjs/types.d.ts

@@ -1,2 +0,2 @@

import { HexString, Transaction } from 'web3-types';
import { HexString, JsonRpcPayload, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIReturnType } from 'web3-types';
export declare type TransactionTypeParser = (transaction: Transaction) => HexString | undefined;

@@ -11,1 +11,9 @@ export interface Method {

}
export interface RequestManagerMiddleware<API> {
processRequest<ParamType = unknown[]>(request: JsonRpcPayload<ParamType>, options?: {
[key: string]: unknown;
}): Promise<JsonRpcPayload<ParamType>>;
processResponse<AnotherMethod extends Web3APIMethod<API>, ResponseType = Web3APIReturnType<API, AnotherMethod>>(response: JsonRpcResponse<ResponseType>, options?: {
[key: string]: unknown;
}): Promise<JsonRpcResponse<ResponseType>>;
}

5

lib/commonjs/web3_config.d.ts

@@ -1,2 +0,2 @@

import { Numbers, HexString, BlockNumberOrTag, Common } from 'web3-types';
import { Numbers, HexString, BlockNumberOrTag, Common, DataFormat } from 'web3-types';
import { TransactionTypeParser } from './types.js';

@@ -31,2 +31,3 @@ import { TransactionBuilder } from './web3_context.js';

transactionTypeParser?: TransactionTypeParser;
defaultReturnFormat: DataFormat;
}

@@ -189,2 +190,4 @@ declare type ConfigEvent<T, P extends keyof T = keyof T> = P extends unknown ? {

set maxListenersWarningThreshold(val: number);
get defaultReturnFormat(): DataFormat;
set defaultReturnFormat(val: DataFormat);
get defaultNetworkId(): Numbers | undefined;

@@ -191,0 +194,0 @@ set defaultNetworkId(val: Numbers | undefined);

@@ -20,2 +20,3 @@ "use strict";

exports.Web3Config = exports.Web3ConfigEvent = void 0;
const web3_types_1 = require("web3-types");
const web3_errors_1 = require("web3-errors");

@@ -58,2 +59,3 @@ const web3_utils_1 = require("web3-utils");

transactionTypeParser: undefined,
defaultReturnFormat: web3_types_1.DEFAULT_RETURN_FORMAT,
};

@@ -279,2 +281,9 @@ this.setConfig(options !== null && options !== void 0 ? options : {});

}
get defaultReturnFormat() {
return this.config.defaultReturnFormat;
}
set defaultReturnFormat(val) {
this._triggerConfigChange('defaultReturnFormat', val);
this.config.defaultReturnFormat = val;
}
get defaultNetworkId() {

@@ -281,0 +290,0 @@ return this.config.defaultNetworkId;

import { EthExecutionAPI, HexString, Numbers, SupportedProviders, Transaction, Web3AccountProvider, Web3APISpec, Web3BaseProvider, Web3BaseWallet, Web3BaseWalletAccount } from 'web3-types';
import { BaseTransaction } from 'web3-eth-accounts';
import { ExtensionObject } from './types.js';
import { ExtensionObject, RequestManagerMiddleware } from './types.js';
import { Web3BatchRequest } from './web3_batch_request.js';

@@ -31,2 +31,3 @@ import { Web3Config, Web3ConfigOptions } from './web3_config.js';

wallet?: Web3BaseWallet<Web3BaseWalletAccount>;
requestManagerMiddleware?: RequestManagerMiddleware<API>;
};

@@ -156,2 +157,3 @@ export declare type Web3ContextConstructor<T extends Web3Context, T2 extends unknown[]> = new (...args: [...extras: T2, context: Web3ContextObject]) => T;

setProvider(provider?: SupportedProviders<API> | string): boolean;
setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>): void;
/**

@@ -163,3 +165,3 @@ * Will return the {@link Web3BatchRequest} constructor.

* This method allows extending the web3 modules.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing some thing new.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing something new.
*/

@@ -190,18 +192,18 @@ extend(extendObj: ExtensionObject): this;

/**
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
export declare abstract class Web3EthPluginBase<API extends Web3APISpec = unknown> extends Web3PluginBase<API & EthExecutionAPI> {

@@ -208,0 +210,0 @@ }

@@ -52,6 +52,6 @@ "use strict";

}
const { config, provider, requestManager, subscriptionManager, registeredSubscriptions, accountProvider, wallet, } = providerOrContext;
const { config, provider, requestManager, subscriptionManager, registeredSubscriptions, accountProvider, wallet, requestManagerMiddleware } = providerOrContext;
this.setConfig(config !== null && config !== void 0 ? config : {});
this._requestManager =
requestManager !== null && requestManager !== void 0 ? requestManager : new web3_request_manager_js_1.Web3RequestManager(provider, (_a = config === null || config === void 0 ? void 0 : config.enableExperimentalFeatures) === null || _a === void 0 ? void 0 : _a.useSubscriptionWhenCheckingBlockTimeout);
requestManager !== null && requestManager !== void 0 ? requestManager : new web3_request_manager_js_1.Web3RequestManager(provider, (_a = config === null || config === void 0 ? void 0 : config.enableExperimentalFeatures) === null || _a === void 0 ? void 0 : _a.useSubscriptionWhenCheckingBlockTimeout, requestManagerMiddleware);
if (subscriptionManager) {

@@ -238,2 +238,5 @@ this._subscriptionManager = subscriptionManager;

}
setRequestManagerMiddleware(requestManagerMiddleware) {
this.requestManager.setMiddleware(requestManagerMiddleware);
}
/**

@@ -247,3 +250,3 @@ * Will return the {@link Web3BatchRequest} constructor.

* This method allows extending the web3 modules.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing some thing new.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing something new.
*/

@@ -301,18 +304,18 @@ extend(extendObj) {

/**
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
class Web3EthPluginBase extends Web3PluginBase {

@@ -319,0 +322,0 @@ }

@@ -18,3 +18,3 @@ import { EventEmitter } from 'web3-utils';

listenerCount<K extends Web3EventKey<T>>(eventName: K): number;
listeners<K extends Web3EventKey<T>>(eventName: K): Function[];
listeners<K extends Web3EventKey<T>>(eventName: K): ((...args: any[]) => void)[];
eventNames(): (string | symbol)[];

@@ -21,0 +21,0 @@ removeAllListeners(): EventEmitter;

import { EthExecutionAPI, JsonRpcBatchRequest, JsonRpcBatchResponse, SupportedProviders, Web3APIMethod, Web3APIRequest, Web3APIReturnType, Web3APISpec, Web3BaseProviderConstructor } from 'web3-types';
import { Web3EventEmitter } from './web3_event_emitter.js';
import { RequestManagerMiddleware } from './types.js';
export declare enum Web3RequestManagerEvent {

@@ -12,3 +13,4 @@ PROVIDER_CHANGED = "PROVIDER_CHANGED",

private readonly useRpcCallSpecification?;
constructor(provider?: SupportedProviders<API> | string, useRpcCallSpecification?: boolean);
middleware?: RequestManagerMiddleware<API>;
constructor(provider?: SupportedProviders<API> | string, useRpcCallSpecification?: boolean, requestManagerMiddleware?: RequestManagerMiddleware<API>);
/**

@@ -40,2 +42,3 @@ * Will return all available providers

setProvider(provider?: SupportedProviders<API> | string): boolean;
setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>): void;
/**

@@ -42,0 +45,0 @@ *

@@ -48,3 +48,3 @@ "use strict";

class Web3RequestManager extends web3_event_emitter_js_1.Web3EventEmitter {
constructor(provider, useRpcCallSpecification) {
constructor(provider, useRpcCallSpecification, requestManagerMiddleware) {
super();

@@ -55,2 +55,4 @@ if (!(0, web3_utils_1.isNullish)(provider)) {

this.useRpcCallSpecification = useRpcCallSpecification;
if (!(0, web3_utils_1.isNullish)(requestManagerMiddleware))
this.middleware = requestManagerMiddleware;
}

@@ -111,2 +113,5 @@ /**

}
setMiddleware(requestManagerMiddleware) {
this.middleware = requestManagerMiddleware;
}
/**

@@ -123,3 +128,6 @@ *

return __awaiter(this, void 0, void 0, function* () {
const response = yield this._sendRequest(request);
const requestObj = Object.assign({}, request);
let response = yield this._sendRequest(requestObj);
if (!(0, web3_utils_1.isNullish)(this.middleware))
response = yield this.middleware.processResponse(response);
if (web3_utils_1.jsonRpc.isResponseWithResult(response)) {

@@ -148,5 +156,8 @@ return response.result;

}
const payload = web3_utils_1.jsonRpc.isBatchRequest(request)
let payload = (web3_utils_1.jsonRpc.isBatchRequest(request)
? web3_utils_1.jsonRpc.toBatchPayload(request)
: web3_utils_1.jsonRpc.toPayload(request);
: web3_utils_1.jsonRpc.toPayload(request));
if (!(0, web3_utils_1.isNullish)(this.middleware)) {
payload = (yield this.middleware.processRequest(payload));
}
if ((0, utils_js_1.isWeb3Provider)(provider)) {

@@ -153,0 +164,0 @@ let response;

@@ -17,2 +17,3 @@ /*

*/
import { DEFAULT_RETURN_FORMAT, } from 'web3-types';
import { ConfigHardforkMismatchError, ConfigChainMismatchError } from 'web3-errors';

@@ -55,2 +56,3 @@ import { isNullish, toHex } from 'web3-utils';

transactionTypeParser: undefined,
defaultReturnFormat: DEFAULT_RETURN_FORMAT,
};

@@ -276,2 +278,9 @@ this.setConfig(options !== null && options !== void 0 ? options : {});

}
get defaultReturnFormat() {
return this.config.defaultReturnFormat;
}
set defaultReturnFormat(val) {
this._triggerConfigChange('defaultReturnFormat', val);
this.config.defaultReturnFormat = val;
}
get defaultNetworkId() {

@@ -278,0 +287,0 @@ return this.config.defaultNetworkId;

@@ -49,6 +49,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

}
const { config, provider, requestManager, subscriptionManager, registeredSubscriptions, accountProvider, wallet, } = providerOrContext;
const { config, provider, requestManager, subscriptionManager, registeredSubscriptions, accountProvider, wallet, requestManagerMiddleware } = providerOrContext;
this.setConfig(config !== null && config !== void 0 ? config : {});
this._requestManager =
requestManager !== null && requestManager !== void 0 ? requestManager : new Web3RequestManager(provider, (_a = config === null || config === void 0 ? void 0 : config.enableExperimentalFeatures) === null || _a === void 0 ? void 0 : _a.useSubscriptionWhenCheckingBlockTimeout);
requestManager !== null && requestManager !== void 0 ? requestManager : new Web3RequestManager(provider, (_a = config === null || config === void 0 ? void 0 : config.enableExperimentalFeatures) === null || _a === void 0 ? void 0 : _a.useSubscriptionWhenCheckingBlockTimeout, requestManagerMiddleware);
if (subscriptionManager) {

@@ -235,2 +235,5 @@ this._subscriptionManager = subscriptionManager;

}
setRequestManagerMiddleware(requestManagerMiddleware) {
this.requestManager.setMiddleware(requestManagerMiddleware);
}
/**

@@ -244,3 +247,3 @@ * Will return the {@link Web3BatchRequest} constructor.

* This method allows extending the web3 modules.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing some thing new.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing something new.
*/

@@ -296,20 +299,20 @@ extend(extendObj) {

/**
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
export class Web3EthPluginBase extends Web3PluginBase {
}
//# sourceMappingURL=web3_context.js.map

@@ -42,3 +42,3 @@ /*

export class Web3RequestManager extends Web3EventEmitter {
constructor(provider, useRpcCallSpecification) {
constructor(provider, useRpcCallSpecification, requestManagerMiddleware) {
super();

@@ -49,2 +49,4 @@ if (!isNullish(provider)) {

this.useRpcCallSpecification = useRpcCallSpecification;
if (!isNullish(requestManagerMiddleware))
this.middleware = requestManagerMiddleware;
}

@@ -105,2 +107,5 @@ /**

}
setMiddleware(requestManagerMiddleware) {
this.middleware = requestManagerMiddleware;
}
/**

@@ -117,3 +122,6 @@ *

return __awaiter(this, void 0, void 0, function* () {
const response = yield this._sendRequest(request);
const requestObj = Object.assign({}, request);
let response = yield this._sendRequest(requestObj);
if (!isNullish(this.middleware))
response = yield this.middleware.processResponse(response);
if (jsonRpc.isResponseWithResult(response)) {

@@ -142,5 +150,8 @@ return response.result;

}
const payload = jsonRpc.isBatchRequest(request)
let payload = (jsonRpc.isBatchRequest(request)
? jsonRpc.toBatchPayload(request)
: jsonRpc.toPayload(request);
: jsonRpc.toPayload(request));
if (!isNullish(this.middleware)) {
payload = (yield this.middleware.processRequest(payload));
}
if (isWeb3Provider(provider)) {

@@ -147,0 +158,0 @@ let response;

@@ -1,2 +0,2 @@

import { HexString, Transaction } from 'web3-types';
import { HexString, JsonRpcPayload, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIReturnType } from 'web3-types';
export declare type TransactionTypeParser = (transaction: Transaction) => HexString | undefined;

@@ -11,2 +11,10 @@ export interface Method {

}
export interface RequestManagerMiddleware<API> {
processRequest<ParamType = unknown[]>(request: JsonRpcPayload<ParamType>, options?: {
[key: string]: unknown;
}): Promise<JsonRpcPayload<ParamType>>;
processResponse<AnotherMethod extends Web3APIMethod<API>, ResponseType = Web3APIReturnType<API, AnotherMethod>>(response: JsonRpcResponse<ResponseType>, options?: {
[key: string]: unknown;
}): Promise<JsonRpcResponse<ResponseType>>;
}
//# sourceMappingURL=types.d.ts.map

@@ -1,2 +0,2 @@

import { Numbers, HexString, BlockNumberOrTag, Common } from 'web3-types';
import { Numbers, HexString, BlockNumberOrTag, Common, DataFormat } from 'web3-types';
import { TransactionTypeParser } from './types.js';

@@ -31,2 +31,3 @@ import { TransactionBuilder } from './web3_context.js';

transactionTypeParser?: TransactionTypeParser;
defaultReturnFormat: DataFormat;
}

@@ -189,2 +190,4 @@ declare type ConfigEvent<T, P extends keyof T = keyof T> = P extends unknown ? {

set maxListenersWarningThreshold(val: number);
get defaultReturnFormat(): DataFormat;
set defaultReturnFormat(val: DataFormat);
get defaultNetworkId(): Numbers | undefined;

@@ -191,0 +194,0 @@ set defaultNetworkId(val: Numbers | undefined);

import { EthExecutionAPI, HexString, Numbers, SupportedProviders, Transaction, Web3AccountProvider, Web3APISpec, Web3BaseProvider, Web3BaseWallet, Web3BaseWalletAccount } from 'web3-types';
import { BaseTransaction } from 'web3-eth-accounts';
import { ExtensionObject } from './types.js';
import { ExtensionObject, RequestManagerMiddleware } from './types.js';
import { Web3BatchRequest } from './web3_batch_request.js';

@@ -31,2 +31,3 @@ import { Web3Config, Web3ConfigOptions } from './web3_config.js';

wallet?: Web3BaseWallet<Web3BaseWalletAccount>;
requestManagerMiddleware?: RequestManagerMiddleware<API>;
};

@@ -156,2 +157,3 @@ export declare type Web3ContextConstructor<T extends Web3Context, T2 extends unknown[]> = new (...args: [...extras: T2, context: Web3ContextObject]) => T;

setProvider(provider?: SupportedProviders<API> | string): boolean;
setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>): void;
/**

@@ -163,3 +165,3 @@ * Will return the {@link Web3BatchRequest} constructor.

* This method allows extending the web3 modules.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing some thing new.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing something new.
*/

@@ -190,18 +192,18 @@ extend(extendObj: ExtensionObject): this;

/**
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
export declare abstract class Web3EthPluginBase<API extends Web3APISpec = unknown> extends Web3PluginBase<API & EthExecutionAPI> {

@@ -208,0 +210,0 @@ }

@@ -18,3 +18,3 @@ import { EventEmitter } from 'web3-utils';

listenerCount<K extends Web3EventKey<T>>(eventName: K): number;
listeners<K extends Web3EventKey<T>>(eventName: K): Function[];
listeners<K extends Web3EventKey<T>>(eventName: K): ((...args: any[]) => void)[];
eventNames(): (string | symbol)[];

@@ -21,0 +21,0 @@ removeAllListeners(): EventEmitter;

import { EthExecutionAPI, JsonRpcBatchRequest, JsonRpcBatchResponse, SupportedProviders, Web3APIMethod, Web3APIRequest, Web3APIReturnType, Web3APISpec, Web3BaseProviderConstructor } from 'web3-types';
import { Web3EventEmitter } from './web3_event_emitter.js';
import { RequestManagerMiddleware } from './types.js';
export declare enum Web3RequestManagerEvent {

@@ -12,3 +13,4 @@ PROVIDER_CHANGED = "PROVIDER_CHANGED",

private readonly useRpcCallSpecification?;
constructor(provider?: SupportedProviders<API> | string, useRpcCallSpecification?: boolean);
middleware?: RequestManagerMiddleware<API>;
constructor(provider?: SupportedProviders<API> | string, useRpcCallSpecification?: boolean, requestManagerMiddleware?: RequestManagerMiddleware<API>);
/**

@@ -40,2 +42,3 @@ * Will return all available providers

setProvider(provider?: SupportedProviders<API> | string): boolean;
setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>): void;
/**

@@ -42,0 +45,0 @@ *

{
"name": "web3-core",
"version": "4.3.3-dev.5afcb54.0+5afcb54",
"version": "4.3.3-dev.5d2f2aa.0+5d2f2aa",
"description": "Web3 core tools for sub-packages. This is an internal package.",

@@ -33,3 +33,3 @@ "main": "./lib/commonjs/index.js",

"build:check": "node -e \"require('./lib')\"",
"lint": "eslint --ext .js,.ts .",
"lint": "eslint --cache --cache-strategy content --ext .ts .",
"lint:fix": "eslint --fix --ext .js,.ts .",

@@ -46,13 +46,13 @@ "format": "prettier --write '**/*'",

"dependencies": {
"web3-errors": "1.1.5-dev.5afcb54.0+5afcb54",
"web3-eth-accounts": "4.1.1-dev.5afcb54.0+5afcb54",
"web3-eth-iban": "4.0.8-dev.5afcb54.0+5afcb54",
"web3-providers-http": "4.1.1-dev.5afcb54.0+5afcb54",
"web3-providers-ws": "4.0.8-dev.5afcb54.0+5afcb54",
"web3-types": "1.3.2-dev.5afcb54.0+5afcb54",
"web3-utils": "4.1.1-dev.5afcb54.0+5afcb54",
"web3-validator": "2.0.4-dev.5afcb54.0+5afcb54"
"web3-errors": "1.1.5-dev.5d2f2aa.0+5d2f2aa",
"web3-eth-accounts": "4.1.3-dev.5d2f2aa.0+5d2f2aa",
"web3-eth-iban": "4.0.8-dev.5d2f2aa.0+5d2f2aa",
"web3-providers-http": "4.1.1-dev.5d2f2aa.0+5d2f2aa",
"web3-providers-ws": "4.0.8-dev.5d2f2aa.0+5d2f2aa",
"web3-types": "1.6.1-dev.5d2f2aa.0+5d2f2aa",
"web3-utils": "4.2.4-dev.5d2f2aa.0+5d2f2aa",
"web3-validator": "2.0.6-dev.5d2f2aa.0+5d2f2aa"
},
"optionalDependencies": {
"web3-providers-ipc": "4.0.8-dev.5afcb54.0+5afcb54"
"web3-providers-ipc": "4.0.8-dev.5d2f2aa.0+5d2f2aa"
},

@@ -68,10 +68,10 @@ "devDependencies": {

"eslint-plugin-import": "^2.26.0",
"jest": "^28.1.3",
"jest": "^29.7.0",
"jest-extended": "^3.0.1",
"jest-when": "^3.5.1",
"prettier": "^2.7.1",
"ts-jest": "^28.0.7",
"ts-jest": "^29.1.1",
"typescript": "^4.7.4"
},
"gitHead": "5afcb5411d35b9c3efb1f323336b7c2661328d28"
"gitHead": "5d2f2aa2cc628e0d73507687449737dfa419e2e4"
}

@@ -18,7 +18,12 @@ /*

import { HexString, Transaction } from 'web3-types';
import {
HexString,
JsonRpcPayload,
JsonRpcResponse,
Transaction,
Web3APIMethod,
Web3APIReturnType,
} from 'web3-types';
export type TransactionTypeParser = (
transaction: Transaction,
) => HexString | undefined;
export type TransactionTypeParser = (transaction: Transaction) => HexString | undefined;

@@ -34,1 +39,16 @@ export interface Method {

}
export interface RequestManagerMiddleware<API> {
processRequest<ParamType = unknown[]>(
request: JsonRpcPayload<ParamType>,
options?: { [key: string]: unknown },
): Promise<JsonRpcPayload<ParamType>>;
processResponse<
AnotherMethod extends Web3APIMethod<API>,
ResponseType = Web3APIReturnType<API, AnotherMethod>,
>(
response: JsonRpcResponse<ResponseType>,
options?: { [key: string]: unknown },
): Promise<JsonRpcResponse<ResponseType>>;
}

@@ -18,3 +18,10 @@ /*

import { Numbers, HexString, BlockNumberOrTag, Common } from 'web3-types';
import {
Numbers,
HexString,
BlockNumberOrTag,
Common,
DEFAULT_RETURN_FORMAT,
DataFormat,
} from 'web3-types';
import { ConfigHardforkMismatchError, ConfigChainMismatchError } from 'web3-errors';

@@ -56,2 +63,3 @@ import { isNullish, toHex } from 'web3-utils';

transactionTypeParser?: TransactionTypeParser;
defaultReturnFormat: DataFormat;
}

@@ -98,2 +106,3 @@

transactionTypeParser: undefined,
defaultReturnFormat: DEFAULT_RETURN_FORMAT,
};

@@ -354,2 +363,11 @@

public get defaultReturnFormat() {
return this.config.defaultReturnFormat;
}
public set defaultReturnFormat(val) {
this._triggerConfigChange('defaultReturnFormat', val);
this.config.defaultReturnFormat = val;
}
public get defaultNetworkId() {

@@ -356,0 +374,0 @@ return this.config.defaultNetworkId;

@@ -28,3 +28,3 @@ /*

// eslint-disable-next-line import/no-cycle
import { ExtensionObject } from './types.js';
import { ExtensionObject, RequestManagerMiddleware } from './types.js';
import { Web3BatchRequest } from './web3_batch_request.js';

@@ -69,2 +69,3 @@ // eslint-disable-next-line import/no-cycle

wallet?: Web3BaseWallet<Web3BaseWalletAccount>;
requestManagerMiddleware?: RequestManagerMiddleware<API>;
};

@@ -108,3 +109,3 @@

super();
// If "providerOrContext" is provided as "string" or an objects matching "SupportedProviders" interface

@@ -135,2 +136,3 @@ if (

wallet,
requestManagerMiddleware
} = providerOrContext as Web3ContextInitOptions<API, RegisteredSubs>;

@@ -145,2 +147,3 @@

config?.enableExperimentalFeatures?.useSubscriptionWhenCheckingBlockTimeout,
requestManagerMiddleware
);

@@ -360,2 +363,7 @@

}
public setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>){
this.requestManager.setMiddleware(requestManagerMiddleware);
}
/**

@@ -373,3 +381,3 @@ * Will return the {@link Web3BatchRequest} constructor.

* This method allows extending the web3 modules.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing some thing new.
* Note: This method is only for backward compatibility, and It is recommended to use Web3 v4 Plugin feature for extending web3.js functionality if you are developing something new.
*/

@@ -417,32 +425,35 @@ public extend(extendObj: ExtensionObject) {

*/
export abstract class Web3PluginBase<
API extends Web3APISpec = Web3APISpec,
export abstract class Web3PluginBase<
API extends Web3APISpec = Web3APISpec,
> extends Web3Context<API> {
public abstract pluginNamespace: string;
public abstract pluginNamespace: string;
// eslint-disable-next-line class-methods-use-this
protected registerNewTransactionType<NewTxTypeClass extends typeof BaseTransaction<unknown>>(type: Numbers, txClass: NewTxTypeClass): void {
TransactionFactory.registerTransactionType(type, txClass);
}
// eslint-disable-next-line class-methods-use-this
protected registerNewTransactionType<NewTxTypeClass extends typeof BaseTransaction<unknown>>(
type: Numbers,
txClass: NewTxTypeClass,
): void {
TransactionFactory.registerTransactionType(type, txClass);
}
}
/**
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
export abstract class Web3EthPluginBase<API extends Web3APISpec = unknown> extends Web3PluginBase<
API & EthExecutionAPI
API & EthExecutionAPI
> {}

@@ -449,0 +460,0 @@

@@ -55,2 +55,3 @@ /*

import { Web3EventEmitter } from './web3_event_emitter.js';
import { RequestManagerMiddleware } from './types.js';

@@ -77,5 +78,8 @@ export enum Web3RequestManagerEvent {

private readonly useRpcCallSpecification?: boolean;
public middleware?: RequestManagerMiddleware<API>;
public constructor(
provider?: SupportedProviders<API> | string,
useRpcCallSpecification?: boolean,
requestManagerMiddleware?: RequestManagerMiddleware<API>,
) {

@@ -88,2 +92,4 @@ super();

this.useRpcCallSpecification = useRpcCallSpecification;
if (!isNullish(requestManagerMiddleware)) this.middleware = requestManagerMiddleware;
}

@@ -148,2 +154,6 @@

public setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>) {
this.middleware = requestManagerMiddleware;
}
/**

@@ -162,3 +172,8 @@ *

>(request: Web3APIRequest<API, Method>): Promise<ResponseType> {
const response = await this._sendRequest<Method, ResponseType>(request);
const requestObj = { ...request };
let response = await this._sendRequest<Method, ResponseType>(requestObj);
if (!isNullish(this.middleware)) response = await this.middleware.processResponse(response);
if (jsonRpc.isResponseWithResult(response)) {

@@ -196,6 +211,11 @@ return response.result;

const payload = jsonRpc.isBatchRequest(request)
? jsonRpc.toBatchPayload(request)
: jsonRpc.toPayload(request);
let payload = (
jsonRpc.isBatchRequest(request)
? jsonRpc.toBatchPayload(request)
: jsonRpc.toPayload(request)
) as JsonRpcPayload;
if (!isNullish(this.middleware)) {
payload = (await this.middleware.processRequest(payload));
}
if (isWeb3Provider(provider)) {

@@ -202,0 +222,0 @@ let response;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc