121 lines
2.7 KiB
Rust
121 lines
2.7 KiB
Rust
use heromodels_core::{Model, BaseModelData, IndexKey};
|
|
use heromodels_derive::model;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Status of a signature
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
pub enum SignatureStatus {
|
|
Active,
|
|
Inactive,
|
|
Pending,
|
|
Revoked,
|
|
}
|
|
|
|
impl Default for SignatureStatus {
|
|
fn default() -> Self {
|
|
SignatureStatus::Pending
|
|
}
|
|
}
|
|
|
|
/// Type of object being signed
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
pub enum ObjectType {
|
|
Account,
|
|
DNSRecord,
|
|
Membership,
|
|
User,
|
|
Transaction,
|
|
KYC,
|
|
}
|
|
|
|
impl Default for ObjectType {
|
|
fn default() -> Self {
|
|
ObjectType::User
|
|
}
|
|
}
|
|
|
|
/// Represents a cryptographic signature for various objects
|
|
#[model]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
pub struct Signature {
|
|
/// Base model data
|
|
pub base_data: BaseModelData,
|
|
#[index]
|
|
pub signature_id: u32,
|
|
#[index]
|
|
pub user_id: u32,
|
|
pub value: String,
|
|
#[index]
|
|
pub objectid: u32,
|
|
pub objecttype: ObjectType,
|
|
pub status: SignatureStatus,
|
|
pub timestamp: u64,
|
|
}
|
|
|
|
impl Signature {
|
|
/// Create a new signature instance
|
|
pub fn new(id: u32) -> Self {
|
|
let mut base_data = BaseModelData::new();
|
|
base_data.update_id(id);
|
|
Self {
|
|
base_data,
|
|
signature_id: 0,
|
|
user_id: 0,
|
|
value: String::new(),
|
|
objectid: 0,
|
|
objecttype: ObjectType::default(),
|
|
status: SignatureStatus::default(),
|
|
timestamp: 0,
|
|
}
|
|
}
|
|
|
|
/// Set the signature ID (fluent)
|
|
pub fn signature_id(mut self, signature_id: u32) -> Self {
|
|
self.signature_id = signature_id;
|
|
self
|
|
}
|
|
|
|
/// Set the user ID (fluent)
|
|
pub fn user_id(mut self, user_id: u32) -> Self {
|
|
self.user_id = user_id;
|
|
self
|
|
}
|
|
|
|
/// Set the signature value (fluent)
|
|
pub fn value(mut self, value: impl ToString) -> Self {
|
|
self.value = value.to_string();
|
|
self
|
|
}
|
|
|
|
/// Set the object ID (fluent)
|
|
pub fn objectid(mut self, objectid: u32) -> Self {
|
|
self.objectid = objectid;
|
|
self
|
|
}
|
|
|
|
/// Set the object type (fluent)
|
|
pub fn objecttype(mut self, objecttype: ObjectType) -> Self {
|
|
self.objecttype = objecttype;
|
|
self
|
|
}
|
|
|
|
/// Set the signature status (fluent)
|
|
pub fn status(mut self, status: SignatureStatus) -> Self {
|
|
self.status = status;
|
|
self
|
|
}
|
|
|
|
/// Set the timestamp (fluent)
|
|
pub fn timestamp(mut self, timestamp: u64) -> Self {
|
|
self.timestamp = timestamp;
|
|
self
|
|
}
|
|
|
|
/// Build the final signature instance
|
|
pub fn build(self) -> Self {
|
|
self
|
|
}
|
|
}
|
|
|
|
|