63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
use heromodels_core::BaseModelData;
|
|
use heromodels_derive::model;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Represents a signature requirement for a flow step.
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[model]
|
|
pub struct SignatureRequirement {
|
|
/// Base model data.
|
|
pub base_data: BaseModelData,
|
|
|
|
/// Foreign key to the FlowStep this requirement belongs to.
|
|
#[index]
|
|
pub flow_step_id: u32,
|
|
|
|
/// The public key required to sign the message.
|
|
pub public_key: String,
|
|
|
|
/// The plaintext message to be signed.
|
|
pub message: String,
|
|
|
|
/// The public key of the entity that signed the message, if signed.
|
|
pub signed_by: Option<String>,
|
|
|
|
/// The signature, if signed.
|
|
pub signature: Option<String>,
|
|
|
|
/// Current status of the signature requirement (e.g., "Pending", "SentToClient", "Signed", "Failed", "Error").
|
|
pub status: String,
|
|
}
|
|
|
|
impl SignatureRequirement {
|
|
/// Create a new signature requirement.
|
|
pub fn new(id: u32, flow_step_id: u32, public_key: impl ToString, message: impl ToString) -> Self {
|
|
Self {
|
|
base_data: BaseModelData::new(id),
|
|
flow_step_id,
|
|
public_key: public_key.to_string(),
|
|
message: message.to_string(),
|
|
signed_by: None,
|
|
signature: None,
|
|
status: String::from("Pending"), // Default status
|
|
}
|
|
}
|
|
|
|
/// Sets the public key of the signer.
|
|
pub fn signed_by(mut self, signed_by: impl ToString) -> Self {
|
|
self.signed_by = Some(signed_by.to_string());
|
|
self
|
|
}
|
|
|
|
/// Sets the signature.
|
|
pub fn signature(mut self, signature: impl ToString) -> Self {
|
|
self.signature = Some(signature.to_string());
|
|
self
|
|
}
|
|
|
|
pub fn status(mut self, status: impl ToString) -> Self {
|
|
self.status = status.to_string();
|
|
self
|
|
}
|
|
}
|