getL1UserTxId function
Generates the L1 Transaction Id based on the spec
TxID (32 bytes) for L1Tx is the Keccak256 (ethereum) hash of:
bytes: | 1 byte | 32 bytes |
SHA256( 8 bytes | 2 bytes )
content: | type | SHA256(ToForgeL1TxsNum | Position
)
where type for L1UserTx is 0
@param {Number} toForgeL1TxsNum
@param {Number} currentPosition
@returns {String}
Implementation
String getL1UserTxId(BigInt toForgeL1TxsNum, BigInt currentPosition) {
final toForgeL1TxsNumBytes = Uint8List(8);
final toForgeL1TxsNumView = ByteData.view(toForgeL1TxsNumBytes.buffer);
toForgeL1TxsNumView.setUint64(0, toForgeL1TxsNum.toInt());
final positionBytes = Uint8List(8);
final positionView = ByteData.view(positionBytes.buffer);
positionView.setUint64(0, currentPosition.toInt());
final toForgeL1TxsNumHex =
bytesToHex(toForgeL1TxsNumView.buffer.asUint8List());
final positionHex =
bytesToHex(positionView.buffer.asUint8List().sublist(6, 8));
final v = toForgeL1TxsNumHex + positionHex;
final h = bytesToHex(keccak256(hexToBytes(v)));
return '0x00' + h;
}