Skip to content

CoseKey.fromPublicKey

Converts a P256 PublicKey.PublicKey to a CBOR-encoded COSE_Key.

The COSE_Key uses integer map keys per RFC 9053: - 1 (kty): 2 (EC2) - 3 (alg): -7 (ES256) - -1 (crv): 1 (P-256) - -2 (x): x coordinate bytes - -3 (y): y coordinate bytes

Imports

Named
import { CoseKey } from 'ox'

Examples

import { CoseKey, P256 } from 'ox'
 
const { publicKey } = P256.createKeyPair()
 
const coseKey = CoseKey.fromPublicKey(publicKey)

Definition

function fromPublicKey(
  publicKey: PublicKey.PublicKey,
): Hex.Hex

Source: src/core/CoseKey.ts

Parameters

publicKey

  • Type: PublicKey.PublicKey

The P256 public key to convert.

publicKey.prefix

  • Type: numberType

publicKey.x

  • Type: bigintType

publicKey.y

  • Type: bigintType

Return Type

The CBOR-encoded COSE_Key as a Hex string.

Hex.Hex