Skip to content

security/message_signing.hpp

secp256k1 sign/verify for inter-node messages (PTDS §4.3) More...

Namespaces

Name
sgns
sgns::neoswarm
sgns::neoswarm::security

Classes

Name
class sgns::neoswarm::security::MessageSigning
Signs and verifies inter-node message payloads.

Detailed Description

secp256k1 sign/verify for inter-node messages (PTDS §4.3)

Date: 2026-05-08

Source code

#ifndef NEOSWARM_SECURITY_MESSAGESIGNING_HPP
#define NEOSWARM_SECURITY_MESSAGESIGNING_HPP

#include "node_identity.hpp"
#include "common/error.hpp"
#include <cstdint>
#include <string>
#include <vector>

namespace sgns::neoswarm::security
{
    class MessageSigning
    {
        public:
        explicit MessageSigning( const NodeIdentity& identity );

        outcome::result<std::vector<uint8_t>> Sign( const std::string& payload ) const;

        static bool Verify( const std::string& payload,
                            const std::vector<uint8_t>& signature,
                            const std::string& m_pubKeyhex );

        static constexpr int64_t kReplayWindowSec = 30;

        static std::string GenerateNonce();

        static uint64_t CurrentTimestampMs();

        std::string AttachSignature( const std::string& payload ) const;

        static bool VerifyAndStrip( std::string& payload, const std::string& m_pubKeyhex );

        private:
        const NodeIdentity& m_identity;
    };

} // namespace sgns::neoswarm::security

#endif // NEOSWARM_SECURITY_MESSAGESIGNING_HPP

Updated on 2026-07-25 at 22:56:57 +0000