unlock method

Future<void> unlock({
  1. String? passphrase,
  2. String? recoveryKey,
  3. String? keyOrPassphrase,
  4. bool postUnlock = true,
})

Implementation

Future<void> unlock(
    {String? passphrase,
    String? recoveryKey,
    String? keyOrPassphrase,
    bool postUnlock = true}) async {
  if (keyOrPassphrase != null) {
    try {
      await unlock(recoveryKey: keyOrPassphrase, postUnlock: postUnlock);
    } catch (_) {
      if (hasPassphrase) {
        await unlock(passphrase: keyOrPassphrase, postUnlock: postUnlock);
      } else {
        rethrow;
      }
    }
    return;
  } else if (passphrase != null) {
    if (!hasPassphrase) {
      throw InvalidPassphraseException(
          'Tried to unlock with passphrase while key does not have a passphrase');
    }
    privateKey = await Future.value(
      ssss.client.nativeImplementations.keyFromPassphrase(
        KeyFromPassphraseArgs(
          passphrase: passphrase,
          info: keyData.passphrase!,
        ),
      ),
    ).timeout(Duration(seconds: 10));
  } else if (recoveryKey != null) {
    privateKey = SSSS.decodeRecoveryKey(recoveryKey);
  } else {
    throw InvalidPassphraseException('Nothing specified');
  }
  // verify the validity of the key
  if (!await ssss.checkKey(privateKey!, keyData)) {
    privateKey = null;
    throw InvalidPassphraseException('Inalid key');
  }
  if (postUnlock) {
    try {
      await _postUnlock();
    } catch (e, s) {
      Logs().e('Error during post unlock', e, s);
    }
  }
}