-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
92 lines (81 loc) · 5.15 KB
/
Copy pathmodels.py
File metadata and controls
92 lines (81 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
********************************************************************************************
* models.py |********************************************************
* Developed by: Ryan Hatch |********************************************************
* Date: August 10th 2022 |********************************************************
* Last Updated: Febuary 13th 2025 |********************************************************
* Version: 6.2-A |********************************************************
********************************************************************************************
********************************#* Description: |*******************************************
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
| models.py is a module that contains the database models for the web-app. *
* SQLite / SQLAlchemy to define the models and their relationships. The models are: *
* - User: stores the user information. *
* - Hash: stores the hashes generated by the user. *
* - EncryptedText: stores the encrypted texts generated by the user. *
* - Key: stores the keys generated by the user. *
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
********************************************************************************************
"""
#* ---------------------- | Import libraries for the web-app | ---------------------- *#
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
from dataclasses import dataclass
__all__ = ['db', 'User', 'Hash', 'EncryptedText', 'Key', 'PGPKey', 'ECCKey', 'ProcessingJob']
#* ---------------------- | Database Models | --------------------- *#
db = SQLAlchemy()
#* ---------------------- | User Model | -------------------------- *#
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True, nullable=True)
password_hash = db.Column(db.String(256), nullable=True)
wallet_address = db.Column(db.String(44), unique=True, nullable=True) # Solana wallet address (base58 encoded)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
# Shared resources for the user
hashes = db.relationship('Hash', backref='user', lazy=True) # hashes, encrypted texts, and keys are linked to the users 'user_id'
encrypted_texts = db.relationship('EncryptedText', backref='user', lazy=True) # Related objects are loaded in a single query for efficiency
#* ---------------------- | Hash Model | ------------------------- *#
class Hash(db.Model):
id = db.Column(db.Integer, primary_key=True)
hash_value = db.Column(db.String(256), nullable=False)
salt = db.Column(db.String(256))
created_at = db.Column(db.DateTime, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
#* ---------------------- | Encrypted Text Model | --------------- *#
class EncryptedText(db.Model):
id = db.Column(db.Integer, primary_key=True)
encrypted_content = db.Column(db.Text, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
#* ---------------------- | Key Model | ------------------------- *#
class Key(db.Model):
id = db.Column(db.Integer, primary_key=True)
key_value = db.Column(db.String(256), nullable=False)
active = db.Column(db.Boolean, default=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
#* ---------------------- | PGP Key Model | ------------------------- *#
class PGPKey(db.Model):
id = db.Column(db.Integer, primary_key=True)
public_key = db.Column(db.Text, nullable=False)
private_key = db.Column(db.Text, nullable=False) # Store encrypted
active = db.Column(db.Boolean, default=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
#* ---------------------- | ECC Key Model | ------------------------- *#
class ECCKey(db.Model):
id = db.Column(db.Integer, primary_key=True)
public_key = db.Column(db.Text, nullable=False)
private_key = db.Column(db.Text, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
active = db.Column(db.Boolean, default=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
#* ---------------------- | Processing Job Model | ------------------------- *#
class ProcessingJob(db.Model):
id = db.Column(db.Integer, primary_key=True)
status = db.Column(db.String(50), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
completed_at = db.Column(db.DateTime)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
merkle_root = db.Column(db.String(64))
chunk_count = db.Column(db.Integer)