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

govesb-connector-js

v0.1.1

Published

GovESB connector for Node.js: OAuth, ECDSA signing, ECDH+HKDF AES-GCM, JSON/XML.

Readme

govesb-connector-js

GovESB connector for Node.js – OAuth (client credentials), payload signing/verification (ECDSA P-256 + SHA-256), request formatting (JSON/XML), and end‑to‑end encryption (ECDH + HKDF-SHA256 + AES‑256‑GCM).

Features

  • OAuth client‑credentials token retrieval
  • Request builders: requestData, requestNida, pushData
  • Response helpers: successResponse, failureResponse, verifyThenReturnData
  • Crypto:
    • ECDSA (P‑256) signing and verification over JSON/XML payloads
    • ECDH key agreement + HKDF‑SHA256 (salt=32 zero bytes, info="aes-encryption") → AES‑256‑GCM
    • Ciphertext format: encryptedData = tag || ciphertext (GCM tag prepended)

Install

Once published:

npm i govesb-connector-js

Local path (before publishing):

npm i /absolute/path/to/systems/govesb/node

Requirements

  • Node.js >= 18 (uses global fetch). If you need older Node, inject your own fetch:
    • new GovEsbHelper({ fetch: myFetch, ... })
  • Keys must be base64‑encoded DER (no PEM headers):
    • Private key: PKCS#8 DER → base64
    • Public key: X.509 SubjectPublicKeyInfo DER → base64

Convert PEM to base64 DER (examples):

# Private (PKCS#8 DER → base64)
openssl pkcs8 -topk8 -nocrypt -in private.pem -outform DER | base64

# Public (X.509 SPKI DER → base64)
openssl pkey -pubin -in public.pem -outform DER | base64

Quick start

const { GovEsbHelper } = require("govesb-connector-js");

const helper = new GovEsbHelper({
  clientPrivateKey: process.env.GOVESB_CLIENT_PRIVATE_KEY, // base64 PKCS#8 DER
  esbPublicKey: process.env.GOVESB_PUBLIC_KEY, // base64 X.509 DER
  clientId: process.env.GOVESB_CLIENT_ID,
  clientSecret: process.env.GOVESB_CLIENT_SECRET,
  esbTokenUrl: process.env.GOVESB_TOKEN_URL,
  esbEngineUrl: process.env.GOVESB_ENGINE_URL,
  nidaUserId: process.env.GOVESB_NIDA_USER_ID || null,
  // fetch: customFetch // optional
});

(async () => {
  await helper.getAccessToken();
  const data = await helper.requestData(
    "API_CODE",
    JSON.stringify({ hello: "world" }),
    "json"
  );
  console.log("Response data:", data);
})();

Signing and verification

// Build a signed success response (JSON) and verify it
const response = await helper.successResponse(
  JSON.stringify({ ok: true }),
  "json"
);
const verifiedData = helper.verifyThenReturnData(response, "json");
if (!verifiedData) {
  throw new Error("Signature verification failed");
}
console.log("Verified:", verifiedData);

Encrypt and decrypt (end‑to‑end)

The library performs ECDH over your private key and the recipient’s public key, derives an AES‑256 key via HKDF‑SHA256 (salt=32 zero bytes, info="aes-encryption"), and encrypts with AES‑GCM. The encryptedData field contains the 16‑byte GCM tag followed by ciphertext.

Encrypt

const payload = JSON.stringify([{ id: 1, title: "example" }]);

// Encrypt to the recipient's public key (base64 X.509 DER).
const encryptedJson = helper.encrypt(payload, helper.esbPublicKey);
// Persist to file or send over the wire
require("fs").writeFileSync("cipher.json", encryptedJson);

The resulting JSON looks like:

{
  "ephemeralKey": "<base64-of-PEM-ephemeral-public-key>",
  "iv": "<base64-12-bytes>",
  "encryptedData": "<base64(tag||ciphertext)>"
}

Decrypt

const encryptedJsonString = require("fs").readFileSync("cipher.json", "utf8");
const plaintext = helper.decrypt(encryptedJsonString);
console.log(JSON.parse(plaintext));

Interoperability notes

  • The format is compatible with the Python and Java examples (ECDH + HKDF‑SHA256 + AES‑GCM, tag first).
  • If you implement your own consumer, ensure you:
    • Use the same curve (P‑256/prime256v1)
    • HKDF parameters match exactly (salt=32 zero bytes, info="aes-encryption", length=32)
    • Keep tag prepended to ciphertext when serializing

Minimal API reference

  • new GovEsbHelper(options)
    • clientPrivateKey (base64 PKCS#8 DER), esbPublicKey (base64 X.509 DER), clientId, clientSecret, esbTokenUrl, esbEngineUrl, nidaUserId?, fetch?
  • getAccessToken(): Promise<any>
  • requestData(apiCode, requestBody, format): Promise<string|null>
  • requestNida(apiCode, requestBody, format): Promise<string|null>
  • pushData(apiCode, requestBody, format): Promise<string|null>
  • successResponse(requestBody, format): Promise<string>
  • failureResponse(requestBody, message, format): Promise<string>
  • verifyThenReturnData(esbResponse, format): string|null
  • encrypt(data, recipientPublicKeyBase64): string (JSON string)
  • decrypt(encryptedDataJson): string (plaintext)

Security best practices

  • Treat private keys as secrets; never commit them.
  • Rotate credentials and tokens regularly.
  • Validate all inputs/outputs when bridging systems.

License

MIT

Contributors

  • Japhari Mbaru
  • Lawrance Massanja