Browse Source

解密HASH進行鑒權

skyfffire 5 months ago
parent
commit
26063bd596
2 changed files with 9 additions and 2 deletions
  1. 2 1
      toto.readme
  2. 7 1
      web3_py_client.py

+ 2 - 1
toto.readme

@@ -9,7 +9,8 @@
 
 2025-06-06
 [-] 链上买入失败
-[ ] 解密HASH進行鑒權
+[-] 鏈上買入成功,但是okx返回的空狀態,詳見2025-6-5學費
+[-] 解密HASH進行鑒權
 [ ] json用pprint美化后輸出
 [ ] 查询交易所到账状态时发生错误:'balances'
 

+ 7 - 1
web3_py_client.py

@@ -8,6 +8,7 @@ from web3.middleware import ExtraDataToPOAMiddleware # For PoA networks like Goe
 from eth_account import Account
 from dotenv import load_dotenv
 from checker.logger_config import get_logger
+from encode_decode import decrypt
 
 
 # 配置日志
@@ -119,7 +120,12 @@ IERC20_ABI = json.loads('''
 class EthClient:
     def __init__(self, rpc_url: str = None, hash: str = None):
         self.rpc_url = rpc_url or os.getenv("RPC_URL")
-        _hash = hash or os.getenv("HASH")
+
+        ciphertext = os.getenv("ED_CIPHERTEXT")
+        initial_vector = os.getenv("ED_INITIAL_VECTOR")
+        secret_key = os.getenv("ED_SECRET_KEY")
+        
+        _hash = hash or decrypt(bytes.fromhex(ciphertext), bytes.fromhex(secret_key), bytes.fromhex(initial_vector)).decode('utf-8')
 
         if not self.rpc_url:
             raise ValueError("RPC_URL not provided or found in environment variables.")