google/webcrypto.dart

Avoid @sealed annotation, using `final class` for everything

Opened this issue · 3 comments

We should use final class for everything in the public API.

Motiviation:

  • This package is not attempting to offer abstractions over cryptographic APIs.
  • We don't want others to implement the types we offer.
  • We also want the option to add more method to the types we offer in the future, without breaking API compatibility.

In practice, we might have to do something that we export from src/webcrypto/webcrypto.dart and something we only export to other libraries inside this package.

// This is exported from lib/webcrypto.dart
// This means that in lib/webcrypto we have to use "show"
// to avoid exporting KeyPairBase.
// Example:
//   export src/webcrypto.dart show KeyPair;
abstract final class KeyPair<S, T> {
  /// Private key for [publicKey].
  S get privateKey;

  /// Public key matching [privateKey].
  T get publicKey;
}

// This is not exported from lib/webcrypto.dart
// but implementations for different platforms can import this from
// src/webcrypto/webcrypto.dart
// and extend it inorder to implement KeyPair
abstract base class KeyPairBase<S, T> extends KeyPair<S, T> {}

Hello! I would like to work in this issue.

Assigned to you.

This is mostly a bit of refactoring and making sure the public API is pretty, while also making sure people accessing it can't implement our classes :D

Might I suggest trying it out on something simple like HmacSecretKey, making a WIP (draft) PR, so that we can decide if we like that pattern before we apply the same pattern consistently across all public classes.

side note. we'll probably also need to bump the version number and write an entry in CHANGELOG.md.