Skip to content

Commit

Permalink
docs: document exportJsonWebKey in EcdhPublicKey (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
HamdaanAliQuatil authored Jun 27, 2024
1 parent 4c2e760 commit dbb2ebb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/src/webcrypto/webcrypto.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,35 @@ abstract class EcdhPublicKey {
/// See compatibility section in [EcdhPublicKey.importSpkiKey].
Future<Uint8List> exportSpkiKey();

/// Export the [EcdhPublicKey] as a [JSON Web Key][1].
///
/// {@macro exportJsonWebKey:returns}
///
/// **Example**
/// ```dart
/// import 'dart:convert';
/// import 'package:webcrypto/webcrypto.dart';
///
/// // Public JSON Web Key data.
/// final jwk = {
/// 'kty': 'EC',
/// 'crv': 'P-256',
/// 'x': 'kgR_PqO07L8sZOBbw6rvv7O_f7clqDeiE3WnMkb5EoI',
/// 'y': 'djI-XqCqSyO9GFk_QT_stROMCAROIvU8KOORBgQUemE'
/// };
///
/// Future<void> main() async {
/// // Alice generates a key-pair
/// final kpA = await EcdhPublicKey.importJsonWebKey(jwk, EllipticCurve.p256);
///
/// // Export the public key as a JSON Web Key.
/// final exportedPublicKey = await kpA.exportJsonWebKey();
///
/// // The Map returned by `exportJsonWebKey()` can be converted to JSON with
/// // `jsonEncode` from `dart:convert`.
/// print(jsonEncode(exportedPublicKey));
/// }
/// ```
/// [1]: https://www.rfc-editor.org/rfc/rfc7518.html#section-6.2
Future<Map<String, dynamic>> exportJsonWebKey();
}

0 comments on commit dbb2ebb

Please sign in to comment.