Skip to content

SubtleCrypto#importKey should accept readonly KeyUsage[] #1929

Open
@yoursunny

Description

@yoursunny

As of @types/web@0.0.208, 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions