getMainKeyVaultStore method

  1. @override
Future<Either<WalletKeyException, VaultStore>> getMainKeyVaultStore(
  1. String name
)

Retrieves the main key vault store from disk.

name is the filepath of the VaultStore to retrieve.

Returns the VaultStore for the Topl Main Secret Key if it exists. If retrieving fails due to an underlying cause, returns a WalletKeyException.

Implementation

@override
Future<Either<WalletKeyException, VaultStore>> getMainKeyVaultStore(
    String name) async {
  if (await _storage.containsKey(key: name)) {
    return (await _storage.read(key: name)).withResult((res) {
      if (res == null) {
        return Either.left(WalletKeyException.decodeVaultStore(
            context: "Vault store {$name} is empty, thus undecodable"));
      }
      try {
        final vs = VaultStore.fromJson(jsonDecode(res));
        return vs.isRight
            ? Either.right(vs.right)
            : Either.left(WalletKeyException.decodeVaultStore(
                context: "Vault store {$name} is undecodable, ${vs.left}"));
      } catch (e) {
        return Either.left(WalletKeyException.decodeVaultStore(
            context: "Vault store {$name} is undecodable"));
      }
    });
  } else {
    return Either.left(
        WalletKeyException.vaultStoreDoesNotExist(context: name));
  }
}