From a866bc4397132da5f0314ca8fa1fa0e777e41226 Mon Sep 17 00:00:00 2001 From: Yaroslav Moria <5eeman@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:27:00 +0100 Subject: [PATCH] Fixed onchain claims fetch use case. --- .../fetch_onchain_claims_use_case.dart | 47 ++++-------------- .../identity_repository_impl.dart | 9 ++++ .../repositories/identity_repository.dart | 5 ++ lib/sdk/di/injector.config.dart | 49 +++++++++---------- lib/sdk/iden3comm.dart | 2 +- 5 files changed, 48 insertions(+), 64 deletions(-) diff --git a/lib/iden3comm/domain/use_cases/fetch_onchain_claims_use_case.dart b/lib/iden3comm/domain/use_cases/fetch_onchain_claims_use_case.dart index 0d12ce4b..06160662 100644 --- a/lib/iden3comm/domain/use_cases/fetch_onchain_claims_use_case.dart +++ b/lib/iden3comm/domain/use_cases/fetch_onchain_claims_use_case.dart @@ -7,7 +7,6 @@ import 'package:polygonid_flutter_sdk/common/domain/error_exception.dart'; import 'package:polygonid_flutter_sdk/common/domain/use_cases/get_env_use_case.dart'; import 'package:polygonid_flutter_sdk/common/domain/use_cases/get_selected_chain_use_case.dart'; import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart'; -import 'package:polygonid_flutter_sdk/credential/domain/use_cases/cache_credential_use_case.dart'; import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/request/base.dart'; import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/request/onchain_offer_iden3_message_entity.dart'; import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/interaction/interaction_entity.dart'; @@ -17,12 +16,10 @@ import 'package:polygonid_flutter_sdk/iden3comm/domain/use_cases/check_profile_a import 'package:polygonid_flutter_sdk/iden3comm/domain/use_cases/fetch_onchain_claim_use_case.dart'; import 'package:polygonid_flutter_sdk/identity/data/data_sources/local_contract_files_data_source.dart'; 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/constants.dart'; 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/credential/domain/use_cases/save_claims_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'; @@ -32,14 +29,14 @@ import 'package:web3dart/web3dart.dart'; class FetchOnchainClaimsParam { final String contractAddress; final String genesisDid; - final BigInt profileNonce; + final BigInt? profileNonce; final String privateKey; final String? chainId; FetchOnchainClaimsParam({ required this.contractAddress, required this.genesisDid, - required this.profileNonce, + this.profileNonce, required this.privateKey, this.chainId, }); @@ -52,10 +49,7 @@ class FetchOnchainClaimsUseCase _checkProfileAndDidCurrentEnvUseCase; final GetEnvUseCase _getEnvUseCase; final GetSelectedChainUseCase _getSelectedChainUseCase; - final GetDidIdentifierUseCase _getDidIdentifierUseCase; final GetDidUseCase _getDidUseCase; - final SaveClaimsUseCase _saveClaimsUseCase; - final CacheCredentialUseCase _cacheCredentialUseCase; final LocalContractFilesDataSource _localContractFilesDataSource; final IdentityRepository _identityRepository; final DidProfileInfoRepository _didProfileInfoRepository; @@ -66,10 +60,7 @@ class FetchOnchainClaimsUseCase this._checkProfileAndDidCurrentEnvUseCase, this._getEnvUseCase, this._getSelectedChainUseCase, - this._getDidIdentifierUseCase, this._getDidUseCase, - this._saveClaimsUseCase, - this._cacheCredentialUseCase, this._localContractFilesDataSource, this._identityRepository, this._didProfileInfoRepository, @@ -90,26 +81,12 @@ class FetchOnchainClaimsUseCase param: CheckProfileAndDidCurrentEnvParam( did: param.genesisDid, privateKey: param.privateKey, - profileNonce: param.profileNonce, - ), - ); - - final env = await _getEnvUseCase.execute(); - final chain = await _getSelectedChainUseCase.execute(); - - final profileDid = await _getDidIdentifierUseCase.execute( - param: GetDidIdentifierParam.withPrivateKey( - privateKey: param.privateKey, - blockchain: chain.blockchain, - network: chain.network, - profileNonce: param.profileNonce, - method: chain.method, + profileNonce: param.profileNonce ?? GENESIS_PROFILE_NONCE, ), ); final claims = await _fetchOnchainClaims( param.contractAddress, - profileDid, param, ); @@ -124,7 +101,6 @@ class FetchOnchainClaimsUseCase Future> _fetchOnchainClaims( String contractAddress, - String profileDid, FetchOnchainClaimsParam param, ) async { final env = await _getEnvUseCase.execute(); @@ -179,23 +155,20 @@ class FetchOnchainClaimsUseCase ); BigInt nonce; - if (info.containsKey("privateProfileNonce")) { + if (param.profileNonce != null) { + nonce = param.profileNonce!; + } else if (info.containsKey("privateProfileNonce")) { nonce = BigInt.parse(info["privateProfileNonce"] as String); } else { nonce = GENESIS_PROFILE_NONCE; } - final did = await _getDidIdentifierUseCase.execute( - param: GetDidIdentifierParam.withPrivateKey( - privateKey: param.privateKey, - blockchain: chain.blockchain, - network: chain.network, - profileNonce: nonce, - method: chain.method, - ), + final profileDid = _identityRepository.getPrivateProfileForGenesisDid( + genesisDid: param.genesisDid, + profileNonce: nonce, ); - final didEntity = await _getDidUseCase.execute(param: did); + final didEntity = await _getDidUseCase.execute(param: profileDid); final userId = await _identityRepository.convertIdToBigInt(id: didEntity.identifier); diff --git a/lib/identity/data/repositories/identity_repository_impl.dart b/lib/identity/data/repositories/identity_repository_impl.dart index 9d3d352f..c175b2d0 100644 --- a/lib/identity/data/repositories/identity_repository_impl.dart +++ b/lib/identity/data/repositories/identity_repository_impl.dart @@ -254,6 +254,15 @@ class IdentityRepositoryImpl extends IdentityRepository { } } + @override + String getPrivateProfileForGenesisDid({ + required String genesisDid, + required BigInt profileNonce, + }) { + return _libPolygonIdCoreIdentityDataSource.calculateProfileId( + genesisDid, profileNonce); + } + @override Future convertIdToBigInt({required String id}) { String idBigInt = _libPolygonIdCoreIdentityDataSource.genesisIdToBigInt(id); diff --git a/lib/identity/domain/repositories/identity_repository.dart b/lib/identity/domain/repositories/identity_repository.dart index afb1f6ab..d4591894 100644 --- a/lib/identity/domain/repositories/identity_repository.dart +++ b/lib/identity/domain/repositories/identity_repository.dart @@ -35,6 +35,11 @@ abstract class IdentityRepository { String? method, }); + String getPrivateProfileForGenesisDid({ + required String genesisDid, + required BigInt profileNonce, + }); + // RHS Future> getNonRevProof( {required String identityState, diff --git a/lib/sdk/di/injector.config.dart b/lib/sdk/di/injector.config.dart index fa3f8681..7f7bb7aa 100644 --- a/lib/sdk/di/injector.config.dart +++ b/lib/sdk/di/injector.config.dart @@ -420,6 +420,17 @@ extension GetItInjectableX on _i174.GetIt { final databaseModule = _$DatabaseModule(); final encryptionModule = _$EncryptionModule(); final repositoriesModule = _$RepositoriesModule(); + gh.factory<_i318.WitnessAuthV2Lib>(() => _i318.WitnessAuthV2Lib()); + gh.factory<_i602.WitnessV3OnchainLib>(() => _i602.WitnessV3OnchainLib()); + gh.factory<_i184.WitnessSigV2Lib>(() => _i184.WitnessSigV2Lib()); + gh.factory<_i695.WitnessV3Lib>(() => _i695.WitnessV3Lib()); + gh.factory<_i896.WitnessLinkedMultiQuery10>( + () => _i896.WitnessLinkedMultiQuery10()); + gh.factory<_i68.WitnessSigV2OnchainLib>( + () => _i68.WitnessSigV2OnchainLib()); + gh.factory<_i569.WitnessMTPV2Lib>(() => _i569.WitnessMTPV2Lib()); + gh.factory<_i436.WitnessMTPV2OnchainLib>( + () => _i436.WitnessMTPV2OnchainLib()); gh.factory<_i502.ProverLibWrapper>(() => _i502.ProverLibWrapper()); gh.factory<_i1039.WitnessIsolatesWrapper>( () => _i1039.WitnessIsolatesWrapper()); @@ -475,17 +486,6 @@ extension GetItInjectableX on _i174.GetIt { () => _i284.Iden3MessageTypeMapper()); gh.factory<_i968.GetFetchRequestsUseCase>( () => _i968.GetFetchRequestsUseCase()); - gh.factory<_i318.WitnessAuthV2Lib>(() => _i318.WitnessAuthV2Lib()); - gh.factory<_i602.WitnessV3OnchainLib>(() => _i602.WitnessV3OnchainLib()); - gh.factory<_i184.WitnessSigV2Lib>(() => _i184.WitnessSigV2Lib()); - gh.factory<_i695.WitnessV3Lib>(() => _i695.WitnessV3Lib()); - gh.factory<_i896.WitnessLinkedMultiQuery10>( - () => _i896.WitnessLinkedMultiQuery10()); - gh.factory<_i68.WitnessSigV2OnchainLib>( - () => _i68.WitnessSigV2OnchainLib()); - gh.factory<_i569.WitnessMTPV2Lib>(() => _i569.WitnessMTPV2Lib()); - gh.factory<_i436.WitnessMTPV2OnchainLib>( - () => _i436.WitnessMTPV2OnchainLib()); gh.lazySingleton<_i920.ProofGenerationStepsStreamManager>( () => _i920.ProofGenerationStepsStreamManager()); gh.lazySingleton<_i267.StacktraceManager>(() => _i267.StacktraceManager()); @@ -1031,6 +1031,18 @@ extension GetItInjectableX on _i174.GetIt { await getAsync<_i732.GetDidIdentifierUseCase>(), gh<_i267.StacktraceManager>(), )); + gh.factoryAsync<_i146.FetchOnchainClaimsUseCase>( + () async => _i146.FetchOnchainClaimsUseCase( + await getAsync<_i1054.FetchOnchainClaimUseCase>(), + await getAsync<_i505.CheckProfileAndDidCurrentEnvUseCase>(), + await getAsync<_i626.GetEnvUseCase>(), + await getAsync<_i737.GetSelectedChainUseCase>(), + await getAsync<_i78.GetDidUseCase>(), + gh<_i22.LocalContractFilesDataSource>(), + await getAsync<_i26.IdentityRepository>(), + gh<_i258.DidProfileInfoRepository>(), + gh<_i267.StacktraceManager>(), + )); gh.factoryAsync<_i675.GetCurrentEnvDidIdentifierUseCase>( () async => _i675.GetCurrentEnvDidIdentifierUseCase( await getAsync<_i737.GetSelectedChainUseCase>(), @@ -1051,21 +1063,6 @@ extension GetItInjectableX on _i174.GetIt { await getAsync<_i484.FetchIdentityStateUseCase>(), gh<_i267.StacktraceManager>(), )); - gh.factoryAsync<_i146.FetchOnchainClaimsUseCase>( - () async => _i146.FetchOnchainClaimsUseCase( - await getAsync<_i1054.FetchOnchainClaimUseCase>(), - await getAsync<_i505.CheckProfileAndDidCurrentEnvUseCase>(), - await getAsync<_i626.GetEnvUseCase>(), - await getAsync<_i737.GetSelectedChainUseCase>(), - await getAsync<_i732.GetDidIdentifierUseCase>(), - await getAsync<_i78.GetDidUseCase>(), - gh<_i635.SaveClaimsUseCase>(), - gh<_i348.CacheCredentialUseCase>(), - gh<_i22.LocalContractFilesDataSource>(), - await getAsync<_i26.IdentityRepository>(), - gh<_i258.DidProfileInfoRepository>(), - gh<_i267.StacktraceManager>(), - )); gh.factoryAsync<_i266.CreateProfilesUseCase>( () async => _i266.CreateProfilesUseCase( await getAsync<_i166.GetPublicKeysUseCase>(), diff --git a/lib/sdk/iden3comm.dart b/lib/sdk/iden3comm.dart index 60a062eb..8650a13e 100644 --- a/lib/sdk/iden3comm.dart +++ b/lib/sdk/iden3comm.dart @@ -403,7 +403,7 @@ class Iden3comm implements PolygonIdSdkIden3comm { param: FetchOnchainClaimsParam( contractAddress: contractAddress, genesisDid: genesisDid, - profileNonce: profileNonce ?? GENESIS_PROFILE_NONCE, + profileNonce: profileNonce, privateKey: privateKey, chainId: chainId, ),