jep-runtime 0.1.1__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.
- jep_runtime-0.1.1/PKG-INFO +150 -0
- jep_runtime-0.1.1/README.md +137 -0
- jep_runtime-0.1.1/jep_runtime/__init__.py +21 -0
- jep_runtime-0.1.1/jep_runtime/archive/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/archive/jsonl.py +78 -0
- jep_runtime-0.1.1/jep_runtime/canonicalization/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/canonicalization/json.py +39 -0
- jep_runtime-0.1.1/jep_runtime/cli/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/cli/main.py +97 -0
- jep_runtime-0.1.1/jep_runtime/conformance/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/conformance/runtime.py +71 -0
- jep_runtime-0.1.1/jep_runtime/core/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/core/event.py +163 -0
- jep_runtime-0.1.1/jep_runtime/core/version.py +13 -0
- jep_runtime-0.1.1/jep_runtime/delegation/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/delegation/runtime.py +137 -0
- jep_runtime-0.1.1/jep_runtime/events/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/events/factory.py +48 -0
- jep_runtime-0.1.1/jep_runtime/examples/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/profiles/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/profiles/adapter.py +38 -0
- jep_runtime-0.1.1/jep_runtime/replay/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/replay/engine.py +42 -0
- jep_runtime-0.1.1/jep_runtime/schemas/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/tests/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/verification/__init__.py +0 -0
- jep_runtime-0.1.1/jep_runtime/verification/runtime.py +77 -0
- jep_runtime-0.1.1/jep_runtime.egg-info/PKG-INFO +150 -0
- jep_runtime-0.1.1/jep_runtime.egg-info/SOURCES.txt +35 -0
- jep_runtime-0.1.1/jep_runtime.egg-info/dependency_links.txt +1 -0
- jep_runtime-0.1.1/jep_runtime.egg-info/entry_points.txt +2 -0
- jep_runtime-0.1.1/jep_runtime.egg-info/requires.txt +1 -0
- jep_runtime-0.1.1/jep_runtime.egg-info/top_level.txt +1 -0
- jep_runtime-0.1.1/pyproject.toml +25 -0
- jep_runtime-0.1.1/setup.cfg +4 -0
- jep_runtime-0.1.1/tests/test_authority_hardening.py +45 -0
- jep_runtime-0.1.1/tests/test_runtime.py +68 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jep-runtime
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Reference runtime for Judgment Event Protocol executable accountability semantics
|
|
5
|
+
Author: JEP Runtime Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: JEP,accountability,protocol,runtime,verification
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Topic :: Security :: Cryptography
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: filelock>=3.12
|
|
13
|
+
|
|
14
|
+
# JEP Reference Runtime
|
|
15
|
+
|
|
16
|
+
`jep-runtime` is a runnable reference implementation for the Judgment Event Protocol (JEP). It turns the current JEP Internet-Draft primitives — Judgment (`J`), Delegation (`D`), Termination (`T`), and Verification (`V`) — into executable accountability semantics: create an event, canonicalize it, hash it, chain it, archive it, replay it, and verify it across neutral profile adapters.
|
|
17
|
+
|
|
18
|
+
This repository is intentionally **not** an agent framework, workflow orchestrator, blockchain, consensus layer, payment executor, or production security system. Mock signatures and mock credential references are provided so protocol semantics can be tested before deployment-specific cryptography is plugged in.
|
|
19
|
+
|
|
20
|
+
## Architecture
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
+-------------------+ +------------------------+ +------------------+
|
|
24
|
+
| Event Runtime | ---> | Canonicalization | ---> | SHA-256 Hashing |
|
|
25
|
+
| J / D / T / V | | UTF-8 sorted JSON | | event_hash |
|
|
26
|
+
+---------+---------+ +-----------+------------+ +---------+--------+
|
|
27
|
+
| | |
|
|
28
|
+
v v v
|
|
29
|
+
+-------------------+ +------------------------+ +------------------+
|
|
30
|
+
| Delegation | ---> | Append-only Archive | ---> | Verification |
|
|
31
|
+
| scoped authority | | JSONL import/export | | chain/replay |
|
|
32
|
+
+---------+---------+ +-----------+------------+ +---------+--------+
|
|
33
|
+
| | |
|
|
34
|
+
v v v
|
|
35
|
+
+-------------------+ +------------------------+ +------------------+
|
|
36
|
+
| Profile Adapters | ---> | Replay Engine | ---> | Conformance |
|
|
37
|
+
| OAuth/X509/DID/IAM| | lineage graph/state | | vectors/report |
|
|
38
|
+
+-------------------+ +------------------------+ +------------------+
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Runtime data flow
|
|
42
|
+
|
|
43
|
+
1. A caller creates a `JEPEvent` with the required core fields.
|
|
44
|
+
2. The event is canonicalized as normalized UTF-8 JSON with stable field ordering and no insignificant whitespace.
|
|
45
|
+
3. `event_hash = SHA256(canonical_event_without_event_hash)` is assigned once; changing a hashed event requires creating a new event.
|
|
46
|
+
4. New events reference `previous_event_hash`, producing an append-only event chain.
|
|
47
|
+
5. Delegation events carry bounded `authority_scope` and `delegation_chain` entries so authority lineage can be replayed.
|
|
48
|
+
6. JSONL archives append one canonical event record per line.
|
|
49
|
+
7. Verification recomputes hashes, validates nonce uniqueness, checks hash continuity, validates delegation scope, and invokes the configured neutral profile adapter.
|
|
50
|
+
|
|
51
|
+
## Replay flow
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
archive.jsonl
|
|
55
|
+
|
|
|
56
|
+
v
|
|
57
|
+
import events -> verify entire chain -> replay J/D/T/V semantics
|
|
58
|
+
| | |
|
|
59
|
+
| | +--> termination_state
|
|
60
|
+
| +--> tamper/nonce/profile/delegation errors
|
|
61
|
+
+--> lineage_graph: hash-chain edges + delegation edges
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Run it with:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
jep replay archive.jsonl
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The replay output is a portable event lineage graph plus authority and termination state. It is evidence reconstruction, not workflow execution.
|
|
71
|
+
|
|
72
|
+
## CLI
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
jep create-event --type J --actor human:alice --subject agent:planner \
|
|
76
|
+
--agent-id agent:planner \
|
|
77
|
+
--scope-json '{"actions":["read"],"resources":["repo:jep"]}' \
|
|
78
|
+
--intent-json '{"task":"summarize JEP"}' \
|
|
79
|
+
--archive archive.jsonl
|
|
80
|
+
|
|
81
|
+
jep verify event.json
|
|
82
|
+
jep archive-verify archive.jsonl
|
|
83
|
+
jep replay archive.jsonl
|
|
84
|
+
jep conformance-test
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Conformance matrix
|
|
88
|
+
|
|
89
|
+
| Capability | Runtime check |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| Canonicalization | Stable UTF-8 JSON with sorted keys and normalized strings |
|
|
92
|
+
| Deterministic hashing | SHA-256 over canonical event without `event_hash` |
|
|
93
|
+
| Delegation semantics | Parent/child scope and expiration checks |
|
|
94
|
+
| Verification semantics | Hash, nonce, timestamp, profile, and chain integrity checks |
|
|
95
|
+
| Profile compatibility | Neutral `ProfileAdapter` contract with mock OAuth/OIDC, X509, DID/VC, Local IAM labels |
|
|
96
|
+
| Replay correctness | Archive replay must re-verify the full chain and emit lineage graph/state |
|
|
97
|
+
|
|
98
|
+
`jep conformance-test` emits test vectors, mock signed vectors, and a compatibility report.
|
|
99
|
+
|
|
100
|
+
## Correspondence with the JEP draft
|
|
101
|
+
|
|
102
|
+
| Draft primitive / concept | Runtime implementation |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| `J` Judgment | `EventType.JUDGMENT` and `create_event("J", ...)` |
|
|
105
|
+
| `D` Delegation | `delegate_authority()`, scoped delegation events, `verify_delegation_chain()` |
|
|
106
|
+
| `T` Termination | `EventType.TERMINATION`, replayed into `termination_state` |
|
|
107
|
+
| `V` Verification | `verify_event()`, `verify_chain()`, `verify_replay()`, verification events |
|
|
108
|
+
| Replay protection | Required `nonce` and duplicate nonce validation |
|
|
109
|
+
| Signed/verifiable event format | Immutable hashed event model plus mock profile references |
|
|
110
|
+
| Optional profiles | `ProfileAdapter` interface; provider-neutral mock adapter |
|
|
111
|
+
| Append-only receipts | JSONL archive with chain verification on replay |
|
|
112
|
+
|
|
113
|
+
## Repository structure
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
jep_runtime/
|
|
117
|
+
core/ # immutable event model and JSON schema generation
|
|
118
|
+
events/ # event factories
|
|
119
|
+
canonicalization/ # deterministic JSON + SHA-256 hashing
|
|
120
|
+
delegation/ # authority propagation and scope validation
|
|
121
|
+
verification/ # event, chain, replay, tamper, profile verification
|
|
122
|
+
profiles/ # provider-neutral profile adapter interface and mock adapter
|
|
123
|
+
archive/ # append-only JSONL archive runtime
|
|
124
|
+
replay/ # lineage graph and termination replay
|
|
125
|
+
conformance/ # conformance vectors and matrix
|
|
126
|
+
cli/ # jep command line entry point
|
|
127
|
+
schemas/ # generated JSON schema
|
|
128
|
+
examples/ # example event scenarios
|
|
129
|
+
tests/ # executable conformance/runtime tests
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Limitations
|
|
133
|
+
|
|
134
|
+
- Signatures are mock/reference only.
|
|
135
|
+
- Profile adapters do not verify real OAuth/OIDC, X509, DID/VC, or IAM credentials.
|
|
136
|
+
- No blockchain, distributed consensus, real payment execution, or production key management is included.
|
|
137
|
+
- The runtime enforces executable protocol invariants, not legal liability, governance policy, or workflow lifecycle orchestration.
|
|
138
|
+
|
|
139
|
+
## Runtime governance extension points
|
|
140
|
+
|
|
141
|
+
- Replace `MockProfileAdapter` with production credential adapters.
|
|
142
|
+
- Add signature suites while preserving the canonicalization boundary.
|
|
143
|
+
- Add draft-version-specific schema adapters without changing the pinned v06 J/D/T/V primitive meaning.
|
|
144
|
+
- Add draft-version-specific schema adapters without changing J/D/T/V primitive meaning.
|
|
145
|
+
- Publish conformance vectors for independent implementations.
|
|
146
|
+
- Add governance-specific validation modules outside the core minimal runtime.
|
|
147
|
+
|
|
148
|
+
## Runtime and verification notes
|
|
149
|
+
|
|
150
|
+
See [HARDENING.md](HARDENING.md) for supported behavior, regression checks, and compatibility boundaries.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# JEP Reference Runtime
|
|
2
|
+
|
|
3
|
+
`jep-runtime` is a runnable reference implementation for the Judgment Event Protocol (JEP). It turns the current JEP Internet-Draft primitives — Judgment (`J`), Delegation (`D`), Termination (`T`), and Verification (`V`) — into executable accountability semantics: create an event, canonicalize it, hash it, chain it, archive it, replay it, and verify it across neutral profile adapters.
|
|
4
|
+
|
|
5
|
+
This repository is intentionally **not** an agent framework, workflow orchestrator, blockchain, consensus layer, payment executor, or production security system. Mock signatures and mock credential references are provided so protocol semantics can be tested before deployment-specific cryptography is plugged in.
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
+-------------------+ +------------------------+ +------------------+
|
|
11
|
+
| Event Runtime | ---> | Canonicalization | ---> | SHA-256 Hashing |
|
|
12
|
+
| J / D / T / V | | UTF-8 sorted JSON | | event_hash |
|
|
13
|
+
+---------+---------+ +-----------+------------+ +---------+--------+
|
|
14
|
+
| | |
|
|
15
|
+
v v v
|
|
16
|
+
+-------------------+ +------------------------+ +------------------+
|
|
17
|
+
| Delegation | ---> | Append-only Archive | ---> | Verification |
|
|
18
|
+
| scoped authority | | JSONL import/export | | chain/replay |
|
|
19
|
+
+---------+---------+ +-----------+------------+ +---------+--------+
|
|
20
|
+
| | |
|
|
21
|
+
v v v
|
|
22
|
+
+-------------------+ +------------------------+ +------------------+
|
|
23
|
+
| Profile Adapters | ---> | Replay Engine | ---> | Conformance |
|
|
24
|
+
| OAuth/X509/DID/IAM| | lineage graph/state | | vectors/report |
|
|
25
|
+
+-------------------+ +------------------------+ +------------------+
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Runtime data flow
|
|
29
|
+
|
|
30
|
+
1. A caller creates a `JEPEvent` with the required core fields.
|
|
31
|
+
2. The event is canonicalized as normalized UTF-8 JSON with stable field ordering and no insignificant whitespace.
|
|
32
|
+
3. `event_hash = SHA256(canonical_event_without_event_hash)` is assigned once; changing a hashed event requires creating a new event.
|
|
33
|
+
4. New events reference `previous_event_hash`, producing an append-only event chain.
|
|
34
|
+
5. Delegation events carry bounded `authority_scope` and `delegation_chain` entries so authority lineage can be replayed.
|
|
35
|
+
6. JSONL archives append one canonical event record per line.
|
|
36
|
+
7. Verification recomputes hashes, validates nonce uniqueness, checks hash continuity, validates delegation scope, and invokes the configured neutral profile adapter.
|
|
37
|
+
|
|
38
|
+
## Replay flow
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
archive.jsonl
|
|
42
|
+
|
|
|
43
|
+
v
|
|
44
|
+
import events -> verify entire chain -> replay J/D/T/V semantics
|
|
45
|
+
| | |
|
|
46
|
+
| | +--> termination_state
|
|
47
|
+
| +--> tamper/nonce/profile/delegation errors
|
|
48
|
+
+--> lineage_graph: hash-chain edges + delegation edges
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Run it with:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
jep replay archive.jsonl
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The replay output is a portable event lineage graph plus authority and termination state. It is evidence reconstruction, not workflow execution.
|
|
58
|
+
|
|
59
|
+
## CLI
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
jep create-event --type J --actor human:alice --subject agent:planner \
|
|
63
|
+
--agent-id agent:planner \
|
|
64
|
+
--scope-json '{"actions":["read"],"resources":["repo:jep"]}' \
|
|
65
|
+
--intent-json '{"task":"summarize JEP"}' \
|
|
66
|
+
--archive archive.jsonl
|
|
67
|
+
|
|
68
|
+
jep verify event.json
|
|
69
|
+
jep archive-verify archive.jsonl
|
|
70
|
+
jep replay archive.jsonl
|
|
71
|
+
jep conformance-test
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Conformance matrix
|
|
75
|
+
|
|
76
|
+
| Capability | Runtime check |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| Canonicalization | Stable UTF-8 JSON with sorted keys and normalized strings |
|
|
79
|
+
| Deterministic hashing | SHA-256 over canonical event without `event_hash` |
|
|
80
|
+
| Delegation semantics | Parent/child scope and expiration checks |
|
|
81
|
+
| Verification semantics | Hash, nonce, timestamp, profile, and chain integrity checks |
|
|
82
|
+
| Profile compatibility | Neutral `ProfileAdapter` contract with mock OAuth/OIDC, X509, DID/VC, Local IAM labels |
|
|
83
|
+
| Replay correctness | Archive replay must re-verify the full chain and emit lineage graph/state |
|
|
84
|
+
|
|
85
|
+
`jep conformance-test` emits test vectors, mock signed vectors, and a compatibility report.
|
|
86
|
+
|
|
87
|
+
## Correspondence with the JEP draft
|
|
88
|
+
|
|
89
|
+
| Draft primitive / concept | Runtime implementation |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `J` Judgment | `EventType.JUDGMENT` and `create_event("J", ...)` |
|
|
92
|
+
| `D` Delegation | `delegate_authority()`, scoped delegation events, `verify_delegation_chain()` |
|
|
93
|
+
| `T` Termination | `EventType.TERMINATION`, replayed into `termination_state` |
|
|
94
|
+
| `V` Verification | `verify_event()`, `verify_chain()`, `verify_replay()`, verification events |
|
|
95
|
+
| Replay protection | Required `nonce` and duplicate nonce validation |
|
|
96
|
+
| Signed/verifiable event format | Immutable hashed event model plus mock profile references |
|
|
97
|
+
| Optional profiles | `ProfileAdapter` interface; provider-neutral mock adapter |
|
|
98
|
+
| Append-only receipts | JSONL archive with chain verification on replay |
|
|
99
|
+
|
|
100
|
+
## Repository structure
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
jep_runtime/
|
|
104
|
+
core/ # immutable event model and JSON schema generation
|
|
105
|
+
events/ # event factories
|
|
106
|
+
canonicalization/ # deterministic JSON + SHA-256 hashing
|
|
107
|
+
delegation/ # authority propagation and scope validation
|
|
108
|
+
verification/ # event, chain, replay, tamper, profile verification
|
|
109
|
+
profiles/ # provider-neutral profile adapter interface and mock adapter
|
|
110
|
+
archive/ # append-only JSONL archive runtime
|
|
111
|
+
replay/ # lineage graph and termination replay
|
|
112
|
+
conformance/ # conformance vectors and matrix
|
|
113
|
+
cli/ # jep command line entry point
|
|
114
|
+
schemas/ # generated JSON schema
|
|
115
|
+
examples/ # example event scenarios
|
|
116
|
+
tests/ # executable conformance/runtime tests
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Limitations
|
|
120
|
+
|
|
121
|
+
- Signatures are mock/reference only.
|
|
122
|
+
- Profile adapters do not verify real OAuth/OIDC, X509, DID/VC, or IAM credentials.
|
|
123
|
+
- No blockchain, distributed consensus, real payment execution, or production key management is included.
|
|
124
|
+
- The runtime enforces executable protocol invariants, not legal liability, governance policy, or workflow lifecycle orchestration.
|
|
125
|
+
|
|
126
|
+
## Runtime governance extension points
|
|
127
|
+
|
|
128
|
+
- Replace `MockProfileAdapter` with production credential adapters.
|
|
129
|
+
- Add signature suites while preserving the canonicalization boundary.
|
|
130
|
+
- Add draft-version-specific schema adapters without changing the pinned v06 J/D/T/V primitive meaning.
|
|
131
|
+
- Add draft-version-specific schema adapters without changing J/D/T/V primitive meaning.
|
|
132
|
+
- Publish conformance vectors for independent implementations.
|
|
133
|
+
- Add governance-specific validation modules outside the core minimal runtime.
|
|
134
|
+
|
|
135
|
+
## Runtime and verification notes
|
|
136
|
+
|
|
137
|
+
See [HARDENING.md](HARDENING.md) for supported behavior, regression checks, and compatibility boundaries.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""JEP Reference Runtime.
|
|
2
|
+
|
|
3
|
+
Executable, portable accountability runtime for Judgment, Delegation,
|
|
4
|
+
Termination, and Verification events.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from jep_runtime.core.event import EventType, JEPEvent
|
|
8
|
+
from jep_runtime.events.factory import create_event
|
|
9
|
+
from jep_runtime.canonicalization.json import canonicalize_event, compute_event_hash
|
|
10
|
+
from jep_runtime.verification.runtime import verify_event, verify_chain, verify_replay
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"EventType",
|
|
14
|
+
"JEPEvent",
|
|
15
|
+
"create_event",
|
|
16
|
+
"canonicalize_event",
|
|
17
|
+
"compute_event_hash",
|
|
18
|
+
"verify_event",
|
|
19
|
+
"verify_chain",
|
|
20
|
+
"verify_replay",
|
|
21
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Append-only JSONL archive runtime."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from filelock import FileLock
|
|
8
|
+
from jep_runtime.canonicalization.json import compute_event_hash
|
|
9
|
+
from typing import Iterable
|
|
10
|
+
|
|
11
|
+
from jep_runtime.core.event import JEPEvent
|
|
12
|
+
from jep_runtime.replay.engine import replay_events
|
|
13
|
+
from jep_runtime.verification.runtime import VerificationResult, verify_chain
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class JSONLArchive:
|
|
17
|
+
def __init__(self, path: str | Path):
|
|
18
|
+
self.path = Path(path).resolve()
|
|
19
|
+
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
20
|
+
self._lock = FileLock(str(self.path) + ".lock", timeout=10)
|
|
21
|
+
|
|
22
|
+
def append_event(self, event: JEPEvent) -> None:
|
|
23
|
+
with self._lock:
|
|
24
|
+
existing = self.import_archive()
|
|
25
|
+
previous = None
|
|
26
|
+
ids = set()
|
|
27
|
+
for candidate in [*existing, event]:
|
|
28
|
+
if candidate.event_hash != compute_event_hash(candidate) or candidate.previous_event_hash != previous:
|
|
29
|
+
raise ValueError("archive hash mismatch or stale previous_event_hash")
|
|
30
|
+
if candidate.event_id in ids:
|
|
31
|
+
raise ValueError("duplicate event identifier")
|
|
32
|
+
ids.add(candidate.event_id)
|
|
33
|
+
previous = candidate.event_hash
|
|
34
|
+
with self.path.open("a", encoding="utf-8") as handle:
|
|
35
|
+
handle.write(json.dumps(event.to_dict(), sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False) + "\n")
|
|
36
|
+
|
|
37
|
+
def import_archive(self) -> list[JEPEvent]:
|
|
38
|
+
with self._lock:
|
|
39
|
+
return self._read_archive()
|
|
40
|
+
|
|
41
|
+
def _read_archive(self) -> list[JEPEvent]:
|
|
42
|
+
if not self.path.exists():
|
|
43
|
+
return []
|
|
44
|
+
events: list[JEPEvent] = []
|
|
45
|
+
with self.path.open("r", encoding="utf-8") as handle:
|
|
46
|
+
for line in handle:
|
|
47
|
+
if line.strip():
|
|
48
|
+
events.append(JEPEvent.from_dict(json.loads(line)))
|
|
49
|
+
return events
|
|
50
|
+
|
|
51
|
+
def export_archive(self) -> str:
|
|
52
|
+
return self.path.read_text(encoding="utf-8") if self.path.exists() else ""
|
|
53
|
+
|
|
54
|
+
def verify_archive(self) -> VerificationResult:
|
|
55
|
+
return verify_chain(self.import_archive())
|
|
56
|
+
|
|
57
|
+
def replay_archive(self) -> dict:
|
|
58
|
+
return replay_events(self.import_archive())
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def append_event(path: str | Path, event: JEPEvent) -> None:
|
|
62
|
+
JSONLArchive(path).append_event(event)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def import_archive(path: str | Path) -> list[JEPEvent]:
|
|
66
|
+
return JSONLArchive(path).import_archive()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def export_archive(path: str | Path) -> str:
|
|
70
|
+
return JSONLArchive(path).export_archive()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def verify_archive(path: str | Path) -> VerificationResult:
|
|
74
|
+
return JSONLArchive(path).verify_archive()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def replay_archive(path: str | Path) -> dict:
|
|
78
|
+
return JSONLArchive(path).replay_archive()
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Deterministic JSON canonicalization and SHA-256 event hashing."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import unicodedata
|
|
8
|
+
from typing import Any, Mapping
|
|
9
|
+
|
|
10
|
+
from jep_runtime.core.event import JEPEvent
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _normalize(value: Any) -> Any:
|
|
14
|
+
if isinstance(value, str):
|
|
15
|
+
return unicodedata.normalize("NFC", value)
|
|
16
|
+
if isinstance(value, Mapping):
|
|
17
|
+
return {unicodedata.normalize("NFC", str(k)): _normalize(v) for k, v in value.items()}
|
|
18
|
+
if isinstance(value, list | tuple):
|
|
19
|
+
return [_normalize(v) for v in value]
|
|
20
|
+
return value
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def canonicalize_event(event: JEPEvent | Mapping[str, Any], *, include_hash: bool = False) -> bytes:
|
|
24
|
+
"""Canonicalize an event as UTF-8 JSON with stable ordering and no whitespace."""
|
|
25
|
+
|
|
26
|
+
if isinstance(event, JEPEvent):
|
|
27
|
+
data = event.to_dict(include_hash=include_hash)
|
|
28
|
+
else:
|
|
29
|
+
data = dict(event)
|
|
30
|
+
if not include_hash:
|
|
31
|
+
data.pop("event_hash", None)
|
|
32
|
+
normalized = _normalize(data)
|
|
33
|
+
return json.dumps(normalized, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def compute_event_hash(event: JEPEvent | Mapping[str, Any]) -> str:
|
|
37
|
+
"""Compute a platform-stable SHA-256 hash over canonical event JSON."""
|
|
38
|
+
|
|
39
|
+
return hashlib.sha256(canonicalize_event(event, include_hash=False)).hexdigest()
|
|
File without changes
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Command line interface for the JEP Reference Runtime."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from jep_runtime.archive.jsonl import JSONLArchive
|
|
10
|
+
from jep_runtime.conformance.runtime import run_conformance
|
|
11
|
+
from jep_runtime.core.event import JEPEvent
|
|
12
|
+
from jep_runtime.events.factory import create_event
|
|
13
|
+
from jep_runtime.replay.engine import replay_events
|
|
14
|
+
from jep_runtime.verification.runtime import verify_event
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _load_event(path: str) -> JEPEvent:
|
|
18
|
+
with open(path, "r", encoding="utf-8") as handle:
|
|
19
|
+
return JEPEvent.from_dict(json.load(handle))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _print(data: object) -> None:
|
|
23
|
+
print(json.dumps(data, indent=2, sort_keys=True, ensure_ascii=False))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
27
|
+
parser = argparse.ArgumentParser(prog="jep", description="JEP Reference Runtime CLI")
|
|
28
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
29
|
+
|
|
30
|
+
create = sub.add_parser("create-event", help="Create and hash a J/D/T/V event")
|
|
31
|
+
create.add_argument("--type", required=True, choices=["J", "D", "T", "V"])
|
|
32
|
+
create.add_argument("--actor", required=True)
|
|
33
|
+
create.add_argument("--subject", required=True)
|
|
34
|
+
create.add_argument("--agent-id")
|
|
35
|
+
create.add_argument("--session-id")
|
|
36
|
+
create.add_argument("--scope-json", default="{}")
|
|
37
|
+
create.add_argument("--intent-json", default="{}")
|
|
38
|
+
create.add_argument("--justification", default="")
|
|
39
|
+
create.add_argument("--previous-event-hash")
|
|
40
|
+
create.add_argument("--profile", default="mock")
|
|
41
|
+
create.add_argument("--credential-reference")
|
|
42
|
+
create.add_argument("--archive", help="Append created event to JSONL archive")
|
|
43
|
+
|
|
44
|
+
verify = sub.add_parser("verify", help="Verify one event JSON file")
|
|
45
|
+
verify.add_argument("event")
|
|
46
|
+
|
|
47
|
+
replay = sub.add_parser("replay", help="Replay a JSONL archive")
|
|
48
|
+
replay.add_argument("archive")
|
|
49
|
+
|
|
50
|
+
archive_verify = sub.add_parser("archive-verify", help="Verify an append-only JSONL archive")
|
|
51
|
+
archive_verify.add_argument("archive")
|
|
52
|
+
|
|
53
|
+
sub.add_parser("conformance-test", help="Run conformance suite and emit vectors/report")
|
|
54
|
+
return parser
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def main(argv: list[str] | None = None) -> int:
|
|
58
|
+
args = build_parser().parse_args(argv)
|
|
59
|
+
if args.command == "create-event":
|
|
60
|
+
event = create_event(
|
|
61
|
+
args.type,
|
|
62
|
+
actor=args.actor,
|
|
63
|
+
subject=args.subject,
|
|
64
|
+
agent_id=args.agent_id,
|
|
65
|
+
session_id=args.session_id,
|
|
66
|
+
authority_scope=json.loads(args.scope_json),
|
|
67
|
+
intent=json.loads(args.intent_json),
|
|
68
|
+
justification=args.justification,
|
|
69
|
+
previous_event_hash=args.previous_event_hash,
|
|
70
|
+
profile=args.profile,
|
|
71
|
+
credential_reference=args.credential_reference,
|
|
72
|
+
)
|
|
73
|
+
if args.archive:
|
|
74
|
+
JSONLArchive(args.archive).append_event(event)
|
|
75
|
+
_print(event.to_dict())
|
|
76
|
+
return 0
|
|
77
|
+
if args.command == "verify":
|
|
78
|
+
result = verify_event(_load_event(args.event))
|
|
79
|
+
_print({"valid": result.valid, "errors": list(result.errors)})
|
|
80
|
+
return 0 if result.valid else 1
|
|
81
|
+
if args.command == "replay":
|
|
82
|
+
archive = JSONLArchive(args.archive)
|
|
83
|
+
_print(archive.replay_archive())
|
|
84
|
+
return 0 if archive.verify_archive().valid else 1
|
|
85
|
+
if args.command == "archive-verify":
|
|
86
|
+
result = JSONLArchive(args.archive).verify_archive()
|
|
87
|
+
_print({"valid": result.valid, "errors": list(result.errors)})
|
|
88
|
+
return 0 if result.valid else 1
|
|
89
|
+
if args.command == "conformance-test":
|
|
90
|
+
report = run_conformance()
|
|
91
|
+
_print(report)
|
|
92
|
+
return 0 if report["passed"] else 1
|
|
93
|
+
return 2
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Conformance vectors and checks for interoperable JEP runtimes."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from jep_runtime.canonicalization.json import canonicalize_event, compute_event_hash
|
|
6
|
+
from jep_runtime.core.event import EventType
|
|
7
|
+
from jep_runtime.delegation.runtime import delegate_authority, verify_delegation_chain
|
|
8
|
+
from jep_runtime.events.factory import create_event
|
|
9
|
+
from jep_runtime.profiles.adapter import MockProfileAdapter
|
|
10
|
+
from jep_runtime.replay.engine import replay_events
|
|
11
|
+
from jep_runtime.verification.runtime import verify_chain, verify_event
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def generate_test_vectors() -> dict:
|
|
15
|
+
adapter = MockProfileAdapter()
|
|
16
|
+
ref = adapter.issue_reference("human:alice", "mock")
|
|
17
|
+
root = create_event(
|
|
18
|
+
EventType.JUDGMENT,
|
|
19
|
+
actor="human:alice",
|
|
20
|
+
subject="agent:planner",
|
|
21
|
+
agent_id="agent:planner",
|
|
22
|
+
session_id="session:conformance",
|
|
23
|
+
authority_scope={"actions": ["read", "summarize"], "resources": ["repo:jep"], "valid_until": 4102444800},
|
|
24
|
+
intent={"task": "summarize current JEP draft"},
|
|
25
|
+
justification="human delegated bounded judgment authority",
|
|
26
|
+
timestamp=1700000000,
|
|
27
|
+
nonce="00000000-0000-4000-8000-000000000001",
|
|
28
|
+
profile="mock",
|
|
29
|
+
credential_reference=ref,
|
|
30
|
+
)
|
|
31
|
+
child = delegate_authority(root, delegatee="agent:worker", agent_id="agent:worker", scope={"actions": ["read"], "resources": ["repo:jep"], "valid_until": 4102444700})
|
|
32
|
+
verify = create_event(
|
|
33
|
+
EventType.VERIFICATION,
|
|
34
|
+
actor="verifier:local",
|
|
35
|
+
subject=child.subject,
|
|
36
|
+
agent_id=child.agent_id,
|
|
37
|
+
session_id=root.session_id,
|
|
38
|
+
delegation_chain=child.delegation_chain,
|
|
39
|
+
authority_scope=child.authority_scope,
|
|
40
|
+
intent={"target_event_hash": child.event_hash, "result": "VALID"},
|
|
41
|
+
previous_event_hash=child.event_hash,
|
|
42
|
+
timestamp=child.timestamp + 1,
|
|
43
|
+
nonce="00000000-0000-4000-8000-000000000003",
|
|
44
|
+
profile="mock",
|
|
45
|
+
credential_reference=ref,
|
|
46
|
+
)
|
|
47
|
+
return {
|
|
48
|
+
"events": [root.to_dict(), child.to_dict(), verify.to_dict()],
|
|
49
|
+
"canonical_root": canonicalize_event(root).decode("utf-8"),
|
|
50
|
+
"root_hash": root.event_hash,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def run_conformance() -> dict:
|
|
55
|
+
vectors = generate_test_vectors()
|
|
56
|
+
reconstructed = [__import__("jep_runtime.core.event", fromlist=["JEPEvent"]).JEPEvent.from_dict(e) for e in vectors["events"]]
|
|
57
|
+
matrix = {
|
|
58
|
+
"canonicalization": canonicalize_event(reconstructed[0]).decode("utf-8") == vectors["canonical_root"],
|
|
59
|
+
"deterministic_hashing": compute_event_hash(reconstructed[0]) == vectors["root_hash"],
|
|
60
|
+
"delegation_semantics": verify_delegation_chain(reconstructed[:2])[0],
|
|
61
|
+
"verification_semantics": verify_event(reconstructed[2]).valid,
|
|
62
|
+
"profile_compatibility": verify_chain(reconstructed).valid,
|
|
63
|
+
"replay_correctness": replay_events(reconstructed)["valid"],
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
"passed": all(matrix.values()),
|
|
67
|
+
"matrix": matrix,
|
|
68
|
+
"test_vectors": vectors,
|
|
69
|
+
"signed_vectors": {"mode": "mock", "signature": "mock-signature-over-canonical-vectors"},
|
|
70
|
+
"compatibility_report": "reference runtime uses stable UTF-8 sorted JSON, SHA-256, JSONL archives, and neutral mock profiles",
|
|
71
|
+
}
|
|
File without changes
|