Skip to content

Commit a0c8e43

Browse files
docs: document exportJsonWebKey in EcdhPrivateKey (#132)
1 parent b295d8d commit a0c8e43

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/src/webcrypto/webcrypto.ecdh.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,28 @@ abstract class EcdhPrivateKey {
206206

207207
Future<Uint8List> exportPkcs8Key();
208208

209+
/// Export the [EcdhPrivateKey] as a [JSON Web Key][1].
210+
///
211+
/// {@macro exportJsonWebKey:returns}
212+
///
213+
/// **Example**
214+
/// ```dart
215+
/// import 'dart:convert';
216+
/// import 'package:webcrypto/webcrypto.dart';
217+
///
218+
/// Future<void> main() async {
219+
/// // Alice generates a key-pair
220+
/// final kpA = await EcdhPrivateKey.generateKey(EllipticCurve.p256);
221+
///
222+
/// // Export the private key as a JSON Web Key.
223+
/// final exportedPrivateKey = await kpA.privateKey.exportJsonWebKey();
224+
///
225+
/// // The Map returned by `exportJsonWebKey()` can be converted to JSON with
226+
/// // `jsonEncode` from `dart:convert`.
227+
/// print(jsonEncode(exportedPrivateKey));
228+
/// }
229+
/// ```
230+
/// [1]: https://www.rfc-editor.org/rfc/rfc7518.html#section-6.2
209231
Future<Map<String, dynamic>> exportJsonWebKey();
210232
}
211233

0 commit comments

Comments
 (0)