buildTransactionHashMessage function

BigInt buildTransactionHashMessage(
  1. Map<String, dynamic> encodedTransaction
)

Builds the message to hash

@param {Object} encodedTransaction - Transaction object

@returns {BigInt} message to sign

Implementation

BigInt buildTransactionHashMessage(Map<String, dynamic> encodedTransaction) {
  final BigInt txCompressedData = buildTxCompressedData(encodedTransaction);
  final element1 = buildElement1(encodedTransaction);
  final toBjjAy = encodedTransaction['toBjjAy'] != null
      ? (encodedTransaction['toBjjAy'].startsWith('0x')
          ? encodedTransaction['toBjjAy'].substring(2)
          : encodedTransaction['toBjjAy'])
      : '0';
  final rqTxCompressedDataV2 =
      encodedTransaction['rqTxCompressedDataV2'] != null
          ? (encodedTransaction['rqTxCompressedDataV2'].startsWith('0x')
              ? encodedTransaction['rqTxCompressedDataV2'].substring(2)
              : encodedTransaction['rqTxCompressedDataV2'])
          : '0';
  final rqToEthAddr = encodedTransaction['rqToEthAddr'] != null
      ? (encodedTransaction['rqToEthAddr'].startsWith('0x')
          ? encodedTransaction['rqToEthAddr'].substring(2)
          : encodedTransaction['rqToEthAddr'])
      : '0';

  final rqToBjjAy = encodedTransaction['rqToBjjAy'] != null
      ? (encodedTransaction['rqToBjjAy'].startsWith('0x')
          ? encodedTransaction['rqToBjjAy'].substring(2)
          : encodedTransaction['rqToBjjAy'])
      : '0';

  CircomLib circomLib = CircomLib();
  String hashPoseidon = circomLib.hashPoseidon(
      txCompressedData.toString(),
      element1.toString(),
      toBjjAy,
      rqTxCompressedDataV2,
      rqToEthAddr,
      rqToBjjAy);
  BigInt h = hexToInt(hashPoseidon);
  return h;
}