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

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

  const [_, body] = line.split('~', 2);
  if (!body) throw new Error('Invalid input');
  
  const tag = lineTag(body);
  if (tag !== line.substring(line.lastIndexOf('~') + 1, -2)) {
    throw new Error('Invalid tag');
  }

  return body;
}
```