/** * The words a person key signs to give an assistant a standing grant * (seal-core `agent_statement`), apart from agent.ts so a Node script * (scripts/open-tables-proof.ts) can sign one without loading the Worker: * this imports only http.ts. */import { refuse, sha256Hex } from"./http.ts";exportconst AGENT_CONTEXT = "cotton-agent-grant-v1";/** Never inside a standing grant: saved passwords, passkeys, the code runner's credentials (seal-core `agent::NEVER`). */exportconst NEVER: readonly string[] = ["code_credential", "passkey", "secret"];/** * Never given to any assistant, not standing and not in a timed window, and never offered on a card (seal-core * `agent::CLOSED`): Cotton Sites' list says where the person banks (assets/design/sites/DECISIONS.md question 14). * The phone and the Mac hand no key for one; the Worker answers an assistant as if the table were not there. */exportconst CLOSED: readonly string[] = ["site"];exportfunction closed(table: string): boolean {return CLOSED.includes(table);}exportfunction plain(what: string, value: string): string {if (!value || /[\n|,]/.test(value)) refuse(400, "bad_args", `${what} ${JSON.stringify(value)} is empty or holds a separator`);return value;}/** `withheld` with NEVER added, sorted, once each. */exportfunction policy(withheld: readonly string[]): string[] {return [...newSet([...NEVER, ...withheld.map((t) => plain("table", t))])].sort();}/** The bytes the person key signs (seal-core `agent_statement`). */exportasyncfunction agentStatement(databaseId: string, memberId: string, memberPub: string, withheld: readonly string[], wrapped: string): Promise<string> {const said = policy(withheld);if (said.join(",") !== withheld.join(",")) refuse(400, "bad_args", "withheld is not sorted, once each, with every never-granted table");return`${AGENT_CONTEXT}\n${plain("database", databaseId)}\n${plain("member", memberId)}\n${memberPub}\n${said.join(",")}\n${await sha256Hex(wrapped)}`;}