mirror of
https://github.com/block/buzz.git
synced 2026-10-29 05:21:31 +00:00
Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <wpfleger@block.xyz> Signed-off-by: Will Pfleger <wpfleger@squareup.com> Signed-off-by: Will Pfleger <wpfleger96@gmail.com> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1fgdl5qqnh3k3f2xkqrvt7cujalhm623x4s7fdjdj5yrtp5fzjl9qrjpucw <4a1bfa0013bc6d14a8d600d8bf6392efefbd2a26ac3c96c9b2a106b0d12297ca@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub16v54tttfqacx9ycvc3k0ut0npj564ahcuajzy6qjvh57ntmsf4uq4806j2 <d32955ad69077062930cc46cfe2df30ca9aaf6f8e76422681265e9e9af704d78@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Will Pfleger <wpfleger96@gmail.com>
50 lines
1.8 KiB
Rust
50 lines
1.8 KiB
Rust
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
use crate::action::AuditAction;
|
|
|
|
/// Materialised audit log entry as stored in the DB.
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct AuditEntry {
|
|
/// Monotonically increasing sequence number.
|
|
pub seq: i64,
|
|
/// When the entry was recorded.
|
|
pub timestamp: DateTime<Utc>,
|
|
/// Nostr event ID that triggered this action.
|
|
pub event_id: String,
|
|
/// Nostr event kind number.
|
|
pub event_kind: u32,
|
|
/// Hex-encoded Nostr pubkey.
|
|
pub actor_pubkey: String,
|
|
/// Action that was performed.
|
|
pub action: AuditAction,
|
|
/// Channel this action applies to, if any.
|
|
pub channel_id: Option<Uuid>,
|
|
/// Arbitrary JSON context. **Included in hash computation** (serialized with
|
|
/// sorted keys for determinism) so that metadata tampering is detectable.
|
|
pub metadata: serde_json::Value,
|
|
/// SHA-256 hex hash of the previous entry (or [`crate::hash::GENESIS_HASH`] for the first).
|
|
pub prev_hash: String,
|
|
/// SHA-256 hex hash of this entry's fields including `prev_hash`.
|
|
pub hash: String,
|
|
}
|
|
|
|
/// Input for creating a new audit entry. `seq`, `prev_hash`, `hash` are computed by `AuditService::log`.
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct NewAuditEntry {
|
|
/// Nostr event ID that triggered this action.
|
|
pub event_id: String,
|
|
/// Must not be 22242 (NIP-42 AUTH).
|
|
pub event_kind: u32,
|
|
/// Hex-encoded Nostr pubkey of the actor.
|
|
pub actor_pubkey: String,
|
|
/// Action that was performed.
|
|
pub action: AuditAction,
|
|
/// Channel this action applies to, if any.
|
|
pub channel_id: Option<Uuid>,
|
|
/// Arbitrary JSON context included in hash computation.
|
|
#[serde(default)]
|
|
pub metadata: serde_json::Value,
|
|
}
|