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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cryo-server

v2.5.1

Published

``` █████ ██████ ██ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████ ██ ██ ██ █████ Server implementation ```

Readme

Cryo-Server

Part of the Cryo Ecosystem

 █████ ██████  ██   ██  █████  
██     ██   ██  ██ ██  ██   ██ 
██     ██████    ███   ██   ██ 
██     ██ ██     ██    ██   ██ 
██     ██  ██    ██    ██   ██ 
 █████ ██   ██   ██     █████  
                Server implementation

Cryo / Overview

Cryo is a lightweight, efficient Websocket framework intended for building real-time systems

Client implementations are available for:

  • TypeScript / JavaScript under Node.Js
  • TypeScript / JavaScript under modern Browsers
  • C# under .NET 8.0

A server implementation is available for TypeScript / JavaScript under Node.Js

Cryo-Server / Overview

The Cryo-Server takes care of the following:

  • Client session authentication
  • Client session lifecycle management
  • Correct framing and structuring of received and sent data

The Cryo-Server provides a public API for creating and destroying an instance. It provides access to sessions for communication purposes via events

The Cryo-Server is extensible via its Extension interface. As such it is possible to, for example, implement an RPC server.

Setup

To set up a Cryo Server, simply import the cryo function from the cryo-server package.

The cryo-function takes two arguments:

  • a required ITokenValidator object
  • an optional ICryoWebsocketServerOptions object

Configuration

ITokenValidator

interface ITokenValidator {
    validate(token: string): Promise<boolean>;
}

This interface describes how the server will authenticate incoming connections.

Cryo-Clients send a token, which you may validate in the validate-function.

ICryoWebsocketServerOptions

interface ICryoWebsocketServerOptions {
    keepAliveIntervalMs?: number;
    port?: number;
    use_cale: boolean;
    ssl?: {
        key: Buffer;
        cert: Buffer;
    };
    backpressure?: {
        highWaterMark?: number;
        lowWaterMark?: number;
        maxQueuedBytes?: number;
        maxQueueCount?: number;
        dropPolicy?: "drop-oldest" | "drop-newest" | "dedupe-latest";
    };
}

This interface describes various configuration options for the CryoServer:

  • keepAliveIntervalMs
    • The frequency in which the server will send application-level pings to the clients, by default 15000 is chosen
  • port
    • The local port to listen on, by default 8080 is chosen
  • use_cale
    • If the Server should use CALE, see CALE

In the ssl object, you may set a key and a cert to enable SSL connections.

Backpressure

The backpressure object allows to you control how the Cryo server handles high load and prevents memory bloating

| Option | Type | Default | Description | |------------------|-----------------------------------------------------|--------------------|------------------------------------------------------------------------------| | highWaterMark | number | 16 * 1024 * 1024 | Maximum number of bytes allowed in the send buffer before throttling starts. | | lowWaterMark | number | 1024 * 1024 | Once buffer usage drops below this, sending resumes. | | maxQueuedBytes | number | 8 * 1024 * 1024 | Hard cap on total queued bytes. Frames beyond this are dropped. | | maxQueueCount | number | 1024 | Hard cap on number of queued frames. | | dropPolicy | "drop-oldest" \| "drop-newest" \| "dedupe-latest" | "drop-oldest" | Strategy used when the queue is full. |

Drop policies

  • drop-oldest
    • Keeps new data, discards the oldest frames first
  • drop-newest
    • Keeps old data, discards the newest frame attempting to be sent
  • dedupe-latest
    • If a frame of the same type or payload is already queued, replace it instead adding a duplicate

Public methods

| Name | Parameter | Description | Returns | |-------------------|----------------|---------------------------------------------|---------| | RegisterExtension | ICryoExtension | Registers a server-side cryo extension | | | Destroy | | Closes the server and destroys all sessions | |

Cryo-Server / Example

import {cryo} from "cryo-server";

const PORT = 8080;
const server = await cryo({
    async validate(token: string): Promise<boolean> {
        return token === "MySuperSecretToken";
    }
}, {use_cale: false, port: PORT});

/*
The cryo server emits events as described by the CryoWebsocketServerEvents interface

interface CryoWebsocketServerEvents {
  "session": (session: CryoServerWebsocketSession) => void;

  "listening": () => void;
}

as such, we can react to when the server starts listening and react to new sessions
*/
server.on("session", async session => {
    console.info(`Session ID: ${session.id}`);
});

server.on("listening", () => {
    console.info("Server is listening...");
});

CryoServerWebsocketSession / Overview

Data Events

These events are emitted when the server-side session receives data from a client-side session

| Name | Parameter | Description | |----------------|--------------|----------------------------------------------------------------| | message-utf8 | data: string | Emitted, when the session receives a utf8 text message | | message-binary | data: Buffer | Emitted, when the session receives an arbitrary binary message |

Statistic Events

These events are emitted periodically and serve as a way to implement metrics, monitoring or other such things

| Name | Parameter | Description | |------------------|--------------|---------------------------------------------------------------| | stat-rtt | data: number | EWMA Average in milliseconds between messages-ACK round trips | | stat-bytes-rx | data: number | Total bytes received from the client session | | stat-bytes-tx | data: number | Total bytes sent to the client session | | stat-ack-timeout | data: number | Count of messages that timed out waiting for an ACK |

Meta events

This sad category of events is emitted when something about the session changes

| Name | Parameter | Description | |--------|-----------|------------------------------------------------------------| | closed | | Emitted, when the session closes or was closed by a client |

Public methods

| Name | Parameter | Description | Returns | |------------|-------------------------|-------------------------------------------------------------------|---------| | SendPing | | Sends a ping to the client session | | | SendUTF8 | data: string | Sends the passed utf8 text to the client session | | | SendBinary | data: Buffer | Sends the passed buffer to the client session | | | Set | key: string, value: any | Sets key to value in the session's custom data store | | | Get | key: string | Retrieves the value of key from the session's custom data store | any | | Destroy | | Closes and destroys the session object | |

Cryo-Server / Extension interface

The extension interface allows you to modify the behaviour of the cryo server's message lifecycle, before sending and after receiving per session.

Extensions can inspect and modify messages, enabling you to do custom behaviour, such as logging, filtering, building metrics or transforming the payloads.

Extensions are registered using the cryo-server's RegisterExtension-method.

Interface definition

type Box<T> = { value: T };

export interface ICryoExtension {

    /**
     * Executed before a binary message is sent to the client session
     * @param session - The cryo websocket session
     * @param outgoing_message - The message buffer to be sent to the client
     * */
    before_send_binary?(session: CryoServerWebsocketSession, outgoing_message: Box<Buffer>): Promise<boolean>;

    /**
     * Executed before a text message is sent to the client session
     * @param session - The cryo websocket session
     * @param outgoing_message - The message text to be sent to the client
     * */
    before_send_utf8?(session: CryoServerWebsocketSession, outgoing_message: Box<string>): Promise<boolean>;

    /**
     * Executed after a binary message is received from the client, but before the session can emit the `message-binary` event
     * Return false to stop event propagation, or true to continue event propagation
     * @param session - The cryo websocket session
     * @param incoming_message - The incoming binary message from the client
     * */
    on_receive_binary?(session: CryoServerWebsocketSession, incoming_message: Box<Buffer>): Promise<boolean>;

    /**
     * Executed after a text message is received from the client, but before the session can emit the `message-utf8` event
     * Return false to stop event propagation, or true to continue event propagation
     * @param session - The cryo websocket session
     * @param incoming_message - The incoming text message from the client
     * */
    on_receive_utf8?(session: CryoServerWebsocketSession, incoming_message: Box<string>): Promise<boolean>;

    /**
     * The unique name of this extension
     * */
    name: string;
}

Diagram

             ┌──────────────────────────┐
             │  Outgoing message starts │
             └────────────┬─────────────┘
                          │
                          ▼
           +--------------------------------+
           | before_send_utf8 / binary hooks |
           +--------------------------------+
                          │
                 (Extensions could:)
                 - inspect message
                 - modify message (via Box<T>)
                 - return false to drop it
                          │
                          ▼
               ┌───────────────────────┐
               │   Message is sent     │
               └─────────┬─────────────┘
                         │
                         ▼
         [Network transmission to client]



         [Incoming message from client]
                         │
                         ▼
           +--------------------------------+
           | on_receive_utf8 / binary hooks  |
           +--------------------------------+
                          │
                 (Extensions could:)
                 - inspect message
                 - modify message (via Box<T>)
                 - return false to suppress emit
                          │
                          ▼
             ┌──────────────────────────┐
             │  message-* event emitted │
             │ (to user application)    │
             └──────────────────────────┘

Example extension

This is an exemplary logging extension. It simply logs each incoming and outgoing message

import {Box, ICryoExtension} from "./CryoExtension";
import {CryoServerWebsocketSession} from "./CryoServerWebsocketSession";

class LoggerExtension implements ICryoExtension {
  public name = "unique_name_for_logger";

  public async before_send_utf8(session: CryoServerWebsocketSession, outgoing_message: Box<string>) {
    console.log(`Outgoing UTF-8 message: "${outgoing_message.value}"`);
    return true;
  }

  public async before_send_binary(session: CryoServerWebsocketSession, outgoing_message: Box<Buffer>) {
    console.log(`Outgoing binary message: "${outgoing_message.value.toString(16)}"`);
    return true;
  }

  public async on_receive_utf8(session: CryoServerWebsocketSession, incoming_message: Box<string>) {
    console.log(`Incoming UTF-8 message: "${outgoing_message.value}"`);
    return true;
  }

  public async before_send_utf8(session: CryoServerWebsocketSession, incoming_message: Box<Buffer>) {
    console.log(`Incoming binary message: "${outgoing_message.value.toString(16)}"`);
    return true;
  }
}

CALE - Cryo application level encryption

Warning - This feature is unavailable in the C# client

CALE is an optional, end-to-end encryption layer for Cryo.

It adds a layer of cryptographic protection on top of WebSockets/TCP, mainly for environments without TLS or custom setups

How:

  • It uses ECDH / P-256 for an ephemeral key exchange
  • Derives symmetric session keys using SHA-256
  • Encrypts frames using AES-128-GCM
  • Performs a 3-step handshake server_hello -> client_hello -> handshake_done
  • Once completed, all frames are encrypted
+-------------+                                      +-------------+
|   Client    |                                      |   Server    |
+------+------+                                      +------+------+
       |                                                    |
       | 1) server_hello(pub_key_s, sid, ack)               |
       | <------------------------------------------------- |
       |                                                    |
       | 2) client_hello(pub_key_c, sid, ack)               |
       | -------------------------------------------------> |
       |                                                    |
       | 3) handshake_done                                  |
       | <------------------------------------------------- |
       |                                                    |
       | 4) handshake_done (ack)                            |
       | -------------------------------------------------> |
       |                                                    |
+------+------ +                                      +------+------+
| Secure Chan. | <---------- AES-128-GCM ------------>| Secure Chan.|
|  (tx/rx)     |                                      |  (tx/rx)    |
+--------------+                                      +-------------+

Session keys are derived as such

secret  = ECDH(pub_key_server, priv_key_client)
hash    = SHA256(secret)
rx_key  = hash[0..15]
tx_key  = hash[16..31]

After the handshake_done-step, both peers switch into secure mode, meaning that all data frames (utf8data, binarydata) will be encrypted using AES-GCM

Why:

CALE is not meant to replace TLS, I wouldn't dare.

It is a protocol-level experiment for extra application-layer encryption, primarily for private deployments or custom setups.

If you are communicating via TLS, you do not need CALE at all and it is recommended to disable it for performance reasons.