importPrivateJwkOrThrow
importPrivateJwkOrThrow
Import a private signing key from a JSON Web Key.
When algorithm is omitted, it is inferred from the JWK's own kty, crv, and alg members (see importPublicJwkOrThrow).
ts
function importPrivateJwkOrThrow(
jwk: JsonWebKey,
algorithm?: PrivateKeyImportInput,
): Promise<CryptoKey>Parameters
jwk:JsonWebKey— JSON Web Key object with private key componentsalgorithm?:PrivateKeyImportInput— Optional expected algorithm; must match JWK'sktyandcrvwhen given
Returns — Extractable CryptoKey with sign usage
Throws
Error— If JWK is malformed, lacks private key material, encodes an unsupported algorithm, or doesn't matchalgorithm
See also
exportPrivateJwkfor the inverse operation
Examples
ts
const jwk = { kty: 'EC', crv: 'P-256', x: '...', y: '...', d: '...' };
const key = await importPrivateJwkOrThrow(jwk, { kind: 'ecdsa', curve: 'P-256' });
const inferred = await importPrivateJwkOrThrow(jwk);