rootproto

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyStore

type KeyStore struct {
	GetPrivateKey         func() ([]byte, error)                           // raw 32-byte scalar
	GetClientPublicKey    func(clientID string) ([]byte, bool)             // raw uncompressed SEC1, (nil,false) if unknown
	CommitClientPublicKey func(clientID string, newPublicKey []byte) error // persist after validated renewKeyAck
}

KeyStore is the server's callback seam into host-owned persistence The server holds one long-lived private key shared across all clients

type Keypair

type Keypair struct {
	PublicKey  []byte
	PrivateKey []byte
}

Keypair holds raw P-256 public and private key bytes Public key: 65-byte uncompressed SEC1 (0x04 || X || Y) Private key: 32-byte raw scalar

func GenerateKeypair

func GenerateKeypair() (*Keypair, error)

GenerateKeypair creates a new P-256 keypair

type ReplayStore

type ReplayStore struct {
	Load   func() ([]byte, error)
	Append func(entry []byte) error
	Save   func(snapshot []byte) error
}

ReplayStore is the host's callback seam for persisting seen requestIDs Append is called after every accepted message; Save replaces the persisted state on client deletion; Load returns the concatenation of every record the host has persisted

type RequestHandler

type RequestHandler func(clientID string, payload []byte) (replyPayload any)

RequestHandler processes a client request and returns the reply payload Payload decrypted, but still-CBOR-encoded; the handler unmarshals into its own types Hosts encode app-level results as they see fit; the library does not inspect the shape

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(selfID string, keyStore KeyStore, replayStore ReplayStore) (*Server, error)

NewServer constructs a server Close when the host shuts down to stop the background key-cleanup goroutine

func (*Server) ClearReplayHistory

func (s *Server) ClearReplayHistory(clientID string) error

ClearReplayHistory drops all recorded requestIDs for the given client

func (*Server) Close

func (s *Server) Close() error

Close stops background goroutines

func (*Server) OffRequest

func (s *Server) OffRequest(msgType string)

OffRequest unregisters the handler for a type

func (*Server) OnRequest

func (s *Server) OnRequest(msgType string, handler RequestHandler)

OnRequest registers the handler for a client-request type Only one handler per type; calling OnRequest twice for the same type replaces the prior handler

func (*Server) Push

func (s *Server) Push(clientID, msgType string, payload any, write WriteFn) error

Push encrypts and sends a message not triggered by an incoming request RequestID on the wire is empty; clients distinguish pushes from replies by that

func (*Server) Receive

func (s *Server) Receive(bytes []byte, write WriteFn) error

Receive is the entry point for every inbound envelope from the transport layer Reserved types are handled internally; app requests are dispatched to the handler registered via OnRequest

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session holds an AES-256-GCM cipher bound to a derived key

func DeriveSession

func DeriveSession(privateKey, publicKey []byte) (*Session, error)

DeriveSession performs P-256 ECDH between your private key and the other side's public key, runs HKDF-SHA256 over the result, and returns an AES-GCM session bound to the derived key

func SessionFromKey

func SessionFromKey(key []byte) (*Session, error)

SessionFromKey builds an AES-GCM session from a 32-byte key

func (*Session) Decrypt

func (s *Session) Decrypt(ciphertext, aad []byte) ([]byte, error)

Decrypt consumes `nonce(12) || ciphertext || tag(16)`

func (*Session) Encrypt

func (s *Session) Encrypt(plaintext, aad []byte) ([]byte, error)

Encrypt produces `nonce(12) || ciphertext || tag(16)`

type WriteFn

type WriteFn func(bytes []byte) error

WriteFn is the host-owned wire

Directories

Path Synopsis
cmd
test_server command
test_server is a Unix-domain-socket helper used by the JS cross-language e2e tests Framing: 4-byte big-endian length prefix + raw envelope bytes
test_server is a Unix-domain-socket helper used by the JS cross-language e2e tests Framing: 4-byte big-endian length prefix + raw envelope bytes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL