|
|
|
@ -166,7 +166,7 @@ const PHISHING_SAFELIST = 'metamask-phishing-safelist'; |
|
|
|
|
|
|
|
|
|
export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* @param {Object} opts |
|
|
|
|
* @param {object} opts |
|
|
|
|
*/ |
|
|
|
|
constructor(opts) { |
|
|
|
|
super(); |
|
|
|
@ -1441,9 +1441,9 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* Gets network state relevant for external providers. |
|
|
|
|
* |
|
|
|
|
* @param {Object} [memState] - The MetaMask memState. If not provided, |
|
|
|
|
* @param {object} [memState] - The MetaMask memState. If not provided, |
|
|
|
|
* this function will retrieve the most recent state. |
|
|
|
|
* @returns {Object} An object with relevant network state properties. |
|
|
|
|
* @returns {object} An object with relevant network state properties. |
|
|
|
|
*/ |
|
|
|
|
getProviderNetworkState(memState) { |
|
|
|
|
const { network } = memState || this.getState(); |
|
|
|
@ -1460,7 +1460,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* The metamask-state of the various controllers, made available to the UI |
|
|
|
|
* |
|
|
|
|
* @returns {Object} status |
|
|
|
|
* @returns {object} status |
|
|
|
|
*/ |
|
|
|
|
getState() { |
|
|
|
|
const { vault } = this.keyringController.store.getState(); |
|
|
|
@ -1477,7 +1477,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* These functions are the interface for the UI. |
|
|
|
|
* The API object can be transmitted over a stream via JSON-RPC. |
|
|
|
|
* |
|
|
|
|
* @returns {Object} Object containing API functions. |
|
|
|
|
* @returns {object} Object containing API functions. |
|
|
|
|
*/ |
|
|
|
|
getApi() { |
|
|
|
|
const { |
|
|
|
@ -2029,7 +2029,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* For example, a mnemonic phrase can generate many accounts, and is a keyring. |
|
|
|
|
* |
|
|
|
|
* @param {string} password |
|
|
|
|
* @returns {Object} vault |
|
|
|
|
* @returns {object} vault |
|
|
|
|
*/ |
|
|
|
|
async createNewVaultAndKeychain(password) { |
|
|
|
|
const releaseLock = await this.createVaultMutex.acquire(); |
|
|
|
@ -2803,8 +2803,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* this wrapper needs to exist so we can provide a reference to |
|
|
|
|
* "newUnapprovedTransaction" before "txController" is instantiated |
|
|
|
|
* |
|
|
|
|
* @param {Object} txParams - The transaction parameters. |
|
|
|
|
* @param {Object} [req] - The original request, containing the origin. |
|
|
|
|
* @param {object} txParams - The transaction parameters. |
|
|
|
|
* @param {object} [req] - The original request, containing the origin. |
|
|
|
|
*/ |
|
|
|
|
async newUnapprovedTransaction(txParams, req) { |
|
|
|
|
return await this.txController.newUnapprovedTransaction(txParams, req); |
|
|
|
@ -2818,8 +2818,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* path, since this data can be a transaction, or can leak private key |
|
|
|
|
* information. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params passed to eth_sign. |
|
|
|
|
* @param {Object} [req] - The original request, containing the origin. |
|
|
|
|
* @param {object} msgParams - The params passed to eth_sign. |
|
|
|
|
* @param {object} [req] - The original request, containing the origin. |
|
|
|
|
*/ |
|
|
|
|
async newUnsignedMessage(msgParams, req) { |
|
|
|
|
const data = normalizeMsgData(msgParams.data); |
|
|
|
@ -2868,7 +2868,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* Signifies user intent to complete an eth_sign method. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params passed to eth_call. |
|
|
|
|
* @param {object} msgParams - The params passed to eth_call. |
|
|
|
|
* @returns {Promise<object>} Full state update. |
|
|
|
|
*/ |
|
|
|
|
async signMessage(msgParams) { |
|
|
|
@ -2910,8 +2910,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* |
|
|
|
|
* We currently define our eth_sign and personal_sign mostly for legacy Dapps. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params of the message to sign & return to the Dapp. |
|
|
|
|
* @param {Object} [req] - The original request, containing the origin. |
|
|
|
|
* @param {object} msgParams - The params of the message to sign & return to the Dapp. |
|
|
|
|
* @param {object} [req] - The original request, containing the origin. |
|
|
|
|
*/ |
|
|
|
|
async newUnsignedPersonalMessage(msgParams, req) { |
|
|
|
|
const promise = this.personalMessageManager.addUnapprovedMessageAsync( |
|
|
|
@ -2927,7 +2927,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* Signifies a user's approval to sign a personal_sign message in queue. |
|
|
|
|
* Triggers signing, and the callback function from newUnsignedPersonalMessage. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params of the message to sign & return to the Dapp. |
|
|
|
|
* @param {object} msgParams - The params of the message to sign & return to the Dapp. |
|
|
|
|
* @returns {Promise<object>} A full state update. |
|
|
|
|
*/ |
|
|
|
|
async signPersonalMessage(msgParams) { |
|
|
|
@ -2969,8 +2969,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* Called when a dapp uses the eth_decrypt method. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params of the message to sign & return to the Dapp. |
|
|
|
|
* @param {Object} req - (optional) the original request, containing the origin |
|
|
|
|
* @param {object} msgParams - The params of the message to sign & return to the Dapp. |
|
|
|
|
* @param {object} req - (optional) the original request, containing the origin |
|
|
|
|
* Passed back to the requesting Dapp. |
|
|
|
|
*/ |
|
|
|
|
async newRequestDecryptMessage(msgParams, req) { |
|
|
|
@ -2986,7 +2986,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* Only decrypt message and don't touch transaction state |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params of the message to decrypt. |
|
|
|
|
* @param {object} msgParams - The params of the message to decrypt. |
|
|
|
|
* @returns {Promise<object>} A full state update. |
|
|
|
|
*/ |
|
|
|
|
async decryptMessageInline(msgParams) { |
|
|
|
@ -3012,7 +3012,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* Signifies a user's approval to decrypt a message in queue. |
|
|
|
|
* Triggers decrypt, and the callback function from newUnsignedDecryptMessage. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params of the message to decrypt & return to the Dapp. |
|
|
|
|
* @param {object} msgParams - The params of the message to decrypt & return to the Dapp. |
|
|
|
|
* @returns {Promise<object>} A full state update. |
|
|
|
|
*/ |
|
|
|
|
async decryptMessage(msgParams) { |
|
|
|
@ -3058,8 +3058,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* Called when a dapp uses the eth_getEncryptionPublicKey method. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params of the message to sign & return to the Dapp. |
|
|
|
|
* @param {Object} req - (optional) the original request, containing the origin |
|
|
|
|
* @param {object} msgParams - The params of the message to sign & return to the Dapp. |
|
|
|
|
* @param {object} req - (optional) the original request, containing the origin |
|
|
|
|
* Passed back to the requesting Dapp. |
|
|
|
|
*/ |
|
|
|
|
async newRequestEncryptionPublicKey(msgParams, req) { |
|
|
|
@ -3113,7 +3113,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* Signifies a user's approval to receiving encryption public key in queue. |
|
|
|
|
* Triggers receiving, and the callback function from newUnsignedEncryptionPublicKey. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params of the message to receive & return to the Dapp. |
|
|
|
|
* @param {object} msgParams - The params of the message to receive & return to the Dapp. |
|
|
|
|
* @returns {Promise<object>} A full state update. |
|
|
|
|
*/ |
|
|
|
|
async encryptionPublicKey(msgParams) { |
|
|
|
@ -3160,8 +3160,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* Called when a dapp uses the eth_signTypedData method, per EIP 712. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params passed to eth_signTypedData. |
|
|
|
|
* @param {Object} [req] - The original request, containing the origin. |
|
|
|
|
* @param {object} msgParams - The params passed to eth_signTypedData. |
|
|
|
|
* @param {object} [req] - The original request, containing the origin. |
|
|
|
|
* @param version |
|
|
|
|
*/ |
|
|
|
|
newUnsignedTypedMessage(msgParams, req, version) { |
|
|
|
@ -3179,8 +3179,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* The method for a user approving a call to eth_signTypedData, per EIP 712. |
|
|
|
|
* Triggers the callback in newUnsignedTypedMessage. |
|
|
|
|
* |
|
|
|
|
* @param {Object} msgParams - The params passed to eth_signTypedData. |
|
|
|
|
* @returns {Object} Full state update. |
|
|
|
|
* @param {object} msgParams - The params passed to eth_signTypedData. |
|
|
|
|
* @returns {object} Full state update. |
|
|
|
|
*/ |
|
|
|
|
async signTypedMessage(msgParams) { |
|
|
|
|
log.info('MetaMaskController - eth_signTypedData'); |
|
|
|
@ -3245,7 +3245,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* ).CustomGasSettings} [customGasSettings] - overrides to use for gas params |
|
|
|
|
* instead of allowing this method to generate them |
|
|
|
|
* @param newTxMetaProps |
|
|
|
|
* @returns {Object} MetaMask state |
|
|
|
|
* @returns {object} MetaMask state |
|
|
|
|
*/ |
|
|
|
|
async createCancelTransaction( |
|
|
|
|
originalTxId, |
|
|
|
@ -3272,7 +3272,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* ).CustomGasSettings} [customGasSettings] - overrides to use for gas params |
|
|
|
|
* instead of allowing this method to generate them |
|
|
|
|
* @param newTxMetaProps |
|
|
|
|
* @returns {Object} MetaMask state |
|
|
|
|
* @returns {object} MetaMask state |
|
|
|
|
*/ |
|
|
|
|
async createSpeedUpTransaction( |
|
|
|
|
originalTxId, |
|
|
|
@ -3331,14 +3331,14 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* A runtime.MessageSender object, as provided by the browser: |
|
|
|
|
* |
|
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/MessageSender
|
|
|
|
|
* @typedef {Object} MessageSender |
|
|
|
|
* @typedef {object} MessageSender |
|
|
|
|
* @property {string} - The URL of the page or frame hosting the script that sent the message. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* A Snap sender object. |
|
|
|
|
* |
|
|
|
|
* @typedef {Object} SnapSender |
|
|
|
|
* @typedef {object} SnapSender |
|
|
|
|
* @property {string} snapId - The ID of the snap. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
@ -3576,7 +3576,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* A method for creating a provider that is safely restricted for the requesting subject. |
|
|
|
|
* |
|
|
|
|
* @param {Object} options - Provider engine options |
|
|
|
|
* @param {object} options - Provider engine options |
|
|
|
|
* @param {string} options.origin - The origin of the sender |
|
|
|
|
* @param {MessageSender | SnapSender} options.sender - The sender object. |
|
|
|
|
* @param {string} options.subjectType - The type of the sender subject. |
|
|
|
@ -3800,8 +3800,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* can be deleted later. |
|
|
|
|
* |
|
|
|
|
* @param {string} origin - The connection's origin string. |
|
|
|
|
* @param {Object} options - Data associated with the connection |
|
|
|
|
* @param {Object} options.engine - The connection's JSON Rpc Engine |
|
|
|
|
* @param {object} options - Data associated with the connection |
|
|
|
|
* @param {object} options.engine - The connection's JSON Rpc Engine |
|
|
|
|
* @returns {string} The connection's id (so that it can be deleted later) |
|
|
|
|
*/ |
|
|
|
|
addConnection(origin, { engine }) { |
|
|
|
@ -3916,7 +3916,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* Handle a KeyringController update |
|
|
|
|
* |
|
|
|
|
* @param {Object} state - the KC state |
|
|
|
|
* @param {object} state - the KC state |
|
|
|
|
* @returns {Promise<void>} |
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
@ -4102,7 +4102,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* @param {string} chainId - The chainId of the selected network. |
|
|
|
|
* @param {string} ticker - The ticker symbol of the selected network. |
|
|
|
|
* @param {string} [nickname] - Nickname of the selected network. |
|
|
|
|
* @param {Object} [rpcPrefs] - RPC preferences. |
|
|
|
|
* @param {object} [rpcPrefs] - RPC preferences. |
|
|
|
|
* @param {string} [rpcPrefs.blockExplorerUrl] - URL of block explorer for the chain. |
|
|
|
|
* @returns {Promise<string>} The RPC Target URL confirmed. |
|
|
|
|
*/ |
|
|
|
@ -4192,8 +4192,8 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
* Returns the first RPC info object that matches at least one field of the |
|
|
|
|
* provided search criteria. Returns null if no match is found |
|
|
|
|
* |
|
|
|
|
* @param {Object} rpcInfo - The RPC endpoint properties and values to check. |
|
|
|
|
* @returns {Object} rpcInfo found in the frequentRpcList |
|
|
|
|
* @param {object} rpcInfo - The RPC endpoint properties and values to check. |
|
|
|
|
* @returns {object} rpcInfo found in the frequentRpcList |
|
|
|
|
*/ |
|
|
|
|
findCustomRpcBy(rpcInfo) { |
|
|
|
|
const frequentRpcListDetail = this.preferencesController.getFrequentRpcListDetail(); |
|
|
|
@ -4238,7 +4238,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
/** |
|
|
|
|
* A method for initializing storage the first time. |
|
|
|
|
* |
|
|
|
|
* @param {Object} initState - The default state to initialize with. |
|
|
|
|
* @param {object} initState - The default state to initialize with. |
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
|
recordFirstTimeInfo(initState) { |
|
|
|
|