use std::str::FromStr;
use thiserror::Error;
pub(super) const DATA_INTEGRITY_PROOF: &str = "DataIntegrityProof";
pub(super) const PROOF_TYPE_JCS_RSA: &str = "MitraJcsRsaSignature2022";
#[cfg(feature = "eip191")]
pub(super) const PROOF_TYPE_JCS_EIP191: &str = "MitraJcsEip191Signature2022";
#[cfg(feature = "minisign")]
pub(super) const PROOF_TYPE_JCS_BLAKE2_ED25519: &str = "MitraJcsEd25519Signature2022";
pub(super) const CRYPTOSUITE_JCS_EDDSA_LEGACY: &str = "jcs-eddsa-2022";
pub(super) const CRYPTOSUITE_JCS_EDDSA: &str = "eddsa-jcs-2022";
#[derive(Debug, PartialEq)]
pub enum ProofType {
#[cfg(feature = "eip191")]
JcsEip191Signature,
#[cfg(feature = "minisign")]
JcsBlake2Ed25519Signature,
#[deprecated]
JcsRsaSignature,
#[deprecated]
JcsEddsaSignature,
EddsaJcsSignature,
}
#[derive(Debug, Error)]
#[error("unsupported proof type")]
pub struct UnsupportedProofType;
impl FromStr for ProofType {
type Err = UnsupportedProofType;
fn from_str(value: &str) -> Result<Self, Self::Err> {
let proof_type = match value {
#[cfg(feature = "eip191")]
PROOF_TYPE_JCS_EIP191 => Self::JcsEip191Signature,
#[cfg(feature = "minisign")]
PROOF_TYPE_JCS_BLAKE2_ED25519 => Self::JcsBlake2Ed25519Signature,
#[allow(deprecated)]
PROOF_TYPE_JCS_RSA => Self::JcsRsaSignature,
_ => return Err(UnsupportedProofType),
};
Ok(proof_type)
}
}
impl ProofType {
pub fn from_cryptosuite(value: &str) -> Result<Self, UnsupportedProofType> {
let proof_type = match value {
#[allow(deprecated)]
CRYPTOSUITE_JCS_EDDSA_LEGACY => Self::JcsEddsaSignature,
CRYPTOSUITE_JCS_EDDSA => Self::EddsaJcsSignature,
_ => return Err(UnsupportedProofType),
};
Ok(proof_type)
}
}