export const hexToUint8Array = (hexString: string): Uint8Array => {
  let hexValue = hexString.slice(0, 2).toLowerCase() === '0x' ? hexString.slice(2) : hexString;

  if (hexValue.length % 2) {
    hexValue = `0${hexValue}`;
  }
  const valueByteLength = hexValue.length / 2;

  const u8array = new Uint8Array(valueByteLength);

  for (let i = 0; i < valueByteLength; i++) {
    const intNumber = parseInt(hexValue.slice(i * 2, i * 2 + 2), 16);

    if (isNaN(intNumber)) {
      throw new Error(`Incorrect hex string: ${hexString}`);
    }

    u8array[i] = intNumber;
  }

  return u8array;
};
