Skip to main content

qualia_core_db/governance/
web_civics.rs

1use ed25519_dalek::VerifyingKey;
2use sha2::{Digest, Sha256};
3use std::net::Ipv6Addr;
4
5/// Derives a Unique Local IPv6 Address (ULA) in the fd00::/8 block
6/// from an Ed25519 Webizen Public Key.
7/// This enforces Cryptokey Routing where the DID is mathematically
8/// synonymous with the IPv6 address.
9pub fn derive_webizen_ipv6(public_key: &VerifyingKey) -> Ipv6Addr {
10    let mut hasher = Sha256::new();
11    hasher.update(public_key.as_bytes());
12    let result = hasher.finalize();
13
14    // ULA addresses start with fd (1111 1101)
15    let mut ipv6_bytes = [0u8; 16];
16    ipv6_bytes[0] = 0xfd;
17
18    // Copy 15 bytes of the hash into the remaining 15 bytes of the IPv6 address
19    ipv6_bytes[1..16].copy_from_slice(&result[0..15]);
20
21    Ipv6Addr::from(ipv6_bytes)
22}