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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ensync-utils

v0.1.0

Published

Shared utilities for EnSync SDK packages - encryption, error handling, and JSON validation

Readme

EnSync Utils

Shared utilities for EnSync SDK packages. This package provides common functionality for encryption, error handling, and JSON validation used across all EnSync client implementations.

Installation

npm install ensync-utils

Features

  • Error Handling: Standardized error types for EnSync operations
  • Encryption: Ed25519 and hybrid encryption/decryption
  • JSON Validation: Type checking and schema validation for payloads

Usage

const {
  EnSyncError,
  encryptEd25519,
  decryptEd25519,
  analyzePayload,
  validatePayloadSchema
} = require("ensync-utils");

API Reference

Error Handling

EnSyncError

Custom error class for EnSync operations.

throw new EnSyncError("Authentication failed", "EnSyncAuthError");

Error Types:

  • EnSyncAuthError - Authentication failures
  • EnSyncPublishError - Publishing failures
  • EnSyncSubscriptionError - Subscription failures
  • EnSyncValidationError - Payload validation failures
  • EnSyncGenericError - Other errors

Encryption

encryptEd25519(payload, recipientPublicKey)

Encrypts a payload using Ed25519.

Parameters:

  • payload (object): Data to encrypt
  • recipientPublicKey (string): Base64 encoded public key

Returns: string (base64 encrypted payload)

decryptEd25519(encryptedPayload, secretKey)

Decrypts an Ed25519 encrypted payload.

Parameters:

  • encryptedPayload (string): Base64 encrypted data
  • secretKey (string): Base64 encoded secret key

Returns: string (decrypted JSON string)

hybridEncrypt(payload, recipientPublicKeys)

Encrypts payload using hybrid encryption (AES + Ed25519).

Parameters:

  • payload (object): Data to encrypt
  • recipientPublicKeys (string[]): Array of base64 public keys

Returns: object with encryptedPayload and encryptedKeys

hybridDecrypt(encryptedPayload, encryptedKey, secretKey)

Decrypts a hybrid encrypted payload.

Parameters:

  • encryptedPayload (string): Encrypted data
  • encryptedKey (string): Encrypted AES key
  • secretKey (string): Base64 secret key

Returns: string (decrypted JSON string)

JSON Utilities

getJsonType(value)

Determines the JSON data type of a value.

Returns: string - One of: string, integer, long, double, float, boolean, object, array, null

getJsonType(123); // "integer"
getJsonType(123.45); // "double"
getJsonType("hello"); // "string"

validateType(value, expectedType)

Validates if a value matches the expected type.

validateType(123, "integer"); // true
validateType("hello", "integer"); // false

validatePayloadSchema(payload, schema)

Validates a payload against a schema.

const result = validatePayloadSchema(
  { userId: "123", age: 25 },
  { userId: "string", age: "integer" }
);
// { success: true, errors: [] }

getPayloadSchema(payload, deep)

Extracts JSON schema from a payload.

getPayloadSchema({ name: "John", age: 30 });
// { name: "string", age: "integer" }

analyzePayload(payload)

Comprehensive payload analysis.

analyzePayload({ orderId: "123", amount: 99.99 });
// {
//   byteSize: 35,
//   schema: { orderId: "string", amount: "double" },
//   fieldCount: 2,
//   isValid: true
// }

isValidJson(value)

Checks if a value can be JSON serialized.

isValidJson({ name: "John" }); // true
isValidJson(undefined); // false

safeJsonParse(jsonString, defaultValue)

Safely parses JSON with error handling.

safeJsonParse('{"name":"John"}', {}); // { name: "John" }
safeJsonParse('invalid', {}); // {}

Data Types

Supported JSON data types (matching EnSync engine):

  • string - String values
  • integer / int - 32-bit integers (-2,147,483,648 to 2,147,483,647)
  • long - 64-bit integers
  • double - Double precision floating point
  • float - Single precision floating point
  • boolean / bool - Boolean values
  • object - JSON objects
  • array - JSON arrays
  • null - Null values

License

ISC

Links