@ -143,32 +143,16 @@ export class AppStorage {
}
}
async decryptStorage ( password ) {
async decryptStorage ( password ) {
try {
if ( password === this . cachedPassword ) {
let storage = await this . getItem ( 'data' ) ;
this . cachedPassword = undefined ;
if ( password ) {
await this . setItem ( AppStorage . FLAG_ENCRYPTED , '' ) ;
let parsedStorage = JSON . parse ( storage ) ;
await this . setItem ( 'deleteWalletAfterUninstall' , '1' ) ;
let mainStorage = parsedStorage [ 0 ] ;
await this . saveToDisk ( ) ;
mainStorage = JSON . stringify ( [ mainStorage ] ) ;
this . wallets = [ ] ;
const decrypted = this . decryptData ( mainStorage , password ) ;
this . tx_metadata = [ ] ;
if ( ! decrypted ) {
return this . loadFromDisk ( ) ;
throw new Error ( 'Wrong password for main storage.' ) ;
} else {
}
throw new Error ( 'Wrong password. Please, try again.' ) ;
const decryptedParsed = JSON . parse ( decrypted ) ;
if ( decrypted . wallets !== null ) {
this . wallets = decryptedParsed . wallets ;
this . tx_metadata = decryptedParsed . tx_metadata ;
this . cachedPassword = undefined ;
await this . setItem ( AppStorage . FLAG_ENCRYPTED , '' , { accessible : ACCESSIBLE . WHEN_UNLOCKED } ) ;
await this . setItem ( 'deleteWalletAfterUninstall' , '1' , { accessible : ACCESSIBLE . WHEN_UNLOCKED } ) ;
await this . saveToDisk ( ) ;
this . wallets = [ ] ;
this . tx_metadata = [ ] ;
return this . loadFromDisk ( ) ;
}
}
} catch ( e ) {
console . log ( e ) ;
throw new Error ( e ) ;
}
}
}
}