# mizcausevic-dev/hash-attestation-rs architecture

> Architecture diagram of the GitHub repository mizcausevic-dev/hash-attestation-rs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mizcausevic-dev/hash-attestation-rs
- Repository: https://github.com/mizcausevic-dev/hash-attestation-rs

## Overview

Purpose and principal workflow: `hash-attestation` is a Rust library for signing JSON documents with Ed25519 and checking attestations against public keys already trusted by the caller; it does not fetch keys or establish vendor identity. The external application caller initiates both signing and verification, providing the document and, for verification, an attestation and trusted key. New signatures use RFC 8785 canonicalization and bind the hash profile, key URL, and signer-asserted timestamp; legacy v0.1 verification remains supported.

Components

Public API
- **Crate API** — `src/lib.rs`: Exposes the attestation, signer, verifier, error, and hash APIs; raw-JSON parsing is also exported here.

Signing and verification
- **Attestor** — `src/attestor.rs`: Signs documents, offers strict raw-JSON signing and legacy signing, and exposes the corresponding verifying key.
- **Verifier and trust set** — `src/attestor.rs`: Keeps an in-memory `key_url -> VerifyingKey` map and verifies against a registered key or an independently expected key URL.
- **Attestation envelope** — `src/attestation.rs`: Defines the serialized signature record and verifies its hash and Ed25519 signature, selecting legacy or v0.2 behavior by hash profile.

Canonicalization and input safety
- **Canonical hashes and strict JSON parsing** — `src/hash.rs`: Computes legacy and RFC 8785 SHA-256 hashes; its raw-input parser rejects duplicate keys and unsafe integer literals.
- **Finite-number validation** — `src/validate.rs`: Recursively rejects NaN and infinity before JCS serialization.

Optional audit emission
- **Audit event emitter** — `src/audit_stream.rs`: With the `audit-stream` feature, posts best-effort signing or verification events to the configured `/events` endpoint.

External participants
- **Application caller** — null repository path: Invokes the library with document data and handles signing keys, trust establishment, and verification results.
- **Independent trust source** — null repository path: Supplies or authenticates the public key and its expected URL outside this crate.
- **Audit-stream endpoint** — null repository path: Optionally receives emitted operational events; it is not part of the cryptographic trust decision.

Relationships
- **Application caller -> Crate API**: Calls the exported Rust library APIs; evidence: `src/lib.rs`.
- **Crate API -> Attestor**: Re-exports the signing API; evidence: `src/lib.rs`.
- **Crate API -> Verifier and trust set**: Re-exports the verification API; evidence: `src/lib.rs`.
- **Attestor -> Canonical hashes and strict JSON parsing**: Hashes structured input with JCS or parses raw JSON before signing; evidence: `src/attestor.rs`.
- **Canonical hashes and strict JSON parsing -> Finite-number validation**: Checks serializable values for non-finite numbers before JCS hashing; evidence: `src/hash.rs`.
- **Attestor -> Attestation envelope**: Constructs the v0.2 envelope, signs its signing input, and stores the signature; evidence: `src/attestor.rs`.
- **Verifier and trust set -> Attestation envelope**: Looks up a registered key and delegates cryptographic verification; evidence: `src/attestor.rs`.
- **Attestation envelope -> Canonical hashes and strict JSON parsing**: Recomputes the body hash for the declared profile; evidence: `src/attestation.rs`.
- **Independent trust source -> Application caller**: The caller must independently establish key ownership and bind it to the expected vendor; evidence: `README.md`.
- **Application caller -> Verifier and trust set**: Registers its trusted key before verification; evidence: `README.md`.
- **Attestor -> Audit event emitter**: Under the optional feature, emits `attestation_signed` after signing; evidence: `src/attestor.rs`.
- **Verifier and trust set -> Audit event emitter**: Under the optional feature, emits verification success or failure after checking; evidence: `src/attestor.rs`.
- **Audit event emitter -> Audit-stream endpoint**: Sends events by HTTP POST to `/events`; evidence: `src/audit_stream.rs`.

Coverage limits: The source excerpts show the library’s core signing, verification, canonicalization, and optional audit paths. No consuming application or audit service implementation is included, so their runtime behavior and trust-establishment mechanisms cannot be established here.

Main entry points: [`src/attestor.rs`](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/attestor.rs) (Attestor), [`src/lib.rs`](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/lib.rs) (Crate API), [`src/attestation.rs`](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/attestation.rs) (Attestation envelope), [`src/hash.rs`](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/hash.rs) (Canonical hashes and strict JSON parsing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public_api["Public API"]
  node_crate_api["Crate API<br/>Library API"]
end

subgraph group_signing_verification["Signing and Verification"]
  node_attestor["Attestor<br/>Signer"]
  node_verifier["Verifier and trust set<br/>[attestor.rs]"]
  node_attestation_envelope["Attestation envelope<br/>Signature record"]
end

subgraph group_canonicalization["Canonicalization and Input Safety"]
  node_canonical_hashes["Canonical hashes and strict JSON parsing<br/>Hashing and parser"]
  node_finite_validation["Finite-number validation<br/>Validator"]
end

subgraph group_audit["Optional Audit Emission"]
  node_audit_emitter["Audit event emitter<br/>[audit_stream.rs]"]
end

node_application_caller["Application caller<br/>External actor"]
node_independent_trust_source["Independent trust source<br/>External actor"]
node_audit_endpoint["Audit-stream endpoint<br/>External service"]

node_application_caller -->|"calls APIs"| node_crate_api
node_crate_api -->|"re-exports"| node_attestor
node_crate_api -->|"re-exports"| node_verifier
node_attestor -->|"hashes or parses"| node_canonical_hashes
node_canonical_hashes -->|"validates numbers"| node_finite_validation
node_attestor -->|"constructs and signs"| node_attestation_envelope
node_verifier -->|"delegates verification"| node_attestation_envelope
node_attestation_envelope -->|"recomputes hash"| node_canonical_hashes
node_independent_trust_source -->|"establishes key trust"| node_application_caller
node_application_caller -->|"registers trusted key"| node_verifier
node_attestor -.->|"emits signed event"| node_audit_emitter
node_verifier -.->|"emits verification result"| node_audit_emitter
node_audit_emitter -.->|"posts events"| node_audit_endpoint

click node_crate_api "https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/lib.rs"
click node_attestor "https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/attestor.rs"
click node_verifier "https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/attestor.rs"
click node_attestation_envelope "https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/attestation.rs"
click node_canonical_hashes "https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/hash.rs"
click node_finite_validation "https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/validate.rs"
click node_audit_emitter "https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/audit_stream.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_crate_api toneBlue
class node_attestor,node_verifier,node_attestation_envelope toneAmber
class node_canonical_hashes,node_finite_validation toneMint
class node_audit_emitter toneRose
class node_application_caller,node_independent_trust_source,node_audit_endpoint toneIndigo
```

## Components

### Public API

Exported library interface.

- [Crate API](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/lib.rs): Library API · `src/lib.rs`

### Signing and Verification

Attestation creation, trusted-key management, and signature verification.

- [Attestor](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/attestor.rs): Signer · `src/attestor.rs`
- [Verifier and trust set](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/attestor.rs): Verifier · Keeps an in-memory key_url-to-VerifyingKey map. · `src/attestor.rs`
- [Attestation envelope](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/attestation.rs): Signature record · `src/attestation.rs`

### Canonicalization and Input Safety

Strict JSON parsing, hash profiles, and finite-number validation.

- [Canonical hashes and strict JSON parsing](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/hash.rs): Hashing and parser · `src/hash.rs`
- [Finite-number validation](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/validate.rs): Validator · `src/validate.rs`

### Optional Audit Emission

Best-effort operational event emission when the audit-stream feature is enabled.

- [Audit event emitter](https://github.com/mizcausevic-dev/hash-attestation-rs/blob/main/src/audit_stream.rs): Event emitter · Optional best-effort event emission. · `src/audit_stream.rs`

### Other components

- **Application caller**: External actor · Provides documents and handles keys, trust establishment, and results.
- **Independent trust source**: External actor · Supplies or authenticates a public key and its expected URL outside the crate.
- **Audit-stream endpoint**: External service · Receives optional operational events; not part of the cryptographic trust decision.

## Connections

- Application caller → Crate API: calls APIs (evidence: `src/lib.rs`)
- Crate API → Attestor: re-exports (evidence: `src/lib.rs`)
- Crate API → Verifier and trust set: re-exports (evidence: `src/lib.rs`)
- Attestor → Canonical hashes and strict JSON parsing: hashes or parses (evidence: `src/attestor.rs`)
- Canonical hashes and strict JSON parsing → Finite-number validation: validates numbers (evidence: `src/hash.rs`)
- Attestor → Attestation envelope: constructs and signs (evidence: `src/attestor.rs`)
- Verifier and trust set → Attestation envelope: delegates verification (evidence: `src/attestor.rs`)
- Attestation envelope → Canonical hashes and strict JSON parsing: recomputes hash (evidence: `src/attestation.rs`)
- Independent trust source → Application caller: establishes key trust · Key ownership and vendor binding are established outside this crate. (evidence: `README.md`)
- Application caller → Verifier and trust set: registers trusted key (evidence: `README.md`)
- Attestor → Audit event emitter: emits signed event · Optional audit-stream feature. (evidence: `src/attestor.rs`)
- Verifier and trust set → Audit event emitter: emits verification result · Optional audit-stream feature. (evidence: `src/attestor.rs`)
- Audit event emitter → Audit-stream endpoint: posts events · HTTP POST to /events. (evidence: `src/audit_stream.rs`)
