TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

SubtleCrypto#importKey should accept `readonly KeyUsage[]`

Open yoursunny opened this issue 11 months ago • 0 comments

As of @types/[email protected], SubtleCrypto is declared as:

interface SubtleCrypto {
    importKey(format: "jwk", keyData: JsonWebKey, algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKey>;
    importKey(format: Exclude<KeyFormat, "jwk">, keyData: BufferSource, algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
}

Notably, the keyUsages argument in the first overload accepts readonly KeyUsage[], while the second overload requires a mutable array.

Web Cryptography API section 14.3.9 does not have any procedure that would mutate this argument. Hence, this argument should accept readonly in both overloads.

The same problem also occurs in one of the overloads in deriveKey and generateKey and unwrapKey methods.

yoursunny avatar Mar 06 '25 02:03 yoursunny