@ -116,7 +116,6 @@ export const METAMASK_CONTROLLER_EVENTS = {
export default class MetamaskController extends EventEmitter {
/ * *
* @ constructor
* @ param { Object } opts
* /
constructor ( opts ) {
@ -1440,6 +1439,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Create a new Vault and restore an existent keyring .
*
* @ param { string } password
* @ param { string } seed
* /
@ -1519,6 +1519,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Get an account balance from the AccountTracker or request it directly from the network .
*
* @ param { string } address - The account address
* @ param { EthQuery } ethQuery - The EthQuery instance to use when asking the network
* /
@ -1544,6 +1545,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Collects all the information that we want to share
* with the mobile client for syncing purposes
*
* @ returns { Promise < Object > } Parts of the state that we want to syncx
* /
async fetchInfoToSync ( ) {
@ -1641,7 +1643,7 @@ export default class MetamaskController extends EventEmitter {
} ;
}
/ *
/ * *
* Submits the user ' s password and attempts to unlock the vault .
* Also synchronizes the preferencesController , to ensure its schema
* is up to date with known accounts once the vault is decrypted .
@ -1685,7 +1687,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Submits a user ' s password to check its validity .
*
* @ param { string } password The user ' s password
* @ param { string } password - The user ' s password
* /
async verifyPassword ( password ) {
await this . keyringController . verifyPassword ( password ) ;
@ -1767,6 +1769,9 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Fetch account list from a trezor device .
*
* @ param deviceName
* @ param page
* @ param hdPath
* @ returns [ ] accounts
* /
async connectHardware ( deviceName , page , hdPath ) {
@ -1798,6 +1803,8 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Check if the device is unlocked
*
* @ param deviceName
* @ param hdPath
* @ returns { Promise < boolean > }
* /
async checkHardwareStatus ( deviceName , hdPath ) {
@ -1808,6 +1815,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Clear
*
* @ param deviceName
* @ returns { Promise < boolean > }
* /
async forgetDevice ( deviceName ) {
@ -1819,8 +1827,8 @@ export default class MetamaskController extends EventEmitter {
/ * *
* get hardware account label
*
* @ return string label
* * /
* @ returns string label
* /
getAccountLabel ( name , index , hdPathDescription ) {
return ` ${ name [ 0 ] . toUpperCase ( ) } ${ name . slice ( 1 ) } ${
@ -1831,6 +1839,10 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Imports an account from a Trezor or Ledger device .
*
* @ param index
* @ param deviceName
* @ param hdPath
* @ param hdPathDescription
* @ returns { } keyState
* /
async unlockHardwareWalletAccount (
@ -1993,7 +2005,6 @@ export default class MetamaskController extends EventEmitter {
* Removes an account from state / storage .
*
* @ param { string [ ] } address - A hex address
*
* /
async removeAccount ( address ) {
// Remove all associated permissions
@ -2015,7 +2026,6 @@ export default class MetamaskController extends EventEmitter {
*
* @ param { string } strategy - A unique identifier for an account import strategy .
* @ param { any } args - The data required by that strategy to import an account .
* @ param { Function } cb - A callback function called with a state update on success .
* /
async importAccountWithStrategy ( strategy , args ) {
const privateKey = await accountImporter . importAccount ( strategy , args ) ;
@ -2039,8 +2049,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 } msgParams - The params passed to eth _sign .
* @ param { Object } req - ( optional ) t he original request , containing the origin
* @ param { Object } txParams - The transaction parameters .
* @ param { Object } [ req ] - T he original request , containing the origin .
* /
async newUnapprovedTransaction ( txParams , req ) {
return await this . txController . newUnapprovedTransaction ( txParams , req ) ;
@ -2055,7 +2065,7 @@ export default class MetamaskController extends EventEmitter {
* information .
*
* @ param { Object } msgParams - The params passed to eth _sign .
* @ param { Function } cb - The callback function called with the signature .
* @ param { Object } [ req ] - The original request , containing the origin .
* /
async newUnsignedMessage ( msgParams , req ) {
const data = normalizeMsgData ( msgParams . data ) ;
@ -2121,8 +2131,7 @@ 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 { Function } cb - The callback function called with the signature .
* Passed back to the requesting Dapp .
* @ param { Object } [ req ] - The original request , containing the origin .
* /
async newUnsignedPersonalMessage ( msgParams , req ) {
const promise = this . personalMessageManager . addUnapprovedMessageAsync (
@ -2166,6 +2175,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Used to cancel a personal _sign type message .
*
* @ param { string } msgId - The ID of the message to cancel .
* /
cancelPersonalMessage ( msgId ) {
@ -2254,6 +2264,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Used to cancel a eth _decrypt type message .
*
* @ param { string } msgId - The ID of the message to cancel .
* /
cancelDecryptMessage ( msgId ) {
@ -2355,6 +2366,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Used to cancel a eth _getEncryptionPublicKey type message .
*
* @ param { string } msgId - The ID of the message to cancel .
* /
cancelEncryptionPublicKey ( msgId ) {
@ -2369,7 +2381,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 { Function } cb - The callback function , called with the signature .
* @ param { Object } [ req ] - The original request , containing the origin .
* @ param version
* /
newUnsignedTypedMessage ( msgParams , req , version ) {
const promise = this . typedMessageManager . addUnapprovedMessageAsync (
@ -2421,6 +2434,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Used to cancel a eth _signTypedData type message .
*
* @ param { string } msgId - The ID of the message to cancel .
* /
cancelTypedMessage ( msgId ) {
@ -2443,12 +2457,14 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Allows a user to attempt to cancel a previously submitted transaction
* by creating a new transaction .
*
* @ param { number } originalTxId - the id of the txMeta that you want to
* attempt to cancel
* @ param { import (
* './controllers/transactions'
* ) . CustomGasSettings } [ customGasSettings ] - overrides to use for gas params
* instead of allowing this method to generate them
* @ param newTxMetaProps
* @ returns { Object } MetaMask state
* /
async createCancelTransaction (
@ -2468,12 +2484,14 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Allows a user to attempt to speed up a previously submitted transaction
* by creating a new transaction .
*
* @ param { number } originalTxId - the id of the txMeta that you want to
* attempt to speed up
* @ param { import (
* './controllers/transactions'
* ) . CustomGasSettings } [ customGasSettings ] - overrides to use for gas params
* instead of allowing this method to generate them
* @ param newTxMetaProps
* @ returns { Object } MetaMask state
* /
async createSpeedUpTransaction (
@ -2511,7 +2529,6 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Allows a user to begin the seed phrase recovery process .
* @ param { Function } cb - A callback function called when complete .
* /
markPasswordForgotten ( ) {
this . preferencesController . setPasswordForgotten ( true ) ;
@ -2520,7 +2537,6 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Allows a user to end the seed phrase recovery process .
* @ param { Function } cb - A callback function called when complete .
* /
unMarkPasswordForgotten ( ) {
this . preferencesController . setPasswordForgotten ( false ) ;
@ -2533,13 +2549,16 @@ 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
* @ property { string } - The URL of the page or frame hosting the script that sent the message .
* /
/ * *
* Used to create a multiplexed stream for connecting to an untrusted context
* like a Dapp or other extension .
*
* @ param { * } connectionStream - The Duplex stream to connect to .
* @ param { MessageSender } sender - The sender of the messages on this stream
* /
@ -2598,6 +2617,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* A method for providing our API over a stream using JSON - RPC .
*
* @ param { * } outStream - The stream to provide our API over .
* /
setupControllerConnection ( outStream ) {
@ -2633,6 +2653,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* A method for serving our ethereum provider over a given stream .
*
* @ param { * } outStream - The stream to provide over .
* @ param { MessageSender } sender - The sender of the messages on this stream
* @ param { boolean } isInternal - True if this is a connection with an internal process
@ -2690,7 +2711,7 @@ export default class MetamaskController extends EventEmitter {
* @ param { string } options . location - The full URL of the sender
* @ param { string } options . subjectType - The type of the sender subject .
* @ param { tabId } [ options . tabId ] - The tab ID of the sender - if the sender is within a tab
* * /
* /
setupProviderEngine ( { origin , location , subjectType , tabId } ) {
// setup json rpc engine stack
const engine = new JsonRpcEngine ( ) ;
@ -2951,6 +2972,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Handle a KeyringController update
*
* @ param { Object } state - the KC state
* @ returns { Promise < void > }
* @ private
@ -3016,6 +3038,8 @@ export default class MetamaskController extends EventEmitter {
* - Ensure isClientOpenAndUnlocked is updated
* - Notifies all connections with the new provider network state
* - The external providers handle diffing the state
*
* @ param newState
* /
_onStateUpdate ( newState ) {
this . isClientOpenAndUnlocked = newState . isUnlocked && this . _isClientOpen ;
@ -3029,6 +3053,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* A method for emitting the full MetaMask state to all registered listeners .
*
* @ private
* /
privateSendUpdate ( ) {
@ -3048,6 +3073,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Returns the nonce that will be associated with a transaction once approved
*
* @ param { string } address - The hex string address for the transaction
* @ returns { Promise < number > }
* /
@ -3064,6 +3090,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Returns the next nonce according to the nonce - tracker
*
* @ param { string } address - The hex string address for the transaction
* @ returns { Promise < number > }
* /
@ -3120,13 +3147,14 @@ export default class MetamaskController extends EventEmitter {
/ * *
* A method for selecting a custom URL for an ethereum RPC provider and updating it
*
* @ param { string } rpcUrl - A URL for a valid Ethereum RPC API .
* @ 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 { string } [ rpcPrefs . blockExplorerUrl ] - URL of block explorer for the chain .
* @ returns { Promise < S tring> } - The RPC Target URL confirmed .
* @ returns { Promise < s tring> } The RPC Target URL confirmed .
* /
async updateAndSetCustomRpc (
rpcUrl ,
@ -3154,11 +3182,13 @@ export default class MetamaskController extends EventEmitter {
/ * *
* A method for selecting a custom URL for an ethereum RPC provider .
*
* @ param { string } rpcUrl - A URL for a valid Ethereum RPC API .
* @ param { string } chainId - The chainId of the selected network .
* @ param { string } ticker - The ticker symbol of the selected network .
* @ param { string } nickname - Optional nickname of the selected network .
* @ returns { Promise < String > } The RPC Target URL confirmed .
* @ param rpcPrefs
* @ returns { Promise < string > } The RPC Target URL confirmed .
* /
async setCustomRpc (
rpcUrl ,
@ -3201,6 +3231,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* A method for deleting a selected custom URL .
*
* @ param { string } rpcUrl - A RPC URL to delete .
* /
async delCustomRpc ( rpcUrl ) {
@ -3232,7 +3263,8 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Sets the Ledger Live preference to use for Ledger hardware wallet support
* @ param { bool } bool - the value representing if the users wants to use Ledger Live
*
* @ param { string } transportType - The Ledger transport type .
* /
async setLedgerTransportPreference ( transportType ) {
const currentValue = this . preferencesController . getLedgerTransportPreference ( ) ;
@ -3255,6 +3287,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* A method for initializing storage the first time .
*
* @ param { Object } initState - The default state to initialize with .
* @ private
* /
@ -3272,6 +3305,7 @@ export default class MetamaskController extends EventEmitter {
/* eslint-disable accessor-pairs */
/ * *
* A method for recording whether the MetaMask user interface is open or not .
*
* @ param { boolean } open
* /
set isClientOpen ( open ) {
@ -3296,6 +3330,8 @@ export default class MetamaskController extends EventEmitter {
/ * *
* A method that is called by the background when a particular environment type is closed ( fullscreen , popup , notification ) .
* Currently used to stop polling in the gasFeeController for only that environement type
*
* @ param environmentType
* /
onEnvironmentTypeClosed ( environmentType ) {
const appStatePollingTokenType =
@ -3314,6 +3350,7 @@ export default class MetamaskController extends EventEmitter {
/ * *
* Adds a domain to the PhishingController safelist
*
* @ param { string } hostname - the domain to safelist
* /
safelistPhishingDomain ( hostname ) {