write method

Uint8List write()

Implementation

Uint8List write() {
  // Convert the BigInt value to a hexadecimal string
  String buff =
      val.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join();

  // Check if the hexadecimal string length exceeds the allowed byte length
  if (buff.length > 2 * bytelen) {
    throw Exception('Out of Bounds!');
  }

  // Pad the string with leading zeros to match the required byte length
  buff = buff.padLeft(2 * bytelen, '0');

  // Convert the padded hexadecimal string to a Uint8List
  Uint8List buffer = Uint8List.fromList(List<int>.generate(buff.length ~/ 2,
      (i) => int.parse(buff.substring(2 * i, 2 * i + 2), radix: 16)));

  return buffer;
}