Skip to content

vex-protocol/crypto-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

134 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@vex-chat/crypto

npm CI Released License Types Type Coverage Node Bundle OpenSSF Scorecard Socket

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.

What's in the box

  • Key generationxBoxKeyPair() / xSignKeyPair() / xSignKeyPairFromSecret() / xBoxKeyPairFromSecret() for X25519 (encryption) and Ed25519 (signing) keypairs.
  • SigningxSign() / xSignVerify() over arbitrary bytes using Ed25519.
  • Authenticated encryptionxSecretbox() / xSecretboxOpen() (NaCl secretbox) plus xDH() for Diffie-Hellman shared secrets.
  • Hashing & KDFxHash() (SHA-512), xKDF() (HKDF-SHA256 via @noble/hashes), xHMAC(), and PBKDF2.
  • EncodingxEncode() / xDecode() for msgpack wire serialization; XUtils.encodeBase64 / encodeUTF8 for constant-time transport encoding.
  • Mnemonic keysxMnemonic() (BIP39) for deriving keys from human-readable phrases.
  • UtilitiesxConcat(), xMakeNonce(), xRandomBytes(), and XKeyConvert (Ed25519 ↔ X25519 conversion via ed2curve).

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.

Install

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/crypto

Usage

import {
    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.

License

AGPL-3.0-or-later

About

Crypto package.

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors