Spaces:
Build error
Build error
:zap: [Enhance] Replace Crypto with hashlib
Browse files- networks/proof_worker.py +8 -6
networks/proof_worker.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
-
import json
|
2 |
import base64
|
|
|
|
|
3 |
import random
|
|
|
4 |
from datetime import datetime, timedelta, timezone
|
5 |
-
|
6 |
from constants.headers import OPENAI_GET_HEADERS
|
7 |
|
8 |
|
@@ -40,10 +42,10 @@ class ProofWorker:
|
|
40 |
config[3] = i
|
41 |
json_str = json.dumps(config)
|
42 |
base = base64.b64encode(json_str.encode()).decode()
|
43 |
-
hasher =
|
44 |
hasher.update((seed + base).encode())
|
45 |
-
hash = hasher.digest()
|
46 |
-
if hash
|
47 |
return "gAAAAAB" + base
|
48 |
self.proof_token = (
|
49 |
self.proof_token_prefix + base64.b64encode(seed.encode()).decode()
|
@@ -56,4 +58,4 @@ if __name__ == "__main__":
|
|
56 |
worker = ProofWorker()
|
57 |
proof_token = worker.calc_proof_token(seed, difficulty)
|
58 |
print(f"proof_token: {proof_token}")
|
59 |
-
# python -m networks.
|
|
|
|
|
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 |
|
|
|
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()
|
|
|
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
|