From a2d046a334a9060fc258610ce2e23c4865bfa3b3 Mon Sep 17 00:00:00 2001 From: rikbellens Date: Thu, 3 Nov 2022 16:57:37 +0100 Subject: [PATCH] feat: add support for es256k algorithm --- lib/src/jwa.dart | 5 +++++ pubspec.yaml | 2 +- test/jwt_test.dart | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/src/jwa.dart b/lib/src/jwa.dart index 3413e7a..c4b0bf4 100644 --- a/lib/src/jwa.dart +++ b/lib/src/jwa.dart @@ -63,6 +63,7 @@ class JsonWebAlgorithm { es256, es384, es512, + es256k, /* ps256, ps384, @@ -118,6 +119,10 @@ class JsonWebAlgorithm { static const es512 = JsonWebAlgorithm('ES512', type: 'EC', use: 'sig', curve: 'P-521'); + /// ECDSA using P-256 and SHA-256 + static const es256k = + JsonWebAlgorithm('ES256K', type: 'EC', use: 'sig', curve: 'P-256K'); + /* TODO: not supported yet in crypto_keys /// RSASSA-PSS using SHA-256 and MGF1 with SHA-256 static const ps256 = diff --git a/pubspec.yaml b/pubspec.yaml index 9123549..f96c5fe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - crypto_keys: '>=0.2.0 <0.4.0' + crypto_keys: ^0.3.0+1 meta: ^1.1.6 typed_data: ^1.0.0 x509: ^0.2.1 diff --git a/test/jwt_test.dart b/test/jwt_test.dart index d9a0f02..fba55d8 100644 --- a/test/jwt_test.dart +++ b/test/jwt_test.dart @@ -158,4 +158,23 @@ void main() { final claims = JsonWebTokenClaims.fromJson({'exp': 1300819380.0}); expect(claims.expiry, DateTime.fromMillisecondsSinceEpoch(1300819380000)); }); + + group('JWT with ES256K signature', () { + test('JWT with ES256K signature', () async { + var key = JsonWebKey.fromJson({ + 'kty': 'EC', + 'd': 'e8HThqO0wR_Qw4pNIb80Cs0mYuCSqT6BSQj-o-tKTrg', + 'x': 'A3hkIubgDggcoHzmVdXIm11gZ7UMaOa71JVf1eCifD8', + 'y': 'ejpRwmCvNMdXMOjR2DodOt09OLPgNUrcKA9hBslaFU0', + 'crv': 'P-256K', + 'kid': '123' + }); + + var jwt = JsonWebToken.unverified( + 'eyJhbGciOiJFUzI1NksiLCJraWQiOiIxMjMiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJ5b3UiLCJpc3MiOiJtZSIsImV4cCI6MTU3NjQ0Mzg2NS4wLCJpYXQiOjE1NzY0NDAyNjUsIm5iZiI6MTU3NjQ0MDI2NX0.nngSyreix-Ri0H1lC4PRGYLNEktMDUag22VmSYe_SRJFd_Oh-Qag1XSLr1Pq0puym8KSVVuPYCzIh5rsuAFH6g'); + + var verified = await jwt.verify(JsonWebKeyStore()..addKey(key)); + expect(verified, true); + }); + }); }