mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #12924: Fix hdmaster-key / seed-key confusion (scripted diff)
6249021d1 [docs] Add release notes for HD master key -> HD seed rename (John Newbery) 79053a5f2 [rpc] [wallet] Add 'hdmasterkeyid' alias return values. (John Newbery) c75c35141 [refactor] manually change remaining instances of master key to seed. (John Newbery) 131d4450b scripted-diff: Rename master key to seed (John Newbery) Pull request description: Addresses #12084 and #8684 This renames a couple of functions and members (no functional changes, expect log prints): - Rename CKey::SetMaster to CKey::SetSeed - Rename CHDChain::masterKeyId to CHDChain::seedID - Rename CHDChain::hdMasterKeyID to CHDChain::hdSeedID - Rename CWallet::GenerateNewHDMasterKey to CWallet::GenerateNewHDSeed - Rename CWallet::SetHDMasterKey to CWallet::SetHDSeed As well it introduces a tiny API change: - RPC API change: Rename "hdmasterkeyid" to "hdseedid", rename "hdmaster" in wallet-dump output to "hdseed" Fixes also a bug: - Bugfix: use "s" instead of the incorrect "m" for the seed-key hd-keypath key metadata Tree-SHA512: c913252636f213135a3b64df5de5d21844fb9c2d646567c1aad0ec65745188587de26119de99492c67e559bd49fdd9606b54276f00dddb84301785beba58f281
This commit is contained in:
parent
ec9f526cec
commit
21bb444ad3
@ -55,7 +55,7 @@ void CHDChain::Debug(const std::string& strName) const
|
|||||||
std::cout << "seed: " << HexStr(vchSeed).c_str() << std::endl;
|
std::cout << "seed: " << HexStr(vchSeed).c_str() << std::endl;
|
||||||
|
|
||||||
CExtKey extkey;
|
CExtKey extkey;
|
||||||
extkey.SetMaster(vchSeed.data(), vchSeed.size());
|
extkey.SetSeed(vchSeed.data(), vchSeed.size());
|
||||||
|
|
||||||
std::cout << "extended private masterkey: " << EncodeExtKey(extkey).c_str() << std::endl;
|
std::cout << "extended private masterkey: " << EncodeExtKey(extkey).c_str() << std::endl;
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ void CHDChain::DeriveChildExtKey(uint32_t nAccountIndex, bool fInternal, uint32_
|
|||||||
CExtKey changeKey; //key at m/purpose'/coin_type'/account'/change
|
CExtKey changeKey; //key at m/purpose'/coin_type'/account'/change
|
||||||
CExtKey childKey; //key at m/purpose'/coin_type'/account'/change/address_index
|
CExtKey childKey; //key at m/purpose'/coin_type'/account'/change/address_index
|
||||||
|
|
||||||
masterKey.SetMaster(vchSeed.data(), vchSeed.size());
|
masterKey.SetSeed(vchSeed.data(), vchSeed.size());
|
||||||
|
|
||||||
// Use hardened derivation for purpose, coin_type and account
|
// Use hardened derivation for purpose, coin_type and account
|
||||||
// (keys >= 0x80000000 are hardened after bip32)
|
// (keys >= 0x80000000 are hardened after bip32)
|
||||||
|
@ -273,7 +273,7 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
|
|||||||
return key.Derive(out.key, out.chaincode, _nChild, chaincode);
|
return key.Derive(out.key, out.chaincode, _nChild, chaincode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CExtKey::SetMaster(const unsigned char *seed, unsigned int nSeedLen) {
|
void CExtKey::SetSeed(const unsigned char *seed, unsigned int nSeedLen) {
|
||||||
static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
|
static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
|
||||||
std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
|
std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
|
||||||
CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data());
|
CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data());
|
||||||
|
@ -158,7 +158,7 @@ struct CExtKey {
|
|||||||
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
|
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
|
||||||
bool Derive(CExtKey& out, unsigned int nChild) const;
|
bool Derive(CExtKey& out, unsigned int nChild) const;
|
||||||
CExtPubKey Neuter() const;
|
CExtPubKey Neuter() const;
|
||||||
void SetMaster(const unsigned char* seed, unsigned int nSeedLen);
|
void SetSeed(const unsigned char* seed, unsigned int nSeedLen);
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
void Serialize(Stream& s) const
|
void Serialize(Stream& s) const
|
||||||
{
|
{
|
||||||
|
@ -91,7 +91,7 @@ static void RunTest(const TestVector &test) {
|
|||||||
std::vector<unsigned char> seed = ParseHex(test.strHexMaster);
|
std::vector<unsigned char> seed = ParseHex(test.strHexMaster);
|
||||||
CExtKey key;
|
CExtKey key;
|
||||||
CExtPubKey pubkey;
|
CExtPubKey pubkey;
|
||||||
key.SetMaster(seed.data(), seed.size());
|
key.SetSeed(seed.data(), seed.size());
|
||||||
pubkey = key.Neuter();
|
pubkey = key.Neuter();
|
||||||
for (const TestDerivation &derive : test.vDerive) {
|
for (const TestDerivation &derive : test.vDerive) {
|
||||||
unsigned char data[74];
|
unsigned char data[74];
|
||||||
|
@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(bip39_vectors)
|
|||||||
CExtKey key;
|
CExtKey key;
|
||||||
CExtPubKey pubkey;
|
CExtPubKey pubkey;
|
||||||
|
|
||||||
key.SetMaster(seed.data(), 64);
|
key.SetSeed(seed.data(), 64);
|
||||||
pubkey = key.Neuter();
|
pubkey = key.Neuter();
|
||||||
|
|
||||||
// printf("CBitcoinExtKey: %s\n", EncodeExtKey(key).c_str());
|
// printf("CBitcoinExtKey: %s\n", EncodeExtKey(key).c_str());
|
||||||
|
@ -939,7 +939,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
|
|||||||
file << "# HD seed: " << HexStr(vchSeed) << "\n\n";
|
file << "# HD seed: " << HexStr(vchSeed) << "\n\n";
|
||||||
|
|
||||||
CExtKey masterKey;
|
CExtKey masterKey;
|
||||||
masterKey.SetMaster(&vchSeed[0], vchSeed.size());
|
masterKey.SetSeed(&vchSeed[0], vchSeed.size());
|
||||||
|
|
||||||
file << "# extended private masterkey: " << EncodeExtKey(masterKey) << "\n";
|
file << "# extended private masterkey: " << EncodeExtKey(masterKey) << "\n";
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
|
|||||||
addr_keypath = comment.split(" addr=")[1]
|
addr_keypath = comment.split(" addr=")[1]
|
||||||
addr = addr_keypath.split(" ")[0]
|
addr = addr_keypath.split(" ")[0]
|
||||||
keypath = None
|
keypath = None
|
||||||
if keytype == "inactivehdmaster=1":
|
if keytype == "inactivehdseed=1":
|
||||||
# ensure the old master is still available
|
# ensure the old master is still available
|
||||||
assert(hd_master_addr_old == addr)
|
assert(hd_master_addr_old == addr)
|
||||||
elif keytype == "hdmaster=1":
|
elif keytype == "hdseed=1":
|
||||||
# ensure we have generated a new hd master key
|
# ensure we have generated a new hd master key
|
||||||
assert(hd_master_addr_old != addr)
|
assert(hd_master_addr_old != addr)
|
||||||
hd_master_addr_ret = addr
|
hd_master_addr_ret = addr
|
||||||
|
Loading…
Reference in New Issue
Block a user