-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from Emurgo/develop
Yoroi 1.4.0 Release - Ledger + Desync fix
- Loading branch information
Showing
145 changed files
with
2,472 additions
and
1,725 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @flow | ||
import Action from '../lib/Action'; | ||
|
||
import type { | ||
BIP32Path | ||
} from '@cardano-foundation/ledgerjs-hw-app-cardano'; | ||
import Wallet from '../../domain/Wallet'; | ||
|
||
// ======= ADDRESSES ACTIONS ======= | ||
|
||
export default class HWVerifyAddressActions { | ||
closeAddressDetailDialog: Action<void> = new Action(); | ||
selectAddress: Action<{ address: string, path: BIP32Path }> = new Action(); | ||
verifyAddress: Action<{ wallet: Wallet }> = new Action(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// @flow | ||
|
||
// Handle migration to newer versions of Yoroi | ||
|
||
import { | ||
reset, | ||
getAddressesList | ||
} from './lib/lovefieldDatabase'; | ||
import { | ||
saveLastReceiveAddressIndex, | ||
} from './adaLocalStorage'; | ||
import LocalStorageApi from '../localStorage/index'; | ||
import { | ||
Logger, | ||
} from '../../utils/logging'; | ||
|
||
const semver = require('semver'); | ||
|
||
export async function migrateToLatest(localStorageApi: LocalStorageApi) { | ||
const lastLaunchVersion = await localStorageApi.getLastLaunchVersion(); | ||
Logger.info(`Starting migration for ${lastLaunchVersion}`); | ||
/** | ||
* Note: Although we don't start migration if the user is running a fresh installation | ||
* We still cannot be certain any key exists in localstorage | ||
* | ||
* For example, somebody may have downloaded Yoroi a long time ago | ||
* but only completed the language select before closing the application | ||
* | ||
* Therefore, you need to always check that data exists before migrating it | ||
*/ | ||
|
||
/** | ||
* Note: Be careful about the kinds of migrations you do here. | ||
* You are essentially swapping the app state under the hood | ||
* Therefore mobx may not notice the change as expected | ||
*/ | ||
|
||
const migrationMap: { [ver: string]: (() => Promise<void>) } = { | ||
'=0.0.0': async () => await testMigration(localStorageApi), | ||
'<1.4.0': bip44Migration | ||
}; | ||
|
||
for (const key of Object.keys(migrationMap)) { | ||
if (semver.satisfies(lastLaunchVersion, key)) { | ||
Logger.info(`Migration started for ${key}`); | ||
await migrationMap[key](); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* We use this as a dummy migration so that our tests can verify migration is working correctly | ||
*/ | ||
async function testMigration(localStorageApi: LocalStorageApi): Promise<void> { | ||
// changing the locale is something we can easily detect from our tests | ||
Logger.info(`Starting testMigration`); | ||
// Note: mobx will not notice this change until you refresh | ||
await localStorageApi.setUserLocale('ja-JP'); | ||
} | ||
|
||
/** | ||
* Previous version of Yoroi were not BIP44 compliant | ||
* Notably, it didnt scan 20 addresses ahead of the last used address. | ||
* This causes desyncs when you use Yoroi either on multiple computers with the same wallet | ||
* or you use the same wallet on Chrome + mobile. | ||
*/ | ||
async function bip44Migration(): Promise<void> { | ||
Logger.info(`Starting bip44Migration`); | ||
const addresses = await getAddressesList(); | ||
if (!addresses || addresses.length === 0) { | ||
return; | ||
} | ||
/** | ||
* We used to consider all addresses in the DB as explicitly generated by the user | ||
* However, BIP44 requires us to also store 20 addresses after the last used address | ||
* Therefore the highest index in the old format is the heightest generated for new format | ||
*/ | ||
const maxIndex = Math.max( | ||
...addresses | ||
.filter(address => address.change === 0) | ||
.map(address => address.index), | ||
0 | ||
); | ||
|
||
// if we had more than one address, then the WALLET key must exist in localstorage | ||
saveLastReceiveAddressIndex(maxIndex); | ||
|
||
/** | ||
* Once we've saved the receive address, we dump the DB entirely | ||
* We need to do this since old wallets may have incorrect history | ||
* Due to desync issue caused by the incorrect bip44 implementation | ||
*/ | ||
reset(); | ||
} |
Oops, something went wrong.