Husnain commited on
Commit
1a49592
1 Parent(s): 8b94302

⚡ [Enhance] Replace Crypto with hashlib

Browse files
Files changed (1) hide show
  1. networks/proof_worker.py +61 -0
networks/proof_worker.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ from hashlib import sha3_512
3
+ import json
4
+ import random
5
+
6
+ from datetime import datetime, timedelta, timezone
7
+
8
+ from constants.headers import OPENAI_GET_HEADERS
9
+
10
+
11
+ class ProofWorker:
12
+ def __init__(self, difficulty=None, required=False, seed=None):
13
+ self.difficulty = difficulty
14
+ self.required = required
15
+ self.seed = seed
16
+ self.proof_token_prefix = "gAAAAABwQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D"
17
+
18
+ def get_parse_time(self):
19
+ now = datetime.now()
20
+ tz = timezone(timedelta(hours=8))
21
+ now = now.astimezone(tz)
22
+ time_format = "%a %b %d %Y %H:%M:%S"
23
+ return now.strftime(time_format) + " GMT+0800 (中国标准时间)"
24
+
25
+ def get_config(self):
26
+ cores = [8, 12, 16, 24]
27
+ core = random.choice(cores)
28
+ screens = [3000, 4000, 6000]
29
+ screen = random.choice(screens)
30
+ return [
31
+ str(core) + str(screen),
32
+ self.get_parse_time(),
33
+ 4294705152,
34
+ 0,
35
+ OPENAI_GET_HEADERS["User-Agent"],
36
+ ]
37
+
38
+ def calc_proof_token(self, seed: str, difficulty: str):
39
+ config = self.get_config()
40
+ diff_len = len(difficulty) // 2
41
+ for i in range(100000):
42
+ config[3] = i
43
+ json_str = json.dumps(config)
44
+ base = base64.b64encode(json_str.encode()).decode()
45
+ hasher = sha3_512()
46
+ hasher.update((seed + base).encode())
47
+ hash = hasher.digest().hex()
48
+ if hash[:diff_len] <= difficulty:
49
+ return "gAAAAAB" + base
50
+ self.proof_token = (
51
+ self.proof_token_prefix + base64.b64encode(seed.encode()).decode()
52
+ )
53
+ return self.proof_token
54
+
55
+
56
+ if __name__ == "__main__":
57
+ seed, difficulty = "0.42665582693491433", "05cdf2"
58
+ worker = ProofWorker()
59
+ proof_token = worker.calc_proof_token(seed, difficulty)
60
+ print(f"proof_token: {proof_token}")
61
+ # python -m networks.proof_worker