MCPcopy
hub / github.com/simstudioai/sim / deriveKeyHashForStoredKey

Function deriveKeyHashForStoredKey

packages/db/scripts/backfill-api-key-hash.ts:74–85  ·  view source on GitHub ↗
(
  storedKey: string,
  apiEncryptionKey: string | null
)

Source from the content-addressed store, hash-verified

72 * value looks encrypted but the caller has no encryption key.
73 */
74export function deriveKeyHashForStoredKey(
75 storedKey: string,
76 apiEncryptionKey: string | null
77): string {
78 if (isEncryptedKey(storedKey)) {
79 if (!apiEncryptionKey) {
80 throw new Error('API_ENCRYPTION_KEY is required to decrypt an encrypted stored key')
81 }
82 return hashApiKey(decryptApiKey(storedKey, apiEncryptionKey))
83 }
84 return hashApiKey(storedKey)
85}
86
87interface BackfillStats {
88 scanned: number

Callers 2

runBackfillFunction · 0.85

Calls 3

isEncryptedKeyFunction · 0.70
hashApiKeyFunction · 0.70
decryptApiKeyFunction · 0.70

Tested by

no test coverage detected