Spaces:
Sleeping
Sleeping
File size: 3,584 Bytes
e61e751 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | """
Federation Node β Data Models & Enums
======================================
Contract: C-FED-NODE-001 v0.1.1
Refusal reason codes (Β§7.4), delivery statuses (Β§9.3),
trust tiers (Β§7), and request/response schemas.
"""
from __future__ import annotations
from datetime import datetime, timezone
from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field
# βββ Refusal Reason Codes (Β§7.4) βββ
class RefusalReason(str, Enum):
"""Structured refusal reason codes per C-FED-NODE-001 Β§7.4."""
UNSUPPORTED_PROTOCOL_VERSION = "UNSUPPORTED_PROTOCOL_VERSION"
UNSUPPORTED_MESSAGE_CLASS = "UNSUPPORTED_MESSAGE_CLASS"
INVALID_DELEGATION = "INVALID_DELEGATION"
SENDER_NOT_TRUSTED = "SENDER_NOT_TRUSTED"
SENDER_BLOCKED = "SENDER_BLOCKED"
MALFORMED_ENVELOPE = "MALFORMED_ENVELOPE"
QUARANTINED = "QUARANTINED"
REFUSED_BY_POLICY = "REFUSED_BY_POLICY"
PAYLOAD_TOO_LARGE = "PAYLOAD_TOO_LARGE"
RATE_LIMITED = "RATE_LIMITED"
INBOX_FULL = "INBOX_FULL"
# βββ Delivery Statuses (Β§9.3) βββ
class DeliveryStatus(str, Enum):
"""Envelope delivery status progression per C-FED-NODE-001 Β§9.3."""
RECEIVED = "RECEIVED"
VALIDATED = "VALIDATED"
REJECTED = "REJECTED"
QUEUED = "QUEUED"
QUARANTINED = "QUARANTINED"
DELIVERED = "DELIVERED"
READ = "READ"
PROCESSED = "PROCESSED"
WITNESSED = "WITNESSED"
EXPIRED = "EXPIRED"
# βββ Trust Tiers (Β§7.2) βββ
class TrustTier(str, Enum):
TRUSTED = "TRUSTED"
KNOWN = "KNOWN"
UNKNOWN = "UNKNOWN"
BLOCKED = "BLOCKED"
# βββ Refusal Response Model βββ
class FederationRefusal(BaseModel):
"""Structured refusal response per C-FED-NODE-001 Β§7.4."""
refusal: bool = True
reason: RefusalReason
message: str
node_seal: str
timestamp: str
# βββ Request Models βββ
class HandshakeRequest(BaseModel):
"""Incoming handshake from another node."""
caller_seal: str = Field(..., description="The Glyph-Seal of the caller")
protocol: str = Field(default="C-FED-001", description="Protocol version")
message: Optional[str] = Field(default=None, description="Optional signal payload")
class HandshakeResponse(BaseModel):
"""Response to a handshake."""
node_seal: str
link_seal: str
status: str
message: str
timestamp: str
class VerifyRequest(BaseModel):
"""Request to verify a seal string."""
seal: str
class MintRequest(BaseModel):
"""Request to mint a new seal."""
class_name: str = Field(..., description="NODE, LAW, LINK, RITE, ART, WIT")
origin: str = Field(..., description="Origin namespace")
state: str = Field(default="VALID")
mode: str = Field(default="hybrid", description="random | hybrid | deterministic")
material: Optional[str] = Field(default=None, description="For deterministic mode")
class EnvelopeSubmission(BaseModel):
"""Incoming envelope per C-FED-NODE-001 Β§9.1."""
protocol_version: str = Field(default="1.0.0")
message_class: str = Field(..., description="Message class (THOUGHT, PROPOSAL, etc.)")
sender: dict = Field(..., description="Sender block: {seal, delegation_token?}")
recipient: dict = Field(..., description="Recipient block: {seal}")
payload: dict = Field(..., description="Payload block: {content_type, body, ...}")
delivery: dict = Field(default_factory=lambda: {"ttl_seconds": 86400, "priority": "normal"})
signature: Optional[dict] = Field(default=None, description="Signature block (Phase 3)")
|