Registry / security / grpc-hmac-interceptor

grpc-hmac-interceptor

JSON →
library1.0.4jsnpmunverified

Node.js library (v1.0.4) for adding HMAC authentication to gRPC applications via interceptors. Works with @grpc/grpc-js, supporting both @grpc/proto-loader and protoc-generated protos. Uses SHA512-256 HMAC with key ID and signature in metadata headers. Lightweight, TypeScript-first, and integrates as a gRPC interceptor without modifying service logic.

npm install grpc-hmac-interceptor
INSTALL
IMPORT
SIG · GRPC-HMAC-INTERCEP
G
grpc-hmac-interceptor
securityjavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NewServerInterceptor
import { NewServerInterceptor } from 'grpc-hmac-interceptor'
const NewServerInterceptor = require('grpc-hmac-interceptor').NewServerInterceptor
Library is ESM-only; CommonJS require not supported. TypeScript types included.
NewClientInterceptor
import { NewClientInterceptor } from 'grpc-hmac-interceptor'
import NewClientInterceptor from 'grpc-hmac-interceptor'
Named export, not default. Second argument is secretKey string, third optional boolean for protoc.
GetSecret
import { GetSecret } from 'grpc-hmac-interceptor'
import { GetSecret } from 'grpc-hmac-interceptor/dist/interceptor'
Type export; version ≥1.0.0 includes type definitions.

Sets up gRPC server and client with HMAC authentication interceptors using grpc-hmac-interceptor.

import { NewServerInterceptor, NewClientInterceptor, GetSecret } from 'grpc-hmac-interceptor'; import { Server, ServerCredentials, credentials } from '@grpc/grpc-js'; // Server side const getSecret: GetSecret = (keyId: string) => { const secrets: Record<string, string> = { 'user1': 'my-secret-key-123', }; if (!secrets[keyId]) throw new Error(`Unknown keyId: ${keyId}`); return secrets[keyId]; }; const serverInterceptor = NewServerInterceptor(getSecret); const server = new Server({ interceptors: [serverInterceptor.WithInterceptor()] }); server.bindAsync('0.0.0.0:50051', ServerCredentials.createInsecure(), () => { server.start(); }); // Client side const keyId = 'user1'; const secretKey = 'my-secret-key-123'; const clientInterceptor = NewClientInterceptor(keyId, secretKey); const client = new SomeServiceClient('localhost:50051', credentials.createInsecure(), { interceptors: [clientInterceptor.WithInterceptor()], });
Debug
Known issues
gotchaIf using protoc-generated protos, pass true as third argument to NewClientInterceptor to handle jspb.Message wrapping.
fix
NewClientInterceptor(keyId, secretKey, true) when using protoc
affects: >=1.0.0
breakingLibrary is ESM-only since v1.0.0; does not support CommonJS require().
fix
Use import syntax in an ESM project or enable ESM via 'type': 'module' in package.json
affects: >=1.0.0
deprecatedUsing strings for key/ID is deprecated; prefer typed GetSecret function.
fix
Use GetSecret callback instead of hardcoded key lookup
affects: >=1.0.0
gotchaInterceptor order matters: must be added to both server and client to avoid mismatched HMACs.
fix
Add server interceptor on server, client interceptor on each client call
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'grpc-hmac-interceptor'
Package not installed or in devDependencies only.
fix
npm install grpc-hmac-interceptor --save
TypeError: NewClientInterceptor is not a function
Using default import instead of named import.
fix
import { NewClientInterceptor } from 'grpc-hmac-interceptor'
Error: Unknown keyId: undefined
GetSecret callback not returning a secret for given keyId.
fix
Ensure GetSecret returns correct secret or handle missing keys
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredPeer dependency; library builds on gRPC interceptor API
Agent activity
13 hits · last 30 days
node
12
Resources
grpc-hmac-interceptor — npm install grpc-hmac-interceptor · libregistry