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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jetit/cryptomancer

v2.2.6

Published

`@jetit/cryptomancer` is a library that provides an implementation of forward secrecy encryption for secure communication between clients and servers built on top of [TweetNacl](https://github.com/dchest/tweetnacl-js) using the [Double Ratchet Algorithm](

Downloads

3,967

Readme

@jetit/cryptomancer

@jetit/cryptomancer is a library that provides an implementation of forward secrecy encryption for secure communication between clients and servers built on top of TweetNacl using the Double Ratchet Algorithm.

Installation

To install Cryptomancer, you can use npm or yarn:

npm install @jetit/cryptomancer

or

yarn add @jetit/cryptomancer

Usage

The library exposes all the code required to achieve secure communication using forward secrecy in a client-server environment. You can also build peer-peer networks by implementing both client/server in each node. The library also offers server signature verification using RSA2048 PKCS1-v1_5 to enable server validation. The below steps show implementation details on the client and the server.

The below diagram shows the setup and message exchange between client and server

Server

To initialize Cryptomancer as the server, you can use the server method provided by the library. Here's an example of how to use it:

import { Server } from '@jetit/cryptomancer';

const server: Server.CryptomancerServer = Server.cryptomancer();

// Step 1: Configure the RSA private key for signature
server.setRsaPrivateKey('RSA_PRIVATE_KEY');

// Step 4: Set the peer's identity public key
server.setPeerIdentityKey('PEER_IDENTITY_PUBLIC_KEY');

// Step 5: Get the identity public key 
const  identityDetails  = await server.getIdentityPublicKey();

// Send the identityDetails, signature to client

// Step 8: Set the peer's handshake public key
server.setPeerHandshakePublicKey('PEER_HANDSHAKE_PUBLIC_KEY');

// Step 9: Get the handshake public key
const handshakeDetails = await server.getHandshakePublicKey();

// Send the handshakeDetails, signature to client

// Step 12: Decrypt a received message
const decryptedMessage = await server.decrypt(encryptedMessage);
console.log(decryptedMessage);

// Step 14: Encrypt and send a message
const message = 'Hello, client!';
const encryptedMessage = await server.encrypt(message);

// Send the encrypted message to the client

Client

To initialize cryptomancer as the client, you can use the client method.

import { Client } from '@jetit/cryptomancer';

const client: Client.CryptomancerClient = Client.cryptomancer();

// Step 2: Get the RSA public Key from server, Configure the RSA public key for verification
client.setRsaPublicKey('RSA_PUBLIC_KEY');

// Step 3: Get the identity public key
const identityPublicKey = await client.getIdentityPublicKey();

// Send the identityPublicKey to server

// Step 6: Set the peer's identity public key
client.setPeerIdentityKey('PEER_IDENTITY_DETAILS');

// Step 7: Get the handshake public key
const handshakePublicKey = await client.getHandshakePublicKey();

// Send the handshakePublicKey to server

// Step 10: Set the peer's handshake public key
client.setPeerHandshakePublicKey('PEER_HANDSHAKE_DETAILS');

// Step 11: Encrypt and send a message
const message = 'Hello, server!';
const encryptedMessage = await client.encrypt(message);

// Send the encrypted message to the server

// Step 13: Decrypt a received message
const decryptedMessage = await client.decrypt(serverEncryptedMessage);
console.log(decryptedMessage);

Server Session Serialization Support

import { fs } from 'fs';

// Step 1: Serialize the session
const serializedServerSession = server.serialize();

// Step 2: Save session for usage later
fs.saveFileSync('server_session.txt', serializedServerSession);

// Step 3: Get saved session details
const existingSession = fs.readFileSync('server_session.txt')

// Step 4: Resume previous session
const deserializedServerSession: Server.CryptomancerServer = Server.cryptomance();

deserializedServerSession.resume(existingSession);
deserializedServerSession.setRsaPrivateKey('RSA_PRIVATE_KEY');

const message1 = 'Hello, client!';
const encryptedMessage1 = await deserializedServerSession.encrypt(message1);

API Reference

Client Methods

  • setRsaPublicKey(key: string): void: Configures the RSA public key for verification. This step is optional.

  • getIdentityPublicKey(): Promise<string>: Retrieves the client's identity public key.

  • setPeerIdentityKey(peerIdentity:string): Promise<void>: Sets the peer's identity public key. The peer's RSA signature is also required.

  • getHandshakePublicKey(): Promise<string>: Retrieves the client's handshake public key.

  • setPeerHandshakePublicKey(peerHandshake: string,): Promise<void>: Sets the peer's handshake public key.

  • encrypt(message: string): Promise<IFSMessage>: Encrypts a message using the Ratchet algorithm.

  • decrypt(message: string): Promise<DecryptedMessage>: Decrypts a received message using the Ratchet algorithm.

Server Methods

  • setRsaPrivateKey(key: string): void: Configures the RSA private key for signature. This step is optional.

  • getIdentityPublicKey(): Promise<string>: Retrieves the server's identity public key and signature. The signature is generated using the RSA private key.

  • setPeerIdentityKey(identityPublicKey: string): Promise<void>: Sets the peer's identity public key.

  • getHandshakePublicKey(): Promise<string>: Retrieves the server's handshake public key.

  • setPeerHandshakePublicKey(handshakePublicKey: string): Promise<void>: Sets the peer's handshake public key.

  • encrypt(message: string): Promise<string>: Encrypts a message using the Ratchet algorithm.

  • decrypt(message: string): Promise<DecryptedMessage>: Decrypts a received message using the Ratchet algorithm.

  • serialize(): string: Serializes the current ratchet session into an encoded string. This allows for storing or transferring the session state.

  • resume(session: string): void: Resumes a ratchet session using a serialized session string. The session string should be previously generated using the serialize() method. This allows for restoring a previous session state.

Acknowledgments