checkProof method

bool checkProof({
  1. String? srcpayload,
})

Implementation

bool checkProof({String? srcpayload}) {
  if (tonProof == null) {
    return false;
  }

  var wcWhash = account!.address.split(':')[2];
  var wc = int.parse(wcWhash[0]);
  var whash = wcWhash[1];

  Uint8List message = Uint8List(0);
  message.addAll(utf8.encode('ton-proof-item-v2/'));
  message.addAll(_intToBytes(wc, Endian.little));
  message.addAll(HEX.decode(whash));
  message.addAll(_intToBytes(tonProof!.domainLen, Endian.little));
  message.addAll(utf8.encode(tonProof!.domainVal));
  message.addAll(_intToBytes(tonProof!.timestamp, Endian.little));
  if (srcpayload != null) {
    message.addAll(utf8.encode(srcpayload));
  } else {
    message.addAll(utf8.encode(tonProof!.payload));
  }

  var signatureMessage = Uint8List(0);
  signatureMessage.addAll(HEX.decode('ffff'));
  signatureMessage.addAll(utf8.encode('ton-connect'));
  signatureMessage.addAll(sha256.convert(message).bytes);

  try {
    var verifyKey =
        VerifyKey(Uint8List.fromList(utf8.encode(account!.publicKey)));
    verifyKey.verify(
        message: Uint8List.fromList(sha256.convert(signatureMessage).bytes),
        signature: tonProof!.signature);
    logger.d('PROOF IS OK');
    return true;
  } catch (e) {
    logger.e('PROOF ERROR');
    return false;
  }
}