```ts
export function lineTag(body: string): string {
  if (typeof body !== 'string') {
    throw new Error('Invalid body type');
  }
  const tag = body.split('').reduce((sum, char) => sum + char.charCodeAt(0), 0) % 256;
  return tag.toString(16).padStart(2, '0');
}

export function checkLine(line: string): string {
  if (typeof line !== 'string') {
    throw new Error('Invalid line type');
  }
  if (line.length < 3) {
    throw new Error('Line too short');
  }
  const tildeIndex = line.lastIndexOf('~', line.length - 4);
  if (tildeIndex === -1) {
    throw new Error('Tilde not found in the correct position');
  }
  const body = line.slice(0, tildeIndex);
  const expectedTag = line.slice(tildeIndex + 1, -2);
  const calculatedTag = lineTag(body);
  if (calculatedTag !== expectedTag) {
    throw new Error('Invalid tag');
  }
  return body;
}
```