pub struct SignedFact {
pub canonical: Vec<u8>,
pub cid: [u8; 32],
pub signature: [u8; 64],
pub public_key: [u8; 32],
pub hash_alg: &'static str,
pub sig_alg: &'static str,
pub canon_ver: &'static str,
pub format_id: &'static str,
}Expand description
Signed Fact — fato assinado imutável (Paper II).
Representa um valor canônico com CID (BLAKE3) e assinatura Ed25519.
Um SignedFact é imutável e verificável por qualquer pessoa que tenha acesso
ao fato, sem necessidade de confiar em terceiros.
§Estrutura
canonical: bytes canônicos JSON✯Atomic do valor originalcid: BLAKE3 hash dos bytes canônicos (32 bytes)signature: assinatura Ed25519 sobre o CID (64 bytes)public_key: chave pública Ed25519 (32 bytes)hash_alg: algoritmo de hash (“blake3”)sig_alg: algoritmo de assinatura (“ed25519”)canon_ver: versão do formato canônico (“1”)format_id: identificador do formato (“json-atomic/1”)
§Exemplo
use ed25519_dalek::SigningKey;
use json_atomic::{seal_value, verify_seal, errors::SealError};
use serde::Serialize;
#[derive(Serialize)]
struct Data { value: u64 }
// Chave de exemplo (em produção, derive de seed/keystore)
let sk = SigningKey::from_bytes(&[0u8; 32]);
let signed = seal_value(&Data { value: 42 }, &sk)?;
// Verifica integridade e autenticidade
verify_seal(&signed)?;
// Acessa o CID em hexadecimal
println!("CID: {}", signed.cid_hex());Fields§
§canonical: Vec<u8>Bytes canônicos JSON✯Atomic do valor original.
cid: [u8; 32]BLAKE3 hash dos bytes canônicos (32 bytes).
signature: [u8; 64]Assinatura Ed25519 sobre o CID (64 bytes).
public_key: [u8; 32]Chave pública Ed25519 (32 bytes).
hash_alg: &'static strAlgoritmo de hash (sempre “blake3”).
sig_alg: &'static strAlgoritmo de assinatura (sempre “ed25519”).
canon_ver: &'static strVersão do formato canônico (sempre “1”).
format_id: &'static strIdentificador do formato (sempre “json-atomic/1”).
Implementations§
Source§impl SignedFact
impl SignedFact
Sourcepub fn verifying_key(&self) -> VerifyingKey
pub fn verifying_key(&self) -> VerifyingKey
Retorna a chave pública Ed25519 para verificação.
§Panics
Panics se a chave pública não for válida (não deve acontecer em SignedFacts válidos).
Sourcepub fn signature_obj(&self) -> Signature
pub fn signature_obj(&self) -> Signature
Retorna a assinatura como objeto ed25519_dalek::Signature.
Sourcepub fn cid_hex(&self) -> String
pub fn cid_hex(&self) -> String
Retorna o CID em formato hexadecimal (64 caracteres).
§Exemplo
use ed25519_dalek::SigningKey;
use json_atomic::seal_value;
use serde::Serialize;
#[derive(Serialize)]
struct Data { x: u32 }
// Chave de exemplo (em produção, derive de seed/keystore)
let sk = SigningKey::from_bytes(&[0u8; 32]);
let signed = seal_value(&Data { x: 1 }, &sk).unwrap();
let hex = signed.cid_hex();
assert_eq!(hex.len(), 64); // 32 bytes = 64 hex charsTrait Implementations§
Source§impl Clone for SignedFact
impl Clone for SignedFact
Source§fn clone(&self) -> SignedFact
fn clone(&self) -> SignedFact
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more