MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / writeAuthFile

Function writeAuthFile

src/services/auth/token-store.ts:61–73  ·  view source on GitHub ↗
(file: AuthFile)

Source from the content-addressed store, hash-verified

59}
60
61async function writeAuthFile(file: AuthFile): Promise<void> {
62 const path = AUTH_FILE()
63 await mkdir(dirname(path), { recursive: true })
64 const data = JSON.stringify(file, null, 2) + '\n'
65 // Tight permissions: only owner can read. Important because the hash, if
66 // leaked alongside the salt, could in principle be brute-forced. 256-bit
67 // input makes that infeasible, but defense in depth still wants chmod 600.
68 await writeFile(path, data, { mode: 0o600 })
69 // Some platforms ignore the `mode` option on writeFile (windows, certain
70 // Docker images with restrictive umask). Force a second chmod to be sure
71 // — best-effort, ignore failures on platforms that don't support it.
72 await chmod(path, 0o600).catch(() => { /* noop */ })
73}
74
75function deriveHash(token: string, salt: Buffer): Buffer {
76 return scryptSync(token, salt, KEY_LEN, { N: SCRYPT_N, r: SCRYPT_R, p: SCRYPT_P })

Callers 1

generateTokenFunction · 0.85

Calls 1

AUTH_FILEFunction · 0.85

Tested by

no test coverage detected