provared 0.9.0__tar.gz → 0.9.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {provared-0.9.0/src/provared.egg-info → provared-0.9.2}/PKG-INFO +2 -2
  2. {provared-0.9.0 → provared-0.9.2}/README.md +1 -1
  3. {provared-0.9.0 → provared-0.9.2}/pyproject.toml +1 -1
  4. {provared-0.9.0 → provared-0.9.2/src/provared.egg-info}/PKG-INFO +2 -2
  5. {provared-0.9.0 → provared-0.9.2}/src/provared.egg-info/SOURCES.txt +3 -1
  6. provared-0.9.2/tests/test_00_no_network.py +214 -0
  7. provared-0.9.2/tests/test_zz_no_network.py +22 -0
  8. {provared-0.9.0 → provared-0.9.2}/LICENSE +0 -0
  9. {provared-0.9.0 → provared-0.9.2}/LICENSE-CC-BY-4.0.txt +0 -0
  10. {provared-0.9.0 → provared-0.9.2}/setup.cfg +0 -0
  11. {provared-0.9.0 → provared-0.9.2}/src/provared/__init__.py +0 -0
  12. {provared-0.9.0 → provared-0.9.2}/src/provared/_js.py +0 -0
  13. {provared-0.9.0 → provared-0.9.2}/src/provared/actions.py +0 -0
  14. {provared-0.9.0 → provared-0.9.2}/src/provared/approval.py +0 -0
  15. {provared-0.9.0 → provared-0.9.2}/src/provared/blockstamp.py +0 -0
  16. {provared-0.9.0 → provared-0.9.2}/src/provared/book.py +0 -0
  17. {provared-0.9.0 → provared-0.9.2}/src/provared/check.py +0 -0
  18. {provared-0.9.0 → provared-0.9.2}/src/provared/compare.py +0 -0
  19. {provared-0.9.0 → provared-0.9.2}/src/provared/cover.py +0 -0
  20. {provared-0.9.0 → provared-0.9.2}/src/provared/denial.py +0 -0
  21. {provared-0.9.0 → provared-0.9.2}/src/provared/der.py +0 -0
  22. {provared-0.9.0 → provared-0.9.2}/src/provared/dev.py +0 -0
  23. {provared-0.9.0 → provared-0.9.2}/src/provared/documents.py +0 -0
  24. {provared-0.9.0 → provared-0.9.2}/src/provared/encoding.py +0 -0
  25. {provared-0.9.0 → provared-0.9.2}/src/provared/fields.py +0 -0
  26. {provared-0.9.0 → provared-0.9.2}/src/provared/guard.py +0 -0
  27. {provared-0.9.0 → provared-0.9.2}/src/provared/headers.py +0 -0
  28. {provared-0.9.0 → provared-0.9.2}/src/provared/jws.py +0 -0
  29. {provared-0.9.0 → provared-0.9.2}/src/provared/keys.py +0 -0
  30. {provared-0.9.0 → provared-0.9.2}/src/provared/pass_.py +0 -0
  31. {provared-0.9.0 → provared-0.9.2}/src/provared/recorder.py +0 -0
  32. {provared-0.9.0 → provared-0.9.2}/src/provared/seal.py +0 -0
  33. {provared-0.9.0 → provared-0.9.2}/src/provared/service.py +0 -0
  34. {provared-0.9.0 → provared-0.9.2}/src/provared/signatures.py +0 -0
  35. {provared-0.9.0 → provared-0.9.2}/src/provared/slip.py +0 -0
  36. {provared-0.9.0 → provared-0.9.2}/src/provared/standing.py +0 -0
  37. {provared-0.9.0 → provared-0.9.2}/src/provared/stub.py +0 -0
  38. {provared-0.9.0 → provared-0.9.2}/src/provared/timestamp.py +0 -0
  39. {provared-0.9.0 → provared-0.9.2}/src/provared/tools.py +0 -0
  40. {provared-0.9.0 → provared-0.9.2}/src/provared/tree.py +0 -0
  41. {provared-0.9.0 → provared-0.9.2}/src/provared/webauthn.py +0 -0
  42. {provared-0.9.0 → provared-0.9.2}/src/provared/witness.py +0 -0
  43. {provared-0.9.0 → provared-0.9.2}/src/provared.egg-info/dependency_links.txt +0 -0
  44. {provared-0.9.0 → provared-0.9.2}/src/provared.egg-info/requires.txt +0 -0
  45. {provared-0.9.0 → provared-0.9.2}/src/provared.egg-info/top_level.txt +0 -0
  46. {provared-0.9.0 → provared-0.9.2}/tests/test_audit_fixes.py +0 -0
  47. {provared-0.9.0 → provared-0.9.2}/tests/test_check_before.py +0 -0
  48. {provared-0.9.0 → provared-0.9.2}/tests/test_denial.py +0 -0
  49. {provared-0.9.0 → provared-0.9.2}/tests/test_dev.py +0 -0
  50. {provared-0.9.0 → provared-0.9.2}/tests/test_documents.py +0 -0
  51. {provared-0.9.0 → provared-0.9.2}/tests/test_held_seals.py +0 -0
  52. {provared-0.9.0 → provared-0.9.2}/tests/test_issuer_origins.py +0 -0
  53. {provared-0.9.0 → provared-0.9.2}/tests/test_record_function.py +0 -0
  54. {provared-0.9.0 → provared-0.9.2}/tests/test_recorder.py +0 -0
  55. {provared-0.9.0 → provared-0.9.2}/tests/test_records.py +0 -0
  56. {provared-0.9.0 → provared-0.9.2}/tests/test_review2.py +0 -0
  57. {provared-0.9.0 → provared-0.9.2}/tests/test_signatures.py +0 -0
  58. {provared-0.9.0 → provared-0.9.2}/tests/test_signers.py +0 -0
  59. {provared-0.9.0 → provared-0.9.2}/tests/test_small_years.py +0 -0
  60. {provared-0.9.0 → provared-0.9.2}/tests/test_tree.py +0 -0
  61. {provared-0.9.0 → provared-0.9.2}/tests/test_vectors.py +0 -0
  62. {provared-0.9.0 → provared-0.9.2}/tests/test_witness.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: provared
3
- Version: 0.9.0
3
+ Version: 0.9.2
4
4
  Summary: Proof of what an AI agent was allowed to do, and what it then did. A passkey-signed permission with limits a machine can check, a signed receipt for each action, and a checker. Evidence, not a verdict.
5
5
  Author: Pavel Izmaylov
6
6
  License-Expression: Apache-2.0 AND CC-BY-4.0
@@ -34,7 +34,7 @@ particular to Python.
34
34
 
35
35
  ## Status
36
36
 
37
- **Version 0.9.0, a draft**, the same version as the JavaScript library.
37
+ **Version 0.9.2, a draft**, the same version as the JavaScript library.
38
38
  Published as it is, by one author in their own time; fixes as time
39
39
  allows. It gives the same answer, case for case, as the shared test
40
40
  files in [`test-vectors/`](https://github.com/provared/provared/tree/main/test-vectors) show: the same result, the
@@ -13,7 +13,7 @@ particular to Python.
13
13
 
14
14
  ## Status
15
15
 
16
- **Version 0.9.0, a draft**, the same version as the JavaScript library.
16
+ **Version 0.9.2, a draft**, the same version as the JavaScript library.
17
17
  Published as it is, by one author in their own time; fixes as time
18
18
  allows. It gives the same answer, case for case, as the shared test
19
19
  files in [`test-vectors/`](https://github.com/provared/provared/tree/main/test-vectors) show: the same result, the
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "provared"
7
- version = "0.9.0"
7
+ version = "0.9.2"
8
8
  description = "Proof of what an AI agent was allowed to do, and what it then did. A passkey-signed permission with limits a machine can check, a signed receipt for each action, and a checker. Evidence, not a verdict."
9
9
  keywords = ["ai-agent", "agent", "audit-trail", "permission", "authorization", "receipt", "tamper-evident", "passkey", "webauthn", "jws", "ed25519", "ml-dsa", "post-quantum", "evidence", "langchain"]
10
10
  readme = "README.md"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: provared
3
- Version: 0.9.0
3
+ Version: 0.9.2
4
4
  Summary: Proof of what an AI agent was allowed to do, and what it then did. A passkey-signed permission with limits a machine can check, a signed receipt for each action, and a checker. Evidence, not a verdict.
5
5
  Author: Pavel Izmaylov
6
6
  License-Expression: Apache-2.0 AND CC-BY-4.0
@@ -34,7 +34,7 @@ particular to Python.
34
34
 
35
35
  ## Status
36
36
 
37
- **Version 0.9.0, a draft**, the same version as the JavaScript library.
37
+ **Version 0.9.2, a draft**, the same version as the JavaScript library.
38
38
  Published as it is, by one author in their own time; fixes as time
39
39
  allows. It gives the same answer, case for case, as the shared test
40
40
  files in [`test-vectors/`](https://github.com/provared/provared/tree/main/test-vectors) show: the same result, the
@@ -39,6 +39,7 @@ src/provared.egg-info/SOURCES.txt
39
39
  src/provared.egg-info/dependency_links.txt
40
40
  src/provared.egg-info/requires.txt
41
41
  src/provared.egg-info/top_level.txt
42
+ tests/test_00_no_network.py
42
43
  tests/test_audit_fixes.py
43
44
  tests/test_check_before.py
44
45
  tests/test_denial.py
@@ -55,4 +56,5 @@ tests/test_signers.py
55
56
  tests/test_small_years.py
56
57
  tests/test_tree.py
57
58
  tests/test_vectors.py
58
- tests/test_witness.py
59
+ tests/test_witness.py
60
+ tests/test_zz_no_network.py
@@ -0,0 +1,214 @@
1
+ """A watch on the network while the library's tests run.
2
+
3
+ Library code that opens a network connection, sends over UDP or looks up
4
+ a name makes a test fail. The library makes no network request, and unlike
5
+ the JavaScript library it has no network code of its own (no counterpart
6
+ of net/), so nothing in it is left out. Left out by design are the tests'
7
+ own files in this folder, whose helpers may start servers on this computer
8
+ and talk to them.
9
+
10
+ The watch is an audit hook (sys.addaudithook, Python's own means), put in
11
+ place when "python -m unittest discover -s tests" loads this file. The
12
+ discovery loads the test files in sorted order, and this file sorts first,
13
+ so the hook is in place before any test file imports the library: a call
14
+ the library makes as it is imported is watched too. It finds the library
15
+ without importing it. A call is judged by the innermost frame on its stack
16
+ that is a file of the library or of this folder: in the library, it is the
17
+ library's. Where there is none, as in a thread whose target is a function
18
+ of Python's own (socket.getaddrinfo, for one), the call is judged by the
19
+ code that started the thread. Such a call is stopped with NetworkUsed,
20
+ which derives from BaseException so that an "except Exception" in the
21
+ library does not hide it, and is noted; the last test of
22
+ test_zz_no_network.py, the file that sorts last, fails where any call was
23
+ noted, even one the library caught.
24
+
25
+ Watched (Python's audit events): socket.connect (connect and connect_ex),
26
+ socket.sendto, socket.sendmsg, socket.getaddrinfo, socket.gethostbyname,
27
+ socket.gethostbyaddr, socket.getnameinfo, http.client.connect and
28
+ urllib.Request.
29
+
30
+ Not watched, as stated limits: native code called through ctypes (or any
31
+ other extension) that opens the network itself; another program the
32
+ library starts, a Python one included, which does not carry the hook; a
33
+ thread that a test started and the library then hands a network function
34
+ to (it is judged by the test that started it); and a call made after the
35
+ last test has run.
36
+ """
37
+
38
+ import importlib.util
39
+ import os
40
+ import socket
41
+ import sys
42
+ import threading
43
+ import unittest
44
+
45
+ # Checked below: the library was not yet imported when the hook went in.
46
+ LOADED_BEFORE = 'provared' not in sys.modules
47
+
48
+
49
+ def _folder(path):
50
+ return os.path.normcase(os.path.dirname(os.path.abspath(path))) + os.sep
51
+
52
+
53
+ # The library's folder, found without running its code.
54
+ LIBRARY = _folder(importlib.util.find_spec('provared').origin)
55
+ TESTS = _folder(__file__)
56
+ EVENTS = frozenset({
57
+ 'socket.connect', 'socket.sendto', 'socket.sendmsg', 'socket.getaddrinfo',
58
+ 'socket.gethostbyname', 'socket.gethostbyaddr', 'socket.getnameinfo',
59
+ 'http.client.connect', 'urllib.Request',
60
+ })
61
+ # Starting a thread raises one of these audit events in newer versions of
62
+ # Python; Python 3.11 raises none, so Thread.start is also wrapped below.
63
+ THREAD_STARTS = frozenset({'_thread.start_joinable_thread', '_thread.start_new_thread'})
64
+ TESTS_OWN = 'tests'
65
+
66
+
67
+ class NetworkUsed(BaseException):
68
+ """Library code opened the network."""
69
+
70
+
71
+ found = []
72
+
73
+
74
+ def _whose(frame):
75
+ """The library file of the innermost frame of the library or of the
76
+ tests' folder; TESTS_OWN where that frame is the tests'; None where
77
+ there is neither."""
78
+ while frame is not None:
79
+ name = os.path.normcase(os.path.abspath(frame.f_code.co_filename))
80
+ if name.startswith(LIBRARY):
81
+ return name
82
+ if name.startswith(TESTS):
83
+ return TESTS_OWN
84
+ frame = frame.f_back
85
+ return None
86
+
87
+
88
+ def library_file_of(frame):
89
+ """The library file that made the call, or None where the innermost
90
+ frame of the library or of the tests' folder is the tests', or where
91
+ there is neither and the thread was not started by library code."""
92
+ who = _whose(frame)
93
+ if who is None:
94
+ who = getattr(threading.current_thread(), '_provared_started_by', None)
95
+ return None if who in (None, TESTS_OWN) else who
96
+
97
+
98
+ def _hook(event, args):
99
+ if event in THREAD_STARTS:
100
+ thread = getattr(args[0], '__self__', None) if args else None
101
+ if isinstance(thread, threading.Thread) and not hasattr(thread, '_provared_started_by'):
102
+ _mark(thread, sys._getframe(1))
103
+ return
104
+ if event not in EVENTS:
105
+ return
106
+ where = library_file_of(sys._getframe(1))
107
+ if where is None:
108
+ return
109
+ found.append((event, os.path.relpath(where, LIBRARY).replace(os.sep, '/')))
110
+ raise NetworkUsed(f'Library code opened the network ({event}, from {found[-1][1]}). The library makes no network request.')
111
+
112
+
113
+ def _mark(thread, frame):
114
+ """Note on the thread who started it: the library file, TESTS_OWN, or
115
+ whoever started the thread that starts it."""
116
+ who = _whose(frame)
117
+ if who is None:
118
+ who = getattr(threading.current_thread(), '_provared_started_by', None)
119
+ thread._provared_started_by = who
120
+
121
+
122
+ if not getattr(sys, '_provared_no_network', False):
123
+ sys._provared_no_network = True
124
+ sys.addaudithook(_hook)
125
+ _thread_start = threading.Thread.start
126
+
127
+ def _marked_start(self, *args, **kwargs):
128
+ _mark(self, sys._getframe(1))
129
+ return _thread_start(self, *args, **kwargs)
130
+
131
+ threading.Thread.start = _marked_start
132
+
133
+
134
+ def _run_as_library(code):
135
+ """Runs code as if it were written in a file of the library, so that
136
+ its frames name that file, without changing the file."""
137
+ space = {'socket': socket}
138
+ exec(compile(code, os.path.join(LIBRARY, 'probe_for_a_test.py'), 'exec'), space) # noqa: S102 -- fixed code written here, run only to give its frames a library file's name
139
+
140
+
141
+ class NoNetwork(unittest.TestCase):
142
+ def _stopped(self, code):
143
+ before = len(found)
144
+ with self.assertRaises(NetworkUsed):
145
+ _run_as_library(code)
146
+ noted = found[before:]
147
+ del found[before:]
148
+ return noted
149
+
150
+ def test_1_the_watch_is_in_place_before_the_library_is_imported(self):
151
+ self.assertTrue(sys._provared_no_network)
152
+ self.assertTrue(LOADED_BEFORE, 'the library was imported before the watch was in place')
153
+ self.assertTrue(LIBRARY.endswith(os.sep + 'provared' + os.sep), LIBRARY)
154
+
155
+ def test_2_library_calls_are_stopped(self):
156
+ listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
157
+ listener.bind(('127.0.0.1', 0))
158
+ listener.listen(1)
159
+ port = listener.getsockname()[1]
160
+ try:
161
+ calls = {
162
+ 'socket.connect': f'with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:\n s.settimeout(5)\n s.connect(("127.0.0.1", {port}))',
163
+ 'socket.getaddrinfo': 'socket.getaddrinfo("localhost", 9)',
164
+ 'socket.sendto': 's = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\ntry:\n s.sendto(b"x", ("127.0.0.1", 9))\nfinally:\n s.close()',
165
+ 'http.client.connect': f'import http.client\nhttp.client.HTTPConnection("127.0.0.1", {port}, timeout=5).connect()',
166
+ }
167
+ for event, code in calls.items():
168
+ with self.subTest(event):
169
+ self.assertEqual(self._stopped(code), [(event, 'probe_for_a_test.py')])
170
+ finally:
171
+ listener.close()
172
+
173
+ def test_3_a_caught_error_is_still_noted(self):
174
+ before = len(found)
175
+ _run_as_library('try:\n socket.getaddrinfo("localhost", 9)\nexcept BaseException:\n pass')
176
+ self.assertEqual(found[before:], [('socket.getaddrinfo', 'probe_for_a_test.py')])
177
+ del found[before:]
178
+
179
+ def test_4_a_thread_the_library_starts_on_a_function_of_python_is_judged_by_the_library(self):
180
+ before = len(found)
181
+ stopped = []
182
+ shown = threading.excepthook
183
+ # The thread's NetworkUsed is taken here, not shown as a traceback.
184
+ threading.excepthook = lambda caught: stopped.append(caught.exc_type)
185
+ try:
186
+ _run_as_library('import threading\nt = threading.Thread(target=socket.getaddrinfo, args=("localhost", 9))\nt.start()\nt.join()')
187
+ finally:
188
+ threading.excepthook = shown
189
+ self.assertEqual(stopped, [NetworkUsed])
190
+ self.assertEqual(found[before:], [('socket.getaddrinfo', 'probe_for_a_test.py')])
191
+ del found[before:]
192
+
193
+ def test_5_the_tests_own_calls_go_through(self):
194
+ listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
195
+ listener.bind(('127.0.0.1', 0))
196
+ listener.listen(1)
197
+ try:
198
+ before = len(found)
199
+ with socket.create_connection(listener.getsockname(), timeout=5):
200
+ pass
201
+ thread = threading.Thread(target=socket.getaddrinfo, args=('localhost', 9))
202
+ thread.start()
203
+ thread.join()
204
+ self.assertEqual(found[before:], [])
205
+ finally:
206
+ listener.close()
207
+
208
+ def test_6_this_file_sorts_first(self):
209
+ names = sorted(n for n in os.listdir(TESTS) if n.startswith('test') and n.endswith('.py'))
210
+ self.assertEqual(names[0], os.path.basename(__file__), 'the watch must be in place before any other test file is loaded')
211
+
212
+
213
+ if __name__ == '__main__':
214
+ unittest.main()
@@ -0,0 +1,22 @@
1
+ """The last check of the watch on the network (test_00_no_network.py, the
2
+ file that sorts first, puts it in place and states what it watches and its
3
+ limits): it fails where library code opened the network while the tests
4
+ ran, even where the library caught the error."""
5
+
6
+ import os
7
+ import unittest
8
+
9
+ from test_00_no_network import TESTS, found
10
+
11
+
12
+ class NoNetworkAtTheEnd(unittest.TestCase):
13
+ def test_1_this_file_sorts_last(self):
14
+ names = sorted(n for n in os.listdir(TESTS) if n.startswith('test') and n.endswith('.py'))
15
+ self.assertEqual(names[-1], os.path.basename(__file__), 'the check below must run after every other test')
16
+
17
+ def test_9_no_library_code_opened_the_network(self):
18
+ self.assertEqual(found, [], 'library code opened the network while the tests ran')
19
+
20
+
21
+ if __name__ == '__main__':
22
+ unittest.main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes