npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@thant-dev/ciphersuite

v1.0.3

Published

A suite of cryptographic utilities, including signal protocol, AES, and public key encryption for secure messaging.

Downloads

99

Readme

Ciphersuite for E2E message encryption

A suite of cryptographic utilities, including secp256k1, AES, and Salsa for secure messaging. This library implements the Signal Double Ratchet protocol for end-to-end encrypted communication. It also provides handy utilities from the @noble/secp256k1 library.

Installation

To use this library in your Vue.js or React.js project, you can install it via npm:

npm install @thant-dev/ciphersuite

Usage in Vue.js

Here's a simple example of how you can use @thant-dev/ciphersuite in a Vue.js project.

<template>
  <div>
    <h1>Secure Messaging</h1>
    <button @click="initializeRatchet">Initialize Ratchet</button>
    <button @click="sendMessage">Send Message</button>
    <button @click="receiveMessage">Receive Message</button>
  </div>
</template>

<script>
import { Ratchet, getPublicKey, secpUtils } from '@thant-dev/ciphersuite';

export default {
  name: 'SecureMessagingComponent',
  data() {
    return {
      ratchetInstance: null,
      encryptedMessage: null
    };
  },
  methods: {
    initializeRatchet() {
      const keyPair = {
        privateKey: secpUtils.randomPrivateKey(),
        publicKey: getPublicKey(privateKey)
      };
      this.ratchetInstance = new Ratchet({ keyPair, isInitiator: true });
      console.log('Ratchet instance:', this.ratchetInstance);
    },
    async sendMessage() {
      if (this.ratchetInstance) {
        const message = "Hello, Bob!";
        this.encryptedMessage = await this.ratchetInstance.encrypt(message);
        console.log('Encrypted Message:', this.encryptedMessage);
      } else {
        console.error('Ratchet instance is not initialized');
      }
    },
    async receiveMessage() {
      if (this.ratchetInstance && this.encryptedMessage) {
        try {
          const decryptedMessage = await this.ratchetInstance.decrypt(this.encryptedMessage);
          console.log('Decrypted Message:', decryptedMessage);
        } catch (error) {
          console.error('Failed to decrypt message:', error);
        }
      } else {
        console.error('Ratchet instance or encrypted message is not available');
      }
    }
  }
};
</script>

Usage in React.js

You can also use @thant-dev/ciphersuite in a React.js project. Below is a simple usage example with React hooks.

import React, { useState } from 'react';
import { Ratchet, getPublicKey, secpUtils } from '@thant-dev/ciphersuite';

const SecureMessagingComponent = () => {
  const [ratchetInstance, setRatchetInstance] = useState(null);
  const [encryptedMessage, setEncryptedMessage] = useState(null);

  const initializeRatchet = () => {
    const keyPair = {
      privateKey: secpUtils.randomPrivateKey(),
      publicKey: getPublicKey(privateKey)
    };
    const ratchet = new Ratchet({ keyPair, isInitiator: true });
    setRatchetInstance(ratchet);
    console.log('Ratchet instance:', ratchet);
  };

  const sendMessage = async () => {
    if (ratchetInstance) {
      const message = "Hello, Bob!";
      const encrypted = await ratchetInstance.encrypt(message);
      setEncryptedMessage(encrypted);
      console.log('Encrypted Message:', encrypted);
    } else {
      console.error('Ratchet instance is not initialized');
    }
  };

  const receiveMessage = async () => {
    if (ratchetInstance && encryptedMessage) {
      try {
        const decryptedMessage = await ratchetInstance.decrypt(encryptedMessage);
        console.log('Decrypted Message:', decryptedMessage);
      } catch (error) {
        console.error('Failed to decrypt message:', error);
      }
    } else {
      console.error('Ratchet instance or encrypted message is not available');
    }
  };

  return (
    <div>
      <h1>Secure Messaging</h1>
      <button onClick={initializeRatchet}>Initialize Ratchet</button>
      <button onClick={sendMessage}>Send Message</button>
      <button onClick={receiveMessage}>Receive Message</button>
    </div>
  );
};

export default SecureMessagingComponent;

API Documentation

Ratchet

The Ratchet class implements the Double Ratchet algorithm. It is used to establish a secure messaging context between two parties.

Constructor

new Ratchet(options: { keyPair: KeyPair, isInitiator: boolean }): Ratchet
  • keyPair: The key pair to use for establishing the ratchet.
  • isInitiator: Indicates if this instance is the initiator of the communication.

Methods

  • encrypt(plaintext: string): Promise<EncryptedMessage>

    • Encrypts a plaintext message.
    • Returns an EncryptedMessage object containing the encrypted data.
    const message = "Hello, Bob!";
    const encryptedMessage = await ratchetInstance.encrypt(message);
    console.log('Encrypted Message:', encryptedMessage);
  • decrypt(packet: EncryptedMessage): Promise<string>

    • Decrypts an EncryptedMessage object.
    • Returns the original plaintext message.
    const decryptedMessage = await ratchetInstance.decrypt(encryptedMessage);
    console.log('Decrypted Message:', decryptedMessage);

getPublicKey

Utility to get the public key from a private key using secp256k1.

Example

const privateKey = secpUtils.randomPrivateKey();
const publicKey = getPublicKey(privateKey);
console.log('Public Key:', publicKey);

Utilities (secpUtils)

The secpUtils object provides several useful cryptographic utilities, such as generating random keys and other secp256k1-related operations.

License

MIT License

Contributing

Feel free to open issues or submit pull requests on GitHub. Contributions are welcome!

Acknowledgements

This package uses @noble/secp256k1 for secp256k1 elliptic curve cryptography, and implements the Signal Double Ratchet protocol for secure messaging.