@seda-protocol/api-keys
v1.0.0
Published
Generate and verify API keys in the format `[PREFIX]_[INFIX]_[ID]_[SECRET][CHECKSUM]`.
Readme
@seda-protocol/api-keys
Generate and verify API keys in the format [PREFIX]_[INFIX]_[ID]_[SECRET][CHECKSUM].
- PREFIX — identifies the API service (e.g.
fast) - INFIX — identifies the key type/network (e.g.
mainnet,testnet) - ID — 8-char base58 public identifier
- SECRET — 24-char base58 private secret
- CHECKSUM — 6-char base58 CRC32 checksum for integrity validation
Base58 encoding avoids ambiguous characters (0, I, O, l) and ensures the full key is easily selectable in any editor or terminal.
Usage
import { generateApiKey, verifyAndDecodeApiKey } from "@seda-protocol/api-keys";
const { apiKey, apiKeyId, apiKeyHash } = generateApiKey({ prefix: "fast", infix: "mainnet" });
// apiKey: "fast_mainnet_fsNiVmkM_JuebYqHyjtBxfjfL1Yk36k6w3CA4MU"
const result = verifyAndDecodeApiKey(apiKey, { prefix: "fast", infix: "mainnet" });
if (result.valid) {
// result.apiKeyId — public identifier, safe to store/display
// result.apiKeyHash — SHA-256 hash of the secret, use for DB lookups
}The apiKeyHash is a SHA-256 digest of the secret portion. Store this in your database instead of the raw key, and use apiKeyId + apiKeyHash together for lookups during verification.
