Skip to content

securecrdt/SecureCrdt.hpp

Mandatory wrapper (D-03) for writing to a registered CRDT key and the reader-side logic (D-04) that always re-derives trust from base_key + sig/<addr> children rather than trusting any "final" marker. This is the ONLY sanctioned write entry point for keys registered via SecureCrdtRegistry. More...

Namespaces

Name
sgns
sgns::securecrdt

Classes

Name
class sgns::securecrdt::SecureCrdt
Mandatory wrapper for reading/writing registered SecureCrdt keys.

Functions

Name
OUTCOME_HPP_DECLARE_ERROR_2(sgns::securecrdt , SecureCrdt::Error )

Detailed Description

Mandatory wrapper (D-03) for writing to a registered CRDT key and the reader-side logic (D-04) that always re-derives trust from base_key + sig/<addr> children rather than trusting any "final" marker. This is the ONLY sanctioned write entry point for keys registered via SecureCrdtRegistry.

Date: 2026-07-23 Henrique A. Klein ([email protected])

Functions Documentation

function OUTCOME_HPP_DECLARE_ERROR_2

OUTCOME_HPP_DECLARE_ERROR_2(
    sgns::securecrdt ,
    SecureCrdt::Error 
)

Source code

#ifndef SGNS_SECURECRDT_SECURECRDT_HPP
#define SGNS_SECURECRDT_SECURECRDT_HPP

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

#include "base/buffer.hpp"
#include "base/logger.hpp"
#include "crdt/globaldb/globaldb.hpp"
#include "crdt/hierarchical_key.hpp"
#include "crdt/proto/delta.pb.h"
#include "outcome/outcome.hpp"
#include "securecrdt/SecureCrdtRegistry.hpp"

namespace sgns::securecrdt
{
    class SecureCrdt : public std::enable_shared_from_this<SecureCrdt>
    {
    public:
        enum class Error : uint8_t
        {
            UNREGISTERED_KEY = 0, 
            NO_VALUE_PROPOSED,    
            INVALID_SIGNATURE,    
            MALFORMED_VALUE,      
        };

        SecureCrdt( std::shared_ptr<sgns::crdt::GlobalDB> db, std::string topic );

        outcome::result<void> ProposeValue( const sgns::crdt::HierarchicalKey &base_key,
                                            const std::vector<uint8_t>        &payload );

        outcome::result<void> AddSignature( const sgns::crdt::HierarchicalKey &base_key,
                                            const std::string                 &signer_address,
                                            const std::vector<uint8_t>        &signature );

        outcome::result<std::optional<sgns::base::Buffer>> ReadIfQuorum(
            const sgns::crdt::HierarchicalKey &base_key );

        bool RegisterFilters();

    private:
        std::optional<std::vector<sgns::crdt::pb::Element>> FilterSecureCrdtUpdate(
            const sgns::crdt::HierarchicalKey &base_key,
            const SecureCrdtRegistryEntry     &entry,
            const sgns::crdt::pb::Element     &element );

        std::shared_ptr<sgns::crdt::GlobalDB> db_;
        std::string                           topic_;
        sgns::base::Logger                    logger_ = sgns::base::createLogger( "SecureCrdt" );
    };
} // namespace sgns::securecrdt

OUTCOME_HPP_DECLARE_ERROR_2( sgns::securecrdt, SecureCrdt::Error );

#endif // SGNS_SECURECRDT_SECURECRDT_HPP

Updated on 2026-08-06 at 13:59:20 +0000