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

@mxmauro/iot-comm.js

v0.2.0

Published

Javascript library to communicate with ESP IoT devices using the IoT-Comm library

Readme

iot-comm.js

A JavaScript client library for secure communication with ESP IoT devices running the esp-iot-comm server component.

Overview

iot-comm.js provides a secure, WebSocket-based client for connecting to ESP32 IoT devices that use the esp-iot-comm component. It implements the same cryptographic protocols and communication patterns as the server, ensuring end-to-end security and reliable device control.

Key Features

  • Secure Communication: AES-256 encryption with ECDH key exchange, ECDSA authentication, and challenge-response protection against replay attacks.
  • WebSocket Transport: Real-time bidirectional communication.
  • User Management: Create, delete, and manage user accounts on the device.
  • Credential Management: Change and reset user credentials securely.
  • Device Configuration: Set mDNS hostname for device discovery.
  • Cross-Platform: Works in both Node.js and browser environments.
  • Event-Driven: Listen for messages and connection events.
  • TypeScript Support: Full TypeScript definitions included.
  • Server Identity Hook: Optional SHA-256 fingerprint approval callback before authentication continues.

Installation

NodeJS

Install from npm:

npm install @mxmauro/iot-comm.js

CDN

You can use the library directly in the browser via jsDelivr CDN without installing it:

<script src="https://cdn.jsdelivr.net/gh/mxmauro/[email protected]/dist/umd/index.js"></script>

Replace v0.1.0 with the desired version tag.

Examples

See the examples/ directory for complete implementations:

  • examples/browser/ - Web browser demo with user interface
  • examples/nodejs/ - Node.js console and key generation examples

Quick Start

Generate ECDSA key pair

import { Client, toB64 } from '@mxmauro/iot-comm.js';

const { privateKey, publicKey } = await Client.generateECDSAKeyPair();

console.log('Private key:', toB64(privateKey));
console.log('Public key:', toB64(publicKey));

Connect to a device

import { Client } from '@mxmauro/iot-comm.js';

const client = new Client();

await client.connect({
	hostname: '192.168.1.25:80',
	username: 'admin',
	privateKey: '<base64-private-key>',
	verifyServerFingerprint: async (fingerprint) => {
		return fingerprint === '<sha256-device-public-key-hex>';
	}
});

The verifyServerFingerprint callback receives the uppercase hexadecimal SHA-256(devicePublicKey) fingerprint derived from the /ws/init response after the library verifies the server-provided device signature. Returning true continues the connection, returning false aborts it with ConnectionAbortedError, and thrown errors are propagated from connect().

Cancel connection setup

Pass an AbortSignal to cancel an in-progress connect() call. The signal affects only setup; aborting it after a successful connection does not close the session.

const abortController = new AbortController();
const connecting = client.connect({
	hostname: '192.168.1.25:80',
	username: 'admin',
	privateKey: '<base64-private-key>',
	signal: abortController.signal
});

abortController.abort(new Error('Connection cancelled'));
await connecting;

Upload firmware with OTA

await client.uploadFirmware({
	image: firmwareBlob,
	onProgress: ({ sentBytes, totalBytes }) => {
		console.log(`Uploaded ${sentBytes}/${totalBytes}`);
	}
});

For browser use, Blob is the simplest input type. For Node.js or advanced cases, you can also pass an ArrayBuffer, Uint8Array, Buffer, or a sync/async iterable of chunks. When the image source is iterable, you must also provide imageSize.

await client.uploadFirmware({
	image: async function* () {
		yield chunk1;
		yield chunk2;
		yield chunk3;
	}(),
	imageSize: totalFirmwareSize,
	chunkSize: 1024,
	signal: abortController.signal
});

The lower-level command methods are also available when you need manual control over the OTA session:

await client.otaBeginCommand(firmwareSize);
await client.otaWriteCommand(chunk);
await client.otaCancelCommand();

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please ensure all changes maintain compatibility with the esp-iot-comm server protocol.