use crate::errors::ApiError; pub use crate::services::pow::*; use api::http::State; use api::middleware::RequestId; use api::rest::{AppResponseData, NoData}; use session::Session; #[utoipa::path( post, path = "/auth/challenge", tag = "auth", operation_id = "auth_challenge", summary = "签发工作量证明挑战", description = "把挑战写进当前会话并返回。客户端需要为 `context` 找出一枚满足 `difficulty`(前导零比特数)的 nonce;`pow.v1` 算法与前端求解器一致。", responses( ( status = 200, description = "挑战已签发并写入会话", body = AppResponseData, example = json!({"code":200,"message":"success","data":{"context":"3xJk9Qp2mV7sLbT1rZa8nHc4wDf6YgU0","difficulty":16,"issued_at":1767139200,"expires_at":1767139500}}) ), ( status = 500, description = "`internal`(挑战无法写入会话)/ `cache` / `session` / `serialization`", body = AppResponseData, example = json!({"code": "internal", "message": "internal server error"}) ) ) )] pub async fn challenge( State(svc): State, session: Session, request_id: RequestId, ) -> Result, ApiError> { let challenge = svc.challenge(session, request_id.0).await?; Ok(AppResponseData::ok(challenge)) }