Skip to content

Commit

Permalink
some update
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Apr 19, 2024
1 parent c343a2f commit 9cdd526
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
30 changes: 26 additions & 4 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:io';

import 'package:bip32/bip32.dart' as bip32;
import 'package:bip39/bip39.dart' as bip393;
import 'package:bs58/bs58.dart';
import 'package:crypto/crypto.dart';
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
import 'package:did_kit/did_kit.dart';
Expand Down Expand Up @@ -300,7 +301,7 @@ class OIDC4VC {
};
credentials.add((credential['types'] as List<dynamic>).last);
} else {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
throw Exception();
}

authorizationDetails.add(data);
Expand Down Expand Up @@ -700,7 +701,7 @@ class OIDC4VC {
'redirect_uri': redirectUri,
};
} else {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
throw Exception();
}

if (authorization == null) {
Expand Down Expand Up @@ -758,7 +759,7 @@ class OIDC4VC {
}

if (openIdConfiguration.jwksUri == null) {
throw Exception('JWKS_URI_IS_NULL');
throw Exception();
}

final response = await dioGet(
Expand Down Expand Up @@ -1736,12 +1737,33 @@ class OIDC4VC {
await secureStorageProvider.set(uri, jsonEncode(value));

return response.data;
} on FormatException catch (_) {
throw Exception();
} catch (e) {
if (e is DioException) {
throw Exception('Issue while getting $uri');
throw Exception();
} else {
rethrow;
}
}
}

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('=', '');

///step 2 : create the JWK for the "type": "Ed
///25519VerificationKey2018",
///it is a edDSA key
final jwk = {
'crv': 'Ed25519',
'kty': 'OKP',
'x': pubKey,
};
return jwk;
}
}
///CsGY5ZB4ctkM3Xs4aDZGMNKd8uK6Pk79geUb6aDkDS4y
1 change: 1 addition & 0 deletions packages/oidc4vc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
dependencies:
bip32: ^2.0.0
bip39: ^1.0.6
bs58: ^1.0.2
credential_manifest:
path: ../credential_manifest
crypto: ^3.0.3
Expand Down
18 changes: 18 additions & 0 deletions packages/oidc4vc/test/src/oidc4vc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ void main() {
});
});

group('publicKeyBase58ToPublicJwk', () {
final oidc4vc = OIDC4VC();

const publicKeyBase58 = '2S73k5pn5umfnaW31qx6dXFndEn6SmWw7LpgSjNNC5BF';

final expectedPublicJWK = {
'crv': 'Ed25519',
'kty': 'OKP',
'x': 'FUoLewH4w4-KdaPH2cjZbL--CKYxQRWR05Yd_bIbhQo',
};

test('convert publicKeyBase58 to PublicJwk', () {
final publicKey = oidc4vc.publicKeyBase58ToPublicJwk(publicKeyBase58);
print('actual - $publicKey');
print('expected - $expectedPublicJWK');
});
});

group('EBSI: getAuthorizationUriForIssuer', () {
const issuer = 'https://talao.co/sandbox/ebsi/issuer/pcbrwbvrsi';

Expand Down

0 comments on commit 9cdd526

Please sign in to comment.