Skip to content

Commit

Permalink
feat: Convert publicKeyBase58 to pubkey #2603
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Apr 22, 2024
1 parent d3f0c1e commit 67c659b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
7 changes: 7 additions & 0 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 12 additions & 14 deletions lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1087,21 +1087,19 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
);
}

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

Expand Down
23 changes: 17 additions & 6 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -884,9 +885,20 @@ class OIDC4VC {
.toList();
}

final value = data.first['publicKeyJwk'];
final method = data.first as Map<String, dynamic>;

return jsonDecode(jsonEncode(value)) as Map<String, dynamic>;
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<String, dynamic>;
}
}

Expand Down Expand Up @@ -1751,9 +1763,9 @@ class OIDC4VC {
Map<String, dynamic> 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",
Expand All @@ -1766,4 +1778,3 @@ class OIDC4VC {
return jwk;
}
}
///CsGY5ZB4ctkM3Xs4aDZGMNKd8uK6Pk79geUb6aDkDS4y
3 changes: 1 addition & 2 deletions packages/oidc4vc/test/src/oidc4vc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 67c659b

Please sign in to comment.