verifyPersonalMessage method

bool verifyPersonalMessage(
  1. List<int> message,
  2. List<int> signature, {
  3. bool hashMessage = true,
  4. int? payloadLength,
  5. dynamic useEthPrefix = false,
})

Verifies a Tron signature of a personal message against the message digest.

Parameters:

  • message: The personal message.
  • signature: The signature bytes.
  • hashMessage: Whether to hash the message before verification (default is true).
  • payloadLength: An optional payload length to include in the message prefix.
  • useEthPrefix: Whether to use the Ethereum or Tron personal sign prefix (default is false).

Returns:

  • True if the signature is valid, false otherwise.

Implementation

bool verifyPersonalMessage(List<int> message, List<int> signature,
    {bool hashMessage = true, int? payloadLength, useEthPrefix = false}) {
  if (hashMessage) {
    String prefix = useEthPrefix
        ? ETHSignerConst.ethPersonalSignPrefix
        : TronSignerConst.tronPersonalSignPrefix;
    prefix =
        prefix + (payloadLength?.toString() ?? message.length.toString());
    final prefixBytes =
        StringUtils.encode(prefix, type: StringEncoding.ascii);
    message = QuickCrypto.keccack256Hash(<int>[...prefixBytes, ...message]);
  }
  if (signature.length > ETHSignerConst.ethSignatureLength) {
    signature = signature.sublist(0, ETHSignerConst.ethSignatureLength);
  }
  return _verifyEcdsa(message, signature);
}