@ -113,34 +113,25 @@ module.exports = class KeyringController extends EventEmitter {
} )
} )
}
}
migrateAndGetKey ( password ) {
migrateOldVaultIfAny ( password ) {
let key
const shouldMigrate = ! ! this . configManager . getWallet ( ) && ! this . configManager . getVault ( )
const shouldMigrate = ! ! this . configManager . getWallet ( ) && ! this . configManager . getVault ( )
return this . loadKey ( password )
return this . idStoreMigrator . migratedVaultForPassword ( password )
. then ( ( derivedKey ) => {
key = derivedKey
this . key = key
return this . idStoreMigrator . migratedVaultForPassword ( password )
} )
. then ( ( serialized ) => {
. then ( ( serialized ) => {
if ( serialized && shouldMigrate ) {
if ( serialized && shouldMigrate ) {
const keyring = this . restoreKeyring ( serialized )
const keyring = this . restoreKeyring ( serialized )
this . keyrings . push ( keyring )
this . keyrings . push ( keyring )
this . configManager . setSelectedAccount ( keyring . getAccounts ( ) [ 0 ] )
this . configManager . setSelectedAccount ( keyring . getAccounts ( ) [ 0 ] )
return this . persistAllKeyrings ( )
return this . persistAllKeyrings ( )
. then ( ( ) => { return key } )
. then ( ( ) => { return } )
}
}
return key
return
} )
} )
}
}
createNewVault ( password , cb ) {
createNewVault ( password , cb ) {
const configManager = this . configManager
return this . migrateOldVaultIfAny ( password )
const salt = this . getSalt ( )
configManager . setSalt ( salt )
return this . migrateAndGetKey ( password )
. then ( ( ) => {
. then ( ( ) => {
this . password = password
return this . persistAllKeyrings ( )
return this . persistAllKeyrings ( )
} )
} )
. then ( ( ) => {
. then ( ( ) => {
@ -184,8 +175,8 @@ module.exports = class KeyringController extends EventEmitter {
}
}
submitPassword ( password , cb ) {
submitPassword ( password , cb ) {
this . migrateAndGetKe y ( password )
this . migrateOldVaultIfAn y ( password )
. then ( ( key ) => {
. then ( ( ) => {
return this . unlockKeyrings ( password )
return this . unlockKeyrings ( password )
} )
} )
. then ( ( keyrings ) => {
. then ( ( keyrings ) => {
@ -200,21 +191,6 @@ module.exports = class KeyringController extends EventEmitter {
} )
} )
}
}
loadKey ( password ) {
const salt = this . getSalt ( )
return this . encryptor . keyFromPassword ( password + salt )
. then ( ( key ) => {
this . key = key
this . configManager . setSalt ( salt )
return key
} )
}
getSalt ( ) {
const vault = this . configManager . getVault ( )
const salt = vault . salt || this . encryptor . generateSalt ( )
}
addNewKeyring ( type , opts , cb ) {
addNewKeyring ( type , opts , cb ) {
const Keyring = this . getKeyringClassForType ( type )
const Keyring = this . getKeyringClassForType ( type )
const keyring = new Keyring ( opts )
const keyring = new Keyring ( opts )
@ -290,7 +266,7 @@ module.exports = class KeyringController extends EventEmitter {
data : keyring . serialize ( ) ,
data : keyring . serialize ( ) ,
}
}
} )
} )
return this . encryptor . encryptWithKey ( this . key , serialized )
return this . encryptor . encrypt ( this . password , serialized )
. then ( ( encryptedString ) => {
. then ( ( encryptedString ) => {
this . configManager . setVault ( encryptedString )
this . configManager . setVault ( encryptedString )
return true
return true
@ -299,7 +275,7 @@ module.exports = class KeyringController extends EventEmitter {
unlockKeyrings ( password ) {
unlockKeyrings ( password ) {
const encryptedVault = this . configManager . getVault ( )
const encryptedVault = this . configManager . getVault ( )
return this . encryptor . decryptWithKey ( key , encryptedVault )
return this . encryptor . decrypt ( this . password , encryptedVault )
. then ( ( vault ) => {
. then ( ( vault ) => {
vault . forEach ( this . restoreKeyring . bind ( this ) )
vault . forEach ( this . restoreKeyring . bind ( this ) )
return this . keyrings
return this . keyrings
@ -407,7 +383,7 @@ module.exports = class KeyringController extends EventEmitter {
} )
} )
}
}
function estimateGas ( txData , blockGasLimitHex , cb ) {
function estimateGas ( txData , blockGasLimitHex , cb ) {
const txParams = txData . txParams
const txParams = txData . txParams
// check if gasLimit is already specified
// check if gasLimit is already specified
txData . gasLimitSpecified = Boolean ( txParams . gas )
txData . gasLimitSpecified = Boolean ( txParams . gas )
@ -419,7 +395,7 @@ module.exports = class KeyringController extends EventEmitter {
query . estimateGas ( txParams , cb )
query . estimateGas ( txParams , cb )
}
}
function checkForGasError ( txData , estimatedGasHex ) {
function checkForGasError ( txData , estimatedGasHex ) {
txData . estimatedGas = estimatedGasHex
txData . estimatedGas = estimatedGasHex
// all gas used - must be an error
// all gas used - must be an error
if ( estimatedGasHex === txData . txParams . gas ) {
if ( estimatedGasHex === txData . txParams . gas ) {
@ -428,7 +404,7 @@ module.exports = class KeyringController extends EventEmitter {
cb ( )
cb ( )
}
}
function setTxGas ( txData , blockGasLimitHex ) {
function setTxGas ( txData , blockGasLimitHex ) {
const txParams = txData . txParams
const txParams = txData . txParams
// if OOG, nothing more to do
// if OOG, nothing more to do
if ( txData . simulationFails ) {
if ( txData . simulationFails ) {