use auths_keri::{Event, Prefix};
use serde::{Deserialize, Serialize};
use super::error::OrgBundleError;
use super::record::SignedOffboardingRecord;
use crate::types::IdentityDID;
pub const AIR_GAPPED_ORG_BUNDLE_SCHEMA_VERSION: u32 = 1;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BundledKel {
pub prefix: Prefix,
pub events: Vec<Event>,
pub attachments: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AirGappedOrgBundle {
pub schema_version: u32,
pub org_did: IdentityDID,
pub org_prefix: Prefix,
pub built_at_org_seq: u128,
pub built_at: String,
pub org_kel: BundledKel,
pub member_kels: Vec<BundledKel>,
pub offboarding_records: Vec<SignedOffboardingRecord>,
pub pinned_roots: Vec<IdentityDID>,
}
impl AirGappedOrgBundle {
pub fn to_canonical_json(&self) -> Result<String, OrgBundleError> {
json_canon::to_string(self)
.map_err(|e| OrgBundleError::Canonicalize(format!("org bundle: {e}")))
}
pub fn from_json(json: &str) -> Result<Self, OrgBundleError> {
serde_json::from_str(json).map_err(|e| OrgBundleError::Parse(format!("org bundle: {e}")))
}
pub fn authenticated_org_state(&self) -> Result<auths_keri::KeyState, OrgBundleError> {
super::verify::authenticate_bundled_kel(&self.org_kel, None)
}
}