Skip to content

Instantly share code, notes, and snippets.

View bencmbrook's full-sized avatar

Ben Brook bencmbrook

View GitHub Profile
@bencmbrook
bencmbrook / derive-ec-private-key.ts
Last active July 18, 2024 21:40
Derive EC key from secret in Node
import { KeyObject, createECDH, createPrivateKey } from "node:crypto";
/**
* The size of the private key for P-384 in bytes.
* 384 bits / 8 = 48 bytes
*/
const P384_BYTE_LENGTH = 48;
export interface DeriveEcPrivateKeyArgs {
/** A high entropy, uniformly random secret. Must have at least 384 bits of entropy and must be uniformly random. */