generate an x25519 private and public keypair (in 32-byte array form) using the curve25519 scalar multiplication algorithm.
you can optionally provide an existing private_key, either as a bigint,
or as a 32-byte array (Uint8Array of size 32).
if your private key is not pre-clamped based on x25519's requirements,
it will be forcefully clampped, and the returned KeyPair.privateKey will be clampped.
if you don't provide a private key, this function will randomly generate one for you,
using: crypto.getRandomValues(new Uint8Array(32)).
Note
to convert the key pairs to base64 strings,
use the freshly added (es2025+) Uint8Array.toBase64 method on each of the keys.
generate an
x25519private and public keypair (in 32-byte array form) using thecurve25519scalar multiplication algorithm.you can optionally provide an existing
private_key, either as abigint, or as a 32-byte array (Uint8Arrayof size32). if your private key is not pre-clamped based onx25519's requirements, it will be forcefully clampped, and the returned KeyPair.privateKey will be clampped.if you don't provide a private key, this function will randomly generate one for you, using:
crypto.getRandomValues(new Uint8Array(32)).to convert the key pairs to base64 strings, use the freshly added (es2025+)
Uint8Array.toBase64method on each of the keys.