Socket
Socket
Sign inDemoInstall

@metamask/eth-json-rpc-middleware

Package Overview
Dependencies
Maintainers
11
Versions
12
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 13.0.0 to 14.0.0

14

CHANGELOG.md

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

## [14.0.0]
### Changed
- **BREAKING:** Adapt to EIP-1193 provider changes by replacing the deprecated `sendAsync` method with the `request` method ([#317](https://github.com/MetaMask/eth-json-rpc-middleware/pull/317))
- **BREAKING:** Refactor `providerAsMiddleware` and middleware functions `retryOnEmpty`, `block-ref` to use the `request` method.
- Bump `@metamask/eth-block-tracker` from `^10.0.0` to `^11.0.1` ([#323](https://github.com/MetaMask/eth-json-rpc-middleware/pull/323))
- Bump `@metamask/eth-json-rpc-provider` from `^4.0.0` to `^4.1.1` ([#323](https://github.com/MetaMask/eth-json-rpc-middleware/pull/323), [#317](https://github.com/MetaMask/eth-json-rpc-middleware/pull/317))
- Bump `@metamask/eth-sig-util` from `^7.0.0` to `^7.0.3` ([#323](https://github.com/MetaMask/eth-json-rpc-middleware/pull/323))
- Bump `@metamask/json-rpc-engine` from `^9.0.0` to `^9.0.2` ([#323](https://github.com/MetaMask/eth-json-rpc-middleware/pull/323))
- Bump `@metamask/rpc-errors` from `^6.0.0` to `^6.3.1` ([#323](https://github.com/MetaMask/eth-json-rpc-middleware/pull/323))
- Bump `@metamask/utils` from `^8.1.0` to `^9.1.0` ([#323](https://github.com/MetaMask/eth-json-rpc-middleware/pull/323))
## [13.0.0]

@@ -189,3 +200,4 @@ ### Changed

[Unreleased]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v13.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v14.0.0...HEAD
[14.0.0]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v13.0.0...v14.0.0
[13.0.0]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v12.1.2...v13.0.0

@@ -192,0 +204,0 @@ [12.1.2]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v12.1.1...v12.1.2

10

dist/block-ref.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,3 +6,2 @@ exports.createBlockRefMiddleware = void 0;

const full_1 = require("klona/full");
const pify_1 = __importDefault(require("pify"));
const logging_utils_1 = require("./logging-utils");

@@ -46,6 +42,4 @@ const cache_1 = require("./utils/cache");

log('Performing another request %o', childRequest);
const childRes = await (0, pify_1.default)(provider.sendAsync).call(provider, childRequest);
// copy child response onto original response
res.result = childRes.result;
res.error = childRes.error;
// copy child result onto original response
res.result = await provider.request(childRequest);
return undefined;

@@ -52,0 +46,0 @@ });

import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import { type JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import type { Json, JsonRpcParams } from '@metamask/utils';
export declare function providerAsMiddleware(provider: SafeEventEmitterProvider): JsonRpcMiddleware<JsonRpcParams, Json>;
export declare function ethersProviderAsMiddleware(provider: SafeEventEmitterProvider): JsonRpcMiddleware<JsonRpcParams, Json>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ethersProviderAsMiddleware = exports.providerAsMiddleware = void 0;
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
function providerAsMiddleware(provider) {
return (req, res, _next, end) => {
// send request to provider
provider.sendAsync(req, (err, providerRes) => {
// forward any error
if (err instanceof Error) {
return end(err);
}
// copy provider response onto original response
Object.assign(res, providerRes);
return end();
});
};
return (0, json_rpc_engine_1.createAsyncMiddleware)(async (req, res) => {
res.result = await provider.request(req);
});
}

@@ -18,0 +10,0 @@ exports.providerAsMiddleware = providerAsMiddleware;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,3 +6,2 @@ exports.createRetryOnEmptyMiddleware = void 0;

const full_1 = require("klona/full");
const pify_1 = __importDefault(require("pify"));
const logging_utils_1 = require("./logging-utils");

@@ -71,16 +67,16 @@ const cache_1 = require("./utils/cache");

// attempt child request until non-empty response is received
const childResponse = await retry(10, async () => {
const childResult = await retry(10, async () => {
log('Performing request %o', childRequest);
const attemptResponse = await (0, pify_1.default)(provider.sendAsync).call(provider, childRequest);
log('Response is %o', attemptResponse);
const attemptResult = await provider.request(childRequest);
log('Result is %o', attemptResult);
// verify result
if (emptyValues.includes(attemptResponse.result)) {
throw new Error(`RetryOnEmptyMiddleware - empty response "${JSON.stringify(attemptResponse)}" for request "${JSON.stringify(childRequest)}"`);
const allEmptyValues = emptyValues;
if (allEmptyValues.includes(attemptResult)) {
throw new Error(`RetryOnEmptyMiddleware - empty result "${JSON.stringify(attemptResult)}" for request "${JSON.stringify(childRequest)}"`);
}
return attemptResponse;
return attemptResult;
});
log('Copying result %o and error %o', childResponse.result, childResponse.error);
// copy child response onto original response
res.result = childResponse.result;
res.error = childResponse.error;
log('Copying result %o', childResult);
// copy child result onto original response
res.result = childResult;
return undefined;

@@ -87,0 +83,0 @@ });

@@ -0,1 +1,11 @@

import type { Hex } from '@metamask/utils';
declare type EIP712Domain = {
verifyingContract: Hex;
};
declare type SignTypedMessageDataV3V4 = {
types: Record<string, unknown>;
domain: EIP712Domain;
primaryType: string;
message: unknown;
};
/**

@@ -8,1 +18,9 @@ * Normalizes the messageData for the eth_signTypedData

export declare function normalizeTypedMessage(messageData: string): string;
/**
* Parses the messageData to obtain the data object for EIP712 normalization
*
* @param data - The messageData to parse.
* @returns The data object for EIP712 normalization.
*/
export declare function parseTypedMessage(data: string): SignTypedMessageDataV3V4;
export {};
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeTypedMessage = void 0;
const utils_1 = require("@metamask/utils");
const bn_js_1 = __importDefault(require("bn.js"));
exports.parseTypedMessage = exports.normalizeTypedMessage = void 0;
/**

@@ -45,4 +40,5 @@ * Normalizes the messageData for the eth_signTypedData

}
exports.parseTypedMessage = parseTypedMessage;
/**
* Normalizes the address to a hexadecimal format
* Normalizes the address to standard hexadecimal format
*

@@ -53,26 +49,7 @@ * @param address - The address to normalize.

function normalizeContractAddress(address) {
if ((0, utils_1.isStrictHexString)(address) && (0, utils_1.isValidHexAddress)(address)) {
return address;
if (address.startsWith('0X')) {
return `0x${address.slice(2)}`;
}
// Check if the address is in octal format, convert to hexadecimal
if (address.startsWith('0o')) {
// If octal, convert to hexadecimal
return octalToHex(address);
}
// Check if the address is in decimal format, convert to hexadecimal
try {
const decimalBN = new bn_js_1.default(address, 10);
const hexString = decimalBN.toString(16);
return (0, utils_1.add0x)(hexString);
}
catch (e) {
// Ignore errors and return the original address
}
// Returning the original address without normalization
return address;
}
function octalToHex(octalAddress) {
const decimalAddress = parseInt(octalAddress.slice(2), 8).toString(16);
return (0, utils_1.add0x)(decimalAddress);
}
//# sourceMappingURL=normalize.js.map
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import type { JsonRpcRequest } from '@metamask/utils';
import { type JsonRpcRequest } from '@metamask/utils';
import type { Block } from './types';

@@ -4,0 +4,0 @@ export declare type TransactionParams = {

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

const rpc_errors_1 = require("@metamask/rpc-errors");
const utils_1 = require("@metamask/utils");
const normalize_1 = require("./utils/normalize");

@@ -140,2 +141,3 @@ function createWalletMiddleware({ getAccounts, processDecryptMessage, processEncryptionPublicKey, processEthSignMessage, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, }) {

const message = (0, normalize_1.normalizeTypedMessage)(params[1]);
validateVerifyingContract(message);
const version = 'V3';

@@ -162,2 +164,3 @@ const msgParams = {

const message = (0, normalize_1.normalizeTypedMessage)(params[1]);
validateVerifyingContract(message);
const version = 'V4';

@@ -289,2 +292,13 @@ const msgParams = {

exports.createWalletMiddleware = createWalletMiddleware;
/**
* Validates verifyingContract of typedSignMessage.
*
* @param data - The data passed in typedSign request.
*/
function validateVerifyingContract(data) {
const { domain: { verifyingContract }, } = (0, normalize_1.parseTypedMessage)(data);
if (!(0, utils_1.isValidHexAddress)(verifyingContract)) {
throw rpc_errors_1.rpcErrors.invalidInput();
}
}
function resemblesAddress(str) {

@@ -291,0 +305,0 @@ // hex prefix 2 + 20 bytes

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

@@ -31,8 +31,8 @@ "repository": {

"dependencies": {
"@metamask/eth-block-tracker": "^10.0.0",
"@metamask/eth-json-rpc-provider": "^4.0.0",
"@metamask/eth-sig-util": "^7.0.0",
"@metamask/json-rpc-engine": "^9.0.0",
"@metamask/rpc-errors": "^6.0.0",
"@metamask/utils": "^8.1.0",
"@metamask/eth-block-tracker": "^11.0.1",
"@metamask/eth-json-rpc-provider": "^4.1.1",
"@metamask/eth-sig-util": "^7.0.3",
"@metamask/json-rpc-engine": "^9.0.2",
"@metamask/rpc-errors": "^6.3.1",
"@metamask/utils": "^9.1.0",
"@types/bn.js": "^5.1.5",

@@ -39,0 +39,0 @@ "bn.js": "^5.2.1",

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