PythiloLesson 8 of 12 · progress kept in this browser

Bind approval to the exact proposed arguments

Approving one tool proposal must not approve a later modified proposal. Bind a review record to a canonical representation of the tool name and arguments. Changing a recipient, amount or target should change the proposal identity even if a conversational summary looks similar.

The exercise computes a content digest and compares it with a trusted approved digest. Key ordering should not matter, but array ordering and every argument value should. This identity check does not authenticate an approver or make a digest secret; a real approval service must separately establish who approved, which policy applies and whether approval has expired.

import hashlib,json
proposal={"tool":"save","args":{"id":"a"}}
raw=json.dumps(proposal,sort_keys=True,separators=(",",":")).encode()
print(hashlib.sha256(raw).hexdigest()[:12])
Your task

Implement proposal_id(tool,args) using canonical UTF-8 JSON {tool,args}, sorted keys, compact separators, ensure_ascii=False, allow_nan=False, then SHA256 hex. Implement approved(tool,args,digest) using compare_digest against that identity.