Skip to main content
Module

x/fido2/lib/keyUtils.js>PublicKey

A node.js library for performing FIDO 2.0 / WebAuthn server functionality
Go to Latest
class PublicKey
import { PublicKey } from "https://deno.land/x/fido2@3.2.5/lib/keyUtils.js";

Class representing a generic public key, with utility functions to convert between different formats using Webcrypto

Constructors

new
PublicKey()

Create a empty public key

Methods

fromCose(cose)

Import public key from COSE data. Throws on any type of failure.

Internally this function converts COSE to a JWK, then calls .fromJwk() to import key to CryptoKey

fromCryptoKey(key, alg)

Import a CryptoKey, makes basic checks and throws on failure

fromJWK(jwk, extractable)

Import public key from JWK. Throws on any type of failure.

fromPem(pem, hashName)

Import public key from SPKI PEM. Throws on any type of failure.

Returns internal algorithm, which should be of one of the following formats

  • RsaHashedImportParams
  • EcKeyImportParams
  • undefined

Returns internal key in CryptoKey format

  • Mainly intended for internal use
  • Throws if internal CryptoKey does not exist
setAlgorithm(algorithmInput)

Sets internal algorithm identifier in format used by webcrypto, should be one of

  • Allows adding missing properties
  • Makes sure alg.hash is is { hash: { name: 'foo'} } format
  • Syncs back updated algorithm to this._key

Exports public key to COSE data

  • Only works if original cose data from 'fromCose()' is available
  • Throws on any kind of failure

Exports public key to JWK.

  • Only works if original jwk from 'fromJwk()' is available
  • Throws on any kind of failure
toPem(forcedExport)

Exports public key to PEM.

  • Reuses original PEM string if present.
  • Possible to force regeneration of PEM string by setting 'forcedExport' parameter to true
  • Throws on any kind of failure