AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-only- ..
- ai.ts
- apps.ts
- audit.ts
- auth.ts
- central-core.d.mts
- central-core.mjs
- central.ts
- cloud.ts
- config.ts
- crypto.ts
- db.ts
- design.ts
- engines.ts
- files.ts
- gates.ts
- gateway.ts
- marketplace-core.d.mts
- marketplace-core.mjs
- metrics.ts
- modules.ts
- motion.ts
- nexus-core.d.mts
- nexus-core.mjs
- oidc-core.d.mts
- oidc-core.mjs
- oidc.ts
- providers.ts
- proxy-core.d.mts
- proxy-core.mjs
- pwauth-core.d.mts
- pwauth-core.mjs
- requirements.ts
- rls.sql.d.mts
- rls.sql.mjs
- ssrf.ts
- status.ts
- tenant.ts
- tlsgate.ts
- workspace.ts
app/src/lib/pwauth-core.mjs
1// Local password authentication primitives (pure). scrypt hashes only; plaintext is never stored. Interim until Zoo IAM is live.2import crypto from "node:crypto";3const N = 16384, R = 8, P = 1, KEYLEN = 64;4export const POLICY = { min: 12, max: 128 };5export function hashPassword(pw) { const salt = crypto.randomBytes(16); const h = crypto.scryptSync(pw, salt, KEYLEN, { N, r: R, p: P }); return `scrypt$${N}$${R}$${P}$${salt.toString("base64url")}$${h.toString("base64url")}`; }6export function verifyPassword(pw, stored) {7 const [alg, n, r, p, salt, hash] = String(stored ?? "").split("$"); if (alg !== "scrypt" || !hash) return false;8 try { const want = Buffer.from(hash, "base64url"); const got = crypto.scryptSync(pw, Buffer.from(salt, "base64url"), want.length, { N: +n, r: +r, p: +p }); return got.length === want.length && crypto.timingSafeEqual(got, want); } catch { return false; }9}10// Equal work for unknown accounts so response timing does not reveal whether an e-mail exists.11const DUMMY = hashPassword("zloud-dummy-password-for-timing");12export const burn = pw => { verifyPassword(pw, DUMMY); };13export function policyError(pw, { email, old } = {}) {14 if (typeof pw !== "string" || pw.length < POLICY.min) return `password must be at least ${POLICY.min} characters`;15 if (pw.length > POLICY.max) return `password must be at most ${POLICY.max} characters`;16 const local = String(email ?? "").split("@")[0].toLowerCase();17 if (local.length >= 4 && pw.toLowerCase().includes(local)) return "password must not contain your e-mail name";18 if ([/[a-z]/, /[A-Z]/, /\d/, /[^A-Za-z0-9]/].filter(r => r.test(pw)).length < 3) return "use at least three of: lowercase, uppercase, digits, symbols";19 if (old && pw === old) return "new password must differ from the temporary one";20 return null;21}22// 32 characters from a 66-symbol alphabet (about 190 bits) with guaranteed class coverage.23export function generatePassword(len = 32) {24 const sets = ["abcdefghijkmnopqrstuvwxyz", "ABCDEFGHJKLMNPQRSTUVWXYZ", "23456789", "-_.!@#"]; const all = sets.join("");25 const pick = s => s[crypto.randomInt(s.length)]; const out = sets.map(pick); while (out.length < len) out.push(pick(all));26 for (let i = out.length - 1; i > 0; i--) { const j = crypto.randomInt(i + 1); [out[i], out[j]] = [out[j], out[i]]; } return out.join("");27}28export const LOCK = { maxFailures: 5, lockMs: 15 * 60 * 1000 };29// Next lockout state after a failed attempt.30export const afterFailure = (failed, now = Date.now()) => { const f = (failed ?? 0) + 1; return f >= LOCK.maxFailures ? { failed: 0, lockedUntil: now + LOCK.lockMs } : { failed: f, lockedUntil: 0 }; };31// ---- TOTP (RFC 6238, SHA-1, 6 digits, 30 s, +-1 step). Enrolment UI is not built yet; verification is enforced for any account with mfa_enabled=1.32const B32 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";33export const b32decode = s => { let bits = 0, v = 0; const out = []; for (const ch of s.replace(/=+$/, "").toUpperCase()) { const i = B32.indexOf(ch); if (i < 0) throw new Error("bad base32"); v = (v << 5) | i; bits += 5; if (bits >= 8) { out.push((v >>> (bits - 8)) & 255); bits -= 8; } } return Buffer.from(out); };34export function totp(secretB32, t = Date.now()) {35 const c = Buffer.alloc(8); c.writeBigUInt64BE(BigInt(Math.floor(t / 30000))); const h = crypto.createHmac("sha1", b32decode(secretB32)).update(c).digest(); const o = h[19] & 15;36 return String((((h[o] & 127) << 24) | (h[o + 1] << 16) | (h[o + 2] << 8) | h[o + 3]) % 1e6).padStart(6, "0");37}38export const verifyTotp = (secretB32, code, t = Date.now()) => /^\d{6}$/.test(String(code)) && [-1, 0, 1].some(d => { const a = Buffer.from(totp(secretB32, t + d * 30000)), b = Buffer.from(String(code)); return a.length === b.length && crypto.timingSafeEqual(a, b); });39
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 1c27633 on master.
Approval requests
None pending.