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

export function checkLine(line: string): string {
  if (typeof line !== 'string') throw new Error('Invalid input');
  if (line.length < 3) throw new Error('Line too short');

  const [_, ~, tag] = line.split('~');
  if (~ === undefined || tag === undefined) throw new Error('Invalid line format');

  const computedTag = lineTag(line.slice(0, -2));
  if (tag !== computedTag) throw new Error('Tag mismatch');

  return body;
}
```