@@ -42,6 +42,7 @@ bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE;
42
42
bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS;
43
43
44
44
const char * DEFAULT_WALLET_DAT = " wallet.dat" ;
45
+ const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000 ;
45
46
46
47
/* *
47
48
* Fees smaller than this (in satoshi) are considered zero fee (for transaction creation)
@@ -112,16 +113,19 @@ CPubKey CWallet::GenerateNewKey()
112
113
masterKey.SetMaster (key.begin (), key.size ());
113
114
114
115
// 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 );
117
118
118
119
// derive m/0'/0'
119
- accountKey.Derive (externalChainChildKey, 0 | 0x80000000 );
120
+ accountKey.Derive (externalChainChildKey, BIP32_HARDENED_KEY_LIMIT );
120
121
121
122
// derive child key at next index, skip keys already known to the wallet
122
123
do
123
124
{
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);
125
129
// increment childkey index
126
130
hdChain.nExternalChainCounter ++;
127
131
} while (HaveKey (childKey.key .GetPubKey ().GetID ()));
0 commit comments