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

mrpc-js

v1.0.0

Published

Zero-dependency mRPC request encoder and HMAC-SHA256 response validator

Readme

mrpc-js

A lightweight, zero-dependency JavaScript reference implementation and serializer for the mRPC (Minimal Remote Procedure Call) protocol.

mrpc-js provides standard encoding, decoding, payload validation, and Web Crypto HMAC-SHA256 signing for secure, decoupled backend-frontend application stacks.

1. Specification (v1.0)

mRPC is a transport-agnostic JSON payload standard designed for high-concurrency, low-overhead communication. It mandates cryptographic payload signing, UTC millisecond timing windows, and unique nonce tracking to ensure transport integrity and prevent replay attacks.

Request Envelope Geometry

Outgoing request packets sent to the server MUST adhere to the following top-level JSON structure:

| Field | Type | Description | |---------------|-----------|----------------------------------------------------------| | user_id | integer | Authenticated user ID. Use 0 if guest/unauthenticated. | | version | string | API version string (e.g., "1.0.0"). | | request_tag | string | Client-generated string to pair asynchronous responses. | | timestamp | integer | UTC timestamp in milliseconds (Date.now()). | | seed | string | High-entropy 64-character random nonce. | | data | object | Domain-specific payload params ({} if empty). | | auth | string | Hex-encoded HMAC-SHA256 signature string. |

Request Example

{
  "user_id": 42,
  "version": "1.0.0",
  "request_tag": "46588f3a1b9c",
  "timestamp": 1724185200000,
  "seed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
  "data": {
    "account_id": 108
  },
  "auth": "a2c8f...91e3"
}

Response Envelope Geometry

Incoming response packets returned by the server MUST adhere to the following structure:

| Field | Type | Description | |---------------|---------|----------------------------------------------------------------------| | success | boolean | true if the request succeeded; false on failure. | | action | string | Optional client directive (e.g., "refresh_token", "logout", "none"). | | request_tag | string | Identical string mirrored directly from the incoming request. | | timestamp | integer | Server UTC timestamp in milliseconds. | | seed | string | High-entropy 64-character random nonce generated by the server. | | data | object | Server response payload (or error metadata on failure). | | auth | string | Hex-encoded HMAC-SHA256 signature returned by the server. |

Response Example

{
  "success": true,
  "action": "none",
  "request_tag": "46588f3a1b9c",
  "timestamp": 1724185200150,
  "seed": "f4c8996fb92427ae41e4649b934ca495991b7852b855e3b0c44298fc1c149afb",
  "data": {
    "status": "active",
    "balance": 250.00
  },
  "auth": "b4e9a...32f1"
}

2. HMAC-SHA256 Signature Rules

To guarantee cryptographic non-repudiation across languages, signatures MUST be generated by running HMAC-SHA256 on the concatenated payload string using the shared secret key.

Message_Payload = serialize(data) + seed
Signature = HMAC-SHA256(Message_Payload, shared_secret)
  • Browser Standard: Generated via globalThis.crypto.subtle (importKey + sign with algorithm "HMAC" / "SHA-256").

  • PHP Boundary (mouse-php): Verified using hash_hmac('sha256', $serializedData . $seed, $secret).

  • Zero Dependencies: Uses standard native platform crypto routines without external libraries.

3. Usage & Examples

Installing

npm install mrpc-js

Encoding & Signing a Request

import { create_mRPC } from 'mrpc-js';

const data = {
    // Domain-specific payload params
  account_id: 108,
};

// Create a new mRPC packet with the following params:
// - user_id:
// - shared secret key:
// - version:
// - data:
// The rest of the fields are automatically generated by the library.
const packet = create_mRPC(42, "your-shared-secret-key", "1.0.0", data);

// Transmit `packet` over HTTP, WebSockets, or custom transport

Decoding & Verifying a Response

import { validate_mRPC_response } from 'mrpc-js';

// To verify a response packet is valid and not replayed:
// Call `validate_mRPC_response` with the following parameters:
// - response_packet: The raw response packet received from the server.
// - request_tag: The `request_tag` value from the original request packet.
// - shared_secret: The shared secret key used to sign the request.
// - window: Allowable time drift window in seconds (defaults to 300 seconds if omitted).
const valid = validate_mRPC_response(response_packet, request_tag, shared_secret, window);

// Returns true if the packet is valid and untampered, otherwise false.

4. Routing & URI Convention

Unlike standard REST endpoints that rely on diverse HTTP verbs (PUT, DELETE, PATCH) across dozens of URLs, mRPC is transport-agnostic and relies on single, action-focused controller endpoints (typically via POST).

Because API versioning is handled directly within the signed version field of the payload envelope, URIs remain flat and clean.

  • Single Controller Mapping: A URI directly targets a server-side controller or handler method (e.g., POST /api/user/login), or a specific route tied directly to that resource (e.g., /api/login).
  • Payload-Driven Actions: The specific operation parameters, domain context, and API version are defined inside the signed request envelope.
  • Unified Transport: This keeps URL structures clean, simplifies reverse-proxy configuration (Nginx/Apache), and lets mouse-php dispatch requests through its high-speed Guard Pipe without route-parsing overhead.