diff --git a/lib/app/shared/enum/type/did_key_type.dart b/lib/app/shared/enum/type/did_key_type.dart index 5514a3deb..36cd62540 100644 --- a/lib/app/shared/enum/type/did_key_type.dart +++ b/lib/app/shared/enum/type/did_key_type.dart @@ -19,11 +19,11 @@ extension DidKeyTypeX on DidKeyType { String getTitle(AppLocalizations l10n) { switch (this) { case DidKeyType.secp256k1: - return l10n.manageKeyDecentralizedIDSecp256k1; + return l10n.keyDecentralizedIDSecp256k1; case DidKeyType.p256: return l10n.keyDecentralizedIDP256; case DidKeyType.ebsiv3: - return l10n.manageEbsiV3DecentralizedId; + return l10n.ebsiV3DecentralizedId; case DidKeyType.jwkP256: return l10n.jwkDecentralizedIDP256; } diff --git a/lib/app/shared/helper_functions/helper_functions.dart b/lib/app/shared/helper_functions/helper_functions.dart index 5e991c11f..f87732674 100644 --- a/lib/app/shared/helper_functions/helper_functions.dart +++ b/lib/app/shared/helper_functions/helper_functions.dart @@ -252,22 +252,16 @@ Future getPrivateKey({ }) async { late String storageKey; - if (didKeyType == DidKeyType.secp256k1) { - if (oidc4vc == null) throw Exception(); - final mnemonic = await secureStorage.get(SecureStorageKeys.ssiMnemonic); - final index = getIndexValue(isEBSIV3: true); - final key = await oidc4vc.privateKeyFromMnemonic( - mnemonic: mnemonic!, - indexValue: index, - ); - return key; - } - - /// for other than DidKeyType.secp256k1 - switch (didKeyType) { case DidKeyType.secp256k1: - throw Exception(); + if (oidc4vc == null) throw Exception(); + final mnemonic = await secureStorage.get(SecureStorageKeys.ssiMnemonic); + final index = getIndexValue(isEBSIV3: true); + final key = await oidc4vc.privateKeyFromMnemonic( + mnemonic: mnemonic!, + indexValue: index, + ); + return key; case DidKeyType.p256: storageKey = SecureStorageKeys.p256PrivateKey; @@ -277,10 +271,11 @@ Future getPrivateKey({ storageKey = SecureStorageKeys.p256PrivateKey3; } + /// return key if it is already created final String? p256PrivateKey = await secureStorage.get(storageKey); + if (p256PrivateKey != null) return p256PrivateKey.replaceAll('=', ''); - if (p256PrivateKey != null) return p256PrivateKey; - + /// create key if it is not created final jwk = JsonWebKey.generate('ES256'); final json = jwk.toJson(); @@ -290,9 +285,11 @@ Future getPrivateKey({ json.entries.toList()..sort((e1, e2) => e1.key.compareTo(e2.key)), )..remove('keyOperations'); - await secureStorage.set(storageKey, jsonEncode(sortedJwk)); + final newKey = jsonEncode(sortedJwk).replaceAll('=', ''); + + await secureStorage.set(storageKey, newKey); - return jsonEncode(sortedJwk); + return newKey; } DidKeyType? getDidKeyFromString(String? didKeyTypeString) { @@ -444,7 +441,7 @@ Future<(String, String)> getDidAndKid({ final List prefixByteList = [0xd1, 0xd6, 0x03]; final List prefix = prefixByteList.map((byte) => byte).toList(); - final encodedData = sortedPublcJwk(private); + final encodedData = sortedPublcJwkBytes(private); final encodedAddress = Base58Encode([...prefix, ...encodedData]); did = 'did:key:z$encodedAddress'; @@ -452,13 +449,17 @@ Future<(String, String)> getDidAndKid({ kid = '$did#$lastPart'; case DidKeyType.jwkP256: final private = jsonDecode(privateKey) as Map; - final base64EncodedJWK = base64UrlEncode(utf8.encode(private.toString())); + + final encodedData = sortedPublcJwkBytes(private); + + final base64EncodedJWK = base64UrlEncode(encodedData); did = 'did:jwk:$base64EncodedJWK'; kid = '$did#0'; case DidKeyType.p256: case DidKeyType.secp256k1: if (didKitProvider == null) throw Exception(); + const didMethod = AltMeStrings.defaultDIDMethod; did = didKitProvider.keyToDID(didMethod, privateKey); kid = await didKitProvider.keyToVerificationMethod(didMethod, privateKey); @@ -502,7 +503,7 @@ Future<(String, String)> fetchDidAndKid({ return (did, kid); } -List sortedPublcJwk(Map privateKey) { +List sortedPublcJwkBytes(Map privateKey) { final publicJWK = Map.of(privateKey)..removeWhere((key, value) => key == 'd'); /// we use crv P-256K in the rest of the package to ensure compatibility diff --git a/lib/dashboard/drawer/ssi/manage_did/cubit/did_private_key_cubit.dart b/lib/dashboard/drawer/ssi/manage_did/cubit/did_private_key_cubit.dart index a0b4c2438..f9cd996be 100644 --- a/lib/dashboard/drawer/ssi/manage_did/cubit/did_private_key_cubit.dart +++ b/lib/dashboard/drawer/ssi/manage_did/cubit/did_private_key_cubit.dart @@ -12,6 +12,6 @@ class DIDPrivateKeyCubit extends Cubit { Future initialize() async { final key = await secureStorageProvider.get(SecureStorageKeys.ssiKey) ?? '...'; - emit(key); + emit(key.replaceAll('=', '')); } } diff --git a/lib/dashboard/drawer/ssi/manage_did/view/did_edDSA/manage_did_ed_dsa_page.dart b/lib/dashboard/drawer/ssi/manage_did/view/did_edDSA/manage_did_ed_dsa_page.dart index 70aea76f0..8803c01ba 100644 --- a/lib/dashboard/drawer/ssi/manage_did/view/did_edDSA/manage_did_ed_dsa_page.dart +++ b/lib/dashboard/drawer/ssi/manage_did/view/did_edDSA/manage_did_ed_dsa_page.dart @@ -20,7 +20,7 @@ class ManageDIDEdDSAPage extends StatelessWidget { final l10n = context.l10n; final did = context.read().state.did ?? '...'; return BasePage( - title: l10n.manageKeyDecentralizedIdEdSA, + title: l10n.keyDecentralizedIdEdSA, titleAlignment: Alignment.topCenter, scrollView: false, titleLeading: const BackLeadingButton(), diff --git a/lib/dashboard/drawer/ssi/manage_did/view/did_menu.dart b/lib/dashboard/drawer/ssi/manage_did/view/did_menu.dart index 52db2d033..1b25a889f 100644 --- a/lib/dashboard/drawer/ssi/manage_did/view/did_menu.dart +++ b/lib/dashboard/drawer/ssi/manage_did/view/did_menu.dart @@ -48,7 +48,7 @@ class DidView extends StatelessWidget { height: Sizes.spaceSmall, ), DrawerItem( - title: l10n.manageKeyDecentralizedIdEdSA, + title: l10n.keyDecentralizedIdEdSA, onTap: () { Navigator.of(context) .push(ManageDIDEdDSAPage.route()); diff --git a/lib/dashboard/drawer/ssi/manage_did/view/did_polygon_id/manage_did_polygon_id_page.dart b/lib/dashboard/drawer/ssi/manage_did/view/did_polygon_id/manage_did_polygon_id_page.dart index 8baea4720..ab0174c63 100644 --- a/lib/dashboard/drawer/ssi/manage_did/view/did_polygon_id/manage_did_polygon_id_page.dart +++ b/lib/dashboard/drawer/ssi/manage_did/view/did_polygon_id/manage_did_polygon_id_page.dart @@ -54,7 +54,7 @@ class ManageDidPolygonIdPage extends StatelessWidget { Widget build(BuildContext context) { final l10n = context.l10n; return BasePage( - title: l10n.managePolygonIdDecentralizedId, + title: l10n.polygonIdDecentralizedId, titleAlignment: Alignment.topCenter, scrollView: false, titleLeading: const BackLeadingButton(), diff --git a/lib/dashboard/drawer/ssi/manage_did/view/other_did/manage_other_did_page.dart b/lib/dashboard/drawer/ssi/manage_did/view/other_did/manage_other_did_page.dart index 28b9fbc5b..2cb8a9593 100644 --- a/lib/dashboard/drawer/ssi/manage_did/view/other_did/manage_other_did_page.dart +++ b/lib/dashboard/drawer/ssi/manage_did/view/other_did/manage_other_did_page.dart @@ -51,7 +51,7 @@ class _ManageDidEbsiPageState extends State { Widget build(BuildContext context) { final l10n = context.l10n; return BasePage( - title: l10n.manageEbsiV3DecentralizedId, + title: l10n.decentralizedIDKey, titleAlignment: Alignment.topCenter, scrollView: false, titleLeading: const BackLeadingButton(), diff --git a/lib/dashboard/drawer/ssi/manage_did/view/other_did/other_did_private_key_page.dart b/lib/dashboard/drawer/ssi/manage_did/view/other_did/other_did_private_key_page.dart index ae7802688..c73a2d68b 100644 --- a/lib/dashboard/drawer/ssi/manage_did/view/other_did/other_did_private_key_page.dart +++ b/lib/dashboard/drawer/ssi/manage_did/view/other_did/other_did_private_key_page.dart @@ -73,7 +73,7 @@ class _OtherDidPrivateKeyPageState extends State final l10n = context.l10n; return BasePage( scrollView: false, - title: l10n.decentralizedIDKey, + title: widget.didKeyType.getTitle(l10n), titleAlignment: Alignment.topCenter, titleLeading: const BackLeadingButton(), secureScreen: true, diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index 09729fdb2..fabc1d323 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -804,10 +804,10 @@ "transactionDoneDialogDescription": "It can take a few minutes for the transfer to complete", "withdrawalFailedMessage": "The withdrawal from the account was unsuccessful", "credentialRequiredMessage": "You need to get those credentials in your wallet to acquire this card:", - "manageKeyDecentralizedIdEdSA": "Key Decentralized ID EdDSA", - "manageKeyDecentralizedIDSecp256k1": "Key Decentralized ID Secp256k1", - "managePolygonIdDecentralizedId": "Polygon Decentralized ID", - "manageEbsiV3DecentralizedId": "EBSI V3 Decentralized ID", + "keyDecentralizedIdEdSA": "Key Decentralized ID EdDSA", + "keyDecentralizedIDSecp256k1": "Key Decentralized ID Secp256k1", + "polygonIdDecentralizedId": "Polygon Decentralized ID", + "ebsiV3DecentralizedId": "EBSI V3 Decentralized ID", "requiredCredentialNotFoundTitle": "We are unable to find the credential\nyou need in Altme.", "requiredCredentialNotFoundSubTitle": "The required credential is not in your wallet", "requiredCredentialNotFoundDescription": "Please contact us on :", @@ -979,6 +979,7 @@ "dateOfRequest": "Date of Request", "keyDecentralizedIDP256": "Key Decentralized ID P-256", "jwkDecentralizedIDP256": "JWK Decentralized ID P-256", + "jwkDecentralizedIDP256": "JWK Decentralized ID P-256", "defaultDid": "Default DID", "selectOneOfTheDid": "Select one of the DIDs", "subjectSyntaxType": "Subject syntax type", diff --git a/lib/l10n/untranslated.json b/lib/l10n/untranslated.json index 4b29688f3..6903195c5 100644 --- a/lib/l10n/untranslated.json +++ b/lib/l10n/untranslated.json @@ -740,10 +740,10 @@ "transactionDoneDialogDescription", "withdrawalFailedMessage", "credentialRequiredMessage", - "manageKeyDecentralizedIdEdSA", - "manageKeyDecentralizedIDSecp256k1", - "managePolygonIdDecentralizedId", - "manageEbsiV3DecentralizedId", + "keyDecentralizedIdEdSA", + "keyDecentralizedIDSecp256k1", + "polygonIdDecentralizedId", + "ebsiV3DecentralizedId", "requiredCredentialNotFoundTitle", "requiredCredentialNotFoundSubTitle", "requiredCredentialNotFoundDescription", @@ -1648,10 +1648,10 @@ "transactionDoneDialogDescription", "withdrawalFailedMessage", "credentialRequiredMessage", - "manageKeyDecentralizedIdEdSA", - "manageKeyDecentralizedIDSecp256k1", - "managePolygonIdDecentralizedId", - "manageEbsiV3DecentralizedId", + "keyDecentralizedIdEdSA", + "keyDecentralizedIDSecp256k1", + "polygonIdDecentralizedId", + "ebsiV3DecentralizedId", "requiredCredentialNotFoundTitle", "requiredCredentialNotFoundSubTitle", "requiredCredentialNotFoundDescription", @@ -1859,10 +1859,10 @@ "saveBackupPolygonCredentialSubtitle", "creationDate", "altmeSupport", - "manageKeyDecentralizedIdEdSA", - "manageKeyDecentralizedIDSecp256k1", - "managePolygonIdDecentralizedId", - "manageEbsiV3DecentralizedId", + "keyDecentralizedIdEdSA", + "keyDecentralizedIDSecp256k1", + "polygonIdDecentralizedId", + "ebsiV3DecentralizedId", "requiredCredentialNotFoundTitle", "requiredCredentialNotFoundSubTitle", "requiredCredentialNotFoundDescription", @@ -2767,10 +2767,10 @@ "transactionDoneDialogDescription", "withdrawalFailedMessage", "credentialRequiredMessage", - "manageKeyDecentralizedIdEdSA", - "manageKeyDecentralizedIDSecp256k1", - "managePolygonIdDecentralizedId", - "manageEbsiV3DecentralizedId", + "keyDecentralizedIdEdSA", + "keyDecentralizedIDSecp256k1", + "polygonIdDecentralizedId", + "ebsiV3DecentralizedId", "requiredCredentialNotFoundTitle", "requiredCredentialNotFoundSubTitle", "requiredCredentialNotFoundDescription", diff --git a/packages/oidc4vc/lib/src/oidc4vc.dart b/packages/oidc4vc/lib/src/oidc4vc.dart index 317fd6b2c..445f259bd 100644 --- a/packages/oidc4vc/lib/src/oidc4vc.dart +++ b/packages/oidc4vc/lib/src/oidc4vc.dart @@ -72,10 +72,10 @@ class OIDC4VC { /// the same as secp256k1, but we are using secp256k1 now final jwk = { 'crv': 'secp256k1', - 'd': d, + 'd': d.replaceAll('=', ''), 'kty': 'EC', - 'x': x, - 'y': y, + 'x': x.replaceAll('=', ''), + 'y': y.replaceAll('=', ''), }; return jwk; }