keypal

Secure API key management for TypeScript

Cryptographic hashing, expiration, scopes, and pluggable storage adapters. Built for production with zero configuration required.

Installation

Install keypal with your preferred package manager

npm install keypal
# or
bun add keypal
# or
pnpm add keypal

Features

Everything you need for secure API key management

Secure by Default

SHA-256/SHA-512 hashing with optional salt and timing-safe comparison

Smart Detection

Automatically extracts keys from Authorization headers or custom headers

Flexible Storage

Memory, Redis, Drizzle, Prisma, and Kysely adapters included

Scope-based Permissions

Fine-grained access control with resource-specific scopes

Built-in Caching

Optional in-memory or Redis caching for validated keys

TypeScript

Full type safety with zero configuration required

Quick Start

Get up and running in minutes with a simple example

import { createKeys } from 'keypal'

const keys = createKeys({
  prefix: 'sk_',
  cache: true,
})

// Create a key
const { key, record } = await keys.create({
  ownerId: 'user_123',
  scopes: ['read', 'write'],
})

// Verify from headers
const result = await keys.verify(request.headers)
if (result.valid) {
  console.log('Authenticated:', result.record.metadata.ownerId)
}

Storage Adapters

Choose the storage backend that fits your infrastructure

Memory

In-memory storage for development

Redis

Distributed storage for production

Drizzle

PostgreSQL, MySQL, SQLite

Prisma

Works with any Prisma database

Kysely

Type-safe SQL query builder

Custom

Implement your own adapter

More

See all adapters in the docs

Ready to get started?

Install keypal and start managing API keys in minutes. Full documentation available with examples and guides.