{"version":3,"file":"normalize-secrets.mjs","names":[],"sources":["../../../src/libs/config/normalize-secrets.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport type { LucidConfig, SecretConfig } from \"../../types/config.js\";\nimport LucidError from \"../../utils/errors/lucid-error.js\";\n\nconst SECRET_LENGTH = 64;\n\nconst secretLabels = {\n\tencryption: \"lucid:secrets:encryption\",\n\tcookie: \"lucid:secrets:cookie\",\n\taccessToken: \"lucid:secrets:access-token\",\n\trefreshToken: \"lucid:secrets:refresh-token\",\n} satisfies Record<keyof SecretConfig, string>;\n\nconst deriveSecret = (rootSecret: string, label: string) =>\n\tcrypto.createHmac(\"sha256\", rootSecret).update(label).digest(\"hex\");\n\nconst assertRootSecret = (rootSecret: string) => {\n\tif (rootSecret.length === SECRET_LENGTH) return;\n\n\tthrow new LucidError({\n\t\tmessage: `Lucid root secret must be ${SECRET_LENGTH} characters long.`,\n\t});\n};\n\nconst normalizeSecrets = (secrets: LucidConfig[\"secrets\"]): SecretConfig => {\n\tif (typeof secrets !== \"string\") {\n\t\treturn secrets;\n\t}\n\n\tassertRootSecret(secrets);\n\n\treturn {\n\t\tencryption: deriveSecret(secrets, secretLabels.encryption),\n\t\tcookie: deriveSecret(secrets, secretLabels.cookie),\n\t\taccessToken: deriveSecret(secrets, secretLabels.accessToken),\n\t\trefreshToken: deriveSecret(secrets, secretLabels.refreshToken),\n\t};\n};\n\nexport default normalizeSecrets;\n"],"mappings":"6EAIA,MAEM,EAAe,CACpB,WAAY,2BACZ,OAAQ,uBACR,YAAa,6BACb,aAAc,6BACf,EAEM,GAAgB,EAAoB,IACzC,EAAO,WAAW,SAAU,CAAU,CAAC,CAAC,OAAO,CAAK,CAAC,CAAC,OAAO,KAAK,EAE7D,EAAoB,GAAuB,CAC5C,KAAW,SAAW,GAE1B,MAAM,IAAI,EAAW,CACpB,QAAS,+CACV,CAAC,CACF,EAEM,EAAoB,GACrB,OAAO,GAAY,UAIvB,EAAiB,CAAO,EAEjB,CACN,WAAY,EAAa,EAAS,EAAa,UAAU,EACzD,OAAQ,EAAa,EAAS,EAAa,MAAM,EACjD,YAAa,EAAa,EAAS,EAAa,WAAW,EAC3D,aAAc,EAAa,EAAS,EAAa,YAAY,CAC9D,GAVQ"}