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

@mites-io/spark-protocol-synergy

v1.0.3

Published

Spark/CoAP TCP gateway for Particle Photon devices — handshake (RSA then AES-128-CBC) and encrypted session layer, on Node built-ins with no native dependencies.

Downloads

71

Readme

@mites-io/spark-protocol-synergy

A TCP gateway library that speaks the Particle Photon "spark" protocol: it runs the device handshake (RSA to agree a key, then an AES-128-CBC encrypted session) and hands you decoded CoAP messages over plain Node EventEmitters. It is the connection layer between a fleet of Photon sensor boards and whatever backend stores their data.

It is built entirely on Node built-ins — crypto, net, worker_threads, events — with no native dependencies and no runtime npm dependencies. That is the whole point: the predecessor this is extracted from was pinned to Node 8 / Ubuntu 16.04 by a native RSA binding (ursa), and this library exists so that pin never happens again.

Status and scope

This is published primarily as the device-gateway layer for the Mites backend. It is a focused library, not a framework — it does the handshake and the encrypted session, emits events, and stops there. It does not decode any particular sensor payload, talk to any database, or expose any metrics; those are the host application's job, wired off the events this library emits. External use is welcome but unsupported: treat the published versions as a moving target gated by semver.

License

LGPL-3.0 (see LICENSE.txt). This is a clean-room descendant of particle/spark-protocol, which is LGPL, and it stays LGPL. The LGPL is a per-library copyleft with no network clause: an application that merely depends on this package — as a separate, unmodified library pulled from npm — carries no copyleft obligation of its own. If you modify this library and ship it, those modifications stay LGPL.

Install

npm install @mites-io/spark-protocol-synergy

Requires Node ≥ 20.

Wire it up

import { CryptoPool, makeFsCoreKeyLoader, Gateway } from '@mites-io/spark-protocol-synergy';
import { readFileSync } from 'node:fs';

const crypto = new CryptoPool();                                  // RSA worker pool, sized to the CPU count
const serverPrivKeyPem = readFileSync('keys/srv_keys/default_key.pem', 'utf8');
const loadCoreKey = makeFsCoreKeyLoader('keys/core_keys');         // per-device public keys on disk

const gateway = new Gateway({
  port: 5683,
  crypto,
  serverPrivKeyPem,
  loadCoreKey,
  registry: myRegistry,        // any object with register(session) / unregister(coreId)
});

gateway.on('session', (session, { durationMs }) => {
  console.log('device online', session.coreId, `(${durationMs} ms)`);
  session.on('message', (msg) => { /* your sensor decode, your storage */ });
});
gateway.on('handshake_failed', ({ coreId, stage, result }) => {
  console.warn('handshake failed', coreId, 'at', stage, '-', result);
});

await gateway.start();

The gateway never reaches into your metrics or logging — every operationally interesting moment is an event (connection, session, handshake_failed, session_disconnected, error), and you decide what each one means.

Documentation

  • Usage.md — the full integration guide: every constructor option, the complete event contract with payload shapes, sending requests to a device, building OTA / operator frames, and clean shutdown.
  • Implementation.md — the protocol internals: the six-stage handshake byte-by-byte, the rolling-IV AES session, the CoAP codec, the TCP framing (and why it is asymmetric), the trust-on-first-use key model, and the RSA worker pool.

The public API

| Export | What it is | |---|---| | Gateway | TCP listener; one Session per connection; emits the lifecycle events. | | Session | Per-device state machine: drives the handshake, runs the message loop, exposes send() / request(). | | CryptoPool | worker_threads pool for the handshake's RSA math. Host owns its lifecycle. | | makeFsCoreKeyLoader | Convenience filesystem loader for per-device public keys. The Gateway takes loadCoreKey as an injected function, so you can supply your own (DB, KMS) instead. | | Code, Option, Type | CoAP constants, for building request frames against the wire format. |

The barrel above is the supported API. The internal modules are also reachable as subpaths — import { aesEncrypt } from '@mites-io/spark-protocol-synergy/lib/crypto.js' — for advanced use such as building a synthetic device in tests. Those internals carry no stability guarantee; depend on the barrel for anything load-bearing.