obscura-server 0.6.2

A server for relaying secure messages using the Signal Protocol
Documentation
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
openapi: 3.0.3
info:
  title: Obscura Server API
  description: |
    A privacy-first messaging relay.
    - **Control Plane (REST):** Registration, Key Management, Sending.
    - **Data Plane (WebSocket):** Real-time message delivery and acknowledgement.
    - **Protocol:** Protocol Buffers (application/x-protobuf) are used for message bodies to minimize metadata leakage and binary bloat.

    **Protobuf Definitions:**
    The WebSocket and Message schemas are defined in the [obscura-proto](https://github.com/barrelmaker97/obscura-proto/blob/main/obscura/v1/obscura.proto) repository.
  version: 0.0.0
  license:
    name: GPL-3.0-or-later
    url: https://www.gnu.org/licenses/gpl-3.0.html
security:
  - bearerAuth: []
paths:
  # --- Account & Identity ---
  /v1/users:
    post:
      operationId: registerUser
      summary: Register a new user device.
      tags: [Account]
      security: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RegistrationRequest'
      responses:
        '201':
          description: Account created.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthResponse'
        '400':
          $ref: '#/components/responses/BadRequestError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '409':
          description: Username already exists.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  /v1/sessions:
    post:
      operationId: login
      summary: Login and retrieve a session token.
      tags: [Account]
      security: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoginRequest'
      responses:
        '200':
          description: Authenticated.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthResponse'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

    delete:
      operationId: logout
      summary: Logout (Revoke Refresh Token).
      description: |
        Revokes the provided Refresh Token, effectively logging the user out of that session.
      tags: [Account]
      security:
        - bearerAuth: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LogoutRequest'
      responses:
        '200':
          description: Session revoked.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  /v1/sessions/refresh:
    post:
      operationId: refreshToken
      summary: Refresh Access Token.
      description: |
        Exchanges a valid Refresh Token for a new pair (Access Token + Refresh Token).
        Implements Rotation: The old Refresh Token is invalidated immediately.
      tags: [Account]
      security: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RefreshRequest'
      responses:
        '200':
          description: Tokens refreshed.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthResponse'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  # --- Keys (X3DH) ---
  /v1/keys:
    post:
      operationId: uploadKeys
      summary: Upload PreKeys or Perform Device Takeover.
      description: |
        Uploads new Signed PreKeys and One-Time PreKeys.

        **Device Takeover:**
        If an `identityKey` is provided and it *differs* from the stored key for this user:
        - Replaces the Identity Key.
        - Deletes ALL old keys (Signed and One-Time).
        - Deletes ALL pending messages.
        - Disconnects active WebSockets.

        If `identityKey` matches the stored key or is omitted, it acts as a standard key refill (appending new keys).
      tags: [Keys]
      security:
        - bearerAuth: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PreKeyUploadRequest'
      responses:
        '200':
          description: Keys updated or takeover successful.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  /v1/keys/{userId}:
    get:
      operationId: getPreKeyBundle
      summary: Fetch PreKey Bundle.
      description: |
        Returns active PreKey bundle for the target user.
        Server atomically consumes one One-Time PreKey (if available).
      tags: [Keys]
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: PreKey Bundle.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PreKeyBundleResponse'
        '404':
          $ref: '#/components/responses/NotFoundError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  # --- Messaging (REST Upstream) ---
  /v1/messages:
    post:
      operationId: sendMessages
      summary: Send one or more encrypted messages.
      description: |
        Pushes an array of encrypted envelopes to target devices' queues.
        Accepts a batch of messages to support multi-device fan-out or single messages.

        **Idempotency:** Requires an `Idempotency-Key` header to safely retry dropped network requests.
        **Payload:** `SendMessageRequest` (Protobuf).
        **Response:** `SendMessageResponse` (Protobuf) detailing any partial failures. An empty response array indicates total success.
      tags: [Messaging]
      security:
        - bearerAuth: []
      parameters:
        - name: Idempotency-Key
          in: header
          required: true
          description: Client-generated UUID. Used to prevent duplicate processing on network retries.
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/x-protobuf:
            schema:
              type: string
              format: binary
              description: Serialized `SendMessageRequest` protobuf.
      responses:
        '200':
          description: Batch processed. Parse the response payload to check for partial failures via the `failed_messages` array.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
          content:
            application/x-protobuf:
              schema:
                type: string
                format: binary
                description: Serialized `SendMessageResponse` protobuf.
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '413':
          description: Payload Too Large. The batch contains too many messages (exceeds server max).
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'


  # --- WebSocket Gateway (Documentation Only) ---
  /v1/gateway:
    get:
      operationId: connectGateway
      summary: Connect to the Message Stream.
      description: |
        **WebSocket Endpoint.**
        Clients must connect here to receive messages.
        - **Protocol:** `WebSocketFrame` (Protobuf).
        - **Auth:** Pass the JWT in the query string: `ws://.../v1/gateway?token=<jwt>`.
        - **Handshake:** Server validates the JWT and ensures the user has an Identity Key stored.
        - **Welcome:** Upon successful connection, the server may immediately push a `PreKeyStatus` frame if the user's one-time pre-key count is below the configured threshold.
        - **Flow:** Server pushes `Envelope` frames. Client MUST respond with `AckMessage` frames. Server batches deletions based on ACKs.
      tags: [Messaging]
      security:
        - tokenAuth: []
      parameters:
        - name: token
          in: query
          required: true
          schema:
            type: string
          description: JWT Access Token.
      responses:
        '101':
          description: Switching Protocols.
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  # --- Attachments (Binary Storage) ---
  /v1/attachments:
    post:
      operationId: uploadAttachment
      summary: Upload an attachment.
      description: |
        Uploads an encrypted binary blob to long-term storage.
        Blobs are automatically deleted after a configured period.
        Maximum and minimum size limits are enforced by the server.
      tags: [Attachments]
      security:
        - bearerAuth: []
      requestBody:
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
              minLength: 1
      responses:
        '201':
          description: Upload successful.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AttachmentResponse'
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '411':
          $ref: '#/components/responses/LengthRequiredError'
        '413':
          $ref: '#/components/responses/PayloadTooLargeError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  /v1/attachments/{id}:
    get:
      operationId: downloadAttachment
      summary: Download an attachment.
      tags: [Attachments]
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: If-None-Match
          in: header
          required: false
          schema:
            type: string
          description: The unique identifier for this attachment (from ETag).
      responses:
        '200':
          description: Binary file stream.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
            ETag:
              description: The unique identifier for this attachment version.
              schema:
                type: string
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        '304':
          description: Attachment not modified (client already has the latest version).
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          $ref: '#/components/responses/NotFoundError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  # --- Backups (Encrypted Identity Recovery) ---
  /v1/backup:
    get:
      operationId: getBackup
      summary: Download the latest backup.
      description: |
        Streams the latest encrypted backup blob.
        Supports conditional caching via `If-None-Match`.
        Returns `ETag` header containing the version number.
      tags: [Backup]
      security:
        - bearerAuth: []
      parameters:
        - name: If-None-Match
          in: header
          required: false
          schema:
            type: string
          description: The current version held by the client (e.g. from ETag).
      responses:
        '200':
          description: Binary backup stream.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
            ETag:
              description: Current backup version.
              schema:
                type: string
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        '304':
          description: Backup not modified (client already has the latest version).
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          $ref: '#/components/responses/NotFoundError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

    head:
      operationId: headBackup
      summary: Check for backup existence.
      description: |
        Returns metadata (Content-Length, ETag) without the body.
        Useful for checking if a local backup is out of date.
      tags: [Backup]
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Backup exists.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
            ETag:
              description: Current backup version.
              schema:
                type: string
            Content-Length:
              schema:
                type: integer
                format: int32
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          $ref: '#/components/responses/NotFoundError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

    post:
      operationId: uploadBackup
      summary: Upload a new backup.
      description: |
        Uploads a new encrypted backup blob.
        Uses Optimistic Locking via headers to prevent concurrent overwrites.

        **Flow:**
        1. **Initial Upload:** Client MUST send `If-None-Match: *`.
        2. **Update:** Client MUST send `If-Match` with the latest version number (as received in a previous `ETag`).
        3. If the preconditions match and no other upload is in progress, the server accepts the stream.
        4. If the version does not match or resource already exists when `*` is used, server returns `412 Precondition Failed`.
        5. If another upload is already in progress, server returns `409 Conflict`.
      tags: [Backup]
      security:
        - bearerAuth: []
      parameters:
        - name: If-Match
          in: header
          required: false
          schema:
            type: string
          description: Current version held by the client (from ETag). Required for updates.
        - name: If-None-Match
          in: header
          required: false
          schema:
            type: string
          description: Set to "*" for the first upload to ensure no backup exists. Required for initial upload.
      requestBody:
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
              minLength: 32
              maxLength: 2097152
      responses:
        '200':
          description: Upload successful.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
            ETag:
              description: The new backup version.
              schema:
                type: string
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '409':
          $ref: '#/components/responses/ConflictError'
        '411':
          $ref: '#/components/responses/LengthRequiredError'
        '412':
          $ref: '#/components/responses/PreconditionFailedError'
        '413':
          $ref: '#/components/responses/PayloadTooLargeError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

  # --- Push Notifications ---
  /v1/push-tokens:
    put:
      operationId: updatePushToken
      summary: Register or update a push notification token.
      description: |
        Associates an FCM or APNS token with the authenticated user device for wake-up signals.
        Obscura uses a "Single Device" policy; updating the token replaces any existing one.
      tags: [Push Notifications]
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RegisterPushTokenRequest'
      responses:
        '200':
          description: Token registered successfully.
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '408':
          $ref: '#/components/responses/RequestTimeoutError'
        '400':
          $ref: '#/components/responses/BadRequestError'
        '429':
          $ref: '#/components/responses/TooManyRequestsError'
        '500':
          $ref: '#/components/responses/InternalServerError'

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    tokenAuth:
      type: apiKey
      in: query
      name: token

  headers:
    x-request-id:
      description: Unique identifier for the request, used for tracing and debugging.
      schema:
        type: string
        format: uuid
    retry-after:
      description: The number of seconds to wait before retrying the request.
      schema:
        type: string

  responses:
    UnauthorizedError:
      description: Unauthorized (Invalid or missing token).
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    BadRequestError:
      description: Invalid input, malformed request, or missing required headers (e.g. version or length).
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFoundError:
      description: The requested resource was not found.
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ConflictError:
      description: Conflict (e.g., concurrent upload already in progress).
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    PreconditionFailedError:
      description: Precondition Failed (Version mismatch or resource already exists).
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RequestTimeoutError:
      description: Request Timeout (The server timed out waiting for the request).
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
    LengthRequiredError:
      description: Length Required (Content-Length header missing).
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    PayloadTooLargeError:
      description: Payload Too Large (Upload exceeds maximum size limit).
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    TooManyRequestsError:
      description: Rate limit exceeded.
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        retry-after:
          $ref: '#/components/headers/retry-after'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: Internal Server Error.
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'

  schemas:
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Semantic error message.

    AuthResponse:
      type: object
      required:
        - token
        - refreshToken
        - expiresAt
      properties:
        token:
          type: string
          description: Short-lived JWT Access Token.
        refreshToken:
          type: string
          description: Long-lived opaque Refresh Token.
        expiresAt:
          type: integer
          format: int64
          description: UNIX timestamp of access token expiration.

    LoginRequest:
      type: object
      required:
        - username
        - password
      properties:
        username:
          type: string
          minLength: 1
          maxLength: 50
        password:
          type: string
          minLength: 12

    LogoutRequest:
      type: object
      required: [refreshToken]
      properties:
        refreshToken:
          type: string

    RefreshRequest:
      type: object
      required: [refreshToken]
      properties:
        refreshToken:
          type: string

    RegisterPushTokenRequest:
      type: object
      required: [token]
      properties:
        token:
          type: string
          description: FCM or APNS device token.

    RegistrationRequest:
      type: object
      required:
        - username
        - password
        - identityKey
        - registrationId
        - signedPreKey
        - oneTimePreKeys
      properties:
        username:
          type: string
          minLength: 1
          maxLength: 50
        password:
          type: string
          minLength: 12
        identityKey:
          type: string
          format: byte
          description: Base64 encoded public identity key.
        registrationId:
          type: integer
          format: int32
        signedPreKey:
          $ref: '#/components/schemas/SignedPreKey'
        oneTimePreKeys:
          type: array
          items:
            $ref: '#/components/schemas/OneTimePreKey'

    PreKeyUploadRequest:
      type: object
      required:
        - signedPreKey
        - oneTimePreKeys
      properties:
        identityKey:
          type: string
          format: byte
          description: Optional Base64 Identity Key. Triggers takeover if changed.
        registrationId:
          type: integer
          format: int32
          description: Required if identityKey is provided.
        signedPreKey:
          description: Signed Pre-Key. ID must be strictly greater than the current stored ID.
          allOf:
            - $ref: '#/components/schemas/SignedPreKey'
        oneTimePreKeys:
          type: array
          items:
            $ref: '#/components/schemas/OneTimePreKey'

    PreKeyBundleResponse:
      type: object
      properties:
        registrationId:
          type: integer
          format: int32
        identityKey:
          type: string
          format: byte
        signedPreKey:
          $ref: '#/components/schemas/SignedPreKey'
        oneTimePreKey:
          type: object
          nullable: true
          allOf:
            - $ref: '#/components/schemas/OneTimePreKey'

    SignedPreKey:
      type: object
      required:
        - keyId
        - publicKey
        - signature
      properties:
        keyId:
          type: integer
          format: int32
        publicKey:
          type: string
          format: byte
          description: Base64 encoded public key
        signature:
          type: string
          format: byte
          description: Base64 encoded signature

    OneTimePreKey:
      type: object
      required:
        - keyId
        - publicKey
      properties:
        keyId:
          type: integer
          format: int32
        publicKey:
          type: string
          format: byte
          description: Base64 encoded public key

    AttachmentResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
        expiresAt:
          type: integer
          format: int64
          description: UNIX timestamp of when the file will be deleted.