```ts
export function lineTag(body: string): string {
  if (typeof body !== 'string') {
    throw new Error('Body must be a string');
  }
  if (body.length < 3) {
    throw new Error('Line must be at least three characters long');
  }

  const tag = [...body]
    .slice(0, -2)
    .map(char => char.charCodeAt(0))
    .reduce((sum, code) => (sum + code) % 256, 0);

  return tag.toString(16).padStart(2, '0');
}

export function checkLine(line: string): string {
  if (typeof line !== 'string') {
    throw new Error('Line must be a string');
  }
  if (line.length < 3) {
    throw new Error('Line must be at least three characters long');
  }

  const parts = line.split('~', 2);
  if (parts.length !== 2 || !/^[0-9a-fA-F]{2}$/.test(parts[1])) {
    throw new Error('Invalid tag format');
  }
  const bodyTag = parseInt(parts[1], 16);

  if (!line.endsWith('~')) {
    throw new Error('Third-from-last character must be a tilde');
  }

  if (parts[0].length !== line.length - 3) {
    throw new Error('Body length does not match tag');
  }

  return parts[0];
}
```