OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
keys.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_COMMON_KEYS_H_
7#define OPENCBDC_TX_SRC_COMMON_KEYS_H_
8
9#include <array>
10#include <cstring>
11#include <vector>
12
13struct secp256k1_context_struct;
14using secp256k1_context = struct secp256k1_context_struct;
15
16namespace cbdc {
18 static constexpr size_t pubkey_len = 32;
20 static constexpr size_t sig_len = 64;
21
23 using privkey_t = std::array<unsigned char, pubkey_len>;
25 using pubkey_t = std::array<unsigned char, pubkey_len>;
27 using witness_t = std::vector<std::byte>;
29 using signature_t = std::array<unsigned char, sig_len>;
30
35 auto pubkey_from_privkey(const privkey_t& privkey, secp256k1_context* ctx)
36 -> pubkey_t;
37
41 template<size_t S>
42 auto to_vector(const std::array<unsigned char, S>& arr)
43 -> std::vector<std::byte> {
44 std::vector<std::byte> ret(S);
45 memcpy(ret.data(), arr.data(), S);
46 return ret;
47 }
48}
49
50#endif // OPENCBDC_TX_SRC_COMMON_KEYS_H_
struct secp256k1_context_struct secp256k1_context
Definition keys.hpp:14
auto to_vector(const std::array< unsigned char, S > &arr) -> std::vector< std::byte >
Converts an std::array into an std::vector of the same size via copy.
Definition keys.hpp:42
std::array< unsigned char, pubkey_len > privkey_t
A private key of a public/private keypair.
Definition keys.hpp:23
std::array< unsigned char, sig_len > signature_t
A signature.
Definition keys.hpp:29
std::vector< std::byte > witness_t
A witness commitment.
Definition keys.hpp:27
auto pubkey_from_privkey(const privkey_t &privkey, secp256k1_context *ctx) -> pubkey_t
Generates a public key from the specified private key.
Definition keys.cpp:12
std::array< unsigned char, pubkey_len > pubkey_t
A public key of a public/private keypair.
Definition keys.hpp:25