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

@superstateinc/api-key-request

v0.1.4

Published

Make an API request to a Superstate endpoint that requires an API key

Downloads

152

Readme

@superstateinc/api-key-request

This package provides a simple way to make requests to Superstate API endpoints that are protected by an API key.

Quickstart

Install the package using npm (or your favorite package manager):

npm install @superstateinc/api-key-request

Use the package in your code:

import { superstateApiKeyRequest, TransactionStatus } from '@superstateinc/api-key-request';

const transactions = await superstateApiKeyRequest({
  apiKey: SUPERSTATE_API_KEY,
  apiSecret: SUPERSTATE_API_SECRET,
  endpoint: "v2/transactions",
  method: "GET",
  queryParams: {
    transaction_status: TransactionStatus.Pending
  },
});

console.log(transactions);

Manually creating a request

The package automatically builds the required headers for you, but manually building the headers is also possible, if you would prefer to do it yourself.

Building the header

The following headers are required for all requests that are protected by an API key:

  • X-Nonce: <nonce>: a randomly-generated UUID
  • X-Timestamp: <epoch_timestamp_ms>: the epoch timestamp in milliseconds
  • X-Params-Hash: <path and query params hashed>: path and query params are parsed and normalized into a single string and hashed as follows:
    • Path params are normalized to include leading slash and remove trailing slash (https://api.example.com/v2/table/cells/9/ becomes /v2/table/cells/9)
    • Query params are sorted alphabetically by key, then by value if any are repeated, and url encoded (?z=10&name=Bob Joe becomes ?name=Bob%20Joe&z=10)
    • Combined: /v2/table/cells/9?id=341&name=Bob Joe&enabled=true becomes /v2/table/cells/9?enabled=true&id=341&name=Bob%20Joe which is then hashed with SHA256
  • X-Body-Hash: <body serialized and hashed>: body of the request is serialized then SHA256-hashed. If the request has no body (such as GET or DELETE), then this should be SHA256("")
  • X-Hmac: <HMAC-SHA256(api_secret, api_key + epoch_timestamp_ms + nonce + params_hash + body_hash)>: generates an HMAC (Hash-based Message Authentication Code) to allow validation of authenticity and integrity of the message; encoded as standard base64 string. + denotes string concatenation.
  • Authorization: Bearer <api_key>: the API key in plaintext.

Authentication Flow

The nonce, timestamp, and hash are used to prevent replay attacks. The system works like so: when generating a request, the client will generate a random UUID to be used as a nonce. The user adds in their API secret which was generated with the API key to generate the HMAC via HMAC-SHA256(api_secret, api_key + epoch_timestamp_ms + nonce + params_hash + body_hash) and includes it in the request header.