From d02a6a1faa4e4981c83c356eaba48f8b0e999c29 Mon Sep 17 00:00:00 2001 From: Garimaa Das Date: Mon, 13 Jul 2026 16:26:29 +0545 Subject: [PATCH 1/4] Enhance documentation for EcdhPublicKey imports Added documentation for importing EcdhPublicKey from raw elliptic curve point and SPKI format. --- lib/src/webcrypto/webcrypto.ecdh.dart | 70 ++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/lib/src/webcrypto/webcrypto.ecdh.dart b/lib/src/webcrypto/webcrypto.ecdh.dart index 064dbb17e..8d717fd10 100644 --- a/lib/src/webcrypto/webcrypto.ecdh.dart +++ b/lib/src/webcrypto/webcrypto.ecdh.dart @@ -282,8 +282,30 @@ final class EcdhPublicKey { factory EcdhPublicKey(EcdhPublicKeyImpl impl) { return EcdhPublicKey._(impl); } - - /// TODO: find out of this works on Firefox +/// Import [EcdhPublicKey] from raw elliptic curve point. + /// + /// Creates an [EcdhPublicKey] from [keyData] given as the raw + /// elliptic curve point in uncompressed format. The [curve] specified + /// must match the curve used to generate [keyData]. + /// + /// **Example** + /// ```dart + /// import 'package:webcrypto/webcrypto.dart'; + /// + /// Future main() async { + /// // Generate a key pair. + /// final keyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p256); + /// + /// // Export the public key as a raw key. + /// final rawPublicKey = await keyPair.publicKey.exportRawKey(); + /// + /// // Import the raw key back as an EcdhPublicKey. + /// final publicKey = await EcdhPublicKey.importRawKey( + /// rawPublicKey, + /// EllipticCurve.p256, + /// ); + /// } + /// ``` static Future importRawKey( List keyData, EllipticCurve curve, @@ -292,6 +314,33 @@ final class EcdhPublicKey { return EcdhPublicKey._(impl); } + /// Import [EcdhPublicKey] in the [SPKI][1] format. + /// + /// Creates an [EcdhPublicKey] from [keyData] given as the DER encoded + /// _SubjectPublicKeyInfo_ structure specified in [RFC 5280][1]. + /// The [curve] specified must match the curve used in [keyData]. + /// + /// **Example** + /// ```dart + /// import 'package:webcrypto/webcrypto.dart'; + /// + /// Future main() async { + /// // Generate a key pair. + /// final keyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p256); + /// + /// // Export the public key as SPKI. + /// final spkiPublicKey = await keyPair.publicKey.exportSpkiKey(); + /// + /// // Import the SPKI key back as an EcdhPublicKey. + /// final publicKey = await EcdhPublicKey.importSpkiKey( + /// spkiPublicKey, + /// EllipticCurve.p256, + /// ); + /// } + /// ``` + /// + /// [1]: https://www.rfc-editor.org/rfc/rfc5280 + /// /// ## Compatibility /// TODO: explain that Chrome can't import SPKI keys from Firefox < 72. /// This is a bug in Chrome / BoringSSL (and package:webcrypto) @@ -373,6 +422,23 @@ final class EcdhPublicKey { return EcdhPublicKey._(impl); } + /// Export the [EcdhPublicKey] as a raw elliptic curve point. + /// + /// Returns the raw elliptic curve point in uncompressed format as a + /// list of bytes. + /// + /// **Example** + /// ```dart + /// import 'package:webcrypto/webcrypto.dart'; + /// + /// Future main() async { + /// // Generate a key pair. + /// final keyPair = await EcdhPrivateKey.generateKey(EllipticCurve.p256); + /// + /// // Export the public key as a raw key. + /// final rawPublicKey = await keyPair.publicKey.exportRawKey(); + /// } + /// ``` Future exportRawKey() => _impl.exportRawKey(); /// Note: Due to bug in Chrome/BoringSSL, SPKI keys exported from Firefox < 72 From a1bc1a53169bb32df2381d3e4275e347b10ba9f7 Mon Sep 17 00:00:00 2001 From: Garimaa Das Date: Thu, 16 Jul 2026 14:42:18 +0545 Subject: [PATCH 2/4] Update documentation comments for EcdhPublicKey --- lib/src/webcrypto/webcrypto.ecdh.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/webcrypto/webcrypto.ecdh.dart b/lib/src/webcrypto/webcrypto.ecdh.dart index 8d717fd10..d5b8f02ac 100644 --- a/lib/src/webcrypto/webcrypto.ecdh.dart +++ b/lib/src/webcrypto/webcrypto.ecdh.dart @@ -282,7 +282,8 @@ final class EcdhPublicKey { factory EcdhPublicKey(EcdhPublicKeyImpl impl) { return EcdhPublicKey._(impl); } -/// Import [EcdhPublicKey] from raw elliptic curve point. + + /// Import [EcdhPublicKey] from raw elliptic curve point. /// /// Creates an [EcdhPublicKey] from [keyData] given as the raw /// elliptic curve point in uncompressed format. The [curve] specified @@ -314,7 +315,7 @@ final class EcdhPublicKey { return EcdhPublicKey._(impl); } - /// Import [EcdhPublicKey] in the [SPKI][1] format. + /// Import [EcdhPublicKey] in the [SPKI][1] format. /// /// Creates an [EcdhPublicKey] from [keyData] given as the DER encoded /// _SubjectPublicKeyInfo_ structure specified in [RFC 5280][1]. @@ -422,7 +423,7 @@ final class EcdhPublicKey { return EcdhPublicKey._(impl); } - /// Export the [EcdhPublicKey] as a raw elliptic curve point. + /// Export the [EcdhPublicKey] as a raw elliptic curve point. /// /// Returns the raw elliptic curve point in uncompressed format as a /// list of bytes. From f44240186d48c273c9a0697c1cf2e2fb3309fbe9 Mon Sep 17 00:00:00 2001 From: Garimaa Das Date: Fri, 17 Jul 2026 20:22:54 +0545 Subject: [PATCH 3/4] Fix formatting in EcdhPublicKey factory method --- lib/src/webcrypto/webcrypto.ecdh.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/webcrypto/webcrypto.ecdh.dart b/lib/src/webcrypto/webcrypto.ecdh.dart index d5b8f02ac..8937b66ab 100644 --- a/lib/src/webcrypto/webcrypto.ecdh.dart +++ b/lib/src/webcrypto/webcrypto.ecdh.dart @@ -281,8 +281,8 @@ final class EcdhPublicKey { factory EcdhPublicKey(EcdhPublicKeyImpl impl) { return EcdhPublicKey._(impl); - } - +} + /// Import [EcdhPublicKey] from raw elliptic curve point. /// /// Creates an [EcdhPublicKey] from [keyData] given as the raw From 397d37114e68f1c4bcfdd473e2944bb4c7ab0eee Mon Sep 17 00:00:00 2001 From: Garimaa Das Date: Mon, 20 Jul 2026 13:36:48 +0000 Subject: [PATCH 4/4] style: format webcrypto.ecdh.dart --- lib/src/webcrypto/webcrypto.ecdh.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/webcrypto/webcrypto.ecdh.dart b/lib/src/webcrypto/webcrypto.ecdh.dart index 8937b66ab..855a7b5a7 100644 --- a/lib/src/webcrypto/webcrypto.ecdh.dart +++ b/lib/src/webcrypto/webcrypto.ecdh.dart @@ -281,7 +281,7 @@ final class EcdhPublicKey { factory EcdhPublicKey(EcdhPublicKeyImpl impl) { return EcdhPublicKey._(impl); -} + } /// Import [EcdhPublicKey] from raw elliptic curve point. ///