```typescript
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 || line[line.length - 3] !== '~') {
    throw new Error("Invalid line format");
  }
  const tag = line.slice(-2);
  const body = line.slice(0, -3);
  if (tag !== lineTag(body)) {
    throw new Error("Tag does not match body");
  }
  return body;
}
```