@olares/lares-core 0.15.24 → 0.15.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/voice/external.js DELETED
@@ -1,26 +0,0 @@
1
- import { createHmac, timingSafeEqual } from "node:crypto";
2
-
3
- /** A configured Router signs the resolved principal; caller-supplied identity headers are ignored. */
4
- export function verifyVoicePrincipal(headers, secret, { now = Date.now } = {}) {
5
- if (typeof secret !== "string" || secret.length < 32) throw new Error("voice_external_disabled");
6
- const claim = headers["x-olares-voice-principal"];
7
- const signature = headers["x-olares-voice-signature"];
8
- if (typeof claim !== "string" || claim.length > 4096 || typeof signature !== "string" || !/^[a-f0-9]{64}$/.test(signature)) throw new Error("voice_external_unauthorized");
9
- const expected = createHmac("sha256", secret).update(claim).digest();
10
- if (!timingSafeEqual(expected, Buffer.from(signature, "hex"))) throw new Error("voice_external_unauthorized");
11
- let principal;
12
- try { principal = JSON.parse(Buffer.from(claim, "base64url").toString("utf8")); } catch { throw new Error("voice_external_unauthorized"); }
13
- if (!Number.isInteger(principal.at) || Math.abs(now() / 1000 - principal.at) > 60 || typeof principal.nonce !== "string" || !/^[a-f0-9]{32}$/.test(principal.nonce) || typeof principal.model !== "string" || (!principal.user && !principal.app)) throw new Error("voice_external_unauthorized");
14
- return principal;
15
- }
16
-
17
- export function authorizeVoicePreset(principal, grants, model) {
18
- if (principal.model !== model) throw new Error("voice_external_model_mismatch");
19
- const preset = { "voice-dictation": "dictation", "voice-chat": "chat", "voice-assistant": "assistant", "voice-direct": "direct" }[model];
20
- if (!preset) throw new Error("voice_external_model_unknown");
21
- const owner = principal.user || `app:${principal.app}`;
22
- const grant = grants[owner];
23
- if (!grant?.presets?.includes(preset)) throw new Error("voice_external_forbidden");
24
- if (["assistant", "direct"].includes(preset) && (!principal.user || !grant.lares)) throw new Error("voice_external_forbidden");
25
- return { owner, preset, sessionId: grant.sessionId || null, workspaceId: grant.workspaceId || null, agentPreset: grant.agentPreset || null };
26
- }