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

enos-poseidon

v0.2.0

Published

Node.js port of the ENOS API client (enos-poseidon). Signs ENOS API requests with an apim-accesstoken header.

Readme

enos-poseidon (Node.js)

A Node.js port of the Python enos-poseidon package. It signs requests to the ENOS (EnvisionIoT) API gateway by generating the apim-accesstoken header, and transparently refreshes the token and retries once when the gateway reports an expired token.

Zero runtime dependencies — it uses only Node's built-in crypto, http, and https modules.

Install

Copy this package into your project, or add it as a local dependency:

npm install /path/to/enos-poseidon

Requires Node.js >= 16.

Usage

const { urlopen } = require('enos-poseidon');

async function main() {
  const accessKey = 'your-appkey';
  const secretKey = 'your-appsecret';
  const url = 'https://ag-cn4.envisioniot.com/connect-service/v2.1/time?orgId=YOUR_ORG';

  // GET
  const data = await urlopen(accessKey, secretKey, url);
  console.log(data);

  // POST with JSON body
  const result = await urlopen(accessKey, secretKey, url, {
    method: 'POST',
    data: { deviceKeys: [{ assetId: 'a1' }] },
  });
  console.log(result);
}

main();

API

urlopen(key, secret, url, options?) => Promise<object|string>

Sends a signed request. Returns parsed JSON when the response is JSON, otherwise the raw string body.

| Option | Type | Default | Description | |---|---|---|---| | data | object | string | null | Request body. Objects are JSON-stringified. | | headers | object | {} | Extra request headers. | | method | string | GET, or POST when data is present | HTTP method. | | timeout | number | 9000 | Timeout in milliseconds. | | contentType | string | application/json;charset=utf-8 | Content-Type override. | | rejectUnauthorized | boolean | false | TLS certificate verification (HTTPS). |

buildAccessToken(key, secret) => string

Returns the apim-accesstoken header value for the given credentials. Useful if you want to sign requests with your own HTTP client.

How the signing works

This is a faithful re-implementation of the Python client:

  1. pin — Take the segment after the first - in both key and secret, concatenate them, parse as a hexadecimal integer, render as decimal, left-pad to 9 digits, and take the first 6 digits.
  2. tokens — Build pin + expiryTimestampMs for a short (2h) and long (30d) window, then HMAC-SHA256 each with the built-in secret key and hex-encode. These are the access and refresh tokens.
  3. accesstoken — Concatenate pin$key$secret$accessToken$refreshToken, RSA-encrypt with the built-in public key using PKCS1-OAEP (SHA-1), and base64-encode. This value is sent as the apim-accesstoken header.
  4. retry — If the response body has apim_status 4011 (access token expired) or 4012 (refresh token expired), the client rebuilds the token and retries the request once.

Security notes

  • Like the original Python client, TLS certificate verification is disabled by default (rejectUnauthorized: false). For production use, pass rejectUnauthorized: true unless you have a specific reason not to.
  • The HMAC secret key and RSA public key are embedded constants shipped by ENOS, identical to the upstream Python package.

Testing

npm test
  • test/verify.js cross-checks the pin derivation and HMAC signing against the actual installed Python package (requires Python + enos-poseidon), and validates the RSA-OAEP output size.
  • test/mock_flow.js spins up a local HTTP server to verify header injection and the 4011 refresh-and-retry flow.

Compatibility

Verified byte-for-byte identical output against the Python package for the deterministic parts (pin, HMAC). The RSA-OAEP step is non-deterministic by design (random padding) but uses the same key, padding scheme, and hash, so the ENOS gateway accepts tokens produced by either client.