mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-02 22:24:27 +01:00
87ce653c86
The "MetaMask middleware" is the set of middleware for handling methods that we don't send to the network. This includes signing, encryption, `getAccounts`, and methods that rely on pending transaction state. Previously this middleware was setup as part of the network client, despite having nothing to do with the network. They have been moved into the main RPC pipeline established in `metamask-controller.js` instead. This is a pure refactor, and should have no functional changes. The middleware are still run in exactly the same order with the same arguments.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import { createScaffoldMiddleware, mergeMiddleware } from 'json-rpc-engine';
|
|
import { createWalletMiddleware } from 'eth-json-rpc-middleware';
|
|
import {
|
|
createPendingNonceMiddleware,
|
|
createPendingTxMiddleware,
|
|
} from './middleware/pending';
|
|
|
|
export default function createMetamaskMiddleware({
|
|
version,
|
|
getAccounts,
|
|
processTransaction,
|
|
processEthSignMessage,
|
|
processTypedMessage,
|
|
processTypedMessageV3,
|
|
processTypedMessageV4,
|
|
processPersonalMessage,
|
|
processDecryptMessage,
|
|
processEncryptionPublicKey,
|
|
getPendingNonce,
|
|
getPendingTransactionByHash,
|
|
}) {
|
|
const metamaskMiddleware = mergeMiddleware([
|
|
createScaffoldMiddleware({
|
|
eth_syncing: false,
|
|
web3_clientVersion: `MetaMask/v${version}`,
|
|
}),
|
|
createWalletMiddleware({
|
|
getAccounts,
|
|
processTransaction,
|
|
processEthSignMessage,
|
|
processTypedMessage,
|
|
processTypedMessageV3,
|
|
processTypedMessageV4,
|
|
processPersonalMessage,
|
|
processDecryptMessage,
|
|
processEncryptionPublicKey,
|
|
}),
|
|
createPendingNonceMiddleware({ getPendingNonce }),
|
|
createPendingTxMiddleware({ getPendingTransactionByHash }),
|
|
]);
|
|
return metamaskMiddleware;
|
|
}
|