open-index/open-npm huggingface dataset:
npm package: @polymerdao/ts-token
Description: Token authentication helpers for Polymer's Prove API, ready for Cloudflare Workers and Next.js Edge runtimes.
Author: Polymer Labs
Latest version: 0.1.0

# ts-token

Utility helpers for creating and verifying Polymer auth tokens in Cloudflare Workers, Next.js (Edge/Pages), or any other runtime that exposes standard Web APIs.

## Installation

```bash
npm install @polymerdao/ts-token
```

## Usage

```ts
import { create, verify } from '@polymerdao/ts-token';

const body = JSON.stringify({ jsonrpc: '2.0', method: 'proof_request', params: [] });

// Generate a token for your fetch call
const token = create({
  body,
  urlPath: '/rpc',
  host: 'polymer.example',
  secret: env.POLYMER_AUTH_SECRET,
});

await fetch(env.POLYMER_API_URL, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${env.POLYMER_API_KEY}`,
    'X-Polymer-Auth-Token': token,
    'Content-Type': 'application/json',
  },
  body,
});

// Verify an incoming token if you proxy traffic through your own service
const verification = verify({
  token: request.headers.get('X-Polymer-Auth-Token') ?? '',
  body,
  urlPath: '/rpc',
  host: 'polymer.example',
  secret: env.POLYMER_AUTH_SECRET,
});

if (!verification.valid) throw new Error(`Invalid token: ${verification.reason}`);

```

## Development

```bash
npm run dev     # Type-checks in watch mode
npm run lint    # ESLint against src/ + tests/
npm test        # Vitest suite
npm run build   # Emit ESM bundle and type declarations
```

## Publishing

1. Update `package.json` with the target version (or run `npm version <major|minor|patch>`).
2. Create a matching git tag following the `v1.2.3` convention and push it (`git tag v1.2.3 && git push origin main --tags`).
3. Run `npm run release` to build and publish to npm (requires `NPM_TOKEN` with publish rights).