From e65ab86904f4ca990fff189af1af983f70e5fff2 Mon Sep 17 00:00:00 2001 From: rink1969 Date: Fri, 27 Feb 2026 13:18:45 +0800 Subject: [PATCH] update deps and add agents.md --- AGENTS.md | 78 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 16 +++++----- src/health_check.rs | 4 +-- src/main.rs | 10 +++--- 4 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..bec0805 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,78 @@ +# CITA-Cloud Crypto SM Service + +## 项目基本信息 +- **名称**: crypto +- **版本**: 6.7.5 +- **描述**: CITA-Cloud 平台的国密(SM)加密服务实现。基于 Rust 语言开发,提供符合 CITA-Cloud 协议标准的加密、签名、哈希等 gRPC 服务。 +- **许可证**: Apache-2.0 +- **维护者**: Rivtower Technologies + +## 核心能力 +本项目实现了 `cita_cloud_proto` 定义的 `CryptoService` 接口,主要提供以下国密算法相关功能: + +1. **加密信息查询 (`get_crypto_info`)** + - 提供当前加密服务的元数据和配置信息。 + +2. **哈希计算 (`hash_data`)** + - 提供数据的哈希计算服务,默认采用 SM3 算法。 + +3. **签名 (`sign_message`)** + - 使用 SM2 算法对消息进行签名。 + +4. **签名恢复 (`recover_signature`)** + - 从签名中恢复公钥或地址,用于验证签名的来源。 + +5. **哈希验证 (`verify_data_hash`)** + - 验证数据与其哈希值是否匹配。 + +6. **健康检查** + - 实现 gRPC 健康检查标准,支持服务健康状态监控。 + +7. **监控指标** + - 集成 Prometheus 指标导出,支持服务运行状态监控。 + +## 运行依赖 +- **开发环境**: + - Rust (Edition 2024) + - Protobuf Compiler (protoc) + +- **核心依赖库**: + - `tonic`: gRPC 框架 + - `tokio`: 异步运行时 + - `libsm`, `efficient-sm2`: 国密算法实现 + - `cita_cloud_proto`: CITA-Cloud 协议定义 + - `cloud-util`: 云原生工具库 + +## 使用示例 + +### 编译构建 +```bash +cargo build --release +``` + +### 运行服务 +服务可以通过命令行启动,支持指定配置文件和私钥路径。 + +**基本命令格式**: +```bash +crypto run [OPTIONS] +``` + +**参数说明**: +- `-c, --config `: 配置文件路径 (默认: "config.toml") +- `-p, --private_key_path `: 私钥文件路径 (默认: "private_key") + +**运行示例**: +```bash +# 使用默认配置运行 +cargo run -- run + +# 指定配置文件和私钥路径运行 +cargo run -- run -c my_config.toml -p my_private_key +``` + +### 配置文件示例 (config.toml) +```toml +# 示例配置结构 (需根据实际 config.rs 确认) +grpc_port = 50005 +``` diff --git a/Cargo.toml b/Cargo.toml index 3a8d513..0e856f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,26 +1,26 @@ [package] name = "crypto" -version = "6.7.4" +version = "6.7.5" authors = ["Rivtower Technologies "] license = "Apache-2.0" -edition = "2021" +edition = "2024" [dependencies] clap = { version = "4.5", features = ["derive"] } -tonic = "0.12" -prost = "0.13" -tokio = { version = "1.41", features = ["full"] } +tonic = "0.14" +prost = "0.14" +tokio = { version = "1.49", features = ["full"] } hex = "0.4" tower = "0.5" libsm = "0.6" efficient-sm2 = "0.2" -rayon = "1.10" +rayon = "1.11" serde = "1.0" serde_derive = "1.0" tracing = "0.1" -cloud-util = { package = "cloud-util", git = "https://github.com/cita-cloud/cloud-common-rs" } -cita_cloud_proto = { package = "cita_cloud_proto", git = "https://github.com/cita-cloud/cloud-common-rs" } +cloud-util = { package = "cloud-util", git = "https://github.com/cita-cloud/cloud-common-rs", branch = "update" } +cita_cloud_proto = { package = "cita_cloud_proto", git = "https://github.com/cita-cloud/cloud-common-rs", branch = "update" } [profile.release.package."*"] # Set the default for dependencies. diff --git a/src/health_check.rs b/src/health_check.rs index ec77f41..1e43c18 100755 --- a/src/health_check.rs +++ b/src/health_check.rs @@ -13,8 +13,8 @@ // limitations under the License. use cita_cloud_proto::health_check::{ - health_check_response::ServingStatus, health_server::Health, HealthCheckRequest, - HealthCheckResponse, + HealthCheckRequest, HealthCheckResponse, health_check_response::ServingStatus, + health_server::Health, }; use tonic::{Request, Response, Status}; diff --git a/src/main.rs b/src/main.rs index 31347bc..b0be9d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,19 +25,19 @@ use crate::crypto::Crypto; use cita_cloud_proto::blockchain::RawTransactions; use cita_cloud_proto::common::{Empty, Hash, HashResponse, StatusCode}; use cita_cloud_proto::crypto::{ - crypto_service_server::CryptoService, crypto_service_server::CryptoServiceServer, GetCryptoInfoResponse, HashDataRequest, RecoverSignatureRequest, RecoverSignatureResponse, SignMessageRequest, SignMessageResponse, VerifyDataHashRequest, + crypto_service_server::CryptoService, crypto_service_server::CryptoServiceServer, }; use cita_cloud_proto::health_check::health_server::HealthServer; use cita_cloud_proto::status_code::StatusCodeEnum; use clap::Parser; -use cloud_util::metrics::{run_metrics_exporter, MiddlewareLayer}; +use cloud_util::metrics::{MiddlewareLayer, run_metrics_exporter}; use config::CryptoConfig; use health_check::HealthCheckServer; -use sm::{crypto_check_batch, ADDR_BYTES_LEN, SM2_SIGNATURE_BYTES_LEN}; +use sm::{ADDR_BYTES_LEN, SM2_SIGNATURE_BYTES_LEN, crypto_check_batch}; use std::net::AddrParseError; -use tonic::{transport::Server, Request, Response, Status}; +use tonic::{Request, Response, Status, transport::Server}; use util::clap_about; #[derive(Parser)] @@ -66,8 +66,6 @@ struct RunOpts { } fn main() { - ::std::env::set_var("RUST_BACKTRACE", "full"); - let opts: Opts = Opts::parse(); // You can handle information about subcommands by requesting their matches by name