Elliptic curve
@webbuf/x25519
Rust/wasm X25519 ECDH (RFC 7748)
Install
npm install @webbuf/x25519 Usage
import { x25519PublicKeyCreate, x25519SharedSecretRaw } from "@webbuf/x25519";
import { FixedBuf } from "@webbuf/fixedbuf";
// Each party generates a 32-byte private key and computes its public key.
const alicePriv = FixedBuf.fromRandom<32>(32);
const alicePub = x25519PublicKeyCreate(alicePriv);
const bobPriv = FixedBuf.fromRandom<32>(32);
const bobPub = x25519PublicKeyCreate(bobPriv);
// Each side computes the same shared secret independently.
const aliceSS = x25519SharedSecretRaw(alicePriv, bobPub);
const bobSS = x25519SharedSecretRaw(bobPriv, alicePub);
// aliceSS.toHex() === bobSS.toHex() API reference (2 exports)
Functions
x25519PublicKeyCreate
functionCompute the X25519 public key (RFC 7748 §5) for a 32-byte private key. Accepts any 32 raw bytes; clamping per RFC 7748 §5 ("decodeScalar25519") is applied internally — callers do not need to pre-clamp.
x25519PublicKeyCreate(privKey: FixedBuf<32>): FixedBuf<32>