Files
llmapikey/lib/keys/key-format.js
T
tiennm99 02fa52ccf9 feat: scaffold OpenRouter key giveaway site (gated, code-only)
- Next.js 15 App Router (JS+JSDoc): landing, auth-gated dashboard, docs
- GitHub OAuth via Supabase; identity anchored on numeric provider_id
- key provisioning: reserve-then-mint-persist-compensate, one key per account
- api_keys in unexposed llmapikey schema via direct Postgres; RLS deny-all
- live minting gated behind PROVISIONING_ENABLED; Vercel auto-deploy disabled
- unit tests (mask, request-body), RLS deny-all test, reconcile script
2026-06-13 14:18:52 +07:00

28 lines
704 B
JavaScript

/**
* Pure key formatting helpers. No secrets, no I/O — safe to import anywhere and
* unit-testable in isolation.
*/
/**
* Last 4 chars of a raw key, for masked display/storage. The raw key itself is
* never stored; only this hint is.
*
* @param {string} rawKey
* @returns {string}
*/
export function last4(rawKey) {
if (typeof rawKey !== "string" || rawKey.length === 0) return "";
return rawKey.slice(-4);
}
/**
* Masked representation from a stored last-4 hint, e.g. "sk-or-v1-••••1234".
*
* @param {string | null | undefined} hint
* @returns {string}
*/
export function maskFromHint(hint) {
if (!hint) return "••••";
return `sk-or-v1-••••${hint}`;
}