dart-lang / web

Lightweight browser API bindings built around JS static interop.
https://pub.dev/packages/web
BSD 3-Clause "New" or "Revised" License
124 stars 21 forks source link

Missing type definitions in `webcryptoapi.dart` #273

Open Schwusch opened 1 month ago

Schwusch commented 1 month ago

In 1.0.0, some SubtleCrypto methods have untyped parameters, thus making them hard to use: E.g. importKey():

image

Before 1.0.0, it was possible to figure out and pass KeyAlgorithm(name: 'AES-GCM') as the algorithm argument. This class is however gone in 1.0.0. Other missing definition examples are AesGcmParams, which was useful for SubtleCrypto.encrypt()/ SubtleCrypto.decrypt(). Current implementation of AlgorithmIdentifier is a simple typedef:

typedef AlgorithmIdentifier = JSAny;
srujzs commented 1 month ago

Hmm, this may be a bug with the Web IDL but not sure.

KeyAlgorithm is defined but never used in the IDL except as a superinterface: https://github.com/w3c/webref/blob/5308f9a9c0914d765fcbbb55f7d01d313ae37eda/ed/idl/WebCryptoAPI.idl#L25. The subinterfaces are never referred to either.

https://github.com/dart-lang/web/commit/7604578eb538c471d438608673c037121d95dba5 uses the MDN compatibility data to avoid emitting experimental/nonstandard APIs. MDN doesn't contain compatibility data for dictionaries, so we depend on whether or not its used by a non-experimental/standard API to determine if we should emit the dictionary. Here, KeyAlgorithm is never actually used except as a superinterface, and the subinterfaces are never used either: https://github.com/w3c/webref/blob/5308f9a9c0914d765fcbbb55f7d01d313ae37eda/ed/idl/WebCryptoAPI.idl#L25. The case is the same with AesGcmParams: https://github.com/w3c/webref/blob/5308f9a9c0914d765fcbbb55f7d01d313ae37eda/ed/idl/WebCryptoAPI.idl#L206.

We could instead choose to only not emit dictionaries that are explicitly used by experimental/nonstandard APIs, and that may cover this, but it also may mean we're including some dictionary types that are subject to change often.