diff --git a/lib/app/shared/helper_functions/helper_functions.dart b/lib/app/shared/helper_functions/helper_functions.dart index 366ce17c8..aac13374e 100644 --- a/lib/app/shared/helper_functions/helper_functions.dart +++ b/lib/app/shared/helper_functions/helper_functions.dart @@ -1216,6 +1216,13 @@ MessageHandler getMessageHandler(dynamic e) { 'error_description': 'Issue while restoring claims.', }, ); + } else if (stringException.contains('PUBLICKEYJWK_EXTRACTION_ERROR')) { + return ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Issue while restoring claims.', + }, + ); } else { return ResponseMessage( message: diff --git a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart index 6143269ea..c69bce946 100644 --- a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart +++ b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart @@ -1087,21 +1087,19 @@ class QRCodeScanCubit extends Cubit { ); } - if (publicKeyJwk != null) { - final VerificationType isVerified = await verifyEncodedData( - issuer: clientId, - jwtDecode: jwtDecode, - jwt: encodedData, - publicKeyJwk: publicKeyJwk, - ); + final VerificationType isVerified = await verifyEncodedData( + issuer: clientId, + jwtDecode: jwtDecode, + jwt: encodedData, + publicKeyJwk: publicKeyJwk, + ); - if (isVerified != VerificationType.verified) { - return emitError( - ResponseMessage( - message: ResponseString.RESPONSE_STRING_invalidRequest, - ), - ); - } + if (isVerified != VerificationType.verified) { + return emitError( + ResponseMessage( + message: ResponseString.RESPONSE_STRING_invalidRequest, + ), + ); } } diff --git a/packages/oidc4vc/lib/src/oidc4vc.dart b/packages/oidc4vc/lib/src/oidc4vc.dart index 17d0c40b2..6bef2cc7c 100644 --- a/packages/oidc4vc/lib/src/oidc4vc.dart +++ b/packages/oidc4vc/lib/src/oidc4vc.dart @@ -20,6 +20,7 @@ import 'package:oidc4vc/src/helper_function.dart'; import 'package:secp256k1/secp256k1.dart'; import 'package:secure_storage/secure_storage.dart'; import 'package:uuid/uuid.dart'; +import 'package:pointycastle/src/utils.dart' as pointycastle_utils; /// {@template ebsi} /// EBSI wallet compliance @@ -884,9 +885,20 @@ class OIDC4VC { .toList(); } - final value = data.first['publicKeyJwk']; + final method = data.first as Map; - return jsonDecode(jsonEncode(value)) as Map; + dynamic publicKeyJwk; + + if (method.containsKey('publicKeyJwk')) { + publicKeyJwk = method['publicKeyJwk']; + } else if (method.containsKey('publicKeyBase58')) { + publicKeyJwk = + publicKeyBase58ToPublicJwk(method['publicKeyBase58'].toString()); + } else { + throw Exception('PUBLICKEYJWK_EXTRACTION_ERROR'); + } + + return jsonDecode(jsonEncode(publicKeyJwk)) as Map; } } @@ -1751,9 +1763,9 @@ class OIDC4VC { Map publicKeyBase58ToPublicJwk(String publicKeyBase58) { ///step 1 : change the publicKeyBase58 format from base58 to base64 : ///decode base58 then encode in base64 urlsafe - final pubKey = base64Url - .encode(base58.decode(base58.encode(utf8.encode(publicKeyBase58)))) - .replaceAll('=', ''); + + final pubKey = + base64UrlEncode(base58.decode(publicKeyBase58)).replaceAll('=', ''); ///step 2 : create the JWK for the "type": "Ed ///25519VerificationKey2018", @@ -1766,4 +1778,3 @@ class OIDC4VC { return jwk; } } -///CsGY5ZB4ctkM3Xs4aDZGMNKd8uK6Pk79geUb6aDkDS4y \ No newline at end of file diff --git a/packages/oidc4vc/test/src/oidc4vc_test.dart b/packages/oidc4vc/test/src/oidc4vc_test.dart index 47bfd8dcc..16d13c8dd 100644 --- a/packages/oidc4vc/test/src/oidc4vc_test.dart +++ b/packages/oidc4vc/test/src/oidc4vc_test.dart @@ -204,8 +204,7 @@ void main() { test('convert publicKeyBase58 to PublicJwk', () { final publicKey = oidc4vc.publicKeyBase58ToPublicJwk(publicKeyBase58); - print('actual - $publicKey'); - print('expected - $expectedPublicJWK'); + expect(publicKey, expectedPublicJWK); }); });