initialize method

  1. @override
Future<void> initialize()
override

Subclasses should put any necessary post-construction async initialization in this method.

Implementation

@override
Future<void> initialize() async {
  try {
    if (!Hive.isAdapterRegistered(AtDataAdapter().typeId)) {
      Hive.registerAdapter(AtDataAdapter());
    }
    if (!Hive.isAdapterRegistered(AtMetaDataAdapter().typeId)) {
      Hive.registerAdapter(AtMetaDataAdapter());
    }
    if (!Hive.isAdapterRegistered(PublicKeyHashAdapter().typeId)) {
      Hive.registerAdapter(PublicKeyHashAdapter());
    }
    final secret = await _getHiveSecretFromFile(atSign, storagePath);
    await openBox(AtUtils.getShaForAtSign(atSign), hiveSecret: secret);
  } on Exception catch (e) {
    logger.severe('HiveAtKeyValueStore.initialize exception: $e');
    throw DataStoreException(
        'Exception initializing secondary keystore: ${e.toString()}');
  }
  await _initExpiryKeysCache();
}