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) {
    if (SSSS.looksLikeRecoveryKey(keyOrPassphrase)) {
      try {
        await unlock(recoveryKey: keyOrPassphrase, postUnlock: postUnlock);
        return;
      } catch (e) {
        if (!hasPassphrase) {
          rethrow;
        }
      }
    }
    if (hasPassphrase) {
      await unlock(passphrase: keyOrPassphrase, postUnlock: postUnlock);
    } else {
      throw InvalidPassphraseException(
        'Tried to unlock with passphrase while key does not have a passphrase',
      );
    }
    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(minutes: 2));
  } 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);
    }
  }
}