In the course of reviewing BIP324 related PRs I noticed a frequent pattern of creating private keys (CKey instances) with data consumed from the fuzz data provider:
auto key_data = provider.ConsumeBytes<unsigned char>(32);
key_data.resize(32);
CKey key;
key.Set(key_data.begin(), key_data.end(), /*fCompressedIn=*/true);
This PR introduces a corresponding helper ConsumePrivateKey in order to deduplicate code. The compressed flag can either be set to a fixed value, or, if std::nullopt is passed (=default), is also consumed from the fuzz data provider via .ConsumeBool().
Note that this is not a pure refactor, as some of the replaced call-sites previously consumed a random length (ConsumeRandomLengthByteVector) instead of a fixed size of 32 bytes for key data. As far as I can see, there is not much value in using a random size, as in all those cases we can only proceed or do something useful with a valid private key, and key data with sizes other than 32 bytes always lead to invalid keys.