/** * 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"; export const AGENT_CONTEXT = "cotton-agent-grant-v1"; /** Never inside a standing grant: saved passwords, passkeys, the code runner's credentials (seal-core `agent::NEVER`). */ export const 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. */ export const CLOSED: readonly string[] = ["site"]; export function closed(table: string): boolean { return CLOSED.includes(table); } export function 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. */ export function policy(withheld: readonly string[]): string[] { return [...new Set([...NEVER, ...withheld.map((t) => plain("table", t))])].sort(); } /** The bytes the person key signs (seal-core `agent_statement`). */ export async function agentStatement(databaseId: string, memberId: string, memberPub: string, withheld: readonly string[], wrapped: string): Promise { 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)}`; }