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

@trustlayer/middleware-express

v0.1.1

Published

Drop-in Express middleware that runs every incoming caller through the TrustLayer /gate before your paywall fires. Pass-through if trustworthy, 403 if not.

Downloads

136

Readme

@trustlayer/middleware-express

Drop-in Express middleware that runs every caller through the TrustLayer /gate before your paywall or business logic fires. Pass-through if the caller's trust score meets your threshold, 403 with structured detail if it doesn't.

Built for x402 servers, A2A endpoints, and any agent-facing API that wants to filter out Sybil-flagged or low-reputation traffic before it costs you compute.

Install

npm install @trustlayer/middleware-express

Quickstart

const express = require('express');
const trustGate = require('@trustlayer/middleware-express');

const app = express();

// Gate any agent hitting /paid through the TrustLayer /gate check.
// Default threshold is 64 (medium-tier or higher).
app.use('/paid', trustGate({ chain: 'base' }), paidHandler);

The middleware resolves the caller's agent id from (in order):

  1. Your resolveAgentId(req) callback (if set)
  2. X-Agent-Id request header
  3. ?agent= query string

If no agent id resolves, the request passes through by default. Set onUnknown: 'block' to refuse anonymous callers.

What the response looks like when blocked

{
  "error": "trustlayer_trust_check_failed",
  "agent_id": "base:1378",
  "score": 38,
  "threshold": 64,
  "sybil_flags": ["review_bombing:high", "duplicate_feedback_content:high"],
  "reason": "below_threshold_and_sybil",
  "recommendation": "High Sybil risk detected. Block payment routing.",
  "learn_more": "https://api.thetrustlayer.xyz/trust/base%3A1378"
}

The full /gate result is also attached to req.trustlayer for downstream handlers that pass through.

Options

| Option | Default | What it does | |---|---|---| | minScore | 64 | Trust score threshold (0–100). Caller passes if score ≥ this. Defer to the server's pass field if not set. | | chain | — | Default chain (e.g. "base", "ethereum"). | | gateUrl | https://api.thetrustlayer.xyz/gate | Override the gate endpoint. | | apiKey | — | API key sent as Authorization: Bearer …. Lifts the 100/hr/IP free-tier limit. | | timeoutMs | 1500 | Per-call timeout. | | cacheTtlMs | 60000 | In-memory cache TTL for repeat queries. Set 0 to disable. | | failOpen | true | If the /gate is unreachable, pass through. Set false to return 503 instead. | | resolveAgentId | — | (req) => string \| null. Custom resolver. | | onUnknown | "pass" | "pass" or "block". What to do when no agent id is resolved. | | onBlock | — | (req, res, gateResult) => void. Override the default 403 response. |

Examples

Block low-reputation callers entirely

app.use('/api', trustGate({
  minScore: 80,
  chain: 'base',
  onUnknown: 'block',
}));

Pair with x402 — filter before the paywall fires

const { paymentMiddleware } = require('x402-express');

app.use(
  '/paid',
  trustGate({ chain: 'base', minScore: 64 }),  // filter Sybil/low-score
  paymentMiddleware(payTo, routes, facilitator), // then run the paywall
  paidHandler
);

This pattern saves you the compute and the facilitator round-trip on traffic you wouldn't want anyway.

Custom resolver for a private agent id schema

app.use('/orchestrator', trustGate({
  chain: 'base',
  resolveAgentId: (req) => req.body?.delegatedAgent,
}));

Custom block response

app.use('/api', trustGate({
  chain: 'base',
  onBlock: (req, res, gate) => res.status(402).json({
    error: 'insufficient_reputation',
    pay_to_unblock: `https://thetrustlayer.xyz/dispute/${gate.agent}`,
  }),
}));

How scoring works

Trust scores are 0–100, derived from three components — profile completeness, feedback volume weighted by reviewer quality, and feedback legitimacy (Sybil detection, spam patterns, temporal anomalies).

Current TrustLayer thresholds:

  • High risk: score < 64
  • Medium: 64–79
  • Low risk: ≥ 80

These are the same thresholds applied across our 19-chain coverage (BSC, Ethereum, Base, Monad, Solana, Polygon, Celo, Gnosis, Optimism, Arbitrum, Avalanche, Linea, Mantle, Metis, Scroll, Taiko, xLayer, GOAT, Soneium).

Free tier vs paid

  • Free tier: 100 requests/hour/IP at /gate. Anonymous, no setup.
  • Paid plans: $49/mo (50K calls), $99/mo (100K), $199/mo (1M). Subscribe at https://api.thetrustlayer.xyz/pricing. Pass the issued API key via the apiKey option.

Related

License

MIT — see LICENSE.