Skip to content

WebCryptoP256.getSharedSecret

Computes a shared secret using ECDH (Elliptic Curve Diffie-Hellman) between a private key and a public key using Web Crypto APIs.

Imports

Named
import { WebCryptoP256 } from 'ox'

Examples

import { WebCryptoP256 } from 'ox'
 
const { privateKey: privateKeyA } = await WebCryptoP256.createKeyPairECDH()
const { publicKey: publicKeyB } = await WebCryptoP256.createKeyPairECDH()
 
const sharedSecret = await WebCryptoP256.getSharedSecret({
  privateKey: privateKeyA,
  publicKey: publicKeyB
})

Definition

function getSharedSecret<as>(
  options: getSharedSecret.Options<as>,
): Promise<getSharedSecret.ReturnType<as>>

Source: src/core/WebCryptoP256.ts

Parameters

options

  • Type: getSharedSecret.Options<as>

The options to compute the shared secret.

options.as

  • Type: "Bytes" | "Hex" | as
  • Optional

Format of the returned shared secret.

options.privateKey

  • Type: CryptoKey

Private key to use for the shared secret computation (must be a CryptoKey for ECDH).

options.publicKey

  • Type: { prefix: number; x: bigint; y: bigint; } | { prefix: number; x: bigint; y?: undefined; }

Public key to use for the shared secret computation.

Return Type

The computed shared secret.

Promise<getSharedSecret.ReturnType<as>>