/tmp/bitcoin/src/kernel/signet.h
Line | Count | Source |
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 | | inline MessageStartChars GetSignetMessageStart(const std::vector<uint8_t>& signet_challenge) |
28 | 2.16k | { |
29 | 2.16k | HashWriter h{}; |
30 | 2.16k | h << signet_challenge; |
31 | 2.16k | const uint256 hash = h.GetHash(); |
32 | 2.16k | MessageStartChars msg_start; |
33 | 2.16k | std::copy_n(hash.begin(), 4, msg_start.begin()); |
34 | 2.16k | return msg_start; |
35 | 2.16k | } |
36 | | } // namespace kernel |
37 | | |
38 | | #endif // BITCOIN_KERNEL_SIGNET_H |