File size: 1,951 Bytes
c59b13c
0616d17
 
c59b13c
0616d17
c59b13c
0616d17
c59b13c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0616d17
c59b13c
0616d17
 
c59b13c
 
 
 
 
 
 
 
 
 
 
 
0616d17
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
import base64
from hashlib import sha3_512
import json
import random

from datetime import datetime, timedelta, timezone

from constants.headers import OPENAI_GET_HEADERS


class ProofWorker:
    def __init__(self, difficulty=None, required=False, seed=None):
        self.difficulty = difficulty
        self.required = required
        self.seed = seed
        self.proof_token_prefix = "gAAAAABwQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D"

    def get_parse_time(self):
        now = datetime.now()
        tz = timezone(timedelta(hours=8))
        now = now.astimezone(tz)
        time_format = "%a %b %d %Y %H:%M:%S"
        return now.strftime(time_format) + " GMT+0800 (中国标准时间)"

    def get_config(self):
        cores = [8, 12, 16, 24]
        core = random.choice(cores)
        screens = [3000, 4000, 6000]
        screen = random.choice(screens)
        return [
            str(core) + str(screen),
            self.get_parse_time(),
            4294705152,
            0,
            OPENAI_GET_HEADERS["User-Agent"],
        ]

    def calc_proof_token(self, seed: str, difficulty: str):
        config = self.get_config()
        diff_len = len(difficulty) // 2
        for i in range(100000):
            config[3] = i
            json_str = json.dumps(config)
            base = base64.b64encode(json_str.encode()).decode()
            hasher = sha3_512()
            hasher.update((seed + base).encode())
            hash = hasher.digest().hex()
            if hash[:diff_len] <= difficulty:
                return "gAAAAAB" + base
        self.proof_token = (
            self.proof_token_prefix + base64.b64encode(seed.encode()).decode()
        )
        return self.proof_token


if __name__ == "__main__":
    seed, difficulty = "0.42665582693491433", "05cdf2"
    worker = ProofWorker()
    proof_token = worker.calc_proof_token(seed, difficulty)
    print(f"proof_token: {proof_token}")
    # python -m networks.proof_worker