Skip to content

importPublicJwkOrThrow ​

importPublicJwkOrThrow ​

Import a public verification key from a JSON Web Key.

When algorithm is omitted, it is inferred from the JWK's own kty, crv, and alg members (e.g. PS256 → RSA-PSS/SHA-256, RSA-OAEP-256 → RSA-OAEP/SHA-256; an RSA JWK without alg defaults to PKCS#1 v1.5 with SHA-256). Pass algorithm to additionally assert an expected algorithm.

ts
function importPublicJwkOrThrow(
	jwk: JsonWebKey,
	algorithm?: PublicKeyImportInput,
): Promise<CryptoKey>

Parameters

  • jwk: JsonWebKey — JSON Web Key object with public key components
  • algorithm?: PublicKeyImportInput — Optional expected algorithm; must match JWK's kty and crv when given

Returns — Extractable CryptoKey with verify usage

Throws

  • Error — If JWK is malformed, encodes an unsupported algorithm, or doesn't match algorithm

See also

Released under the MIT License.