Private-Key
Python 的 DDEX Api 問題…簽署 ETH 交易?
為DDEX api簽署消息時遇到問題……我正在嘗試在 python 中進行,由於某種原因,我的簽名被兩個字元關閉。這是我在文件中使用私鑰和 UTC 時間戳的程式碼。
import web3 from eth_keys import keys from web3.auto import w3 from eth_utils import decode_hex from eth_account.messages import encode_defunct private_key_0 = "0xe4abcbf75d38cf61c4fde0ade1148f90376616f5233b7c1fef2a78c5992a9a50" # Testing the Auth function... epoch_time = "1524088776656" message = "HYDRO-AUTHENTICATION@1524088776656" message_bytes = ''.join(hex(ord(c)) for c in message) message_hex = b'{message_bytes}'.hex() priv_key_bytes = decode_hex(private_key_0) priv_key = keys.PrivateKey(priv_key_bytes) pub_key = priv_key.public_key public_address_0 = pub_key.to_checksum_address() print("PUBLIC KEY: " + public_address_0) print("PRIVATE KEY: " +private_key_0) # print("Message hex: " +message_hex) msg = encode_defunct(text=message.rstrip()) signed_message = w3.eth.account.sign_message(msg,private_key=private_key_0) print("SIGNED MESSAGE") print(signed_message) sig = signed_message['signature'] # test should be: # 0x603efd7241bfb6c61f4330facee0f7027d98e030ef241ad03a372638c317859a50620dacee177b771ce05812770a637c4c7395da0042c94250f86fb52472f93500 # but is: # 0x603efd7241bfb6c61f4330facee0f7027d98e030ef241ad03a372638c317859a50620dacee177b771ce05812770a637c4c7395da0042c94250f86fb52472f9351b test = str(sig.hex()) header = str(public_address_0) + "#" + message + "#" + test print(header)
我來到這裡是因為當我嘗試使用自己的私鑰時,我從 DDEX api 收到了“未經授權”的錯誤。我認為它必須與簽名功能有關,但不能完全弄清楚……有什麼想法嗎?
乙太坊期望
v
簽名的組成部分(最後一個字節)是 27 或 28,而不是 0 或 1。您只需將 27 (0x1b) 添加到最後一個字節。