/*
 * Copyright 2023 Signal Messenger, LLC
 * SPDX-License-Identifier: AGPL-3.0-only
 */

syntax = "proto3";

option java_multiple_files = true;

package org.signal.chat.common;

import "org/signal/chat/require.proto";

enum IdentityType {
  IDENTITY_TYPE_UNSPECIFIED = 0;
  IDENTITY_TYPE_ACI = 1;
  IDENTITY_TYPE_PNI = 2;
}

message ServiceIdentifier {
  // The type of identity represented by this service identifier.
  IdentityType identity_type = 1;

  // The UUID of the identity represented by this service identifier.
  bytes uuid = 2 [(require.exactlySize) = 16];
}

message AccountIdentifiers {
  // A list of service identifiers for the identified account.
  repeated ServiceIdentifier service_identifiers = 1;

  // The phone number associated with the identified account.
  string e164 = 2;

  // The username hash (if any) associated with the identified account. May be
  // empty if no username is associated with the identified account.
  bytes username_hash = 3;
}

message EcPreKey {
  // A locally-unique identifier for this key, which will be provided by
  // peers using this key to encrypt messages so the private key can be looked
  // up.
  uint32 key_id = 1;

  // The public key, serialized in libsignal's elliptic-curve public key format.
  bytes public_key = 2  [(require.nonEmpty) = true];
}

message EcSignedPreKey {
  // A locally-unique identifier for this key, which will be provided by
  // peers using this key to encrypt messages so the private key can be looked
  // up.
  uint32 key_id = 1;

  // The public key, serialized in libsignal's elliptic-curve public key format.
  bytes public_key = 2  [(require.nonEmpty) = true];

  // A signature of the public key, verifiable with the identity key for the
  // account/identity associated with this pre-key.
  bytes signature = 3  [(require.nonEmpty) = true];
}

message KemSignedPreKey {
  // An locally-unique identifier for this key, which will be provided by peers
  // using this key to encrypt messages so the private key can be looked up.
  uint32 key_id = 1;

  // The public key, serialized in libsignal's Kyber1024 public key format.
  bytes public_key = 2 [(require.nonEmpty) = true];

  // A signature of the public key, verifiable with the identity key for the
  // account/identity associated with this pre-key.
  bytes signature = 3 [(require.nonEmpty) = true];
}

enum DeviceCapability {
  DEVICE_CAPABILITY_UNSPECIFIED = 0;
  DEVICE_CAPABILITY_STORAGE = 1;
  DEVICE_CAPABILITY_TRANSFER = 2;
  reserved 3;
  reserved 4;
  reserved 5;
  DEVICE_CAPABILITY_ATTACHMENT_BACKFILL = 6;
  DEVICE_CAPABILITY_SPARSE_POST_QUANTUM_RATCHET = 7;
}

message ZkCredential {
  /*
   * Day on which this credential can be redeemed, in UTC seconds since epoch
   */
  int64 redemption_time = 1;

  /*
   * The ZK credential, using libsignal's serialization
   */
  bytes credential = 2  [(require.nonEmpty) = true];
}

// An upload location and credentials which may be used to upload an object
// to an external CDN
message UploadForm {
  // Indicates the CDN type. 3 indicates resumable uploads using TUS
  uint32 cdn = 1;

  // The location within the specified cdn where the finished upload can be found
  string key = 2;

  // A map of headers to include with all upload requests. Potentially contains
  // time-limited upload credentials
  map<string, string> headers = 3;

  // The URL to upload to with the appropriate protocol
  string signed_upload_location = 4;
}
