https://github.com/chronicleprotocol/api-auth-npm
Repo for the NPM package that handles auth token signing for the public API
https://github.com/chronicleprotocol/api-auth-npm
Last synced: 5 months ago
JSON representation
Repo for the NPM package that handles auth token signing for the public API
- Host: GitHub
- URL: https://github.com/chronicleprotocol/api-auth-npm
- Owner: chronicleprotocol
- License: mit
- Created: 2025-02-05T14:30:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-11T03:43:23.000Z (10 months ago)
- Last Synced: 2025-10-05T20:18:59.279Z (9 months ago)
- Language: TypeScript
- Size: 123 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Getting Started
## Install the NPM module
```sh
npm install --save @chronicleprotocol/api-auth
```
## Usage
Generating authentication tokens programmatically:
```js
import { signAuthToken } from "@chronicleprotocol/api-auth";
const { token, message } = signAuthToken({
// private key is 0x prefixed 32 byte hex string
privateKey: "0xabc...",
});
// `token` is hex string to be included as Authorization header (see below)
// `message` is object containing decoded data within `token`. Optional,
// but can be useful for programmatic token handling
```
To generate a token via the command line, use:
```bash
# Please do not put your private key directly in the command and have it show up in your shell history :-(
npx @chronicleprotocol/api-auth --privateKey=$PRIVATE_KEY
```
> NOTE: Your public signing address must be allow-listed on our servers before your tokens will be valid.
Using an auth token to fetch an API endpoint programmatically:
```js
fetch("https://chroniclelabs.org/api/authTest", {
headers: {
Authorization: `Bearer ${token}`,
},
});
```
or via command line:
```bash
curl --header "Authorization: Bearer $AUTH_TOKEN" https://chroniclelabs.org/api/authTest
```