{"library":"prefixed-api-key","title":"Prefixed API Key Generator","description":"The `prefixed-api-key` package, currently at version 1.1.1, provides a robust solution for generating 'Seam-style' API keys in JavaScript and TypeScript environments. These keys incorporate a user-defined prefix, a short token for identification and blocklisting, and a long token that is never stored directly, only its hash. This design enhances security by reducing the server's attack surface and enables features like GitHub secret scanning due to the predictable prefix format. The library leverages standard cryptographic practices, including Base58 encoding (RFC-compliant) for the token components, offering advantages such as shorter keys compared to hex/base32, double-click selection, and high entropy comparable to UUIDv4. It ships with TypeScript types and is suitable for both Node.js and browser environments, focusing on a secure and developer-friendly approach to API key management.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install prefixed-api-key"],"cli":null},"imports":["import { generateAPIKey } from 'prefixed-api-key'","import { checkAPIKey } from 'prefixed-api-key'","import { getTokenComponents } from 'prefixed-api-key'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { generateAPIKey } from 'prefixed-api-key';\n\nasync function createAndStoreApiKey() {\n  const key = await generateAPIKey({\n    keyPrefix: 'mycompany' // Required: a prefix for your keys\n  });\n\n  // IMPORTANT: Store key.shortToken and key.longTokenHash in your database.\n  // NEVER store key.longToken directly. Provide key.token to your customer.\n  console.log('Generated Key Details:');\n  console.log(`  Full API Key (for customer): ${key.token}`);\n  console.log(`  Short Token (for DB & display): ${key.shortToken}`);\n  console.log(`  Long Token Hash (for DB validation): ${key.longTokenHash}`);\n  // console.log(`  Long Token (secret, do not store): ${key.longToken}`); // Do NOT log or store this in production!\n\n  // Example of storing in a mock database\n  const mockDb = new Map();\n  mockDb.set(key.shortToken, { hash: key.longTokenHash, createdAt: new Date() });\n  console.log('\\nStored in mock DB:');\n  console.log(mockDb.get(key.shortToken));\n\n  return key;\n}\n\ncreateAndStoreApiKey().catch(console.error);","lang":"typescript","description":"Demonstrates how to generate a new Seam-style API key, highlighting which components to store securely and which to provide to the end-user, along with an example of safe storage.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}