Skip to content

Commit c022e5b

Browse files
committed
[Wallet] use constant for bip32 hardened key limit
1 parent f190251 commit c022e5b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE;
4242
bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS;
4343

4444
const char * DEFAULT_WALLET_DAT = "wallet.dat";
45+
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
4546

4647
/**
4748
* Fees smaller than this (in satoshi) are considered zero fee (for transaction creation)
@@ -112,16 +113,19 @@ CPubKey CWallet::GenerateNewKey()
112113
masterKey.SetMaster(key.begin(), key.size());
113114

114115
// derive m/0'
115-
// use hardened derivation (child keys > 0x80000000 are hardened after bip32)
116-
masterKey.Derive(accountKey, 0 | 0x80000000);
116+
// use hardened derivation (child keys >= 0x80000000 are hardened after bip32)
117+
masterKey.Derive(accountKey, BIP32_HARDENED_KEY_LIMIT);
117118

118119
// derive m/0'/0'
119-
accountKey.Derive(externalChainChildKey, 0 | 0x80000000);
120+
accountKey.Derive(externalChainChildKey, BIP32_HARDENED_KEY_LIMIT);
120121

121122
// derive child key at next index, skip keys already known to the wallet
122123
do
123124
{
124-
externalChainChildKey.Derive(childKey, hdChain.nExternalChainCounter | 0x80000000);
125+
// always derive hardened keys
126+
// childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened child-index-range
127+
// example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649
128+
externalChainChildKey.Derive(childKey, hdChain.nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
125129
// increment childkey index
126130
hdChain.nExternalChainCounter++;
127131
} while(HaveKey(childKey.key.GetPubKey().GetID()));

0 commit comments

Comments
 (0)