```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") {
    throw new Error("checkLine expects a string");
  }
  const parts = line.split("~");
  if (parts.length !== 3) {
    throw new Error("line must contain exactly two tilde separators and one body");
  }
  const tag = parts[1];
  const body = parts[2];
  if (typeof body !== "string") {
    throw new Error("body must be a string");
  }
  const expectedTag = lineTag(body);
  if (tag !== expectedTag) {
    throw new Error(`lineTag(${body}) returned ${expectedTag}, but got ${tag}`);
  }
  return body;
}
```