SignedFact

Struct SignedFact 

Source
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 original
  • cid: 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 str

Algoritmo de hash (sempre “blake3”).

§sig_alg: &'static str

Algoritmo de assinatura (sempre “ed25519”).

§canon_ver: &'static str

Versão do formato canônico (sempre “1”).

§format_id: &'static str

Identificador do formato (sempre “json-atomic/1”).

Implementations§

Source§

impl SignedFact

Source

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).

Source

pub fn signature_obj(&self) -> Signature

Retorna a assinatura como objeto ed25519_dalek::Signature.

Source

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 chars

Trait Implementations§

Source§

impl Clone for SignedFact

Source§

fn clone(&self) -> SignedFact

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SignedFact

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.