Skip to content

Commit 8bd49be

Browse files
committed
Fix first run initialization of zwallet with encrypted wallet.dat file
When running the client with a `wallet.dat` file that has never initialized it's zwallet or dzPIV, there is an incorrect code pathway that leads to the dzPIV seed hash never being written to the wallet file. Instead, we copy the seed generation code into `crypter.cpp` which will allow for proper dzPIV seed generation upon first unlock.
1 parent 8046a52 commit 8bd49be

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/crypter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
261261
return error("Failed to read zPIV seed from DB. Wallet is probably corrupt.");
262262
}
263263
pwalletMain->zwalletMain->SetMasterSeed(nSeed, false);
264+
} else {
265+
// First time this wallet has been unlocked with dzPIV
266+
// Borrow random generator from the key class so that we don't have to worry about randomness
267+
CKey key;
268+
key.MakeNewKey(true);
269+
uint256 seed = key.GetPrivKey_256();
270+
LogPrintf("%s: first run of zpiv wallet detected, new seed generated. Seedhash=%s\n", __func__, Hash(seed.begin(), seed.end()).GetHex());
271+
pwalletMain->zwalletMain->SetMasterSeed(seed, true);
272+
pwalletMain->zwalletMain->GenerateMintPool();
264273
}
265274
}
266275

src/zpivwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CzPIVWallet::CzPIVWallet(std::string strWalletFile)
3939
}
4040

4141
//Don't try to do anything if the wallet is locked.
42-
if (pwalletMain->IsLocked() && !fFirstRun) {
42+
if (pwalletMain->IsLocked()) {
4343
seedMaster = 0;
4444
nCountLastUsed = 0;
4545
this->mintPool = CMintPool();

0 commit comments

Comments
 (0)