```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 non-empty string of at least three characters");
  }

  const tildeIndex = line.lastIndexOf("~");
  if (tildeIndex === -1 || tildeIndex + 2 >= line.length) {
    throw new Error("checkLine expects a line with a tilde separating the body from the tag");
  }

  const body = line.slice(0, tildeIndex);
  const expectedTag = lineTag(body);

  if (line[tildeIndex + 1] !== "~" || line.slice(tildeIndex + 2) !== expectedTag) {
    throw new Error("checkLine expects the tag to match the computed tag for the body");
  }

  return body;
}
```