syntax = "proto3";
package passwordless_recovery;

// Used as envelope for TrustedFriendShare and RecoveryData.
// Encrypted using XChaCha20-Poly1305.
message EncryptedEnvelope {
  bytes encrypted_data = 1;
  bytes iv = 2;
  bytes mac = 3;
}

// Sent from the trusted friend to the recovering user via the server.
// This is symmetrically encrypted using the encryption key received from the recovery link.
message TrustedFriendShare {

  // This allows to display to the recovering user which trusted friend has sent their recovery data.
  User trusted_friend = 1;

  // This allows to display the userdata, showing that the trusted friend is recovering the correct person.
  User share_user = 2;

  // The minimum threshold required to reconstruct the shares.
  int32 threshold = 3;

  // The actual share which will be used to reconstruct SharedSecretData.
  bytes shared_secret_data = 4;

  message User {
    int64 user_id = 1;
    string display_name = 2;
    bytes avatar = 3;
  }
}

// The user identity keys. Can be used to restore the data backup.
message RecoveryData {
  int64 user_id = 1;
  bytes key_manager = 3;
}

// After receiving threshold shares, this is reconstructed by the recovering user.
message SharedSecretData {

  // The recovery data (RecoveryData). It is encrypted with the server_key in case a second factor was chosen.
  bytes recovery_data = 1;
  
  // Combined with the user's PIN/Email via HKDF to derive the key to decrypt the encrypted server_key.
  // The server NEVER sees this value.
  optional bytes server_key_protection = 3;

  // Used to authenticate with the server to fetch the encrypted server_key.
  optional bytes pin_unlock_token = 5;

  optional string email_hint = 6;
}
