diff --git a/nac-acc-1410/src/cross_partition_transfer.rs b/nac-acc-1410/src/cross_partition_transfer.rs index 02984bb..928ed73 100644 --- a/nac-acc-1410/src/cross_partition_transfer.rs +++ b/nac-acc-1410/src/cross_partition_transfer.rs @@ -27,8 +27,8 @@ pub struct CrossPartitionTransferRequest { /// 分区间转账记录 #[derive(Debug, Clone)] pub struct CrossPartitionTransferRecord { - /// 转账ID - pub transfer_id: [u8; 32], + /// 转账ID (SHA3-384 Hash) + pub transfer_id: [u8; 48], /// 发送方账户 pub from: String, /// 接收方账户 @@ -91,7 +91,7 @@ pub struct TransferValidationRule { #[derive(Debug)] pub struct CrossPartitionTransferManager { /// 转账记录 - records: HashMap<[u8; 32], CrossPartitionTransferRecord>, + records: HashMap<[u8; 48], CrossPartitionTransferRecord>, /// 验证规则 validation_rules: HashMap, /// 转账通知监听器 @@ -193,7 +193,7 @@ impl CrossPartitionTransferManager { pub fn create_transfer_record( &mut self, request: &CrossPartitionTransferRequest, - ) -> [u8; 32] { + ) -> [u8; 48] { self.transfer_counter += 1; // 生成转账ID @@ -225,7 +225,7 @@ impl CrossPartitionTransferManager { /// 更新转账状态 pub fn update_transfer_status( &mut self, - transfer_id: &[u8; 32], + transfer_id: &[u8; 48], status: CrossPartitionTransferStatus, failure_reason: Option, ) -> Result<()> { @@ -257,7 +257,7 @@ impl CrossPartitionTransferManager { } /// 获取转账记录 - pub fn get_transfer_record(&self, transfer_id: &[u8; 32]) -> Result { + pub fn get_transfer_record(&self, transfer_id: &[u8; 48]) -> Result { self.records .get(transfer_id) .cloned() @@ -292,7 +292,7 @@ impl CrossPartitionTransferManager { } /// 取消转账 - pub fn cancel_transfer(&mut self, transfer_id: &[u8; 32]) -> Result<()> { + pub fn cancel_transfer(&mut self, transfer_id: &[u8; 48]) -> Result<()> { let record = self.records .get_mut(transfer_id) .ok_or_else(|| Acc1410Error::NotFound(format!("Transfer record not found")))?; @@ -308,14 +308,14 @@ impl CrossPartitionTransferManager { } /// 生成转账ID - fn generate_transfer_id(&self, counter: u64) -> [u8; 32] { - use sha2::{Sha256, Digest}; - let mut hasher = Sha256::new(); + fn generate_transfer_id(&self, counter: u64) -> [u8; 48] { + use sha3::{Sha3_384, Digest}; + let mut hasher = Sha3_384::new(); hasher.update(b"cross_partition_transfer"); hasher.update(&counter.to_be_bytes()); hasher.update(&Self::current_timestamp().to_be_bytes()); let hash = hasher.finalize(); - let mut id = [0u8; 32]; + let mut id = [0u8; 48]; id.copy_from_slice(&hash); id } diff --git a/nac-acc-1410/src/events.rs b/nac-acc-1410/src/events.rs index c3b5edc..d171d6c 100644 --- a/nac-acc-1410/src/events.rs +++ b/nac-acc-1410/src/events.rs @@ -90,12 +90,12 @@ pub struct EventRecord { pub timestamp: u64, /// 区块高度(可选) pub block_height: Option, - /// 交易哈希(可选) - pub tx_hash: Option<[u8; 32]>, + /// 交易哈希 (SHA3-384 Hash)(可选) + pub tx_hash: Option<[u8; 48]>, } /// 事件监听器trait -pub trait EventListener: Send + Sync { +pub trait EventListener: Send + Sync + std::fmt::Debug { /// 处理事件 fn on_event(&self, event: &EventRecord); @@ -117,6 +117,7 @@ pub struct EventFilter { } /// 事件管理器 +#[derive(Debug)] pub struct EventManager { /// 事件日志 event_log: Vec, @@ -164,7 +165,7 @@ impl EventManager { &mut self, event: Acc1410Event, block_height: Option, - tx_hash: Option<[u8; 32]>, + tx_hash: Option<[u8; 48]>, ) { self.event_counter += 1; diff --git a/nac-wallet-core/src/constitutional_receipt.rs b/nac-wallet-core/src/constitutional_receipt.rs index 513bf94..b011416 100644 --- a/nac-wallet-core/src/constitutional_receipt.rs +++ b/nac-wallet-core/src/constitutional_receipt.rs @@ -1,34 +1,34 @@ //! 宪法收据模块 use serde::{Deserialize, Serialize}; -use sha3::{Digest, Sha3_256}; +use sha3::{Digest, Sha3_384}; /// 宪法收据 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ConstitutionalReceipt { - /// 交易哈希 - pub transaction_hash: [u8; 32], - /// 宪法哈希 - pub constitutional_hash: [u8; 32], + /// 交易哈希 (SHA3-384) + pub transaction_hash: [u8; 48], + /// 宾法哈希 (SHA3-384) + pub constitutional_hash: [u8; 48], /// 条款掩码 pub clause_mask: u64, - /// 执行结果哈希 - pub execution_result_hash: [u8; 32], + /// 执行结果哈希 (SHA3-384) + pub execution_result_hash: [u8; 48], /// 时间戳 pub timestamp: u64, /// 有效期窗口 pub validity_window: u64, /// CEE节点签名列表 pub signatures: Vec>, - /// 收据ID - pub receipt_id: [u8; 32], + /// 收据ID (SHA3-384) + pub receipt_id: [u8; 48], } impl ConstitutionalReceipt { /// 创建新的宪法收据 pub fn new( - transaction_hash: [u8; 32], - constitutional_hash: [u8; 32], + transaction_hash: [u8; 48], + constitutional_hash: [u8; 48], clause_mask: u64, ) -> Self { let receipt_id = Self::generate_receipt_id(&transaction_hash); @@ -37,7 +37,7 @@ impl ConstitutionalReceipt { transaction_hash, constitutional_hash, clause_mask, - execution_result_hash: [0u8; 32], + execution_result_hash: [0u8; 48], timestamp: 0, validity_window: 300, signatures: Vec::new(), @@ -45,13 +45,13 @@ impl ConstitutionalReceipt { } } - fn generate_receipt_id(transaction_hash: &[u8; 32]) -> [u8; 32] { - let mut hasher = Sha3_256::new(); + fn generate_receipt_id(transaction_hash: &[u8; 48]) -> [u8; 48] { + let mut hasher = Sha3_384::new(); hasher.update(transaction_hash); hasher.update(b"NAC_CR"); let result = hasher.finalize(); - let mut id = [0u8; 32]; + let mut id = [0u8; 48]; id.copy_from_slice(&result); id } @@ -87,7 +87,7 @@ pub struct CEERequest { impl CEERequest { /// 创建新的CEE请求 - pub fn new(transaction_hash: [u8; 32]) -> Self { + pub fn new(transaction_hash: [u8; 48]) -> Self { Self { transaction_hash: format!("{:?}", transaction_hash), transaction_payload: None, diff --git a/nac-wallet-core/src/transaction.rs b/nac-wallet-core/src/transaction.rs index 004a145..a110779 100644 --- a/nac-wallet-core/src/transaction.rs +++ b/nac-wallet-core/src/transaction.rs @@ -145,14 +145,14 @@ impl TransactionPayload { } } - /// 计算交易哈希 - pub fn hash(&self) -> [u8; 32] { + /// 计算交易哈希 (SHA3-384) + pub fn hash(&self) -> [u8; 48] { let serialized = bincode::serialize(self).unwrap_or_default(); - let mut hasher = Sha3_256::new(); + let mut hasher = Sha3_384::new(); hasher.update(&serialized); let result = hasher.finalize(); - let mut hash = [0u8; 32]; + let mut hash = [0u8; 48]; hash.copy_from_slice(&result); hash }