#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ZkArtifactKind {
QueryMaterial,
NullifierMaterial,
OwnershipProver,
OwnershipVerifier,
}
impl std::fmt::Display for ZkArtifactKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self {
Self::QueryMaterial => "query proof material",
Self::NullifierMaterial => "nullifier proof material",
Self::OwnershipProver => "ownership prover",
Self::OwnershipVerifier => "ownership verifier",
};
f.write_str(name)
}
}
#[derive(Debug, thiserror::Error)]
pub enum ZkArtifactError {
#[error(
"{kind} is not provided by this ZK artifact source{}",
fmt_detail(detail)
)]
NotProvided {
kind: ZkArtifactKind,
detail: Option<String>,
},
#[error("{kind} is unavailable: {reason}")]
Unavailable {
kind: ZkArtifactKind,
reason: &'static str,
},
#[error("failed to load {kind}: {message}")]
Load {
kind: ZkArtifactKind,
message: String,
},
}
impl ZkArtifactError {
#[must_use]
pub fn kind(&self) -> ZkArtifactKind {
match self {
Self::NotProvided { kind, .. }
| Self::Unavailable { kind, .. }
| Self::Load { kind, .. } => *kind,
}
}
pub fn load(kind: ZkArtifactKind, error: impl Into<eyre::Report>) -> Self {
Self::Load {
kind,
message: format!("{:#}", error.into()),
}
}
}
fn fmt_detail(detail: &Option<String>) -> String {
detail
.as_deref()
.map(|d| format!(" ({d})"))
.unwrap_or_default()
}