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

  import idl "common.avdl";

  record ConfiguredAccount {
    string username;
    boolean hasStoredSecret;
  }

  /**
    Returns an array of information about accounts configured on the local
    machine. Currently configured accounts are defined as those that have stored
    secrets, but this definition may be expanded in the future.
    */
  array<ConfiguredAccount> getConfiguredAccounts(int sessionID);

  /**
    Performs login.  deviceType should be libkb.DeviceTypeDesktop
    or libkb.DeviceTypeMobile.  usernameOrEmail is optional.
    If the current device isn't provisioned, this function will
    provision it.

    Note that if usernameOrEmail is an email address, only provisioning
    will be attempted.  If the device is already provisioned, login
    via email address does not work.
    */
  void login(int sessionID, string deviceType, string usernameOrEmail, ClientType clientType);
 
  /**
    Login a user only if the user is on a provisioned device.  Username is optional.
    If noPassphrasePrompt is set, then only a stored secret will be used to unlock
    the device keys.
    */ 
  void loginProvisionedDevice(int sessionID, string username, boolean noPassphrasePrompt);

  /**
    Login and unlock by
  - trying unlocked device keys if available
  - prompting for a paper key and using that
    */
  void loginWithPaperKey(int sessionID);

  /**
    Removes any existing stored secret for the given username.
    loginWithStoredSecret(_, username) will fail after this is called.
    */
  void clearStoredSecret(int sessionID, string username);

  void logout(int sessionID);
  void deprovision(int sessionID, string username, boolean doRevoke);

  void recoverAccountFromEmailAddress(string email);

  /**
    PaperKey generates paper backup keys for restoring an account.
    It calls login_ui.displayPaperKeyPhrase with the phrase.
    */
  void paperKey(int sessionID);

  /**
    paperKeySubmit checks that paperPhrase is a valid paper key
    for the logged in user, caches the keys, and sends a notification.
    */
  void paperKeySubmit(int sessionID, string paperPhrase);

  /**
    Unlock restores access to local key store by priming passphrase stream cache.
    */
  void unlock(int sessionID);
  void unlockWithPassphrase(int sessionID, string passphrase);

  /**
    pgpProvision is for devel/testing to provision a device via pgp using CLI
    with no user interaction.
    */
  void pgpProvision(int sessionID, string username, string passphrase, string deviceName);

  /**
    accountDelete is for devel/testing to delete the current user's account.
    */
  void accountDelete(int sessionID);
}
