@metamask/eth-json-rpc-middleware
Advanced tools
Comparing version 11.0.2 to 12.0.0
@@ -9,2 +9,13 @@ # Changelog | ||
## [12.0.0] | ||
### Changed | ||
- **BREAKING:** Minimum Node.js version is now v16 ([#243](https://github.com/MetaMask/eth-json-rpc-middleware/pull/243)) | ||
- **BREAKING:** Bump `@metamask/utils` from `^5.0.2` to `^8.1.0` ([#241](https://github.com/MetaMask/eth-json-rpc-middleware/pull/241)) | ||
- **BREAKING:** Bump `@metamask/eth-json-rpc-provider` from `^1.0.0` to `^2.1.0` ([#245](https://github.com/MetaMask/eth-json-rpc-middleware/pull/245)) | ||
- **BREAKING:** Migrate from eth-rpc-errors `^4.0.3` to `@metamask/rpc-errors` `^6.0.0` ([#245](https://github.com/MetaMask/eth-json-rpc-middleware/pull/245)) | ||
- **BREAKING:** Migrate from json-rpc-engine `^6.1.0` to `@metamask/json-rpc-engine` `^7.1.1` ([#245](https://github.com/MetaMask/eth-json-rpc-middleware/pull/245)) | ||
- Bump `@metamask/eth-sig-util` from `^6.0.0` to `^7.0.0` ([#248](https://github.com/MetaMask/eth-json-rpc-middleware/pull/248)) | ||
- Bump `@metamask/eth-block-tracker` from `^7.0.1` to `^8.0.0` ([#245](https://github.com/MetaMask/eth-json-rpc-middleware/pull/245)) | ||
- Replace deep-cloning implemantation `clone` with `klona/full`([#250](https://github.com/MetaMask/eth-json-rpc-middleware/pull/250)) | ||
## [11.0.2] | ||
@@ -138,3 +149,4 @@ ### Changed | ||
[Unreleased]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v11.0.2...HEAD | ||
[Unreleased]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v12.0.0...HEAD | ||
[12.0.0]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v11.0.2...v12.0.0 | ||
[11.0.2]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v11.0.1...v11.0.2 | ||
@@ -141,0 +153,0 @@ [11.0.1]: https://github.com/MetaMask/eth-json-rpc-middleware/compare/v11.0.0...v11.0.1 |
@@ -0,1 +1,2 @@ | ||
import type { Json, JsonRpcParams } from '@metamask/utils'; | ||
import type { PollingBlockTracker } from 'eth-block-tracker'; | ||
@@ -6,3 +7,3 @@ import type { JsonRpcCacheMiddleware } from './types'; | ||
} | ||
export declare function createBlockCacheMiddleware({ blockTracker, }?: BlockCacheMiddlewareOptions): JsonRpcCacheMiddleware<unknown, unknown>; | ||
export declare function createBlockCacheMiddleware({ blockTracker, }?: BlockCacheMiddlewareOptions): JsonRpcCacheMiddleware<JsonRpcParams, Json>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createBlockCacheMiddleware = void 0; | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const json_rpc_engine_1 = require("@metamask/json-rpc-engine"); | ||
const logging_utils_1 = require("./logging-utils"); | ||
@@ -6,0 +6,0 @@ const cache_1 = require("./utils/cache"); |
@@ -0,7 +1,8 @@ | ||
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
import type { Json, JsonRpcParams } from '@metamask/utils'; | ||
import type { PollingBlockTracker } from 'eth-block-tracker'; | ||
import type { JsonRpcMiddleware } from 'json-rpc-engine'; | ||
interface BlockRefRewriteMiddlewareOptions { | ||
blockTracker?: PollingBlockTracker; | ||
} | ||
export declare function createBlockRefRewriteMiddleware({ blockTracker, }?: BlockRefRewriteMiddlewareOptions): JsonRpcMiddleware<unknown, unknown>; | ||
export declare function createBlockRefRewriteMiddleware({ blockTracker, }?: BlockRefRewriteMiddlewareOptions): JsonRpcMiddleware<JsonRpcParams, Json>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createBlockRefRewriteMiddleware = void 0; | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const json_rpc_engine_1 = require("@metamask/json-rpc-engine"); | ||
const cache_1 = require("./utils/cache"); | ||
@@ -17,9 +17,6 @@ function createBlockRefRewriteMiddleware({ blockTracker, } = {}) { | ||
// skip if not "latest" | ||
let blockRef = Array.isArray(req.params) | ||
const blockRef = Array.isArray(req.params) && req.params[blockRefIndex] | ||
? req.params[blockRefIndex] | ||
: undefined; | ||
// omitted blockRef implies "latest" | ||
if (blockRef === undefined) { | ||
blockRef = 'latest'; | ||
} | ||
: // omitted blockRef implies "latest" | ||
'latest'; | ||
if (blockRef !== 'latest') { | ||
@@ -26,0 +23,0 @@ return next(); |
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; | ||
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
import type { Json, JsonRpcParams } from '@metamask/utils'; | ||
import type { PollingBlockTracker } from 'eth-block-tracker'; | ||
import type { JsonRpcMiddleware } from 'json-rpc-engine'; | ||
interface BlockRefMiddlewareOptions { | ||
@@ -8,3 +9,3 @@ blockTracker?: PollingBlockTracker; | ||
} | ||
export declare function createBlockRefMiddleware({ provider, blockTracker, }?: BlockRefMiddlewareOptions): JsonRpcMiddleware<unknown, unknown>; | ||
export declare function createBlockRefMiddleware({ provider, blockTracker, }?: BlockRefMiddlewareOptions): JsonRpcMiddleware<JsonRpcParams, Json>; | ||
export {}; |
@@ -7,4 +7,4 @@ "use strict"; | ||
exports.createBlockRefMiddleware = void 0; | ||
const clone_1 = __importDefault(require("clone")); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const json_rpc_engine_1 = require("@metamask/json-rpc-engine"); | ||
const full_1 = require("klona/full"); | ||
const pify_1 = __importDefault(require("pify")); | ||
@@ -40,3 +40,3 @@ const logging_utils_1 = require("./logging-utils"); | ||
// create child request with specific block-ref | ||
const childRequest = (0, clone_1.default)(req); | ||
const childRequest = (0, full_1.klona)(req); | ||
if (Array.isArray(childRequest.params)) { | ||
@@ -43,0 +43,0 @@ childRequest.params[blockRefIndex] = latestBlockNumber; |
@@ -0,7 +1,8 @@ | ||
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
import type { Json, JsonRpcParams } from '@metamask/utils'; | ||
import type { PollingBlockTracker } from 'eth-block-tracker'; | ||
import type { JsonRpcMiddleware } from 'json-rpc-engine'; | ||
interface BlockTrackerInspectorMiddlewareOptions { | ||
blockTracker: PollingBlockTracker; | ||
} | ||
export declare function createBlockTrackerInspectorMiddleware({ blockTracker, }: BlockTrackerInspectorMiddlewareOptions): JsonRpcMiddleware<unknown, unknown>; | ||
export declare function createBlockTrackerInspectorMiddleware({ blockTracker, }: BlockTrackerInspectorMiddlewareOptions): JsonRpcMiddleware<JsonRpcParams, Json>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createBlockTrackerInspectorMiddleware = void 0; | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const json_rpc_engine_1 = require("@metamask/json-rpc-engine"); | ||
const logging_utils_1 = require("./logging-utils"); | ||
@@ -6,0 +6,0 @@ const log = (0, logging_utils_1.createModuleLogger)(logging_utils_1.projectLogger, 'block-tracker-inspector'); |
@@ -1,3 +0,4 @@ | ||
import type { JsonRpcMiddleware, JsonRpcRequest } from 'json-rpc-engine'; | ||
export interface PayloadWithOrigin extends JsonRpcRequest<unknown> { | ||
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils'; | ||
export interface PayloadWithOrigin extends JsonRpcRequest { | ||
origin?: string; | ||
@@ -30,3 +31,3 @@ } | ||
originHttpHeaderKey?: string; | ||
}): JsonRpcMiddleware<unknown, unknown>; | ||
}): JsonRpcMiddleware<JsonRpcParams, Json>; | ||
/** | ||
@@ -33,0 +34,0 @@ * Generate `fetch` configuration for sending the given request to an RPC API. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createFetchConfigFromReq = exports.createFetchMiddleware = void 0; | ||
const eth_rpc_errors_1 = require("eth-rpc-errors"); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const json_rpc_engine_1 = require("@metamask/json-rpc-engine"); | ||
const rpc_errors_1 = require("@metamask/rpc-errors"); | ||
const timeout_1 = require("./utils/timeout"); | ||
@@ -80,3 +80,3 @@ const RETRIABLE_ERRORS = [ | ||
case 405: | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotFound(); | ||
throw rpc_errors_1.rpcErrors.methodNotFound(); | ||
case 418: | ||
@@ -94,3 +94,3 @@ throw createRatelimitError(); | ||
if (fetchRes.status !== 200) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.internal({ | ||
throw rpc_errors_1.rpcErrors.internal({ | ||
message: `Non-200 status code: '${fetchRes.status}'`, | ||
@@ -102,3 +102,3 @@ data: body, | ||
if (body.error) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.internal({ | ||
throw rpc_errors_1.rpcErrors.internal({ | ||
data: body.error, | ||
@@ -172,3 +172,3 @@ }); | ||
function createRatelimitError() { | ||
return eth_rpc_errors_1.ethErrors.rpc.internal({ message: `Request is being rate limited.` }); | ||
return rpc_errors_1.rpcErrors.internal({ message: `Request is being rate limited.` }); | ||
} | ||
@@ -178,4 +178,4 @@ function createTimeoutError() { | ||
msg += `This can happen when querying logs over too wide a block range.`; | ||
return eth_rpc_errors_1.ethErrors.rpc.internal({ message: msg }); | ||
return rpc_errors_1.rpcErrors.internal({ message: msg }); | ||
} | ||
//# sourceMappingURL=fetch.js.map |
@@ -0,2 +1,3 @@ | ||
import type { JsonRpcParams, Json } from '@metamask/utils'; | ||
import type { JsonRpcCacheMiddleware } from './types'; | ||
export declare function createInflightCacheMiddleware(): JsonRpcCacheMiddleware<unknown, unknown>; | ||
export declare function createInflightCacheMiddleware(): JsonRpcCacheMiddleware<JsonRpcParams, Json>; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createInflightCacheMiddleware = void 0; | ||
const clone_1 = __importDefault(require("clone")); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const json_rpc_engine_1 = require("@metamask/json-rpc-engine"); | ||
const full_1 = require("klona/full"); | ||
const logging_utils_1 = require("./logging-utils"); | ||
@@ -55,4 +52,4 @@ const cache_1 = require("./utils/cache"); | ||
// append a copy of the result and error to the response | ||
res.result = (0, clone_1.default)(handledRes.result); | ||
res.error = (0, clone_1.default)(handledRes.error); | ||
res.result = (0, full_1.klona)(handledRes.result); | ||
res.error = (0, full_1.klona)(handledRes.error); | ||
resolve(); | ||
@@ -59,0 +56,0 @@ }); |
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; | ||
import type { JsonRpcMiddleware } from 'json-rpc-engine'; | ||
export declare function providerAsMiddleware(provider: SafeEventEmitterProvider): JsonRpcMiddleware<unknown, unknown>; | ||
export declare function ethersProviderAsMiddleware(provider: SafeEventEmitterProvider): JsonRpcMiddleware<unknown, unknown>; | ||
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>; |
@@ -25,3 +25,3 @@ "use strict"; | ||
if (err) { | ||
// TODO: Remove this cast when next major `json-rpc-engine` release is out | ||
// TODO: Remove this cast when next major `@metamask/json-rpc-engine` release is out | ||
// The next release changes how errors are propogated. | ||
@@ -28,0 +28,0 @@ return end(err); |
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; | ||
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
import type { Json, JsonRpcParams } from '@metamask/utils'; | ||
import type { PollingBlockTracker } from 'eth-block-tracker'; | ||
import type { JsonRpcMiddleware } from 'json-rpc-engine'; | ||
interface RetryOnEmptyMiddlewareOptions { | ||
@@ -8,3 +9,3 @@ provider?: SafeEventEmitterProvider; | ||
} | ||
export declare function createRetryOnEmptyMiddleware({ provider, blockTracker, }?: RetryOnEmptyMiddlewareOptions): JsonRpcMiddleware<unknown, unknown>; | ||
export declare function createRetryOnEmptyMiddleware({ provider, blockTracker, }?: RetryOnEmptyMiddlewareOptions): JsonRpcMiddleware<JsonRpcParams, Json>; | ||
export {}; |
@@ -7,4 +7,4 @@ "use strict"; | ||
exports.createRetryOnEmptyMiddleware = void 0; | ||
const clone_1 = __importDefault(require("clone")); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const json_rpc_engine_1 = require("@metamask/json-rpc-engine"); | ||
const full_1 = require("klona/full"); | ||
const pify_1 = __importDefault(require("pify")); | ||
@@ -42,3 +42,3 @@ const logging_utils_1 = require("./logging-utils"); | ||
// skip if not exact block references | ||
let blockRef = Array.isArray(req.params) | ||
let blockRef = Array.isArray(req.params) && req.params[blockRefIndex] | ||
? req.params[blockRefIndex] | ||
@@ -69,3 +69,3 @@ : undefined; | ||
// create child request with specific block-ref | ||
const childRequest = (0, clone_1.default)(req); | ||
const childRequest = (0, full_1.klona)(req); | ||
// attempt child request until non-empty response is received | ||
@@ -72,0 +72,0 @@ const childResponse = await retry(10, async () => { |
@@ -1,6 +0,7 @@ | ||
import type { JsonRpcMiddleware, JsonRpcRequest } from 'json-rpc-engine'; | ||
export interface JsonRpcRequestToCache<T> extends JsonRpcRequest<T> { | ||
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils'; | ||
export interface JsonRpcRequestToCache<Params extends JsonRpcParams> extends JsonRpcRequest<Params> { | ||
skipCache?: boolean; | ||
} | ||
export declare type JsonRpcCacheMiddleware<T, U> = JsonRpcMiddleware<T, U> extends (req: JsonRpcRequest<T>, ...args: infer X) => infer Y ? (req: JsonRpcRequestToCache<T>, ...args: X) => Y : never; | ||
export declare type JsonRpcCacheMiddleware<Params extends JsonRpcParams, Result extends Json> = JsonRpcMiddleware<Params, Result> extends (req: JsonRpcRequest<Params>, ...args: infer X) => infer Y ? (req: JsonRpcRequestToCache<Params>, ...args: X) => Y : never; | ||
export declare type BlockData = string | string[]; | ||
@@ -7,0 +8,0 @@ export declare type Block = Record<string, BlockData>; |
@@ -1,2 +0,2 @@ | ||
import type { JsonRpcRequest } from 'json-rpc-engine'; | ||
import type { Json, JsonRpcRequest } from '@metamask/utils'; | ||
/** | ||
@@ -38,3 +38,3 @@ * The cache strategy to use for a given method. | ||
*/ | ||
export declare function cacheIdentifierForRequest(request: JsonRpcRequest<unknown>, skipBlockRef?: boolean): string | null; | ||
export declare function cacheIdentifierForRequest(request: JsonRpcRequest, skipBlockRef?: boolean): string | null; | ||
/** | ||
@@ -53,3 +53,3 @@ * Return whether a method can be cached or not. | ||
*/ | ||
export declare function blockTagForRequest(request: JsonRpcRequest<unknown>): unknown; | ||
export declare function blockTagForRequest(request: JsonRpcRequest): Json | undefined; | ||
/** | ||
@@ -56,0 +56,0 @@ * Returns the index of the block parameter for the given method. |
@@ -1,24 +0,25 @@ | ||
import type { JsonRpcMiddleware, JsonRpcRequest } from 'json-rpc-engine'; | ||
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
import type { JsonRpcRequest } from '@metamask/utils'; | ||
import type { Block } from './types'; | ||
export interface TransactionParams { | ||
export declare type TransactionParams = { | ||
from: string; | ||
} | ||
export interface MessageParams extends TransactionParams { | ||
}; | ||
export declare type MessageParams = TransactionParams & { | ||
data: string; | ||
} | ||
export interface TypedMessageParams extends MessageParams { | ||
}; | ||
export declare type TypedMessageParams = MessageParams & { | ||
version: string; | ||
} | ||
}; | ||
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>; | ||
processTransaction?: (txParams: TransactionParams, req: JsonRpcRequest<unknown>) => Promise<string>; | ||
processSignTransaction?: (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<string>; | ||
processTypedMessageV4?: (msgParams: TypedMessageParams, req: JsonRpcRequest<unknown>, version: string) => Promise<string>; | ||
getAccounts: (req: JsonRpcRequest) => Promise<string[]>; | ||
processDecryptMessage?: (msgParams: MessageParams, req: JsonRpcRequest) => Promise<string>; | ||
processEncryptionPublicKey?: (address: string, req: JsonRpcRequest) => Promise<string>; | ||
processEthSignMessage?: (msgParams: MessageParams, req: JsonRpcRequest) => Promise<string>; | ||
processPersonalMessage?: (msgParams: MessageParams, req: JsonRpcRequest) => Promise<string>; | ||
processTransaction?: (txParams: TransactionParams, req: JsonRpcRequest) => Promise<string>; | ||
processSignTransaction?: (txParams: TransactionParams, req: JsonRpcRequest) => Promise<string>; | ||
processTypedMessage?: (msgParams: MessageParams, req: JsonRpcRequest, version: string) => Promise<string>; | ||
processTypedMessageV3?: (msgParams: TypedMessageParams, req: JsonRpcRequest, version: string) => Promise<string>; | ||
processTypedMessageV4?: (msgParams: TypedMessageParams, req: JsonRpcRequest, version: string) => Promise<string>; | ||
} | ||
export declare function createWalletMiddleware({ getAccounts, processDecryptMessage, processEncryptionPublicKey, processEthSignMessage, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, }: WalletMiddlewareOptions): JsonRpcMiddleware<string, Block>; | ||
export declare function createWalletMiddleware({ getAccounts, processDecryptMessage, processEncryptionPublicKey, processEthSignMessage, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, }: WalletMiddlewareOptions): JsonRpcMiddleware<any, Block>; |
@@ -28,4 +28,4 @@ "use strict"; | ||
const sigUtil = __importStar(require("@metamask/eth-sig-util")); | ||
const eth_rpc_errors_1 = require("eth-rpc-errors"); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const json_rpc_engine_1 = require("@metamask/json-rpc-engine"); | ||
const rpc_errors_1 = require("@metamask/rpc-errors"); | ||
function createWalletMiddleware({ getAccounts, processDecryptMessage, processEncryptionPublicKey, processEthSignMessage, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, }) { | ||
@@ -66,15 +66,31 @@ if (!getAccounts) { | ||
async function sendTransaction(req, res) { | ||
var _a; | ||
if (!processTransaction) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
const txParams = req.params[0] || {}; | ||
txParams.from = await validateAndNormalizeKeyholder(txParams.from, req); | ||
if (!req.params || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 1)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const txParams = { | ||
from: await validateAndNormalizeKeyholder(((_a = params[0]) === null || _a === void 0 ? void 0 : _a.from) || '', req), | ||
}; | ||
res.result = await processTransaction(txParams, req); | ||
} | ||
async function signTransaction(req, res) { | ||
var _a; | ||
if (!processSignTransaction) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
const txParams = req.params[0] || {}; | ||
txParams.from = await validateAndNormalizeKeyholder(txParams.from, req); | ||
if (!req.params || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 1)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const txParams = { | ||
from: await validateAndNormalizeKeyholder(((_a = params[0]) === null || _a === void 0 ? void 0 : _a.from) || '', req), | ||
}; | ||
res.result = await processSignTransaction(txParams, req); | ||
@@ -87,7 +103,13 @@ } | ||
if (!processEthSignMessage) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
const address = await validateAndNormalizeKeyholder(req.params[0], req); | ||
const message = req.params[1]; | ||
const extraParams = req.params[2] || {}; | ||
if (!(req === null || req === void 0 ? void 0 : req.params) || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 2)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const address = await validateAndNormalizeKeyholder(params[0], req); | ||
const message = params[1]; | ||
const extraParams = params[2] || {}; | ||
const msgParams = Object.assign(Object.assign({}, extraParams), { from: address, data: message }); | ||
@@ -98,8 +120,14 @@ res.result = await processEthSignMessage(msgParams, req); | ||
if (!processTypedMessage) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
const message = req.params[0]; | ||
const address = await validateAndNormalizeKeyholder(req.params[1], req); | ||
if (!(req === null || req === void 0 ? void 0 : req.params) || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 2)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const message = params[0]; | ||
const address = await validateAndNormalizeKeyholder(params[1], req); | ||
const version = 'V1'; | ||
const extraParams = req.params[2] || {}; | ||
const extraParams = params[2] || {}; | ||
const msgParams = Object.assign(Object.assign({}, extraParams), { from: address, data: message }); | ||
@@ -110,6 +138,12 @@ res.result = await processTypedMessage(msgParams, req, version); | ||
if (!processTypedMessageV3) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
const address = await validateAndNormalizeKeyholder(req.params[0], req); | ||
const message = req.params[1]; | ||
if (!(req === null || req === void 0 ? void 0 : req.params) || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 2)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const address = await validateAndNormalizeKeyholder(params[0], req); | ||
const message = params[1]; | ||
const version = 'V3'; | ||
@@ -125,6 +159,12 @@ const msgParams = { | ||
if (!processTypedMessageV4) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
const address = await validateAndNormalizeKeyholder(req.params[0], req); | ||
const message = req.params[1]; | ||
if (!(req === null || req === void 0 ? void 0 : req.params) || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 2)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const address = await validateAndNormalizeKeyholder(params[0], req); | ||
const message = params[1]; | ||
const version = 'V4'; | ||
@@ -140,9 +180,15 @@ const msgParams = { | ||
if (!processPersonalMessage) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
if (!(req === null || req === void 0 ? void 0 : req.params) || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 2)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
// process normally | ||
const firstParam = req.params[0]; | ||
const secondParam = req.params[1]; | ||
const firstParam = params[0]; | ||
const secondParam = params[1]; | ||
// non-standard "extraParams" to be appended to our "msgParams" obj | ||
const extraParams = req.params[2] || {}; | ||
const extraParams = params[2] || {}; | ||
// We initially incorrectly ordered these parameters. | ||
@@ -175,4 +221,10 @@ // To gracefully respect users who adopted this API early, | ||
async function personalRecover(req, res) { | ||
const message = req.params[0]; | ||
const signature = req.params[1]; | ||
if (!(req === null || req === void 0 ? void 0 : req.params) || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 2)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const message = params[0]; | ||
const signature = params[1]; | ||
const signerAddress = sigUtil.recoverPersonalSignature({ | ||
@@ -186,5 +238,11 @@ data: message, | ||
if (!processEncryptionPublicKey) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
const address = await validateAndNormalizeKeyholder(req.params[0], req); | ||
if (!(req === null || req === void 0 ? void 0 : req.params) || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 1)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const address = await validateAndNormalizeKeyholder(params[0], req); | ||
res.result = await processEncryptionPublicKey(address, req); | ||
@@ -194,7 +252,13 @@ } | ||
if (!processDecryptMessage) { | ||
throw eth_rpc_errors_1.ethErrors.rpc.methodNotSupported(); | ||
throw rpc_errors_1.rpcErrors.methodNotSupported(); | ||
} | ||
const ciphertext = req.params[0]; | ||
const address = await validateAndNormalizeKeyholder(req.params[1], req); | ||
const extraParams = req.params[2] || {}; | ||
if (!(req === null || req === void 0 ? void 0 : req.params) || | ||
!Array.isArray(req.params) || | ||
!(req.params.length >= 1)) { | ||
throw rpc_errors_1.rpcErrors.invalidInput(); | ||
} | ||
const params = req.params; | ||
const ciphertext = params[0]; | ||
const address = await validateAndNormalizeKeyholder(params[1], req); | ||
const extraParams = params[2] || {}; | ||
const msgParams = Object.assign(Object.assign({}, extraParams), { from: address, data: ciphertext }); | ||
@@ -227,5 +291,5 @@ res.result = await processDecryptMessage(msgParams, req); | ||
} | ||
throw eth_rpc_errors_1.ethErrors.provider.unauthorized(); | ||
throw rpc_errors_1.providerErrors.unauthorized(); | ||
} | ||
throw eth_rpc_errors_1.ethErrors.rpc.invalidParams({ | ||
throw rpc_errors_1.rpcErrors.invalidParams({ | ||
message: `Invalid parameters: must provide an Ethereum address.`, | ||
@@ -232,0 +296,0 @@ }); |
{ | ||
"name": "@metamask/eth-json-rpc-middleware", | ||
"version": "11.0.2", | ||
"version": "12.0.0", | ||
"description": "Ethereum-related json-rpc-engine middleware.", | ||
@@ -31,11 +31,11 @@ "repository": { | ||
"dependencies": { | ||
"@metamask/eth-json-rpc-provider": "^1.0.0", | ||
"@metamask/eth-sig-util": "^6.0.0", | ||
"@metamask/utils": "^5.0.1", | ||
"clone": "^2.1.1", | ||
"eth-block-tracker": "^7.0.1", | ||
"eth-rpc-errors": "^4.0.3", | ||
"json-rpc-engine": "^6.1.0", | ||
"pify": "^3.0.0", | ||
"safe-stable-stringify": "^2.3.2" | ||
"@metamask/eth-json-rpc-provider": "^2.1.0", | ||
"@metamask/eth-sig-util": "^7.0.0", | ||
"@metamask/json-rpc-engine": "^7.1.1", | ||
"@metamask/rpc-errors": "^6.0.0", | ||
"@metamask/utils": "^8.1.0", | ||
"eth-block-tracker": "^8.0.0", | ||
"klona": "^2.0.6", | ||
"pify": "^5.0.0", | ||
"safe-stable-stringify": "^2.4.3" | ||
}, | ||
@@ -51,6 +51,5 @@ "devDependencies": { | ||
"@types/btoa": "^1.2.3", | ||
"@types/clone": "^2.1.0", | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^17.0.23", | ||
"@types/pify": "^3.0.2", | ||
"@types/pify": "^5.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.42.1", | ||
@@ -76,3 +75,3 @@ "@typescript-eslint/parser": "^5.42.1", | ||
"engines": { | ||
"node": ">=14.0.0" | ||
"node": "^16.20 || ^18.16 || >=20" | ||
}, | ||
@@ -79,0 +78,0 @@ "publishConfig": { |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159865
28
1446
8
+ Added@metamask/rpc-errors@^6.0.0
+ Addedklona@^2.0.6
+ Added@metamask/abi-utils@2.0.4(transitive)
+ Added@metamask/eth-json-rpc-provider@2.3.2(transitive)
+ Added@metamask/eth-sig-util@7.0.3(transitive)
+ Addedeth-block-tracker@8.1.0(transitive)
+ Addedklona@2.0.6(transitive)
+ Addedpify@5.0.0(transitive)
- Removedclone@^2.1.1
- Removedeth-rpc-errors@^4.0.3
- Removedjson-rpc-engine@^6.1.0
- Removed@metamask/abi-utils@1.2.0(transitive)
- Removed@metamask/eth-json-rpc-provider@1.0.1(transitive)
- Removed@metamask/eth-sig-util@6.0.2(transitive)
- Removed@metamask/utils@3.6.05.0.2(transitive)
- Removedclone@2.1.2(transitive)
- Removedeth-block-tracker@7.1.0(transitive)
- Removedeth-rpc-errors@4.0.3(transitive)
- Removedethjs-util@0.1.6(transitive)
- Removedis-hex-prefixed@1.0.0(transitive)
- Removedjson-rpc-engine@6.1.0(transitive)
- Removedpify@3.0.0(transitive)
- Removedstrip-hex-prefix@1.0.0(transitive)
- Removedsuperstruct@1.0.4(transitive)
- Removedtweetnacl-util@0.15.1(transitive)
Updated@metamask/utils@^8.1.0
Updatedeth-block-tracker@^8.0.0
Updatedpify@^5.0.0
Updatedsafe-stable-stringify@^2.4.3