@metamask/eth-json-rpc-middleware
Advanced tools
Comparing version 15.2.0 to 15.3.0
@@ -7,4 +7,7 @@ export * from './block-cache'; | ||
export * from './inflight-cache'; | ||
export type { GetCallsStatusParams, GetCallsStatusReceipt, GetCallsStatusResult, GetTransactionReceiptsByBatchIdHook, } from './methods/wallet-get-calls-status'; | ||
export type { GetCapabilitiesHook, GetCapabilitiesParams, GetCapabilitiesResult, } from './methods/wallet-get-capabilities'; | ||
export type { ProcessSendCallsHook, SendCalls, SendCallsParams, } from './methods/wallet-send-calls'; | ||
export * from './providerAsMiddleware'; | ||
export * from './retryOnEmpty'; | ||
export * from './wallet'; |
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
import { type JsonRpcRequest } from '@metamask/utils'; | ||
import type { JsonRpcRequest } from '@metamask/utils'; | ||
import type { GetTransactionReceiptsByBatchIdHook } from './methods/wallet-get-calls-status'; | ||
import type { GetCapabilitiesHook } from './methods/wallet-get-capabilities'; | ||
import type { ProcessSendCallsHook } from './methods/wallet-send-calls'; | ||
import type { Block } from './types'; | ||
@@ -19,2 +22,4 @@ export declare type TransactionParams = { | ||
getAccounts: (req: JsonRpcRequest) => Promise<string[]>; | ||
getCapabilities?: GetCapabilitiesHook; | ||
getTransactionReceiptsByBatchId?: GetTransactionReceiptsByBatchIdHook; | ||
processDecryptMessage?: (msgParams: MessageParams, req: JsonRpcRequest) => Promise<string>; | ||
@@ -28,3 +33,4 @@ processEncryptionPublicKey?: (address: string, req: JsonRpcRequest) => Promise<string>; | ||
processTypedMessageV4?: (msgParams: TypedMessageParams, req: JsonRpcRequest, version: string) => Promise<string>; | ||
processSendCalls?: ProcessSendCallsHook; | ||
} | ||
export declare function createWalletMiddleware({ getAccounts, processDecryptMessage, processEncryptionPublicKey, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, }: WalletMiddlewareOptions): JsonRpcMiddleware<any, Block>; | ||
export declare function createWalletMiddleware({ getAccounts, getCapabilities, getTransactionReceiptsByBatchId, processDecryptMessage, processEncryptionPublicKey, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, processSendCalls, }: WalletMiddlewareOptions): JsonRpcMiddleware<any, Block>; |
@@ -31,5 +31,9 @@ "use strict"; | ||
const utils_1 = require("@metamask/utils"); | ||
const wallet_get_calls_status_1 = require("./methods/wallet-get-calls-status"); | ||
const wallet_get_capabilities_1 = require("./methods/wallet-get-capabilities"); | ||
const wallet_send_calls_1 = require("./methods/wallet-send-calls"); | ||
const common_1 = require("./utils/common"); | ||
const normalize_1 = require("./utils/normalize"); | ||
function createWalletMiddleware({ getAccounts, processDecryptMessage, processEncryptionPublicKey, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, }) { | ||
const validation_1 = require("./utils/validation"); | ||
function createWalletMiddleware({ getAccounts, getCapabilities, getTransactionReceiptsByBatchId, processDecryptMessage, processEncryptionPublicKey, processPersonalMessage, processTransaction, processSignTransaction, processTypedMessage, processTypedMessageV3, processTypedMessageV4, processSendCalls, }) { | ||
if (!getAccounts) { | ||
@@ -53,2 +57,8 @@ throw new Error('opts.getAccounts is required'); | ||
personal_ecRecover: (0, json_rpc_engine_1.createAsyncMiddleware)(personalRecover), | ||
// EIP-5792 | ||
wallet_getCapabilities: (0, json_rpc_engine_1.createAsyncMiddleware)(async (params, req) => (0, wallet_get_capabilities_1.walletGetCapabilities)(params, req, { getCapabilities })), | ||
wallet_sendCalls: (0, json_rpc_engine_1.createAsyncMiddleware)(async (params, req) => (0, wallet_send_calls_1.walletSendCalls)(params, req, { getAccounts, processSendCalls })), | ||
wallet_getCallsStatus: (0, json_rpc_engine_1.createAsyncMiddleware)(async (params, req) => (0, wallet_get_calls_status_1.walletGetCallsStatus)(params, req, { | ||
getTransactionReceiptsByBatchId, | ||
})), | ||
}); | ||
@@ -183,3 +193,3 @@ // | ||
let address, message; | ||
if (resemblesAddress(firstParam) && !resemblesAddress(secondParam)) { | ||
if ((0, validation_1.resemblesAddress)(firstParam) && !(0, validation_1.resemblesAddress)(secondParam)) { | ||
let warning = `The eth_personalSign method requires params ordered `; | ||
@@ -259,18 +269,3 @@ warning += `[message, address]. This was previously handled incorrectly, `; | ||
async function validateAndNormalizeKeyholder(address, req) { | ||
if (typeof address === 'string' && | ||
address.length > 0 && | ||
resemblesAddress(address)) { | ||
// Ensure that an "unauthorized" error is thrown if the requester does not have the `eth_accounts` | ||
// permission. | ||
const accounts = await getAccounts(req); | ||
const normalizedAccounts = accounts.map((_address) => _address.toLowerCase()); | ||
const normalizedAddress = address.toLowerCase(); | ||
if (normalizedAccounts.includes(normalizedAddress)) { | ||
return normalizedAddress; | ||
} | ||
throw rpc_errors_1.providerErrors.unauthorized(); | ||
} | ||
throw rpc_errors_1.rpcErrors.invalidParams({ | ||
message: `Invalid parameters: must provide an Ethereum address.`, | ||
}); | ||
return (0, validation_1.validateAndNormalizeKeyholder)(address, req, { getAccounts }); | ||
} | ||
@@ -316,6 +311,2 @@ } | ||
} | ||
function resemblesAddress(str) { | ||
// hex prefix 2 + 20 bytes | ||
return str.length === 2 + 20 * 2; | ||
} | ||
//# sourceMappingURL=wallet.js.map |
{ | ||
"name": "@metamask/eth-json-rpc-middleware", | ||
"version": "15.2.0", | ||
"version": "15.3.0", | ||
"description": "Ethereum-related json-rpc-engine middleware.", | ||
@@ -37,2 +37,3 @@ "repository": { | ||
"@metamask/rpc-errors": "^7.0.2", | ||
"@metamask/superstruct": "^3.1.0", | ||
"@metamask/utils": "^11.1.0", | ||
@@ -39,0 +40,0 @@ "@types/bn.js": "^5.1.5", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
195713
69
1926
0
12
+ Added@metamask/superstruct@^3.1.0