use crate::base::hash::{sha256_utf8, Hash256};
pub type SchemaId = Hash256;
pub fn schema_id(name: &str) -> SchemaId {
sha256_utf8(name)
}
pub const SPEC_VERSION: &str = "0.2";
pub const DEFAULT_SPACE_NAME: &str = "bellbook.default_space.v1";
#[inline]
pub fn default_space() -> Hash256 {
sha256_utf8(DEFAULT_SPACE_NAME)
}
pub const SCHEMA_REQUEST: &str = "bellbook.request.v1";
pub const SCHEMA_ACTION: &str = "bellbook.action.v1";
pub const SCHEMA_RESPONSE: &str = "bellbook.response.v1";
pub const SCHEMA_RESULT: &str = "bellbook.result.v1";
pub const SCHEMA_RESULT_EXTERNAL: &str = "bellbook.result.external_receipt.v1";
pub const SCHEMA_RESULT_EFFECT_CONFIRMATION: &str = "bellbook.result.effect_confirmation.v1";
pub const SCHEMA_CAPABILITY: &str = "bellbook.capability.v1";
pub const SCHEMA_APPROVAL: &str = "bellbook.approval.v1";
pub const SCHEMA_SUMMARY: &str = "bellbook.summary.v1";
pub const SCHEMA_REFUSAL: &str = "bellbook.refusal.v1";
pub const SCHEMA_USAGE: &str = "bellbook.usage.v1";
pub const SCHEMA_VERDICT: &str = "bellbook.verdict.v1";
pub const SCHEMA_PLAN: &str = "bellbook.plan.v1";
pub const SCHEMA_RETRACTION: &str = "bellbook.retraction.v1";
pub const ALL_SCHEMAS: &[&str] = &[
SCHEMA_REQUEST,
SCHEMA_ACTION,
SCHEMA_RESPONSE,
SCHEMA_RESULT,
SCHEMA_RESULT_EXTERNAL,
SCHEMA_RESULT_EFFECT_CONFIRMATION,
SCHEMA_CAPABILITY,
SCHEMA_APPROVAL,
SCHEMA_SUMMARY,
SCHEMA_REFUSAL,
SCHEMA_USAGE,
SCHEMA_VERDICT,
SCHEMA_PLAN,
SCHEMA_RETRACTION,
];
pub fn schema_name_for_id(id: &SchemaId) -> Option<&'static str> {
ALL_SCHEMAS.iter().copied().find(|n| schema_id(n) == *id)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_schema_id_determinism() {
let id1 = schema_id(SCHEMA_REQUEST);
let id2 = schema_id(SCHEMA_REQUEST);
assert_eq!(id1, id2);
}
#[test]
fn test_different_schemas_different_ids() {
let id1 = schema_id(SCHEMA_REQUEST);
let id2 = schema_id(SCHEMA_ACTION);
assert_ne!(id1, id2);
}
}