Line data Source code
1 : // Copyright (c) The Bitcoin Core developers
2 : // Distributed under the MIT software license, see the accompanying
3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 :
5 : #ifndef BITCOIN_KERNEL_SIGNET_H
6 : #define BITCOIN_KERNEL_SIGNET_H
7 :
8 : #include <hash.h>
9 : #include <kernel/messagestartchars.h>
10 : #include <uint256.h>
11 : #include <util/strencodings.h>
12 :
13 : #include <algorithm>
14 : #include <cstdint>
15 : #include <vector>
16 :
17 : namespace kernel {
18 : using namespace util::hex_literals;
19 :
20 : inline const std::vector<uint8_t> SIGNET_DEFAULT_CHALLENGE{
21 : "512103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae"_hex_v_u8};
22 :
23 : /**
24 : * Return the message start bytes for a signet: the first four bytes of the
25 : * double-SHA256 hash of the serialized signet challenge script (BIP325)
26 : */
27 891 : inline MessageStartChars GetSignetMessageStart(const std::vector<uint8_t>& signet_challenge)
28 : {
29 891 : HashWriter h{};
30 891 : h << signet_challenge;
31 891 : const uint256 hash = h.GetHash();
32 891 : MessageStartChars msg_start;
33 891 : std::copy_n(hash.begin(), 4, msg_start.begin());
34 891 : return msg_start;
35 : }
36 : } // namespace kernel
37 :
38 : #endif // BITCOIN_KERNEL_SIGNET_H
|