8#include "crypto/sha256.h"
15 return m_tx_id == rhs.m_tx_id && m_index == rhs.m_index;
19 return std::tie(m_tx_id, m_index) < std::tie(rhs.m_tx_id, rhs.m_index);
27 return m_witness_program_commitment == rhs.m_witness_program_commitment
28 && m_value == rhs.m_value;
32 return !(*
this == rhs);
36 : m_witness_program_commitment(witness_program_commitment),
40 return m_prevout == rhs.m_prevout
41 && m_prevout_data == rhs.m_prevout_data;
45 return !(*
this == rhs);
54 sha.Write(buf.c_ptr(), buf.size());
55 sha.Finalize(result.data());
61 return rhs.m_inputs == m_inputs && rhs.m_outputs == m_outputs
62 && rhs.m_witness == m_witness;
68 std::memcpy(&ret, tx.m_id.data(),
sizeof(ret));
76 sha.Write(inp_buf.c_ptr(), inp_buf.size());
79 sha.Write(out_buf.c_ptr(), out_buf.size());
82 sha.Finalize(ret.data());
88 -> std::optional<input> {
90 if(i >= tx.m_outputs.size()) {
100 -> std::optional<input> {
101 const auto id =
tx_id(tx);
110 sha.Write(entropy.data(), entropy.size());
111 std::array<
unsigned char,
sizeof(i)> index_arr{};
112 std::memcpy(index_arr.data(), &i,
sizeof(i));
113 sha.Write(index_arr.data(),
sizeof(i));
117 sha.Write(buf.c_ptr(), buf.size());
118 sha.Finalize(ret.data());
123 return m_id == tx.m_id;
128 for(
const auto& inp : tx.
m_inputs) {
131 for(uint64_t i = 0; i < tx.
m_outputs.size(); i++) {
139 auto payload = hash();
141 secp256k1_keypair keypair{};
142 [[maybe_unused]]
const auto ret
143 = secp256k1_keypair_create(ctx, &keypair, key.data());
147 [[maybe_unused]]
const auto sign_ret
148 = secp256k1_schnorrsig_sign(ctx,
154 assert(sign_ret == 1);
155 return {pubkey, sig};
161 ctx.m_attestations.clear();
163 auto sha = CSHA256();
164 sha.Write(buf.c_ptr(), buf.size());
166 sha.Finalize(ret.data());
172 auto payload = hash();
173 secp256k1_xonly_pubkey pubkey{};
174 if(secp256k1_xonly_pubkey_parse(ctx, &pubkey, att.first.data()) != 1) {
178 if(secp256k1_schnorrsig_verify(ctx,
struct secp256k1_context_struct secp256k1_context
auto uhs_id_from_output(const hash_t &entropy, uint64_t i, const output &output) -> hash_t
std::pair< pubkey_t, signature_t > sentinel_attestation
Sentinel attestation type.
auto tx_id(const full_tx &tx) noexcept -> hash_t
Calculates the unique hash of a full transaction.
auto input_from_output(const full_tx &tx, size_t i, const hash_t &txid) -> std::optional< input >
Converts the output at the specified index to an input.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
std::array< unsigned char, pubkey_len > privkey_t
A private key of a public/private keypair.
std::array< unsigned char, sig_len > signature_t
A signature.
auto make_buffer(const T &obj) -> std::enable_if_t< std::is_same_v< B, nuraft::ptr< nuraft::buffer > >, nuraft::ptr< nuraft::buffer > >
Serialize object into nuraft::buffer using a cbdc::nuraft_serializer.
auto pubkey_from_privkey(const privkey_t &privkey, secp256k1_context *ctx) -> pubkey_t
Generates a public key from the specified private key.
auto operator()(compact_tx const &tx) const noexcept -> size_t
A condensed, hash-only transaction representation.
std::vector< hash_t > m_inputs
The set of hashes of the transaction's inputs.
hash_t m_id
The hash of the full transaction returned by tx_id.
std::vector< hash_t > m_uhs_outputs
The set of hashes of the new outputs created in the transaction.
auto hash() const -> hash_t
Return the hash of the compact transaction, without the sentinel attestations included.
auto operator==(const compact_tx &tx) const noexcept -> bool
Equality of two compact transactions.
auto verify(secp256k1_context *ctx, const sentinel_attestation &att) const -> bool
Verify the given attestation contains a valid signature that matches the compact transaction.
auto sign(secp256k1_context *ctx, const privkey_t &key) const -> sentinel_attestation
Sign the compact transaction and return the signature.
std::vector< input > m_inputs
The set of inputs for the transaction.
std::vector< output > m_outputs
The set of new outputs created by the transaction.
auto operator==(const full_tx &rhs) const -> bool
The unique identifier of a specific output from a transaction.
hash_t m_tx_id
The hash of the transaction which created the out_point.
auto operator==(const out_point &rhs) const -> bool
uint64_t m_index
The index of the output in the transaction's output list.
auto operator<(const out_point &rhs) const -> bool
An output of a transaction.
auto operator!=(const output &rhs) const -> bool
auto operator==(const output &rhs) const -> bool