Skip to content

Commit

Permalink
Merge pull request #454 from 0xPolygonID/feature/env_cache_folder
Browse files Browse the repository at this point in the history
Added cacheDir to env config.
  • Loading branch information
5eeman authored Nov 5, 2024
2 parents 09be3af + 3b08766 commit 1cca8b5
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 100 deletions.
16 changes: 16 additions & 0 deletions lib/common/domain/entities/env_config_entity.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import 'package:polygonid_flutter_sdk/common/domain/entities/chain_config_entity.dart';
import 'package:polygonid_flutter_sdk/common/domain/entities/did_method_entity.dart';

/// https://github.com/0xPolygonID/c-polygonid?tab=readme-ov-file#configuration
class EnvConfigEntity {
final String ipfsNodeUrl;
final Map<String, ChainConfigEntity> chainConfigs;
final List<DidMethodEntity> didMethods;
final String? cacheDir;

EnvConfigEntity({
required this.ipfsNodeUrl,
this.chainConfigs = const {},
this.didMethods = const [],
this.cacheDir,
});

factory EnvConfigEntity.fromJson(Map<String, dynamic> json) {
return EnvConfigEntity(
ipfsNodeUrl: json['ipfsNodeUrl'],
chainConfigs: (json['chainConfigs'] as Map<dynamic, dynamic>).map(
(key, value) => MapEntry(key, ChainConfigEntity.fromJson(value))),
didMethods: (json['didMethods'] as List<dynamic>)
.map((value) => DidMethodEntity.fromJson(value))
.toList(),
cacheDir: json['cacheDir'],
);
}

Map<String, dynamic> toJson() {
return {
'ipfsNodeUrl': ipfsNodeUrl,
'chainConfigs':
chainConfigs.map((key, value) => MapEntry(key, value.toJson())),
'didMethods': didMethods.map((e) => e.toJson()).toList(),
'cacheDir': cacheDir,
};
}
}
16 changes: 12 additions & 4 deletions lib/common/domain/entities/env_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class EnvEntity {
final String? pinataGateway;
final String? pinataGatewayToken;

final String? cacheDir;

EnvEntity._({
required this.pushUrl,
required this.ipfsUrl,
Expand All @@ -22,6 +24,7 @@ class EnvEntity {
this.stacktraceEncryptionKey,
this.pinataGateway,
this.pinataGatewayToken,
this.cacheDir,
});

EnvEntity({
Expand All @@ -32,6 +35,7 @@ class EnvEntity {
this.stacktraceEncryptionKey,
this.pinataGateway,
this.pinataGatewayToken,
this.cacheDir,
});

factory EnvEntity.fromJson(Map<String, dynamic> json) {
Expand All @@ -50,6 +54,7 @@ class EnvEntity {
stacktraceEncryptionKey: json['stacktraceEncryptionKey'],
pinataGateway: json['pinataGateway'],
pinataGatewayToken: json['pinataGatewayToken'],
cacheDir: json['cacheDir'],
);
}

Expand All @@ -67,11 +72,12 @@ class EnvEntity {
'stacktraceEncryptionKey': stacktraceEncryptionKey,
'pinataGateway': pinataGateway,
'pinataGatewayToken': pinataGatewayToken,
'cacheDir': cacheDir,
};

@override
String toString() {
return 'EnvEntity{pushUrl: $pushUrl, ipfsUrl: $ipfsUrl, chainConfig: $chainConfigs, didMethods: $didMethods, stacktraceEncryptionKey: $stacktraceEncryptionKey, , pinataGateway: $pinataGateway, pinataGatewayToken: $pinataGatewayToken}';
return 'EnvEntity{pushUrl: $pushUrl, ipfsUrl: $ipfsUrl, chainConfig: $chainConfigs, didMethods: $didMethods, stacktraceEncryptionKey: $stacktraceEncryptionKey, , pinataGateway: $pinataGateway, pinataGatewayToken: $pinataGatewayToken, cacheDir: $cacheDir}';
}

@override
Expand All @@ -84,7 +90,8 @@ class EnvEntity {
listEquals(didMethods, other.didMethods) &&
stacktraceEncryptionKey == other.stacktraceEncryptionKey &&
pinataGateway == other.pinataGateway &&
pinataGatewayToken == other.pinataGatewayToken;
pinataGatewayToken == other.pinataGatewayToken &&
cacheDir == other.cacheDir;

@override
int get hashCode => runtimeType.hashCode;
Expand All @@ -101,6 +108,7 @@ class EnvEntity {
String? stacktraceEncryptionKey,
String? pinataGateway,
String? pinataGatewayToken,
String? cacheDir,
}) {
return EnvEntity._(
pushUrl: pushUrl ?? this.pushUrl,
Expand All @@ -111,16 +119,16 @@ class EnvEntity {
stacktraceEncryptionKey ?? this.stacktraceEncryptionKey,
pinataGateway: pinataGateway ?? this.pinataGateway,
pinataGatewayToken: pinataGatewayToken ?? this.pinataGatewayToken,
cacheDir: cacheDir ?? this.cacheDir,
);
}
}

extension EnvEntityExtension on EnvEntity {
EnvConfigEntity get config {
return EnvConfigEntity(
ipfsNodeUrl: ipfsUrl,
chainConfigs: chainConfigs,
didMethods: didMethods,
cacheDir: cacheDir,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'dart:convert';

import 'package:polygonid_flutter_sdk/common/domain/entities/env_config_entity.dart';
import 'package:polygonid_flutter_sdk/common/domain/use_case.dart';
import 'package:polygonid_flutter_sdk/credential/domain/entities/claim_entity.dart';
import 'package:polygonid_flutter_sdk/credential/domain/repositories/credential_repository.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';

class CacheCredentialParam {
final ClaimEntity credential;
final ConfigParam? config;
final EnvConfigEntity? config;

CacheCredentialParam({
required this.credential,
Expand Down
10 changes: 3 additions & 7 deletions lib/credential/domain/use_cases/cache_credentials_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:polygonid_flutter_sdk/common/domain/domain_logger.dart';
import 'package:polygonid_flutter_sdk/common/domain/entities/env_config_entity.dart';
import 'package:polygonid_flutter_sdk/common/domain/use_cases/get_env_use_case.dart';
import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart';
import 'package:polygonid_flutter_sdk/credential/domain/entities/claim_entity.dart';
import 'package:polygonid_flutter_sdk/credential/domain/use_cases/cache_credential_use_case.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';

class CacheCredentialsUseCase {
final CacheCredentialUseCase _cacheCredentialUseCase;
Expand All @@ -18,16 +18,12 @@ class CacheCredentialsUseCase {

Future<void> execute({
required List<ClaimEntity> credentials,
ConfigParam? configParam,
EnvConfigEntity? configParam,
}) async {
// if we don't have the configParam, we get it from the environment
if (configParam == null) {
final env = await _getEnvUseCase.execute();
configParam = ConfigParam(
ipfsNodeURL: env.ipfsUrl,
chainConfigs: env.chainConfigs,
didMethods: env.didMethods,
);
configParam = env.config;
}

for (var credential in credentials) {
Expand Down
3 changes: 1 addition & 2 deletions lib/iden3comm/authenticate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import 'package:polygonid_flutter_sdk/identity/domain/repositories/smt_repositor
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/get_did_identifier_use_case.dart';
import 'package:polygonid_flutter_sdk/proof/data/data_sources/circuits_files_data_source.dart';
import 'package:polygonid_flutter_sdk/proof/data/data_sources/gist_mtproof_data_source.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/gist_mtproof_entity.dart';
import 'package:polygonid_flutter_sdk/proof/domain/entities/circuit_data_entity.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/mtproof_dto.dart';
Expand Down Expand Up @@ -428,7 +427,7 @@ class Authenticate {
);
}

config = ConfigParam.fromEnv(env).toJson();
config = env.config.toJson();

List<String> splittedDid = genesisDid.split(":");
String id = splittedDid[4];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/reque
import 'package:polygonid_flutter_sdk/iden3comm/domain/use_cases/get_auth_token_use_case.dart';
import 'package:polygonid_flutter_sdk/iden3comm/domain/use_cases/get_fetch_requests_use_case.dart';
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/get_did_use_case.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';
import 'package:polygonid_flutter_sdk/sdk/di/injector.dart';
import 'package:web3dart/crypto.dart';
import 'package:web3dart/web3dart.dart';
Expand Down Expand Up @@ -134,12 +133,7 @@ class FetchAndSaveClaimsUseCase
_stacktraceManager.addTrace(
"[FetchAndSaveClaimsUseCase] All claims have been saved: claimsLength ${claims.length}");

final config = ConfigParam(
ipfsNodeURL: env.ipfsUrl,
chainConfigs: env.chainConfigs,
didMethods: env.didMethods,
);

final config = env.config;
for (final claim in claims) {
// cache claim
try {
Expand Down Expand Up @@ -251,7 +245,7 @@ class FetchAndSaveClaimsUseCase
final issuerIdInt = await getIssuerId.getId();
final issuerDid = (await _identityRepository.describeId(
id: issuerIdInt,
config: ConfigParam.fromEnv(env),
config: env.config,
))
.did;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'package:polygonid_flutter_sdk/identity/data/data_sources/local_contract_
import 'package:polygonid_flutter_sdk/identity/domain/repositories/identity_repository.dart';
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/get_did_identifier_use_case.dart';
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/get_did_use_case.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';
import 'package:polygonid_flutter_sdk/sdk/di/injector.dart';
import 'package:web3dart/crypto.dart';
import 'package:web3dart/web3dart.dart';
Expand Down Expand Up @@ -210,7 +209,7 @@ class FetchCredentialsUseCase {
final issuerIdInt = await getIssuerId.getId();
final issuerDid = (await _identityRepository.describeId(
id: issuerIdInt,
config: ConfigParam.fromEnv(env),
config: env.config,
))
.did;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'package:polygonid_flutter_sdk/credential/domain/entities/claim_entity.da
import 'package:polygonid_flutter_sdk/iden3comm/data/data_sources/remote_iden3comm_data_source.dart';
import 'package:polygonid_flutter_sdk/iden3comm/domain/exceptions/iden3comm_exceptions.dart';
import 'package:polygonid_flutter_sdk/identity/data/data_sources/local_contract_files_data_source.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';
import 'package:polygonid_flutter_sdk/sdk/di/injector.dart';
import 'package:web3dart/crypto.dart';
import 'package:web3dart/web3dart.dart';
Expand Down Expand Up @@ -116,7 +115,7 @@ class FetchOnchainClaimUseCase
issuerDID: param.issuerDid,
hexdata: rawCredential,
version: param.adapterVersion,
config: ConfigParam.fromEnv(env).toJsonString(),
config: jsonEncode(env.config),
);

final claimJson = jsonDecode(rawClaim);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'package:polygonid_flutter_sdk/common/domain/domain_logger.dart';
import 'package:polygonid_flutter_sdk/common/domain/use_case.dart';
import 'package:polygonid_flutter_sdk/credential/domain/entities/claim_entity.dart';
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/get_did_use_case.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';
import 'package:polygonid_flutter_sdk/sdk/di/injector.dart';
import 'package:web3dart/crypto.dart';
import 'package:web3dart/web3dart.dart';
Expand Down Expand Up @@ -138,7 +137,7 @@ class FetchOnchainClaimsUseCase
final issuerIdInt = await getIssuerId.getId();
final issuerDid = (await _identityRepository.describeId(
id: issuerIdInt,
config: ConfigParam.fromEnv(env),
config: env.config,
))
.did;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'package:polygonid_flutter_sdk/identity/domain/use_cases/get_identity_aut
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/get_latest_state_use_case.dart';
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/identity/get_identity_use_case.dart';
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/identity/sign_message_use_case.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';
import 'package:polygonid_flutter_sdk/proof/domain/entities/circuit_data_entity.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/gist_mtproof_entity.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/mtproof_dto.dart';
Expand Down Expand Up @@ -196,11 +195,7 @@ class GenerateIden3commProofUseCase

final envConfig = param.config;
if (envConfig != null) {
config = ConfigParam(
ipfsNodeURL: envConfig.ipfsNodeUrl,
chainConfigs: envConfig.chainConfigs,
didMethods: envConfig.didMethods,
).toJson();
config = envConfig.toJson();
_stacktraceManager.addTrace(
"[GenerateIden3commProofUseCase] AtomicQueryInputsConfigParam: success");
}
Expand Down
7 changes: 4 additions & 3 deletions lib/identity/data/repositories/identity_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:polygonid_flutter_sdk/identity/domain/entities/identity_entity.d
import 'package:polygonid_flutter_sdk/identity/domain/entities/rhs_node_entity.dart';
import 'package:polygonid_flutter_sdk/identity/domain/exceptions/identity_exceptions.dart';
import 'package:polygonid_flutter_sdk/identity/domain/repositories/identity_repository.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';
import 'package:poseidon/poseidon.dart';
import 'package:web3dart/crypto.dart';

Expand Down Expand Up @@ -265,8 +264,10 @@ class IdentityRepositoryImpl extends IdentityRepository {
}

@override
Future<IdDescription> describeId(
{required BigInt id, ConfigParam? config}) async {
Future<IdDescription> describeId({
required BigInt id,
EnvConfigEntity? config,
}) async {
final idDescriptionJson = _libPolygonIdCoreIdentityDataSource.describeId(
idAsInt: id.toString(),
config: config == null ? null : jsonEncode(config.toJson()),
Expand Down
4 changes: 2 additions & 2 deletions lib/identity/domain/repositories/identity_repository.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:polygonid_flutter_sdk/common/domain/entities/env_config_entity.dart';
import 'package:polygonid_flutter_sdk/identity/data/dtos/id_description.dart';
import 'package:polygonid_flutter_sdk/identity/domain/entities/node_entity.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';

import '../entities/identity_entity.dart';
import '../entities/rhs_node_entity.dart';
Expand Down Expand Up @@ -52,7 +51,8 @@ abstract class IdentityRepository {

Future<String> convertIdToBigInt({required String id});

Future<IdDescription> describeId({required BigInt id, ConfigParam? config});
Future<IdDescription> describeId(
{required BigInt id, EnvConfigEntity? config});

Future<RhsNodeEntity> getStateRoots({required String url});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:polygonid_flutter_sdk/common/domain/entities/env_entity.dart';
import 'package:polygonid_flutter_sdk/common/domain/use_cases/get_env_use_case.dart';
import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart';
import 'package:polygonid_flutter_sdk/identity/domain/use_cases/get_genesis_state_use_case.dart';
Expand Down
10 changes: 5 additions & 5 deletions lib/proof/data/data_sources/lib_pidcore_proof_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
import 'package:polygonid_flutter_sdk/common/domain/domain_logger.dart';
import 'package:polygonid_flutter_sdk/common/domain/entities/env_config_entity.dart';
import 'package:polygonid_flutter_sdk/common/domain/error_exception.dart';
import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart';
import 'package:polygonid_flutter_sdk/credential/data/dtos/claim_info_dto.dart';
import 'package:polygonid_flutter_sdk/identity/data/dtos/circuit_type.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_config_param.dart';
import 'package:polygonid_flutter_sdk/proof/data/dtos/atomic_query_inputs_param.dart';
import 'package:polygonid_flutter_sdk/proof/domain/exceptions/proof_generation_exceptions.dart';
import 'package:polygonid_flutter_sdk/proof/libs/polygonidcore/pidcore_proof.dart';

class ComputeAtomicQueryInputs {
final AtomicQueryInputsParam param;
final ConfigParam? configParam;
final EnvConfigEntity? configParam;

ComputeAtomicQueryInputs({
required this.param,
Expand All @@ -39,7 +39,7 @@ class LibPolygonIdCoreWrapper {

Future<String> getProofInputs(
AtomicQueryInputsParam atomicQueryInputsParam,
ConfigParam? atomicQueryInputsConfigParam,
EnvConfigEntity? atomicQueryInputsConfigParam,
) async {
ComputeAtomicQueryInputs param = ComputeAtomicQueryInputs(
param: atomicQueryInputsParam,
Expand Down Expand Up @@ -245,9 +245,9 @@ class LibPolygonIdCoreProofDataSource {
_stacktraceManager.addTrace(
"[LibPolygonIdCoreProofDataSource][MainFlow]getProofInputs input param: ${jsonEncode(inputParam.toJson())}");

ConfigParam? configParam;
EnvConfigEntity? configParam;
if (config != null) {
configParam = ConfigParam.fromJson(config);
configParam = EnvConfigEntity.fromJson(config);

logger().i(
"[LibPolygonIdCoreProofDataSource][MainFlow]getProofInputs config param: ${jsonEncode(inputParam.toJson())}");
Expand Down
Loading

0 comments on commit 1cca8b5

Please sign in to comment.