Crypto primitives for the Vex encrypted chat platform. Sign, encrypt, hash, derive keys, and encode bytes — everything the client and server need to speak the protocol.
- Key generation —
xBoxKeyPair()/xSignKeyPair()/xSignKeyPairFromSecret()/xBoxKeyPairFromSecret()for X25519 (encryption) and Ed25519 (signing) keypairs. - Signing —
xSign()/xSignVerify()over arbitrary bytes using Ed25519. - Authenticated encryption —
xSecretbox()/xSecretboxOpen()(NaCl secretbox) plusxDH()for Diffie-Hellman shared secrets. - Hashing & KDF —
xHash()(SHA-512),xKDF()(HKDF-SHA256 via@noble/hashes),xHMAC(), and PBKDF2. - Encoding —
xEncode()/xDecode()for msgpack wire serialization;XUtils.encodeBase64/encodeUTF8for constant-time transport encoding. - Mnemonic keys —
xMnemonic()(BIP39) for deriving keys from human-readable phrases. - Utilities —
xConcat(),xMakeNonce(),xRandomBytes(), andXKeyConvert(Ed25519 ↔ X25519 conversion viaed2curve).
All primitives use constant-time operations where relevant. Native Node crypto is used for HKDF/PBKDF2/HMAC/SHA; tweetnacl and @noble/hashes cover the rest.
npm install @vex-chat/crypto@vex-chat/types is a peer dependency — install it alongside if you don't already have it:
npm install @vex-chat/types @vex-chat/cryptoimport {
xBoxKeyPair,
xSignKeyPair,
xSign,
xSecretbox,
xSecretboxOpen,
xDH,
xMakeNonce,
xEncode,
xDecode,
XUtils,
} from "@vex-chat/crypto";
// Generate identity keys
const signKeys = xSignKeyPair();
const boxKeys = xBoxKeyPair();
// Sign a message
const message = XUtils.encodeUTF8("hello vex");
const signature = xSign(message, signKeys.secretKey);
// Derive a shared secret and encrypt
const shared = xDH(boxKeys.secretKey, otherPartyPublicKey);
const nonce = xMakeNonce();
const ciphertext = xSecretbox(message, nonce, shared);
// Decrypt
const plaintext = xSecretboxOpen(ciphertext, nonce, shared);
// msgpack wire encoding
const frame = xEncode({ type: "success", transmissionID: "abc", data: null });
const decoded = xDecode(frame);See the generated API docs at vex-chat.github.io/crypto-js for the full surface.