
@namespace("keybase.1")
protocol Common {

  @typedef("long")
  record Time {}

  // Duration in seconds
  @typedef("double")
  record DurationSec {}

  record StringKVPair {
    string key;
    string value;
  }

  record Status {
    int code;
    string name;
    string desc;
    array<StringKVPair> fields;
  }

  @typedef("string")
  record UID {}

  @typedef("string")
  record DeviceID {}

  @typedef("string")
  record SigID {}

  // Most appearances of KIDs in protocol are in hex....
  @typedef("string")
  record KID {}

  // Chain link IDs
  @typedef("string")
  record LinkID {}

  // But sometimes we need binary kids...
  @typedef("bytes")
  record BinaryKID {}

  @typedef("string")
  record TLFID {}

  fixed Bytes32(32);

  record Text {
    string data;
    boolean markup;
  }

  record PGPIdentity {
    string username;
    string comment;
    string email;
  }

  record PublicKey {
    @lint("ignore")
    KID KID;
    @lint("ignore")
    string PGPFingerprint; // empty for non-PGP keys
    @lint("ignore")
    array<PGPIdentity> PGPIdentities; // same
    boolean isSibkey;
    boolean isEldest;
    string parentID;
    DeviceID deviceID;
    string deviceDescription;
    string deviceType;
    Time cTime;
    Time eTime;
    boolean isRevoked;
  }

  record KeybaseTime {
    Time unix;
    int chain;
  }

  record RevokedKey {
    PublicKey key;
    KeybaseTime time;
    KID by;
  }

  record User {
    UID uid;
    string username;
  }

  record Device {
    string type;
    string name;
    DeviceID deviceID;
    Time cTime;
    Time mTime;
    Time lastUsedTime;
    KID encryptKey;
    KID verifyKey;
    int status;
  }

  enum DeviceType {
    DESKTOP_0,
    MOBILE_1
  }

  record Stream {
    int fd;
  }

  enum LogLevel {
    NONE_0,
    DEBUG_1,
    INFO_2,
    NOTICE_3,
    WARN_4,
    ERROR_5,
    CRITICAL_6,
    FATAL_7
  }

  @go("nostring")
  enum ClientType {
    NONE_0,
    CLI_1,
    GUI_MAIN_2,
    KBFS_3,
    GUI_HELPER_4
  }

  record UserVersionVector {
      long id;
      int sigHints;
      long sigChain;
      Time cachedAt;
      Time lastIdentifiedAt;
  }

  record UserPlusKeys {
      UID uid;
      string username;

      // deviceKeys is a list of active device keys.  It does
      // not include PGP keys.
      array<PublicKey> deviceKeys;

      // revokedDeviceKeys is a list of revoked device keys.
      array<RevokedKey> revokedDeviceKeys;

      // number of pgp keys associated with this user
      int pgpKeyCount;

      UserVersionVector uvv;

      // deletedDeviceKeys is a list of deleted device keys.
      // (i.e. keys that were used before an account reset)
      array<PublicKey> deletedDeviceKeys;
  }

  record RemoteTrack {
      string username;
      UID uid;
      LinkID linkID;
  }

  record UserPlusAllKeys {
      UserPlusKeys base;
      array<PublicKey> pgpKeys;
      array<RemoteTrack> remoteTracks;
  }

  @go("nostring")
  enum MerkleTreeID {
       MASTER_0,
       KBFS_PUBLIC_1,
       KBFS_PRIVATE_2
  }

  /**
    SocialAssertionService is a service that can be used to assert proofs for a
    user.
    */
  @typedef("string")
  record SocialAssertionService {}

  /**
    SocialAssertion contains a service and username for that service, that
    together form an assertion about a user. Resolving an assertion requires
    that the user posts a Keybase proof on the asserted service as the asserted
    user.
    */
  record SocialAssertion {
      string user;
      SocialAssertionService service;
  }

  /**
    UserResolution maps how an unresolved user assertion has been resolved.
    */
  record UserResolution {
      SocialAssertion assertion;
      UID userID;
  }

}
