Skip to content

P256.getSharedSecret

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

Imports

Named
import { P256 } from 'ox'

Examples

import { P256 } from 'ox'
 
const { privateKey: privateKeyA } = P256.createKeyPair()
const { publicKey: publicKeyB } = P256.createKeyPair()
 
const sharedSecret = P256.getSharedSecret({
  privateKey: privateKeyA,
  publicKey: publicKeyB
})

Definition

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

Source: src/core/P256.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: 0x${string} | Uint8Array

Private key to use for the shared secret computation.

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.

getSharedSecret.ReturnType<as>