【问题标题】:Unable to verify TronLink/TronWeb.js signed message in Python无法在 Python 中验证 TronLink/TronWeb.js 签名消息
【发布时间】:2020-09-26 03:32:58
【问题描述】:

我正在使用 TronLink/TronWeb.js 签署一条消息,但无法在 Python 中验证它

我正在使用的 Python 库https://github.com/iexbase/tron-api-python/

签名消息的Javascript代码:

const original_message = "557e3517549cf8ed47d8b205654ea2a7"
const signedtxn = await tronWeb.trx.sign(original_message);
// result 0x862e16c28684bed7162e9a1dd34962882d887610de6c775054ffbad989baec65707b2ba898366c02e9f20730bc2daf54bb7e6d33d77c64f8930f8c9365f5993a1b

验证签名消息的 Python 代码

from tronapi import Tron
from hexbytes import HexBytes

tron = Tron()

class signed_message:
     # signedtxn variable in javascript
    signature = HexBytes('0x862e16c28684bed7162e9a1dd34962882d887610de6c775054ffbad989baec65707b2ba898366c02e9f20730bc2daf54bb7e6d33d77c64f8930f8c9365f5993a1b')

original_message = "557e3517549cf8ed47d8b205654ea2a7"
address = "<!-- Tron Base58 Address in TronLink/TronWeb -->"
tron.trx.verify_message(original_message, signed_message, address=address)

我在 python 中遇到了这个错误

ValueError: Signature does not match

我可以在 TronWeb.js 中验证消息,但不能在 Python 中验证

【问题讨论】:

    标签: python tron tronweb tronlink


    【解决方案1】:

    你可以使用tronpy(是的,我是tronpy的作者。)

    PublicKey.verify_msg

    您签名的最后一个字节应该是0x010x00,这与ETH 不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多