CoseKey
Utility functions for converting between COSE_Key and P256 public keys.
COSE_Key is the key format used in WebAuthn attestation objects, as defined in RFC 9053.
Examples
Below are some examples demonstrating common usages of the CoseKey module:
Encoding a Public Key to COSE_Key
import { CoseKey, P256 } from 'ox'
const { publicKey } = P256.createKeyPair()
const coseKey = CoseKey.fromPublicKey(publicKey)Decoding a COSE_Key to Public Key
import { CoseKey, P256 } from 'ox'
const { publicKey } = P256.createKeyPair()
const coseKey = CoseKey.fromPublicKey(publicKey)
const publicKey2 = CoseKey.toPublicKey(coseKey)Functions
| Name | Description |
|---|---|
CoseKey.fromPublicKey | Converts a P256 PublicKey.PublicKey to a CBOR-encoded COSE_Key. |
CoseKey.toPublicKey | Converts a CBOR-encoded COSE_Key to a P256 PublicKey.PublicKey. |
Errors
| Name | Description |
|---|---|
CoseKey.InvalidCoseKeyError | Thrown when a COSE_Key does not contain valid P256 public key coordinates. |

