aboutsummaryrefslogtreecommitdiff
path: root/src/key.cpp
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-09-12 03:35:40 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-12-23 13:26:00 +0100
commitfa1d49542e4b69a5d8b1177ffe4207f051a468bb (patch)
tree9c2cf8f46ea9d058c7c1c38d7244eb8eefc3b6fd /src/key.cpp
parent4b1196a9855dcd188a24f393aa2fa21e2d61f061 (diff)
downloadbitcoin-fa1d49542e4b69a5d8b1177ffe4207f051a468bb.tar.xz
refactor: share and use `GenerateRandomKey` helper
Making the `GenerateRandomKey` helper available to other modules via key.{h.cpp} allows us to create random private keys directly at instantiation of CKey, in contrast to the two-step process of creating the instance and then having to call `MakeNewKey(...)`.
Diffstat (limited to 'src/key.cpp')
-rw-r--r--src/key.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/key.cpp b/src/key.cpp
index 0f283ca3e3..512790252a 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -369,6 +369,13 @@ ECDHSecret CKey::ComputeBIP324ECDHSecret(const EllSwiftPubKey& their_ellswift, c
return output;
}
+CKey GenerateRandomKey(bool compressed) noexcept
+{
+ CKey key;
+ key.MakeNewKey(/*fCompressed=*/compressed);
+ return key;
+}
+
bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
if (nDepth == std::numeric_limits<unsigned char>::max()) return false;
out.nDepth = nDepth + 1;
@@ -420,8 +427,7 @@ void CExtKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {
}
bool ECC_InitSanityCheck() {
- CKey key;
- key.MakeNewKey(true);
+ CKey key = GenerateRandomKey();
CPubKey pubkey = key.GetPubKey();
return key.VerifyPubKey(pubkey);
}