query('device_id'); $secret = $deviceId !== '' ? $this->devices->secretFor($deviceId) : null; $nonce = $req->header('X-Nonce') ?? ''; $ts = $req->header('X-Timestamp') ?? ''; $sig = $req->header('X-Signature') ?? ''; if ($secret === null || !Hmac::verify($secret, $nonce, $ts, $req->body(), $sig)) { return Response::json(['error' => 'unauthorized'], 401); } if (abs($now - (int)(float)$ts) > $this->cfg->timestampWindow()) { return Response::json(['error' => 'stale'], 401); } if ($nonce === '' || $this->nonces->seen($nonce)) { return Response::json(['error' => 'replay'], 401); } $this->nonces->remember($nonce, $now + $this->cfg->nonceTtl()); return Response::json([ 'version' => $this->devices->configVersion($deviceId), 'zones' => $this->zones->forDevice($deviceId), 'thresholds' => $this->thresholds->forDevice($deviceId), ], 200); } }