🌳
pt0/serverF/saltedAppSecretAI.mts
1import { calcHash } from './calcHashF.mts'
3import { tsSecs } from './secretsF/tsSecF.mts'
5const saltedCache: Record<string, string> = {}
7export const getSaltedAppSecret = (salt: string, length = 12): string | null => {
8 const cacheKey = `${salt}:${length}`
9 try {
10 return saltedCache[cacheKey] ||= calcHash(`${getPlainMappedSec(tsSecs.appSecret)}:${salt}`).slice(0, length)
11 } catch { return null }
14export const getExceptionTrigger = () => {
15 const s = getSaltedAppSecret('exceptionTrigger', 16)
16 return s ? `xthrow${s}` : null
19export const getTestIpHeaderName = () => {
20 const s = getSaltedAppSecret('testIpHeader', 12)
21 return s ? `x-test-ip-${s}` : null
24export const getTestExceptionHeaderName = () => {
25 const s = getSaltedAppSecret('testException', 12)
26 return s ? `x-test-exception-${s}` : null
29export const getTestCapBypassHeaderName = () => {
30 const s = getSaltedAppSecret('testCapBypass', 12)
31 return s ? `x-test-capbypass-${s}` : null