From cce5a94cb2f3b9998236594a62612e1145c7b9fa Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Wed, 13 Dec 2023 16:26:12 +0545 Subject: [PATCH] feat: Migration code added for custom profile --- .../profile/cubit/profile_cubit.dart | 96 ++++++++++++++++++- 1 file changed, 92 insertions(+), 4 deletions(-) diff --git a/lib/dashboard/profile/cubit/profile_cubit.dart b/lib/dashboard/profile/cubit/profile_cubit.dart index ad58eafe2..4c83ed631 100644 --- a/lib/dashboard/profile/cubit/profile_cubit.dart +++ b/lib/dashboard/profile/cubit/profile_cubit.dart @@ -76,11 +76,99 @@ class ProfileCubit extends Cubit { final profileSettingJsonString = await secureStorageProvider.get(SecureStorageKeys.profileSettings); - final ProfileSetting profileSetting = profileSettingJsonString == null - ? ProfileSetting.initial() - : ProfileSetting.fromJson( - jsonDecode(profileSettingJsonString) as Map, + ProfileSetting profileSetting = ProfileSetting.initial(); + + /// migration - remove later + if (profileSettingJsonString == null) { + final customProfileBackupValue = await secureStorageProvider.get( + SecureStorageKeys.customProfileBackup, + ); + + if (customProfileBackupValue != null) { + try { + final customProfileBackup = + json.decode(customProfileBackupValue) as Map; + + // // didKeyType: customProfileBackup.didKeyType, + + var didKeyType = DidKeyType.p256; + + if (customProfileBackup.containsKey('didKeyType')) { + for (final value in DidKeyType.values) { + if (value.toString() == + customProfileBackup.containsKey('didKeyType').toString()) { + didKeyType = value; + } + } + } + + profileSetting = ProfileSetting( + blockchainOptions: BlockchainOptions.initial(), + generalOptions: GeneralOptions.empty(), + helpCenterOptions: HelpCenterOptions.initial(), + selfSovereignIdentityOptions: SelfSovereignIdentityOptions( + displayManageDecentralizedId: true, + displaySsiAdvancedSettings: true, + displayVerifiableDataRegistry: true, + oidv4vcProfile: 'custom', + customOidc4vcProfile: CustomOidc4VcProfile( + clientAuthentication: customProfileBackup + .containsKey('useBasicClientAuthentication') && + customProfileBackup['useBasicClientAuthentication'] == + 'true' + ? ClientAuthentication.clientSecretBasic + : ClientAuthentication.none, + credentialManifestSupport: customProfileBackup + .containsKey('enableCredentialManifestSupport') && + customProfileBackup['enableCredentialManifestSupport'] == + 'true', + cryptoHolderBinding: customProfileBackup + .containsKey('enableCryptographicHolderBinding') && + customProfileBackup['enableCryptographicHolderBinding'] == + 'true', + defaultDid: didKeyType, + oidc4vciDraft: OIDC4VCIDraftType.draft11, + oidc4vpDraft: OIDC4VPDraftType.draft18, + scope: + customProfileBackup.containsKey('enableScopeParameter') && + customProfileBackup['enableScopeParameter'] == 'true', + securityLevel: + customProfileBackup.containsKey('enableSecurity') && + customProfileBackup['enableSecurity'] == 'true' + ? SecurityLevel.high + : SecurityLevel.low, + siopv2Draft: SIOPV2DraftType.draft12, + subjectSyntaxeType: customProfileBackup + .containsKey('enableJWKThumbprint') && + customProfileBackup['enableJWKThumbprint'] == 'true' + ? SubjectSyntax.jwkThumbprint + : SubjectSyntax.did, + userPinDigits: customProfileBackup + .containsKey('enable4DigitPINCode') && + customProfileBackup['enable4DigitPINCode'] == 'true' + ? UserPinDigits.four + : UserPinDigits.six, + clientId: customProfileBackup.containsKey('clientId') + ? customProfileBackup['clientId'].toString() + : Parameters.clientId, + clientSecret: customProfileBackup.containsKey('clientSecret') + ? customProfileBackup['clientSecret'].toString() + : Parameters.clientSecret, + ), + ), + settingsMenu: SettingsMenu.initial(), + version: '', + walletSecurityOptions: WalletSecurityOptions.initial(), ); + } catch (e) { + profileSetting = ProfileSetting.initial(); + } + } + } else { + profileSetting = ProfileSetting.fromJson( + jsonDecode(profileSettingJsonString) as Map, + ); + } final profileType = (await secureStorageProvider.get(SecureStorageKeys.profileType)) ??