# Code Contracts — PD-248

story_id: "PD-248"
version: "1.0.0"
created_at: "2026-02-19"

contracts:
  - id: CC-248-01
    name: "useScreenshotProtection"
    type: hook
    file: "src/hooks/useScreenshotProtection.ts"
    signature: "export function useScreenshotProtection(): void"
    invariants:
      - INV-248-01
      - INV-248-02
      - INV-248-03
      - INV-248-04
      - INV-248-08
    description: |
      Hook de protection screenshot pour écrans sensibles.
      - Activation automatique sur focus (useFocusEffect)
      - Désactivation sur blur (sauf sensible→sensible)
      - Silencieux (pas d'alerte utilisateur)
      - Activation < 10ms
    dependencies:
      - "expo-screen-capture"
      - "@react-navigation/native"
    tests:
      - TC-248-NOM-01
      - TC-248-NOM-02
      - TC-248-NOM-03
      - TC-248-NOM-04
      - TC-248-NOM-06
      - TC-248-SIL-01

  - id: CC-248-02
    name: "Intégration écrans sensibles"
    type: integration
    files:
      - "src/screens/recovery/MnemonicDisplay.tsx"
      - "src/screens/settings/MFASetupScreen.tsx"
      - "src/components/mfa/TOTPCodeDisplay.tsx"
      - "src/screens/settings/APIKeyDisplay.tsx"
    invariants:
      - INV-248-02
      - INV-248-05
    description: |
      Pattern d'intégration: appeler useScreenshotProtection()
      en première ligne du composant écran sensible.
    pattern: |
      function SensitiveScreen() {
        useScreenshotProtection(); // OBLIGATOIRE
        // ... reste du composant
      }
    tests:
      - TC-248-NOM-01
      - TC-248-NOM-02
      - TC-248-NOM-03
      - TC-248-NOM-04

  - id: CC-248-03
    name: "ScreenshotProtectionLogger"
    type: service
    file: "src/services/screenshotProtection.ts"
    interface: |
      interface ScreenshotProtectionLogger {
        logActivationError(screen: ScreenId, error: Error): void;
        logMaintainError(from: ScreenId, to: ScreenId, error: Error): void;
        logUnregisteredComponent(component: string): void;
        logIncompatibleEnvironment(): void;
      }
    invariants:
      - INV-248-04
    error_codes:
      - ERR-248-001
      - ERR-248-002
      - ERR-248-003
      - ERR-248-004
    description: |
      Service de logging technique pour erreurs de protection.
      Aucune alerte utilisateur (INV-248-04).
    tests:
      - TC-248-ERR-01
      - TC-248-ERR-02
      - TC-248-ERR-03
      - TC-248-ERR-04

  - id: CC-248-04
    name: "Tests unitaires"
    type: test
    file: "src/__tests__/hooks/useScreenshotProtection.test.ts"
    coverage:
      - INV-248-01
      - INV-248-02
      - INV-248-03
      - INV-248-04
      - INV-248-08
    description: |
      Tests unitaires du hook useScreenshotProtection.
      Mock expo-screen-capture.
    test_cases:
      - TC-248-NOM-01
      - TC-248-NOM-02
      - TC-248-NOM-03
      - TC-248-NOM-04
      - TC-248-NOM-05
      - TC-248-NOM-06
      - TC-248-NOM-07
      - TC-248-SIL-01

  - id: CC-248-05
    name: "Tests E2E avec OCR"
    type: test
    file: "src/__tests__/e2e/screenshot-protection.e2e.ts"
    tool: "Tesseract 5.x"
    coverage:
      - CA-248-01
      - CA-248-02
      - CA-248-03
      - CA-248-04
      - CA-248-06
      - CA-248-08
    description: |
      Tests E2E avec vérification OCR.
      Capture screenshot, exécute Tesseract, vérifie absence données sensibles.
    test_cases:
      - TC-248-NOM-01
      - TC-248-NOM-02
      - TC-248-NOM-03
      - TC-248-NOM-04
      - TC-248-PERF-01
      - TC-248-ENV-02

tasks:
  - id: TASK-1
    name: "Installation expo-screen-capture"
    agent: agent-sre
    contracts: []
    invariants: [INV-248-07]
    files:
      - package.json
      - app.json

  - id: TASK-2
    name: "Hook useScreenshotProtection"
    agent: agent-developer
    contracts: [CC-248-01]
    invariants: [INV-248-01, INV-248-02, INV-248-03, INV-248-04, INV-248-08]
    files:
      - src/hooks/useScreenshotProtection.ts

  - id: TASK-3
    name: "Intégration écrans sensibles"
    agent: agent-developer
    contracts: [CC-248-02]
    invariants: [INV-248-02, INV-248-05]
    files:
      - src/screens/recovery/MnemonicDisplay.tsx
      - src/screens/settings/MFASetupScreen.tsx
      - src/components/mfa/TOTPCodeDisplay.tsx
      - src/screens/settings/APIKeyDisplay.tsx

  - id: TASK-4
    name: "Service de logging"
    agent: agent-developer
    contracts: [CC-248-03]
    invariants: [INV-248-04]
    files:
      - src/services/screenshotProtection.ts

  - id: TASK-5
    name: "Tests unitaires"
    agent: agent-qa-unit-integration
    contracts: [CC-248-04]
    files:
      - src/__tests__/hooks/useScreenshotProtection.test.ts

  - id: TASK-6
    name: "Tests E2E avec OCR"
    agent: agent-qa-e2e
    contracts: [CC-248-05]
    files:
      - src/__tests__/e2e/screenshot-protection.e2e.ts
