chore: remove unused api key format helpers (#5359)

Integrated into release/v3.8.41 — dead-code removal (typecheck:core EXIT 0, 102 affected tests green, fabricated-docs clean). Thanks @JxnLexn.
This commit is contained in:
Jan Leon
2026-06-29 17:05:32 +02:00
committed by GitHub
parent ad6b83738f
commit f56fb31bfa
2 changed files with 29 additions and 26 deletions

View File

@@ -90,29 +90,3 @@ export function parseApiKey(
return null;
}
/**
* Verify API key CRC (only for new format)
* @param {string} apiKey
* @returns {boolean}
*/
export function verifyApiKeyCrc(apiKey: string): boolean {
const parsed = parseApiKey(apiKey);
if (!parsed) return false;
// Old format doesn't have CRC, always valid if parsed
if (!parsed.isNewFormat) return true;
// New format already verified in parseApiKey
return true;
}
/**
* Check if API key is new format (contains machineId)
* @param {string} apiKey
* @returns {boolean}
*/
export function isNewFormatKey(apiKey: string): boolean {
const parsed = parseApiKey(apiKey);
return parsed?.isNewFormat === true;
}

View File

@@ -0,0 +1,29 @@
import test from "node:test";
import assert from "node:assert/strict";
process.env.API_KEY_SECRET = "test-api-key-utils-secret";
const apiKeyUtils = await import("../../src/shared/utils/apiKey.ts");
test("api key utility public surface keeps generation and parsing only", () => {
const machineId = "testmachine";
const { key, keyId } = apiKeyUtils.generateApiKeyWithMachine(machineId);
assert.equal(typeof key, "string");
assert.equal(typeof keyId, "string");
assert.match(key, new RegExp(`^sk-${machineId}-${keyId}-[a-f0-9]{8}$`));
assert.deepEqual(apiKeyUtils.parseApiKey(key), {
machineId,
keyId,
isNewFormat: true,
});
assert.deepEqual(apiKeyUtils.parseApiKey("sk-legacykey"), {
machineId: null,
keyId: "legacykey",
isNewFormat: false,
});
assert.equal(apiKeyUtils.parseApiKey("not-a-key"), null);
assert.equal("verifyApiKeyCrc" in apiKeyUtils, false);
assert.equal("isNewFormatKey" in apiKeyUtils, false);
});