Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate wallet date when restoring from seed #3749

Merged
merged 1 commit into from
Dec 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
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;
Expand Down Expand Up @@ -249,16 +250,26 @@ private void checkIfEncrypted() {
}

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);
Expand Down