governanceos 0.1.0__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.
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,4 @@
1
+ GovernanceOS
2
+ Copyright 2026 GovernanceOS
3
+
4
+ The Ed25519 verification in src/governanceos/verify.py follows the reference code in RFC 8032, section 6.
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: governanceos
3
+ Version: 0.1.0
4
+ Summary: Open-source tools from GovernanceOS. First: gos-verify, the offline verifier for GovernanceOS evidence packs.
5
+ Author: GovernanceOS
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://governanceos.si
8
+ Project-URL: Source, https://github.com/GovernanceOS/governanceos
9
+ Project-URL: Verify a pack, https://governanceos.si/verify
10
+ Keywords: ai governance,evidence pack,offline verification,ed25519,model risk
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Financial and Insurance Industry
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Security :: Cryptography
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ License-File: NOTICE
21
+ Dynamic: license-file
22
+
23
+ # GovernanceOS
24
+
25
+ Open-source tools from [GovernanceOS](https://governanceos.si), under the Apache License 2.0. They run on your own machine with Python 3 and nothing else installed, and they make no network calls.
26
+
27
+ ```
28
+ pip install governanceos
29
+ ```
30
+
31
+ ## gos-verify: verify an evidence pack offline
32
+
33
+ An institution that keeps its AI governance records in GovernanceOS can share an evidence pack with an examiner. `gos-verify` checks that pack on the examiner's own machine:
34
+
35
+ 1. It recomputes the SHA-256 hash of every record, checks that each links to the one before it, and checks that the positions run without a gap.
36
+ 2. It checks the Ed25519 signature over the whole pack: the header, every record and the summaries.
37
+ 3. It prints the signing key's hash and compares it with the one the institution sent you by another route (`--key`), and compares the head with a head it sent you (`--expect`).
38
+ 4. It says plainly that the public anchor was not checked, because that needs a network.
39
+
40
+ ```
41
+ gos-verify PACK.json --key KEYHASH [--expect HEAD]
42
+ ```
43
+
44
+ | Exit | Meaning |
45
+ |---|---|
46
+ | 0 | Verified: intact, and signed by the key you pinned |
47
+ | 1 | Intact, but the signer is not pinned |
48
+ | 2 | Chain broken |
49
+ | 3 | Signature invalid |
50
+ | 4 | Head differs from `--expect` |
51
+ | 5 | The pack cannot be read |
52
+ | 6 | The key differs from `--key` |
53
+
54
+ **What it proves:** the pack was not changed after the key you pinned signed it.
55
+ **What it does not prove:** that the records were true when they were written. That is for the examination.
56
+
57
+ The same verifier is the single-file download at [governanceos.si/verify](https://governanceos.si/verify). The two are byte-identical.
58
+
59
+ ## Try it
60
+
61
+ `tests/data` holds a sample pack from a fictional institution and a tampered copy of it:
62
+
63
+ ```
64
+ python -m unittest discover -s tests -v
65
+ ```
66
+
67
+ ## License
68
+
69
+ Apache License 2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). The license grants no rights to the GovernanceOS name or marks (section 6).
@@ -0,0 +1,47 @@
1
+ # GovernanceOS
2
+
3
+ Open-source tools from [GovernanceOS](https://governanceos.si), under the Apache License 2.0. They run on your own machine with Python 3 and nothing else installed, and they make no network calls.
4
+
5
+ ```
6
+ pip install governanceos
7
+ ```
8
+
9
+ ## gos-verify: verify an evidence pack offline
10
+
11
+ An institution that keeps its AI governance records in GovernanceOS can share an evidence pack with an examiner. `gos-verify` checks that pack on the examiner's own machine:
12
+
13
+ 1. It recomputes the SHA-256 hash of every record, checks that each links to the one before it, and checks that the positions run without a gap.
14
+ 2. It checks the Ed25519 signature over the whole pack: the header, every record and the summaries.
15
+ 3. It prints the signing key's hash and compares it with the one the institution sent you by another route (`--key`), and compares the head with a head it sent you (`--expect`).
16
+ 4. It says plainly that the public anchor was not checked, because that needs a network.
17
+
18
+ ```
19
+ gos-verify PACK.json --key KEYHASH [--expect HEAD]
20
+ ```
21
+
22
+ | Exit | Meaning |
23
+ |---|---|
24
+ | 0 | Verified: intact, and signed by the key you pinned |
25
+ | 1 | Intact, but the signer is not pinned |
26
+ | 2 | Chain broken |
27
+ | 3 | Signature invalid |
28
+ | 4 | Head differs from `--expect` |
29
+ | 5 | The pack cannot be read |
30
+ | 6 | The key differs from `--key` |
31
+
32
+ **What it proves:** the pack was not changed after the key you pinned signed it.
33
+ **What it does not prove:** that the records were true when they were written. That is for the examination.
34
+
35
+ The same verifier is the single-file download at [governanceos.si/verify](https://governanceos.si/verify). The two are byte-identical.
36
+
37
+ ## Try it
38
+
39
+ `tests/data` holds a sample pack from a fictional institution and a tampered copy of it:
40
+
41
+ ```
42
+ python -m unittest discover -s tests -v
43
+ ```
44
+
45
+ ## License
46
+
47
+ Apache License 2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). The license grants no rights to the GovernanceOS name or marks (section 6).
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "governanceos"
7
+ version = "0.1.0"
8
+ description = "Open-source tools from GovernanceOS. First: gos-verify, the offline verifier for GovernanceOS evidence packs."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE", "NOTICE"]
12
+ requires-python = ">=3.8"
13
+ authors = [{ name = "GovernanceOS" }]
14
+ keywords = ["ai governance", "evidence pack", "offline verification", "ed25519", "model risk"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Financial and Insurance Industry",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Topic :: Security :: Cryptography",
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://governanceos.si"
26
+ Source = "https://github.com/GovernanceOS/governanceos"
27
+ "Verify a pack" = "https://governanceos.si/verify"
28
+
29
+ [project.scripts]
30
+ gos-verify = "governanceos.cli:verify"
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ """Open-source tools from GovernanceOS (Apache-2.0). https://governanceos.si"""
2
+ from .verify import VERSION as VERIFIER_VERSION
3
+
4
+ __version__ = "0.1.0"
5
+ __all__ = ["__version__", "VERIFIER_VERSION"]
@@ -0,0 +1,9 @@
1
+ """Console entry points. verify.py is byte-identical to the download at governanceos.si/verify."""
2
+ import sys
3
+
4
+ from .verify import main
5
+
6
+
7
+ def verify():
8
+ """gos-verify PACK.json --key KEYHASH [--expect HEAD]"""
9
+ raise SystemExit(main(sys.argv))
@@ -0,0 +1,281 @@
1
+ #!/usr/bin/env python3
2
+ # GovernanceOS pack verifier 1.2.1
3
+ # Copyright 2026 GovernanceOS. Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License. You may obtain a copy of the License at
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is
7
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ #
9
+ # What it does, offline, with Python 3 and nothing else installed:
10
+ # 1. recomputes the SHA-256 hash of every record, checks each one links to the record before it, and checks the
11
+ # positions run without a gap;
12
+ # 2. checks the Ed25519 signature (RFC 8032, pure Python below) over the whole pack: the header, every record and
13
+ # the summaries. Only the anchors are outside it, because they are added later and checked online;
14
+ # 3. prints the signing key's hash (SHA-256 of the public key) and compares it with the one the institution sent
15
+ # you separately (--key), and compares the head with a head it sent you (--expect);
16
+ # 4. says plainly that the public anchor was not checked, because it needs a network.
17
+ # The key inside a pack proves nothing on its own: anyone can change or shorten a pack, rebuild the chain and sign it
18
+ # with a key of their own. Only the pack key hash, received by another route, ties the pack to the institution, so
19
+ # the result is VERIFIED only when --key matches. A head alone shows the records end there, not that nothing earlier
20
+ # was left out.
21
+ # What it proves: the pack was not changed after the key you pinned signed it.
22
+ # What it does not prove: that the records were true when they were written.
23
+ #
24
+ # Usage: python gos-verify.py PACK.json --key KEYHASH [--expect HEAD]
25
+ # Exit: 0 verified (intact, signed by the pinned key) · 1 intact but the signer is not pinned · 2 chain broken
26
+ # 3 signature invalid · 4 head differs from --expect · 5 cannot be read · 6 key differs from --key
27
+ import hashlib, json, sys, unicodedata
28
+
29
+ VERSION = "1.2.1"
30
+ MAX_BYTES = 200 * 1024 * 1024 # a pack larger than this is refused, unread
31
+
32
+ # ---- Ed25519 verification, after the reference code in RFC 8032, section 6 ----
33
+ _p = 2 ** 255 - 19
34
+ _L = 2 ** 252 + 27742317777372353535851937790883648493
35
+ _d = -121665 * pow(121666, _p - 2, _p) % _p
36
+ _I = pow(2, (_p - 1) // 4, _p)
37
+
38
+
39
+ def _inv(x):
40
+ return pow(x, _p - 2, _p)
41
+
42
+
43
+ def _recover_x(y, sign):
44
+ if y >= _p:
45
+ return None
46
+ x2 = (y * y - 1) * _inv(_d * y * y + 1)
47
+ if x2 == 0:
48
+ return None if sign else 0
49
+ x = pow(x2, (_p + 3) // 8, _p)
50
+ if (x * x - x2) % _p != 0:
51
+ x = x * _I % _p
52
+ if (x * x - x2) % _p != 0:
53
+ return None
54
+ if (x & 1) != sign:
55
+ x = _p - x
56
+ return x
57
+
58
+
59
+ def _add(P, Q):
60
+ A = (P[1] - P[0]) * (Q[1] - Q[0]) % _p
61
+ B = (P[1] + P[0]) * (Q[1] + Q[0]) % _p
62
+ C = 2 * P[3] * Q[3] * _d % _p
63
+ D = 2 * P[2] * Q[2] % _p
64
+ E, F, G, H = B - A, D - C, D + C, B + A
65
+ return (E * F % _p, G * H % _p, F * G % _p, E * H % _p)
66
+
67
+
68
+ def _mul(s, P):
69
+ Q = (0, 1, 1, 0)
70
+ while s > 0:
71
+ if s & 1:
72
+ Q = _add(Q, P)
73
+ P = _add(P, P)
74
+ s >>= 1
75
+ return Q
76
+
77
+
78
+ def _equal(P, Q):
79
+ return (P[0] * Q[2] - Q[0] * P[2]) % _p == 0 and (P[1] * Q[2] - Q[1] * P[2]) % _p == 0
80
+
81
+
82
+ _gy = 4 * _inv(5) % _p
83
+ _gx = _recover_x(_gy, 0)
84
+ _G = (_gx, _gy, 1, _gx * _gy % _p)
85
+
86
+
87
+ def _decompress(b):
88
+ if len(b) != 32:
89
+ return None
90
+ y = int.from_bytes(b, "little")
91
+ sign = y >> 255
92
+ y &= (1 << 255) - 1
93
+ x = _recover_x(y, sign)
94
+ return None if x is None else (x, y, 1, x * y % _p)
95
+
96
+
97
+ def ed25519_verify(public, message, signature):
98
+ if len(public) != 32 or len(signature) != 64:
99
+ return False
100
+ A = _decompress(public)
101
+ R = _decompress(signature[:32])
102
+ if A is None or R is None:
103
+ return False
104
+ s = int.from_bytes(signature[32:], "little")
105
+ if s >= _L:
106
+ return False
107
+ h = int.from_bytes(hashlib.sha512(signature[:32] + public + message).digest(), "little") % _L
108
+ return _equal(_mul(s, _G), _add(R, _mul(h, A)))
109
+
110
+
111
+ # ---- the pack ----
112
+ UNSIGNED = ("signature", "anchors", "anchors_note", "verifier") # anchors: added later, checked online; verifier: checked by its own SHA-256
113
+ HEX = set("0123456789abcdef")
114
+
115
+
116
+ def canonical(obj):
117
+ return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
118
+
119
+
120
+ def record_hash(prev_hash, record):
121
+ return hashlib.sha256(bytes.fromhex(prev_hash) + canonical(record)).hexdigest()
122
+
123
+
124
+ def signed_message(pack):
125
+ """Everything the institution signs: the whole pack except the signature and the anchors."""
126
+ return canonical({k: v for k, v in pack.items() if k not in UNSIGNED})
127
+
128
+
129
+ def key_hash(public_hex):
130
+ """SHA-256 of the raw 32-byte public key, as 64 lowercase hex characters."""
131
+ return hashlib.sha256(bytes.fromhex(public_hex)).hexdigest()
132
+
133
+
134
+ def _grouped(h):
135
+ return " ".join(h[i:i + 8] for i in range(0, len(h), 8))
136
+
137
+
138
+ def clean(v, limit=400):
139
+ """Pack text as it may be printed: no control or direction characters, so a pack cannot write its own result lines."""
140
+ t = "".join("?" if unicodedata.category(c) in ("Cc", "Cf", "Zl", "Zp") else c for c in str(v))
141
+ return t if len(t) <= limit else t[:limit] + "…"
142
+
143
+
144
+ USAGE = "Usage: python gos-verify.py PACK.json --key KEYHASH [--expect HEAD]"
145
+ HELP = USAGE + """
146
+ --key KEYHASH the pack key hash the institution sent you by another route (64 hex characters, or at least 32)
147
+ --expect HEAD a chain head the institution sent you (64 hex characters); optional
148
+ Exit: 0 verified · 1 signer not pinned · 2 chain broken · 3 signature invalid · 4 head differs · 5 cannot be read · 6 key differs"""
149
+
150
+
151
+ def _option(args, name):
152
+ """The value after name. A value pasted in groups of eight (as the pages show it) is read whole."""
153
+ if name not in args:
154
+ return None, True
155
+ i = args.index(name)
156
+ if i + 1 >= len(args):
157
+ return None, False
158
+ v = args[i + 1].strip().lower().replace(" ", "").replace("sha256:", "")
159
+ j = i + 2
160
+ while len(v) < 64 and j < len(args) and len(args[j]) == 8 and all(c in HEX for c in args[j].lower()):
161
+ v += args[j].lower(); j += 1
162
+ del args[i:j]
163
+ return v, True
164
+
165
+
166
+ def _strict_object(pairs):
167
+ """A JSON object with a repeated key is refused: two readers could see two different packs."""
168
+ keys = [k for k, _ in pairs]
169
+ if len(keys) != len(set(keys)):
170
+ raise ValueError("a key appears twice")
171
+ return dict(pairs)
172
+
173
+
174
+ def _no_constant(name):
175
+ raise ValueError("NaN or Infinity is not a number in a pack")
176
+
177
+
178
+ def main(argv):
179
+ try: # a non-ASCII issuer line must never turn a good pack into an unreadable one on a redirected console
180
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace")
181
+ except Exception:
182
+ pass
183
+ args = [a for a in argv[1:]]
184
+ if any(a in ("-h", "--help") for a in args):
185
+ print(HELP); return 0
186
+ expect, ok1 = _option(args, "--expect")
187
+ pin, ok2 = _option(args, "--key")
188
+ if not (ok1 and ok2) or len(args) != 1:
189
+ print(USAGE); return 5
190
+ if pin is not None and (len(pin) < 32 or len(pin) > 64 or any(c not in HEX for c in pin)):
191
+ print("Key: give the pack key hash you were sent, 64 hexadecimal characters (at least 32)."); print(USAGE); return 5
192
+ if expect is not None and (len(expect) != 64 or any(c not in HEX for c in expect)):
193
+ print("Head: give the chain head you were sent, 64 hexadecimal characters."); print(USAGE); return 5
194
+ print(f"GovernanceOS pack verifier {VERSION} (Apache-2.0)")
195
+ try:
196
+ return _verify(args[0], pin, expect)
197
+ except Exception as e: # anything the checks did not expect means the file is not a pack this verifier reads
198
+ print(f"Format: NOT READABLE ({e.__class__.__name__}). The file is not a pack this verifier reads, or it is cut short.")
199
+ print("What to do: download it again, check its SHA-256, and ask the institution if it persists.")
200
+ return 5
201
+
202
+
203
+ def _verify(path, pin, expect):
204
+ try:
205
+ import os
206
+ if os.path.getsize(path) > MAX_BYTES:
207
+ raise ValueError("larger than the verifier reads")
208
+ with open(path, encoding="utf-8") as f:
209
+ pack = json.load(f, object_pairs_hook=_strict_object, parse_constant=_no_constant)
210
+ recs = pack["records"]
211
+ assert isinstance(pack, dict) and pack["format"] == "governanceos-pack/1" and isinstance(recs, list) and recs
212
+ assert all(isinstance(r, dict) and isinstance(r["position"], int) for r in recs)
213
+ except Exception as e:
214
+ print(f"Format: NOT READABLE ({e.__class__.__name__}). The file is not a pack this verifier reads, or it is cut short.")
215
+ print("What to do: download it again, check its SHA-256, and ask the institution if it persists.")
216
+ return 5
217
+ print(f"Pack: {clean(pack['pack_id'], 120)} · {len(recs)} records, chain positions {recs[0]['position']} to {recs[-1]['position']}")
218
+ print(f"Created: {clean(pack.get('created', 'not stated'), 40)} · Period: {clean(pack.get('period', 'not stated'), 60)}")
219
+ print(f"Issued by: {clean(pack['issued_by'], 200)}")
220
+ if pack.get("notice"):
221
+ print(f"Notice: {clean(pack['notice'])}")
222
+ prev = pack["segment_start_prev_hash"]
223
+ for i, r in enumerate(recs):
224
+ if i and r["position"] != recs[i - 1]["position"] + 1:
225
+ print(f"Chain: BROKEN at position {r['position']}: the positions do not run on from {recs[i - 1]['position']}.")
226
+ print("What to do: keep this output as evidence and ask the institution (the issuer above) to explain the gap."); return 2
227
+ if r["prev_hash"] != prev:
228
+ print(f"Chain: BROKEN at position {r['position']}: it does not link to the record before it.")
229
+ print("What to do: keep this output as evidence and ask the institution (the issuer above) to explain the break."); return 2
230
+ h = record_hash(prev, r["record"])
231
+ if h != r["hash"]:
232
+ print(f"Chain: BROKEN at position {r['position']}: the stored hash differs from the hash recomputed from the record.")
233
+ print("What to do: keep this output as evidence and ask the institution (the issuer above) to explain the change."); return 2
234
+ prev = h
235
+ if prev != pack["head"]:
236
+ print("Chain: BROKEN: the last record's hash is not the head the pack declares."); return 2
237
+ print(f"Chain: OK ({len(recs)} of {len(recs)} records recomputed and linked)")
238
+ try:
239
+ ok = ed25519_verify(bytes.fromhex(pack["public_key"]), signed_message(pack), bytes.fromhex(pack["signature"]))
240
+ except Exception:
241
+ ok = False
242
+ if not ok:
243
+ print(f"Signature: INVALID (key {clean(pack.get('key_id'), 80)}). The pack changed after it was signed, or another key signed it.")
244
+ print("What to do: keep this output and ask the institution which key signed the pack."); return 3
245
+ print(f"Signature: OK (Ed25519, key {clean(pack['key_id'], 80)}; it covers the header, every record and the summaries)")
246
+ fp = key_hash(pack["public_key"])
247
+ if pin is None:
248
+ print(f"Key: SHA256 {_grouped(fp)}")
249
+ print(" Not compared. The key inside a pack is the pack's own claim.")
250
+ elif fp.startswith(pin):
251
+ print(f"Key: SHA256 {_grouped(fp)} MATCH with the pack key hash you were sent")
252
+ else:
253
+ print(f"Key: SHA256 {_grouped(fp)} MISMATCH: the pack was signed by a key other than the one you were sent.")
254
+ print("What to do: do not rely on this pack; ask the institution, by a route you trust, which key signs its packs."); return 6
255
+ head = pack["head"]
256
+ grouped = _grouped(head)
257
+ if expect is None:
258
+ print(f"Head: {grouped}")
259
+ print(" Not compared. Add --expect with a head the institution sent you to compare it too.")
260
+ elif expect == head:
261
+ print(f"Head: {grouped} MATCH with the value you were sent")
262
+ else:
263
+ print(f"Head: {grouped} MISMATCH: you were sent a different head.")
264
+ print("What to do: do not rely on this pack; ask the institution which head is correct."); return 4
265
+ print("Anchor: not checked (offline). No anchor operator is named yet; once one is, compare the head with its published anchor.")
266
+ if pin is None:
267
+ if expect is None:
268
+ print("Result: INTACT, NOT PINNED. The pack matches its own chain and its own key, but nothing ties that key to the")
269
+ else:
270
+ print("Result: INTACT, SIGNER NOT PINNED. The records end at the head you were sent, but a shortened or changed pack")
271
+ print(" can be re-signed with another key. Nothing ties this pack's key to the")
272
+ print(" institution. Run again with --key and the pack key hash the institution sent you by another route.")
273
+ return 1
274
+ print("Result: VERIFIED. The pack was not changed after the pack key you were sent signed it: the header, every record")
275
+ print(" and the summaries. The same key signs every pack, so check the pack name and positions above are the ones")
276
+ print(" you expect. It does not prove the records were true when written; that is for the examination.")
277
+ return 0
278
+
279
+
280
+ if __name__ == "__main__":
281
+ sys.exit(main(sys.argv))
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: governanceos
3
+ Version: 0.1.0
4
+ Summary: Open-source tools from GovernanceOS. First: gos-verify, the offline verifier for GovernanceOS evidence packs.
5
+ Author: GovernanceOS
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://governanceos.si
8
+ Project-URL: Source, https://github.com/GovernanceOS/governanceos
9
+ Project-URL: Verify a pack, https://governanceos.si/verify
10
+ Keywords: ai governance,evidence pack,offline verification,ed25519,model risk
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Financial and Insurance Industry
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Security :: Cryptography
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ License-File: NOTICE
21
+ Dynamic: license-file
22
+
23
+ # GovernanceOS
24
+
25
+ Open-source tools from [GovernanceOS](https://governanceos.si), under the Apache License 2.0. They run on your own machine with Python 3 and nothing else installed, and they make no network calls.
26
+
27
+ ```
28
+ pip install governanceos
29
+ ```
30
+
31
+ ## gos-verify: verify an evidence pack offline
32
+
33
+ An institution that keeps its AI governance records in GovernanceOS can share an evidence pack with an examiner. `gos-verify` checks that pack on the examiner's own machine:
34
+
35
+ 1. It recomputes the SHA-256 hash of every record, checks that each links to the one before it, and checks that the positions run without a gap.
36
+ 2. It checks the Ed25519 signature over the whole pack: the header, every record and the summaries.
37
+ 3. It prints the signing key's hash and compares it with the one the institution sent you by another route (`--key`), and compares the head with a head it sent you (`--expect`).
38
+ 4. It says plainly that the public anchor was not checked, because that needs a network.
39
+
40
+ ```
41
+ gos-verify PACK.json --key KEYHASH [--expect HEAD]
42
+ ```
43
+
44
+ | Exit | Meaning |
45
+ |---|---|
46
+ | 0 | Verified: intact, and signed by the key you pinned |
47
+ | 1 | Intact, but the signer is not pinned |
48
+ | 2 | Chain broken |
49
+ | 3 | Signature invalid |
50
+ | 4 | Head differs from `--expect` |
51
+ | 5 | The pack cannot be read |
52
+ | 6 | The key differs from `--key` |
53
+
54
+ **What it proves:** the pack was not changed after the key you pinned signed it.
55
+ **What it does not prove:** that the records were true when they were written. That is for the examination.
56
+
57
+ The same verifier is the single-file download at [governanceos.si/verify](https://governanceos.si/verify). The two are byte-identical.
58
+
59
+ ## Try it
60
+
61
+ `tests/data` holds a sample pack from a fictional institution and a tampered copy of it:
62
+
63
+ ```
64
+ python -m unittest discover -s tests -v
65
+ ```
66
+
67
+ ## License
68
+
69
+ Apache License 2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). The license grants no rights to the GovernanceOS name or marks (section 6).
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ NOTICE
3
+ README.md
4
+ pyproject.toml
5
+ src/governanceos/__init__.py
6
+ src/governanceos/cli.py
7
+ src/governanceos/verify.py
8
+ src/governanceos.egg-info/PKG-INFO
9
+ src/governanceos.egg-info/SOURCES.txt
10
+ src/governanceos.egg-info/dependency_links.txt
11
+ src/governanceos.egg-info/entry_points.txt
12
+ src/governanceos.egg-info/top_level.txt
13
+ tests/test_verify.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ gos-verify = governanceos.cli:verify
@@ -0,0 +1 @@
1
+ governanceos
@@ -0,0 +1,47 @@
1
+ """The verifier against the sample pack and its tampered twin (both public at governanceos.si/verify)."""
2
+ import io
3
+ import json
4
+ import os
5
+ import unittest
6
+ from contextlib import redirect_stdout
7
+
8
+ from governanceos.verify import key_hash, main
9
+
10
+ D = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
11
+ GOOD = os.path.join(D, "nebula-mutual-2026Q3.pack.json")
12
+ BAD = os.path.join(D, "nebula-mutual-2026Q3-tampered.pack.json")
13
+
14
+
15
+ def run(*args):
16
+ out = io.StringIO()
17
+ with redirect_stdout(out):
18
+ code = main(["gos-verify"] + list(args))
19
+ return code, out.getvalue()
20
+
21
+
22
+ class Verify(unittest.TestCase):
23
+ def setUp(self):
24
+ with open(GOOD, encoding="utf-8") as f:
25
+ self.kh = key_hash(json.load(f)["public_key"])
26
+
27
+ def test_good_pack_verifies_with_the_pinned_key(self):
28
+ code, out = run(GOOD, "--key", self.kh)
29
+ self.assertEqual(code, 0)
30
+ self.assertIn("VERIFIED", out)
31
+
32
+ def test_without_a_pinned_key_it_is_not_verified(self):
33
+ code, out = run(GOOD)
34
+ self.assertEqual(code, 1)
35
+ self.assertNotIn("Result: VERIFIED", out)
36
+
37
+ def test_tampered_twin_breaks_the_chain(self):
38
+ code, _ = run(BAD, "--key", self.kh)
39
+ self.assertEqual(code, 2)
40
+
41
+ def test_a_different_pinned_key_is_refused(self):
42
+ code, _ = run(GOOD, "--key", "0" * 64)
43
+ self.assertEqual(code, 6)
44
+
45
+
46
+ if __name__ == "__main__":
47
+ unittest.main()