New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@metamask/eth-json-rpc-middleware

Package Overview
Dependencies
Maintainers
8
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/eth-json-rpc-middleware - npm Package Compare versions

Comparing version 10.0.0 to 11.0.0

dist/utils/timeout.d.ts

27

CHANGELOG.md

@@ -9,2 +9,26 @@ # Changelog

## [11.0.0]
### Changed
- **BREAKING:** Update `eth-block-tracker` to v7 ([#196](https://github.com/MetaMask/eth-json-rpc-middleware/pull/196), [#188](https://github.com/MetaMask/eth-json-rpc-middleware/pull/188))
- This changes the expected type of the `blockTracker` parameter for the following functions:
- `createBlockCacheMiddleware`
- `createBlockRefMiddleware`
- `createBlockRefRewriteMiddleware`
- `createBlockTrackerInspectorMiddleware`
- `createRetryOnEmptyMiddleware`
- Only the type change is breaking; there is no functional change here.
- **BREAKING:** Add new required parameters for the `fetch` middleware ([#192](https://github.com/MetaMask/eth-json-rpc-middleware/pull/192), [#190](https://github.com/MetaMask/eth-json-rpc-middleware/pull/190))
- The required parameters are `fetch` and `btoa`. Previously we would either use the global by that name (if one existed), or a polyfill. Those polyfills have been removed.
- Replace `json-stable-stringify` with `safe-stable-stringify` ([#104](https://github.com/MetaMask/eth-json-rpc-middleware/pull/104))
- This should slightly improve performance of the inlight cache and block cache middleware
### Removed
- **BREAKING:** Remove `providerFromEngine` and `providerFromMiddleware` ([#194](https://github.com/MetaMask/eth-json-rpc-middleware/pull/194))
- These are now provided by the package `@metamask/eth-json-rpc-provider` instead
- **BREAKING:** Remove unnecessary `suppressUnauthorized` option ([#193](https://github.com/MetaMask/eth-json-rpc-middleware/pull/193))
### Fixed
- **BREAKING:** Fix types for `createWalletMiddleware` ([#111](https://github.com/MetaMask/eth-json-rpc-middleware/pull/111))
- This middleware had previously included a number of errors, where the type contradicted the Ethereum JSON-RPC specification and how we've been using this middleware in practice. They should all now match the specification.
## [10.0.0]

@@ -105,3 +129,4 @@ ### Changed

[Unreleased]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v10.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v11.0.0...HEAD
[11.0.0]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v10.0.0...v11.0.0
[10.0.0]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v9.0.1...v10.0.0

@@ -108,0 +133,0 @@ [9.0.1]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v9.0.0...v9.0.1

2

dist/block-ref.d.ts
import { PollingBlockTracker } from 'eth-block-tracker';
import { JsonRpcMiddleware } from 'json-rpc-engine';
import type { SafeEventEmitterProvider } from './types';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
interface BlockRefMiddlewareOptions {

@@ -5,0 +5,0 @@ blockTracker?: PollingBlockTracker;

@@ -14,11 +14,35 @@ import { JsonRpcMiddleware, JsonRpcRequest } from 'json-rpc-engine';

}
interface FetchMiddlewareOptions {
/**
* Create middleware for sending a JSON-RPC request to the given RPC URL.
*
* @param options - Options
* @param options.btoa - Generates a base64-encoded string from a binary string.
* @param options.fetch - The `fetch` function; expected to be equivalent to `window.fetch`.
* @param options.rpcUrl - The URL to send the request to.
* @param options.originHttpHeaderKey - If provider, the origin field for each JSON-RPC request
* will be attached to each outgoing fetch request under this header.
* @returns The fetch middleware.
*/
export declare function createFetchMiddleware({ btoa, fetch, rpcUrl, originHttpHeaderKey, }: {
btoa: (stringToEncode: string) => string;
fetch: typeof global.fetch;
rpcUrl: string;
originHttpHeaderKey?: string;
}
interface FetchMiddlewareFromReqOptions extends FetchMiddlewareOptions {
}): JsonRpcMiddleware<unknown, unknown>;
/**
* Generate `fetch` configuration for sending the given request to an RPC API.
*
* @param options - Options
* @param options.btoa - Generates a base64-encoded string from a binary string.
* @param options.rpcUrl - The URL to send the request to.
* @param options.originHttpHeaderKey - If provider, the origin field for each JSON-RPC request
* will be attached to each outgoing fetch request under this header.
* @returns The fetch middleware.
*/
export declare function createFetchConfigFromReq({ btoa, req, rpcUrl, originHttpHeaderKey, }: {
btoa: (stringToEncode: string) => string;
rpcUrl: string;
originHttpHeaderKey?: string;
req: PayloadWithOrigin;
}
export declare function createFetchMiddleware({ rpcUrl, originHttpHeaderKey, }: FetchMiddlewareOptions): JsonRpcMiddleware<unknown, unknown>;
export declare function createFetchConfigFromReq({ req, rpcUrl, originHttpHeaderKey, }: FetchMiddlewareFromReqOptions): FetchConfig;
}): FetchConfig;
export {};

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

const eth_rpc_errors_1 = require("eth-rpc-errors");
/* eslint-disable @typescript-eslint/no-require-imports,@typescript-eslint/no-shadow */
const fetch = global.fetch || require('node-fetch');
const btoa = global.btoa || require('btoa');
/* eslint-enable @typescript-eslint/no-require-imports,@typescript-eslint/no-shadow */
const timeout_1 = require("./utils/timeout");
const RETRIABLE_ERRORS = [

@@ -21,5 +18,21 @@ // ignore server overload errors

];
function createFetchMiddleware({ rpcUrl, originHttpHeaderKey, }) {
/**
* Create middleware for sending a JSON-RPC request to the given RPC URL.
*
* @param options - Options
* @param options.btoa - Generates a base64-encoded string from a binary string.
* @param options.fetch - The `fetch` function; expected to be equivalent to `window.fetch`.
* @param options.rpcUrl - The URL to send the request to.
* @param options.originHttpHeaderKey - If provider, the origin field for each JSON-RPC request
* will be attached to each outgoing fetch request under this header.
* @returns The fetch middleware.
*/
function createFetchMiddleware({
// eslint-disable-next-line @typescript-eslint/no-shadow
btoa,
// eslint-disable-next-line @typescript-eslint/no-shadow
fetch, rpcUrl, originHttpHeaderKey, }) {
return json_rpc_engine_1.createAsyncMiddleware(async (req, res, _next) => {
const { fetchUrl, fetchParams } = createFetchConfigFromReq({
btoa,
req,

@@ -60,3 +73,3 @@ rpcUrl,

// delay before retrying
await timeout(retryInterval);
await timeout_1.timeout(retryInterval);
}

@@ -97,3 +110,15 @@ });

}
function createFetchConfigFromReq({ req, rpcUrl, originHttpHeaderKey, }) {
/**
* Generate `fetch` configuration for sending the given request to an RPC API.
*
* @param options - Options
* @param options.btoa - Generates a base64-encoded string from a binary string.
* @param options.rpcUrl - The URL to send the request to.
* @param options.originHttpHeaderKey - If provider, the origin field for each JSON-RPC request
* will be attached to each outgoing fetch request under this header.
* @returns The fetch middleware.
*/
function createFetchConfigFromReq({
// eslint-disable-next-line @typescript-eslint/no-shadow
btoa, req, rpcUrl, originHttpHeaderKey, }) {
const parsedUrl = new URL(rpcUrl);

@@ -154,5 +179,2 @@ const fetchUrl = normalizeUrlFromParsed(parsedUrl);

}
function timeout(duration) {
return new Promise((resolve) => setTimeout(resolve, duration));
}
//# sourceMappingURL=fetch.js.map

@@ -8,6 +8,3 @@ export * from './block-cache';

export * from './providerAsMiddleware';
export * from './providerFromEngine';
export * from './providerFromMiddleware';
export * from './retryOnEmpty';
export type { SafeEventEmitterProvider } from './types';
export * from './wallet';

@@ -20,6 +20,4 @@ "use strict";

__exportStar(require("./providerAsMiddleware"), exports);
__exportStar(require("./providerFromEngine"), exports);
__exportStar(require("./providerFromMiddleware"), exports);
__exportStar(require("./retryOnEmpty"), exports);
__exportStar(require("./wallet"), exports);
//# sourceMappingURL=index.js.map
import { JsonRpcMiddleware } from 'json-rpc-engine';
import type { SafeEventEmitterProvider } from './types';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
export declare function providerAsMiddleware(provider: SafeEventEmitterProvider): JsonRpcMiddleware<unknown, unknown>;
export declare function ethersProviderAsMiddleware(provider: SafeEventEmitterProvider): JsonRpcMiddleware<unknown, unknown>;

@@ -25,2 +25,4 @@ "use strict";

if (err) {
// TODO: Remove this cast when next major `json-rpc-engine` release is out
// The next release changes how errors are propogated.
return end(err);

@@ -27,0 +29,0 @@ }

import { PollingBlockTracker } from 'eth-block-tracker';
import { JsonRpcMiddleware } from 'json-rpc-engine';
import { SafeEventEmitterProvider } from './types';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
interface RetryOnEmptyMiddlewareOptions {

@@ -5,0 +5,0 @@ provider?: SafeEventEmitterProvider;

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

const cache_1 = require("./utils/cache");
const timeout_1 = require("./utils/timeout");
//

@@ -94,3 +95,3 @@ // RetryOnEmptyMiddleware will retry any request with an empty response that has

log('(call %i) Request failed, waiting 1s to retry again...', index + 1);
await timeout(1000);
await timeout_1.timeout(1000);
}

@@ -101,5 +102,2 @@ }

}
function timeout(duration) {
return new Promise((resolve) => setTimeout(resolve, duration));
}
//# sourceMappingURL=retryOnEmpty.js.map

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

import { JsonRpcMiddleware, JsonRpcRequest, JsonRpcResponse } from 'json-rpc-engine';
import SafeEventEmitter from '@metamask/safe-event-emitter';
import { JsonRpcMiddleware, JsonRpcRequest } from 'json-rpc-engine';
export interface JsonRpcRequestToCache<T> extends JsonRpcRequest<T> {

@@ -11,7 +10,1 @@ skipCache?: boolean;

export declare type Cache = Record<number, BlockCache>;
export declare type SendAsyncCallBack<T> = (err: unknown, providerRes: JsonRpcResponse<T>) => void;
export declare type SendCallBack = (err: any, providerRes: JsonRpcResponse<any>) => void;
export interface SafeEventEmitterProvider extends SafeEventEmitter {
sendAsync: <T, U>(req: JsonRpcRequest<T>, cb: SendAsyncCallBack<U>) => void;
send: (req: JsonRpcRequest<any>, callback: SendCallBack) => void;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cacheTypeForMethod = exports.blockTagParamIndex = exports.blockTagForRequest = exports.canCache = exports.cacheIdentifierForRequest = exports.CacheStrategy = void 0;
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
const safe_stable_stringify_1 = require("safe-stable-stringify");
const stringify = safe_stable_stringify_1.configure({ bigint: false, circularValue: Error });
/**

@@ -51,3 +49,3 @@ * The cache strategy to use for a given method.

if (canCache(request.method)) {
return `${request.method}:${json_stable_stringify_1.default(simpleParams)}`;
return `${request.method}:${stringify(simpleParams)}`;
}

@@ -54,0 +52,0 @@ return null;

@@ -9,12 +9,10 @@ import { JsonRpcMiddleware, JsonRpcRequest } from 'json-rpc-engine';

}
interface TypedMessageParams extends MessageParams {
export interface TypedMessageParams extends MessageParams {
version: string;
}
interface WalletMiddlewareOptions {
getAccounts: (req: JsonRpcRequest<unknown>, options?: {
suppressUnauthorized?: boolean;
}) => Promise<string[]>;
processDecryptMessage?: (msgParams: MessageParams, req: JsonRpcRequest<unknown>) => Promise<Record<string, unknown>>;
processEncryptionPublicKey?: (address: string, req: JsonRpcRequest<unknown>) => Promise<Record<string, unknown>>;
processEthSignMessage?: (msgParams: MessageParams, req: JsonRpcRequest<unknown>) => Promise<Record<string, unknown>>;
export interface WalletMiddlewareOptions {
getAccounts: (req: JsonRpcRequest<unknown>) => Promise<string[]>;
processDecryptMessage?: (msgParams: MessageParams, req: JsonRpcRequest<unknown>) => Promise<string>;
processEncryptionPublicKey?: (address: string, req: JsonRpcRequest<unknown>) => Promise<string>;
processEthSignMessage?: (msgParams: MessageParams, req: JsonRpcRequest<unknown>) => Promise<string>;
processPersonalMessage?: (msgParams: MessageParams, req: JsonRpcRequest<unknown>) => Promise<string>;

@@ -24,6 +22,5 @@ processTransaction?: (txParams: TransactionParams, req: JsonRpcRequest<unknown>) => Promise<string>;

processTypedMessage?: (msgParams: MessageParams, req: JsonRpcRequest<unknown>, version: string) => Promise<string>;
processTypedMessageV3?: (msgParams: TypedMessageParams, req: JsonRpcRequest<unknown>, version: string) => Promise<Record<string, unknown>>;
processTypedMessageV4?: (msgParams: TypedMessageParams, req: JsonRpcRequest<unknown>, version: string) => Promise<Record<string, unknown>>;
processTypedMessageV3?: (msgParams: TypedMessageParams, req: JsonRpcRequest<unknown>, version: string) => Promise<string>;
processTypedMessageV4?: (msgParams: TypedMessageParams, req: JsonRpcRequest<unknown>, version: string) => Promise<string>;
}
export declare function createWalletMiddleware({ getAccounts, processDecryptMessage, processEncryptionPublicKey, processEthSignMessage, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, }: WalletMiddlewareOptions): JsonRpcMiddleware<string, Block>;
export {};

@@ -205,8 +205,5 @@ "use strict";

resemblesAddress(address)) {
// ensure address is included in provided accounts. `suppressUnauthorized: false` is passed to `getAccounts`
// so that an "unauthorized" error is thrown if the requester does not have the `eth_accounts`
// Ensure that an "unauthorized" error is thrown if the requester does not have the `eth_accounts`
// permission.
const accounts = await getAccounts(req, {
suppressUnauthorized: false,
});
const accounts = await getAccounts(req);
const normalizedAccounts = accounts.map((_address) => _address.toLowerCase());

@@ -213,0 +210,0 @@ const normalizedAddress = address.toLowerCase();

{
"name": "@metamask/eth-json-rpc-middleware",
"version": "10.0.0",
"version": "11.0.0",
"description": "Ethereum-related json-rpc-engine middleware.",

@@ -31,13 +31,11 @@ "repository": {

"dependencies": {
"@metamask/eth-json-rpc-provider": "^1.0.0",
"@metamask/eth-sig-util": "^5.0.0",
"@metamask/safe-event-emitter": "^2.0.0",
"@metamask/utils": "^3.0.3",
"btoa": "^1.2.1",
"clone": "^2.1.1",
"eth-block-tracker": "^5.0.1",
"eth-block-tracker": "^7.0.0",
"eth-rpc-errors": "^4.0.3",
"json-rpc-engine": "^6.1.0",
"json-stable-stringify": "^1.0.1",
"node-fetch": "^2.6.7",
"pify": "^3.0.0"
"pify": "^3.0.0",
"safe-stable-stringify": "^2.3.2"
},

@@ -55,3 +53,2 @@ "devDependencies": {

"@types/jest": "^27.4.1",
"@types/json-stable-stringify": "^1.0.32",
"@types/node": "^17.0.23",

@@ -90,2 +87,2 @@ "@types/pify": "^3.0.2",

}
}
}

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