验证hex格式字符串的签名。不推荐使用,即将废弃,请使用signMessageV2及verifyMessageV2对字符串进行签名和校验
用法
tronWeb.trx.verifyMessage(hexMsg, signedMsg, address)
参数
Parameter | Description | Data Type |
---|---|---|
hexMsg | Hex格式的待签名string | String |
signedMsg | 待验证的签名 | String |
address | 签名的地址(base58格式 或 hex格式) | String |
返回值
bool - 验证通过返回true;验证不通过返回错误信息
示例
// sign a string message
var str = "helloworld";
// convert to hex format and remove the beginning "0x"
var hexStrWithout0x = tronWeb.toHex(str).replace(/^0x/, '');
// conert hex string to byte array
var byteArray = tronWeb.utils.code.hexStr2byteArray(hexStrWithout0x)
// keccak256 computing, then remove "0x"
var strHash= tronWeb.sha3(byteArray).replace(/^0x/, '');
// sign
var signedStr = await tronWeb.trx.sign(strHash).replace(/^0x/, '');
var tail = signedStr.substring(128, 130);
if(tail == '01')
{
signedStr = signedStr.substring(0,128)+'1c';
}
else if(tail == '00')
{
signedStr = signedStr.substring(0,128)+'1b';
}
// verify the signature
var res = await tronWeb.trx.verifyMessage(strHash,signedStr,'TPNcZ1j55FrGpsaw6K6rVjuL4HfT8ZbBf7')
console.log(res);
>true