stage17-delegated-authority.py
TEXT FILE806 B · Public source code for developers, search crawlers and AI agents
1"""Offline educational example; no wallet calls."""
2def permits(grant, intent, now):
3 fields = ("agent", "wallet", "network", "destination")
4 return (grant["network"] in ("main", "test") and
5 all(type(grant[k]) is str and grant[k] and grant[k] == intent[k] for k in fields) and
6 type(now) is int and type(grant["expires"]) is int and now < grant["expires"] and
7 type(intent["debit"]) is int and type(grant["max_debit"]) is int and
8 0 < intent["debit"] <= grant["max_debit"])
9
10g = dict(agent="a", wallet="w", network="test", destination="fixture", expires=100, max_debit=500)
11i = dict(agent="a", wallet="w", network="test", destination="fixture", debit=500)
12assert permits(g,i,99)
13assert not permits(g,i,100)
14assert not permits(g,dict(i,network="main"),99)Read-only source · Select a line number to link directly · Raw download above
