@lowerdeck/api-key
Create and parse structured API keys with embedded configuration. Supports versioning, type prefixes, and automatic validation for secure key management.
Installation
npm install @lowerdeck/api-key
yarn add @lowerdeck/api-key
bun add @lowerdeck/api-key
pnpm add @lowerdeck/api-key
Usage
import { createApiKeyGenerator } from '@lowerdeck/api-key';
const keyTypes = {
uk: 'user_auth_token',
ak: 'app_access_token',
sk: 'secret_key'
} as const;
const ApiKey = createApiKeyGenerator(keyTypes, {
prefix: 'myapp',
secretLength: 60
});
const key = ApiKey.create({
type: 'user_auth_token',
config: {
url: 'https://api.example.com'
}
});
console.log(key.toString());
const parsed = ApiKey.from('myapp_uk_...');
if (parsed) {
console.log(parsed.type);
console.log(parsed.config.url);
}
const redacted = ApiKey.redact(key);
console.log(redacted);
License
This project is licensed under the Apache License 2.0.