| 15 | #include <vector> |
| 16 | |
| 17 | void MockedDescriptorConverter::Init() |
| 18 | { |
| 19 | // The data to use as a private key or a seed for an xprv. |
| 20 | std::array<std::byte, 32> key_data{std::byte{1}}; |
| 21 | // Generate keys of all kinds and store them in the keys array. |
| 22 | for (size_t i{0}; i < TOTAL_KEYS_GENERATED; i++) { |
| 23 | key_data[31] = std::byte(i); |
| 24 | |
| 25 | // If this is a "raw" key, generate a normal privkey. Otherwise generate |
| 26 | // an extended one. |
| 27 | if (IdIsCompPubKey(i) || IdIsUnCompPubKey(i) || IdIsXOnlyPubKey(i) || IdIsConstPrivKey(i)) { |
| 28 | CKey privkey; |
| 29 | privkey.Set(key_data.begin(), key_data.end(), !IdIsUnCompPubKey(i)); |
| 30 | if (IdIsCompPubKey(i) || IdIsUnCompPubKey(i)) { |
| 31 | CPubKey pubkey{privkey.GetPubKey()}; |
| 32 | keys_str[i] = HexStr(pubkey); |
| 33 | } else if (IdIsXOnlyPubKey(i)) { |
| 34 | const XOnlyPubKey pubkey{privkey.GetPubKey()}; |
| 35 | keys_str[i] = HexStr(pubkey); |
| 36 | } else { |
| 37 | keys_str[i] = EncodeSecret(privkey); |
| 38 | } |
| 39 | } else { |
| 40 | CExtKey ext_privkey; |
| 41 | ext_privkey.SetSeed(key_data); |
| 42 | if (IdIsXprv(i)) { |
| 43 | keys_str[i] = EncodeExtKey(ext_privkey); |
| 44 | } else { |
| 45 | const CExtPubKey ext_pubkey{ext_privkey.Neuter()}; |
| 46 | keys_str[i] = EncodeExtPubKey(ext_pubkey); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | std::optional<uint8_t> MockedDescriptorConverter::IdxFromHex(std::string_view hex_characters) const { |
| 53 | if (hex_characters.size() != 2) return {}; |
no test coverage detected