esg_tokenization_protocol/
lib.rs1use serde::{Serialize, Deserialize};
2use sha3::{Digest, Sha3_512};
3use uuid::Uuid;
4
5#[derive(Debug, Serialize, Deserialize, Clone)]
7pub struct ESGMetadata {
8 pub standard: String,
9 pub category: String,
10 pub geo: String,
11 pub carbon_value: f64,
12 pub cycle: String,
13 pub digest: String,
14 pub physical_id: String,
15 pub attestation: Attestation,
16 pub status: String,
17 pub evidence: String,
18}
19
20#[derive(Debug, Serialize, Deserialize, Clone)]
22pub struct Attestation {
23 pub atf_digest: String,
24 pub signer: String,
25}
26
27pub fn generate_digest(input: &str) -> String {
29 let mut hasher = Sha3_512::new();
30 hasher.update(input.as_bytes());
31 format!("{:x}", hasher.finalize())
32}
33
34pub fn create_metadata(category: &str, geo: &str, carbon_value: f64, cycle: &str) -> ESGMetadata {
36 let digest = generate_digest(&format!(
38 "{}:{}:{}:{}",
39 category, geo, carbon_value, cycle
40 ));
41
42 let physical_id = format!("seal:{}", Uuid::new_v4());
44
45 let attestation = Attestation {
47 atf_digest: digest.clone(),
48 signer: "did:atf:ai:validator".to_string(),
49 };
50
51 ESGMetadata {
52 standard: "ERC-ESG/1.0".to_string(),
53 category: category.to_string(),
54 geo: geo.to_string(),
55 carbon_value,
56 cycle: cycle.to_string(),
57 digest,
58 physical_id,
59 attestation,
60 status: "issued".to_string(),
61 evidence: "cid:QmExample".to_string(),
62 }
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn test_metadata_generation() {
71 let meta = create_metadata("carbon", "BR-RS", 12.5, "2025-Q3");
72 assert_eq!(meta.standard, "ERC-ESG/1.0");
73 assert_eq!(meta.category, "carbon");
74 assert_eq!(meta.geo, "BR-RS");
75 assert_eq!(meta.status, "issued");
76 assert!(!meta.digest.is_empty());
77 assert!(!meta.attestation.atf_digest.is_empty());
78 }
79}