Skip to content

Commit dbb2ebb

Browse files
docs: document exportJsonWebKey in EcdhPublicKey (#138)
1 parent 4c2e760 commit dbb2ebb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/src/webcrypto/webcrypto.ecdh.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,35 @@ abstract class EcdhPublicKey {
301301
/// See compatibility section in [EcdhPublicKey.importSpkiKey].
302302
Future<Uint8List> exportSpkiKey();
303303

304+
/// Export the [EcdhPublicKey] as a [JSON Web Key][1].
305+
///
306+
/// {@macro exportJsonWebKey:returns}
307+
///
308+
/// **Example**
309+
/// ```dart
310+
/// import 'dart:convert';
311+
/// import 'package:webcrypto/webcrypto.dart';
312+
///
313+
/// // Public JSON Web Key data.
314+
/// final jwk = {
315+
/// 'kty': 'EC',
316+
/// 'crv': 'P-256',
317+
/// 'x': 'kgR_PqO07L8sZOBbw6rvv7O_f7clqDeiE3WnMkb5EoI',
318+
/// 'y': 'djI-XqCqSyO9GFk_QT_stROMCAROIvU8KOORBgQUemE'
319+
/// };
320+
///
321+
/// Future<void> main() async {
322+
/// // Alice generates a key-pair
323+
/// final kpA = await EcdhPublicKey.importJsonWebKey(jwk, EllipticCurve.p256);
324+
///
325+
/// // Export the public key as a JSON Web Key.
326+
/// final exportedPublicKey = await kpA.exportJsonWebKey();
327+
///
328+
/// // The Map returned by `exportJsonWebKey()` can be converted to JSON with
329+
/// // `jsonEncode` from `dart:convert`.
330+
/// print(jsonEncode(exportedPublicKey));
331+
/// }
332+
/// ```
333+
/// [1]: https://www.rfc-editor.org/rfc/rfc7518.html#section-6.2
304334
Future<Map<String, dynamic>> exportJsonWebKey();
305335
}

0 commit comments

Comments
 (0)