buildElement1 function
Build element_1 for L2HashSignature
@param {Object} tx - Transaction object returned by encodeTransaction
@returns {BigInt} element_1 L2 signature
Implementation
BigInt buildElement1(Map<String, dynamic> tx) {
BigInt res = BigInt.zero;
final toEthereumAddress = BigInt.parse(
tx['toEthereumAddress'] != null
? tx['toEthereumAddress'].substring(2)
: '0',
radix: 16);
double amount = tx['amount'] != null ? double.parse(tx['amount']) : 0;
final amountF = BigInt.from(
HermezCompressedAmount.compressAmount(amount).value.toInt()) <<
160;
final maxNumBatch =
BigInt.from(tx['maxNumBatch'] != null ? tx['maxNumBatch'] : 0) << 200;
res = res + toEthereumAddress; // ethAddr --> 160 bits
res = res + amountF; // amountF --> 40 bits
res = res + maxNumBatch; // maxNumBatch --> 32 bits
return res;
}