Skip to content

Commit

Permalink
feat: Migration code added for custom profile
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Dec 13, 2023
1 parent 7392c78 commit cce5a94
Showing 1 changed file with 92 additions and 4 deletions.
96 changes: 92 additions & 4 deletions lib/dashboard/profile/cubit/profile_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,99 @@ class ProfileCubit extends Cubit<ProfileState> {
final profileSettingJsonString =
await secureStorageProvider.get(SecureStorageKeys.profileSettings);

final ProfileSetting profileSetting = profileSettingJsonString == null
? ProfileSetting.initial()
: ProfileSetting.fromJson(
jsonDecode(profileSettingJsonString) as Map<String, dynamic>,
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<String, dynamic>;

// // 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<String, dynamic>,
);
}

final profileType =
(await secureStorageProvider.get(SecureStorageKeys.profileType)) ??
Expand Down

0 comments on commit cce5a94

Please sign in to comment.