# Content Addressing

**Last Updated:** 2025-01-31
**Confidence:** High

## Summary

Content addressing means the ID of data is derived from its content via cryptographic hash. Same content = same ID. This enables immutability, deduplication, and integrity verification.

**Key Facts:**
- Hash algorithm: BLAKE3 (fast, secure)
- Assertion ID = hash of (subject, predicate, object, agent, timestamp)
- Enables "append-only" semantics - no mutations, only new versions
- Automatic deduplication of identical assertions

**File Pointer:** `crates/stemedb-core/src/assertion.rs:hash()` (planned)

## How It Works

```rust
use blake3::Hasher;

impl Assertion {
    pub fn hash(&self) -> Hash {
        let mut hasher = Hasher::new();
        hasher.update(self.subject.as_bytes());
        hasher.update(self.predicate.as_bytes());
        hasher.update(&self.object.to_bytes());
        hasher.update(&self.agent.0);  // Ed25519 pubkey
        hasher.update(&self.timestamp.to_le_bytes());
        Hash(hasher.finalize().into())
    }
}
```

## Benefits

1. **Immutability:** Cannot modify without changing hash
2. **Deduplication:** Same claim from same agent at same time = one entry
3. **Integrity:** Verify data hasn't been tampered
4. **Caching:** Safe to cache by hash forever

## Related Topics

- [Assertion](../services/assertion.md)
- [Storage](../services/storage.md)
