Skip to content

Commit

Permalink
feat: add support for es256k algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
rbellens committed Nov 3, 2022
1 parent 3b4d7f7 commit a2d046a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/src/jwa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class JsonWebAlgorithm {
es256,
es384,
es512,
es256k,
/*
ps256,
ps384,
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/jwt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

0 comments on commit a2d046a

Please sign in to comment.