Validate wallet date when restoring from seed

Prevent a date that is older than the oldest wallet date, or a date that
is newer than the current date.
This commit is contained in:
Devin Bileck 2019-11-20 23:42:54 -08:00
parent d0bed936bd
commit d1932fe213
No known key found for this signature in database
GPG Key ID: C86D829C2399D073

View File

@ -61,6 +61,7 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.TimeZone;
import static bisq.desktop.util.FormBuilder.*;
import static javafx.beans.binding.Bindings.createBooleanBinding;
@ -249,16 +250,26 @@ public class SeedWordsView extends ActivatableView<GridPane, Void> {
}
private void doRestore() {
LocalDate value = restoreDatePicker.getValue();
if (value == null) {
// If no date was specified, use Bisq 0.5 release date (no current Bisq wallet could have been created before that date).
value = LocalDate.of(2017, Month.JUNE, 28);
LocalDate walletDate = restoreDatePicker.getValue();
// Even though no current Bisq wallet could have been created before the v0.5 release date (2017.06.28),
// the user may want to import from a seed generated by another wallet.
// So use when the BIP39 standard was finalised (2013.10.09) as the oldest possible wallet date.
LocalDate oldestWalletDate = LocalDate.ofInstant(
Instant.ofEpochMilli(MnemonicCode.BIP39_STANDARDISATION_TIME_SECS * 1000),
TimeZone.getDefault().toZoneId());
if (walletDate == null) {
// No date was specified, perhaps the user doesn't know the wallet date
walletDate = oldestWalletDate;
} else if (walletDate.isBefore(oldestWalletDate)) {
walletDate = oldestWalletDate;
} else if (walletDate.isAfter(LocalDate.now())) {
walletDate = LocalDate.now();
}
// We subtract 1 day to be sure to not have any issues with timezones. Even if we can be sure that the timezone
// is handled correctly it could be that the user created the wallet in one timezone and make a restore at
// a different timezone which could lead in the worst case that he miss the first day of the wallet transactions.
LocalDateTime localDateTime = value.atStartOfDay().minusDays(1);
LocalDateTime localDateTime = walletDate.atStartOfDay().minusDays(1);
long date = localDateTime.toEpochSecond(ZoneOffset.UTC);
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(seedWordsTextArea.getText()), null, "", date);