|
| 1 | +{-# OPTIONS --safe --without-K #-} |
| 2 | + |
| 3 | +module Trigger.API where |
| 4 | + |
| 5 | +open import Data.Product using (Σ; _,_) |
| 6 | +open import Data.Sum using (_⊎_) |
| 7 | +open import Relation.Binary.PropositionalEquality using (_≡_; refl) |
| 8 | + |
| 9 | +-- ===================================================================== |
| 10 | +-- Level 4: API Equivalence & MTProto Well-Formedness |
| 11 | +-- ===================================================================== |
| 12 | + |
| 13 | +-- The state of an MTProto connection session |
| 14 | +data SessionState : Set where |
| 15 | + Unauth : SessionState |
| 16 | + AuthReq : SessionState |
| 17 | + AuthAck : SessionState |
| 18 | + SessionActive : SessionState |
| 19 | + |
| 20 | +-- A session identifier |
| 21 | +postulate SessionID : Set |
| 22 | + |
| 23 | +-- Abstract tracking of state per session |
| 24 | +postulate stateOf : SessionID → SessionState |
| 25 | + |
| 26 | +-- ===================================================================== |
| 27 | +-- Well-Formedness Rules |
| 28 | +-- ===================================================================== |
| 29 | + |
| 30 | +-- Proof that a session is fully active |
| 31 | +data IsAuthorized (s : SessionID) : Set where |
| 32 | + authorized : stateOf s ≡ SessionActive → IsAuthorized s |
| 33 | + |
| 34 | +-- Postulate the Idris2 API actions as transitions that preserve or |
| 35 | +-- require these invariants. |
| 36 | +postulate Message : Set |
| 37 | +postulate Reason : Set |
| 38 | +postulate Result : Set |
| 39 | + |
| 40 | +-- You cannot issue a report unless the session is in the SessionActive state. |
| 41 | +-- This mirrors the Idris2 dependent type signature. |
| 42 | +postulate reportMessage : (s : SessionID) → Message → Reason |
| 43 | + → IsAuthorized s |
| 44 | + → Result |
| 45 | + |
| 46 | +-- Cryptographic opacity (simplified placeholder for Level 4) |
| 47 | +postulate CipherText : Set |
| 48 | +postulate isOpaque : CipherText → Set |
0 commit comments