```ts
export function lineTag(body: string): string {
  if (typeof body !== "string") {
    throw new Error("lineTag expects a string");
  }
  let sum = 0;
  for (const ch of body) {
    sum = (sum + ch.codePointAt(0)!) % 256;
  }
  return sum.toString(16).padStart(2, "0");
}

export function checkLine(line: string): string {
  if (typeof line !== "string" || line.length < 3) {
    throw new Error("checkLine expects a valid line of at least three characters");
  }

  const parts = line.split("~");

  // Ensure there are exactly two parts after splitting by '~'
  if (parts.length !== 2) {
    throw new Error("Invalid line format: '~' separator is missing or misplaced");
  }

  const body = parts[0];
  const tag = parts[1];

  if (!/^[0-9a-fA-F]{2}$/.test(tag)) {
    throw new Error("Tag must be exactly two lowercase hexadecimal digits");
  }

  const computedTag = lineTag(body);

  if (tag !== computedTag) {
    throw new Error(`Line tag does not match: expected ${computedTag}, got ${tag}`);
  }

  return body;
}
```