dacar 1.0.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.
Files changed (47) hide show
  1. dacar-1.0.0/PKG-INFO +228 -0
  2. dacar-1.0.0/README.md +200 -0
  3. dacar-1.0.0/dacar/__init__.py +113 -0
  4. dacar-1.0.0/dacar/challenge.py +340 -0
  5. dacar-1.0.0/dacar/cli/__init__.py +346 -0
  6. dacar-1.0.0/dacar/cli/__main__.py +8 -0
  7. dacar-1.0.0/dacar/cli/commands.py +772 -0
  8. dacar-1.0.0/dacar/cli/store.py +662 -0
  9. dacar-1.0.0/dacar/config.py +139 -0
  10. dacar-1.0.0/dacar/crdt.py +330 -0
  11. dacar-1.0.0/dacar/delta.py +114 -0
  12. dacar-1.0.0/dacar/engine.py +161 -0
  13. dacar-1.0.0/dacar/hlc.py +81 -0
  14. dacar-1.0.0/dacar/namespace.py +125 -0
  15. dacar-1.0.0/dacar/naming.py +38 -0
  16. dacar-1.0.0/dacar/operation.py +237 -0
  17. dacar-1.0.0/dacar/serialization.py +27 -0
  18. dacar-1.0.0/dacar/threshold.py +75 -0
  19. dacar-1.0.0/dacar/transport/__init__.py +43 -0
  20. dacar-1.0.0/dacar/transport/lxmf_sync.py +156 -0
  21. dacar-1.0.0/dacar/transport/rns_challenge.py +206 -0
  22. dacar-1.0.0/dacar/transport/rns_identity.py +63 -0
  23. dacar-1.0.0/dacar/tuple.py +118 -0
  24. dacar-1.0.0/dacar/verifier.py +131 -0
  25. dacar-1.0.0/dacar.egg-info/PKG-INFO +228 -0
  26. dacar-1.0.0/dacar.egg-info/SOURCES.txt +45 -0
  27. dacar-1.0.0/dacar.egg-info/dependency_links.txt +1 -0
  28. dacar-1.0.0/dacar.egg-info/entry_points.txt +2 -0
  29. dacar-1.0.0/dacar.egg-info/requires.txt +6 -0
  30. dacar-1.0.0/dacar.egg-info/top_level.txt +1 -0
  31. dacar-1.0.0/pyproject.toml +53 -0
  32. dacar-1.0.0/setup.cfg +4 -0
  33. dacar-1.0.0/tests/test_challenge.py +200 -0
  34. dacar-1.0.0/tests/test_cli.py +379 -0
  35. dacar-1.0.0/tests/test_config.py +119 -0
  36. dacar-1.0.0/tests/test_crdt.py +185 -0
  37. dacar-1.0.0/tests/test_delta.py +215 -0
  38. dacar-1.0.0/tests/test_engine.py +207 -0
  39. dacar-1.0.0/tests/test_hlc.py +66 -0
  40. dacar-1.0.0/tests/test_namespace.py +105 -0
  41. dacar-1.0.0/tests/test_operation.py +142 -0
  42. dacar-1.0.0/tests/test_threshold.py +104 -0
  43. dacar-1.0.0/tests/test_transport_lxmf.py +154 -0
  44. dacar-1.0.0/tests/test_transport_resolver.py +105 -0
  45. dacar-1.0.0/tests/test_transport_rns.py +174 -0
  46. dacar-1.0.0/tests/test_tuple.py +115 -0
  47. dacar-1.0.0/tests/test_verifier.py +191 -0
dacar-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: dacar
3
+ Version: 1.0.0
4
+ Summary: Python implementation of Dacar, a Decentralized Access Control system for Reticulum
5
+ Author: Henri Bergius
6
+ License: EUPL-1.2
7
+ Project-URL: Homepage, https://github.com/bergie/dacar
8
+ Project-URL: Repository, https://github.com/bergie/dacar
9
+ Project-URL: Issues, https://github.com/bergie/dacar/issues
10
+ Project-URL: Specification, https://github.com/bergie/dacar/blob/main/SPEC.md
11
+ Project-URL: Changelog, https://github.com/bergie/dacar/releases
12
+ Keywords: reticulum,rns,access-control,authorization,crdt,mesh,offline
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Topic :: Security
20
+ Classifier: Topic :: System :: Networking
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: cryptography>=2.8
24
+ Requires-Dist: msgpack>=1.0
25
+ Requires-Dist: rns>=1.4
26
+ Provides-Extra: transport
27
+ Requires-Dist: lxmf>=0.3; extra == "transport"
28
+
29
+ # Dacar — Python reference implementation
30
+
31
+ A Python implementation of the [Dacar 1.0-RC7](../README.md) specification:
32
+ decentralized, offline-first access control for Reticulum mesh networks.
33
+
34
+ Dacar is a tuple-based authorization system (inspired by Google Zanzibar) built
35
+ on an LWW-Element-Set CRDT. Each node evaluates permissions locally against a
36
+ replicated, eventually-consistent authorization state, with delegation chains
37
+ that terminate at configured Root Trust Anchors.
38
+
39
+ ## Dependencies
40
+
41
+ | Need | Choice | Why |
42
+ | ----------------- | ---------------------------------------- | ---------------------------------------------- |
43
+ | Ed25519 (§5.2) | [`cryptography`](https://cryptography.io) | Same backend RNS (Reticulum) selects when present |
44
+ | SHA-256 / HMAC (§3.3, §6.1) | stdlib `hashlib` / `hmac` | In the standard library |
45
+ | MessagePack (§5.3)| `msgpack` | Spec-listed dependency |
46
+ | RNS Identity / §8 Challenge | [`rns`](https://reticulum.network) (Reticulum) | The `dacar` CLI keeps an RNS Identity; §8 transport adapters build on RNS |
47
+
48
+ ## Install
49
+
50
+ ```bash
51
+ cd python
52
+ pip install -e . # core + the `dacar` CLI (cryptography, msgpack, rns)
53
+ pip install -e ".[transport]" # + the §11.2/§11.3 LXMF transport adapters (lxmf)
54
+ ```
55
+
56
+ The pure core stays import-clean: `import dacar` never pulls in the
57
+ `dacar.transport` subpackage. `rns` is a base dependency (the `dacar` CLI
58
+ keeps an RNS Identity, and the §8 transport adapters build on it); only `lxmf`
59
+ is opt-in, via the `transport` extra. The `dacar` command is part of the base
60
+ install — `pip install dacar` gives a working `dacar` CLI with no extras.
61
+
62
+ ## Layout
63
+
64
+ ```
65
+ dacar/
66
+ hlc.py §5.1 Hybrid Logical Clocks (64-bit packed, big-endian)
67
+ namespace.py §3.3 Namespace Label Privacy: salted HMAC-SHA256 hashing,
68
+ object segmenting, wildcard flag, hashed-object matching
69
+ tuple.py §3.1, §6.1 hashed authorization Tuple + SHA-256 Tuple Hash
70
+ threshold.py §4.1 N-of-M Threshold Groups + 16-byte Group ID
71
+ operation.py §5.2, §5.3 signed Operation (single + multi-sig), pre-image,
72
+ MessagePack transport payload
73
+ serialization.py MessagePack helpers
74
+ crdt.py §6, §9 LWW-Element-Set state, merge (Remove wins ties),
75
+ Time-Horizon Tombstone Pruning, intake rejection,
76
+ verify-then-apply ingest() entry point
77
+ config.py §4, §10 Root Trust Anchors, Privacy Salts (Primary + Legacy),
78
+ Authoritative Identity, deletion horizon
79
+ engine.py §7 recursive delegation evaluation, hashed hypotheses,
80
+ multi-salt shared work bound
81
+ challenge.py §8 Strict Consistency Challenge (hashed, multi-salt) +
82
+ signed Freshness Receipts
83
+ verifier.py §5.2, §11.2.4 verify-on-ingest: IssuerKeyset, KeyResolver,
84
+ Keyring, verify_operation()
85
+ delta.py §11.2.4 DeltaReceiver — transport-agnostic receive boundary
86
+ (decode → verify → apply)
87
+ naming.py §8, §11 RNS naming constants (fixed discriminators +
88
+ configurable RFed topic)
89
+ cli/ the `dacar` command-line tool (work doc #2):
90
+ __init__.py argparse dispatch + `main()` entry point
91
+ store.py persistent node store (INI config, identity, HLC clock,
92
+ CRDT state, rnns aliases, plaintext ledger)
93
+ commands.py command implementations + identity/tuple rendering
94
+ transport/ §8, §11.2, §11.3 RNS & LXMF adapters (`rns` is a base dep; `lxmf`
95
+ needs the `transport` extra):
96
+ rns_challenge.py §8 Challenge over an RNS Link (server endpoint + client transport)
97
+ rns_identity.py §3.1, §11.2.4 RnsIdentityResolver (recall → verify key)
98
+ lxmf_sync.py §11.2/§11.3 targeted LXMF Delta delivery + Paper Messages
99
+ tests/ unittest smoketests for every module
100
+ ```
101
+
102
+ ## Quick start
103
+
104
+ ```python
105
+ from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
106
+ from dacar import (
107
+ Action, Clock, Config, Engine, NamespaceHasher,
108
+ Operation, StateVector, Tuple,
109
+ )
110
+
111
+ HASH = b"\x01" * 16 # a 16-byte RNS.Identity hash
112
+ ROOT = b"\x00" * 16 # your Root Trust Anchor
113
+
114
+ hasher = NamespaceHasher() # default salt is FAIL-OPEN; supply a real 32-byte salt!
115
+ state = StateVector()
116
+ clock = Clock()
117
+
118
+ # Bootstrap: the root anchor grants Alice the "read" relation on "sensor:wind".
119
+ state.apply(
120
+ Operation(
121
+ tuple=Tuple.from_plaintext(
122
+ object_id="sensor:wind", relation="read",
123
+ grantee=HASH, issuer=ROOT, hasher=hasher,
124
+ ),
125
+ action=Action.GRANT,
126
+ hlc=clock.now(),
127
+ ).sign(Ed25519PrivateKey.generate()) # in practice, ROOT's private key
128
+ )
129
+
130
+ engine = Engine(Config(root_trust_anchors=frozenset({ROOT})), state)
131
+ assert engine.evaluate("sensor:wind", "read", HASH) is True
132
+ ```
133
+
134
+ ## Verify-on-ingest & identity resolution
135
+
136
+ Every Delta received over the network (RFed, LXMF, or a scanned Paper Message)
137
+ flows through one seam — `DeltaReceiver.apply_payload` — which decodes the
138
+ §5.3 payload, **authenticates it by Ed25519 signature before it may mutate
139
+ state** (§11.2.4), and only then merges it. A `KeyResolver` maps an Operation's
140
+ 16-byte Issuer Hash to the public key(s) needed to check that signature:
141
+
142
+ - **`Keyring`** — a dict-backed resolver for offline / air-gapped / test use; you
143
+ register each Issuer hash → keyset out of band.
144
+ - **`RnsIdentityResolver`** (base; needs `rns`) — resolves a single-identity
145
+ Issuer by **recalling the `RNS.Identity` behind its hash from the network's
146
+ announce store**, with no out-of-band key exchange. Threshold Groups (composite
147
+ IDs RNS cannot recall) and any out-of-band identities fall through to an
148
+ optional inner resolver — RNS is consulted first, then the fallback.
149
+
150
+ ```python
151
+ import RNS
152
+ from dacar import DeltaReceiver, Keyring, Operation, StateVector
153
+ from dacar.transport import RnsIdentityResolver
154
+
155
+ issuer = RNS.Identity() # the Issuer's RNS identity
156
+ state = StateVector()
157
+ resolver = RnsIdentityResolver(fallback=Keyring()) # + registered groups
158
+ rx = DeltaReceiver(state, resolver)
159
+
160
+ op = Operation(...).sign(issuer.sig_prv) # op.issuer is issuer.hash
161
+ rx.apply_payload(op.to_payload()) # recall issuer.hash → verify → merge
162
+ ```
163
+
164
+ For **bulk / full-state convergence** (e.g. RFed catch-up or a periodic sync),
165
+ pack many signed Deltas into one message and ingest them as a batch — each is
166
+ still independently verified-on-ingest, so a forged element is dropped without
167
+ aborting the rest. This is the secure alternative to `StateVector.merge()`,
168
+ which is trusted-local-only (snapshot/restore of a node's own state) and must
169
+ never be fed network bytes:
170
+
171
+ ```python
172
+ batch = DeltaReceiver.pack_payloads([op_a.to_payload(), op_b.to_payload()])
173
+ applied = rx.apply_payloads(batch) # → count of Deltas verified + applied
174
+ ```
175
+
176
+ > **The Issuer Hash must be the canonical RNS identity hash.** RNS defines an
177
+ > identity hash as `SHA-256(P)[:16]` where `P` is the 64-byte public key
178
+ > (`X25519_pub ‖ Ed25519_pub`) — *not* a hash of the Ed25519 signing key alone.
179
+ > Only that hash is recallable, so a single-identity Issuer Hash MUST be
180
+ > `RNS.Identity().hash`; any other value cannot be authenticated and is dropped.
181
+ > (Threshold Group IDs are exempt — they are resolved by explicit keyset
182
+ > registration, not recall.) The quick-start example above uses a placeholder
183
+ > 16-byte hash purely to demonstrate the API; real deployments use RNS identity
184
+ > hashes for Issuer and Grantee.
185
+
186
+ ## Command-line tool (`dacar`)
187
+
188
+ `pip install dacar` provides a `dacar` command for managing authorization
189
+ grants offline-first — no running daemon, no network. It keeps its own RNS
190
+ Identity in its store dir (like `rnid`/`rnx`/`rncp`), signs Grant/Revoke
191
+ operations, ingests received deltas (verify-on-ingest), and evaluates
192
+ permissions locally against the persisted CRDT.
193
+
194
+ ```bash
195
+ dacar init # bootstrap ~/.dacar (random salt, own identity)
196
+ dacar alias add bergie 7f3a9c2b… # name an identity hash (rnns format)
197
+ dacar grant bergie read sensor:wind # sign + apply locally; hex payload on stdout
198
+ dacar grant bergie read sensor:wind --no-apply > delta.hex # export only
199
+ dacar apply delta.hex # ingest a received delta (verify-on-ingest)
200
+ dacar check bergie read sensor:wind # local Engine.evaluate → ALLOW/DENY
201
+ dacar grants # list active grants (plaintext + alias + hash)
202
+ dacar grants --all # include revoked tombstones
203
+ dacar grants --effective # ✔/⚠ whether each issuer traces to an anchor
204
+ dacar revoke bergie read sensor:wind # sign + apply a Revoke
205
+ dacar prune # §9 Time-Horizon Tombstone Pruning
206
+ dacar config show --reveal # show config (salt masked unless --reveal)
207
+ dacar salt new # rotate the Privacy Salt (§10.2)
208
+ ```
209
+
210
+ Global flags on every command: `--store DIR` (default `$DACAR_HOME` or
211
+ `~/.dacar`), `--identity PATH` (override the signing identity), and
212
+ `-v`/`--full-hashes` (show full 32-hex hashes).
213
+
214
+ **Offline verification model:** verify-on-ingest resolves issuer pubkeys from
215
+ the node's own identity (`<store>/identity`) and any `--identity PATH`.
216
+ Issuers RNS cannot resolve offline are dropped (§11.2.4) — not silently
217
+ trusted. Full network recall (`RnsIdentityResolver`) arrives with the
218
+ live-transport phase. `init` bootstraps the node's own identity as the root
219
+ trust anchor (aliased `self`), so locally-issued grants evaluate ALLOW.
220
+
221
+ ## Tests
222
+
223
+ Pure stdlib `unittest` (no `pytest` dependency):
224
+
225
+ ```bash
226
+ cd python
227
+ python -m unittest discover -s tests -v
228
+ ```
dacar-1.0.0/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # Dacar — Python reference implementation
2
+
3
+ A Python implementation of the [Dacar 1.0-RC7](../README.md) specification:
4
+ decentralized, offline-first access control for Reticulum mesh networks.
5
+
6
+ Dacar is a tuple-based authorization system (inspired by Google Zanzibar) built
7
+ on an LWW-Element-Set CRDT. Each node evaluates permissions locally against a
8
+ replicated, eventually-consistent authorization state, with delegation chains
9
+ that terminate at configured Root Trust Anchors.
10
+
11
+ ## Dependencies
12
+
13
+ | Need | Choice | Why |
14
+ | ----------------- | ---------------------------------------- | ---------------------------------------------- |
15
+ | Ed25519 (§5.2) | [`cryptography`](https://cryptography.io) | Same backend RNS (Reticulum) selects when present |
16
+ | SHA-256 / HMAC (§3.3, §6.1) | stdlib `hashlib` / `hmac` | In the standard library |
17
+ | MessagePack (§5.3)| `msgpack` | Spec-listed dependency |
18
+ | RNS Identity / §8 Challenge | [`rns`](https://reticulum.network) (Reticulum) | The `dacar` CLI keeps an RNS Identity; §8 transport adapters build on RNS |
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ cd python
24
+ pip install -e . # core + the `dacar` CLI (cryptography, msgpack, rns)
25
+ pip install -e ".[transport]" # + the §11.2/§11.3 LXMF transport adapters (lxmf)
26
+ ```
27
+
28
+ The pure core stays import-clean: `import dacar` never pulls in the
29
+ `dacar.transport` subpackage. `rns` is a base dependency (the `dacar` CLI
30
+ keeps an RNS Identity, and the §8 transport adapters build on it); only `lxmf`
31
+ is opt-in, via the `transport` extra. The `dacar` command is part of the base
32
+ install — `pip install dacar` gives a working `dacar` CLI with no extras.
33
+
34
+ ## Layout
35
+
36
+ ```
37
+ dacar/
38
+ hlc.py §5.1 Hybrid Logical Clocks (64-bit packed, big-endian)
39
+ namespace.py §3.3 Namespace Label Privacy: salted HMAC-SHA256 hashing,
40
+ object segmenting, wildcard flag, hashed-object matching
41
+ tuple.py §3.1, §6.1 hashed authorization Tuple + SHA-256 Tuple Hash
42
+ threshold.py §4.1 N-of-M Threshold Groups + 16-byte Group ID
43
+ operation.py §5.2, §5.3 signed Operation (single + multi-sig), pre-image,
44
+ MessagePack transport payload
45
+ serialization.py MessagePack helpers
46
+ crdt.py §6, §9 LWW-Element-Set state, merge (Remove wins ties),
47
+ Time-Horizon Tombstone Pruning, intake rejection,
48
+ verify-then-apply ingest() entry point
49
+ config.py §4, §10 Root Trust Anchors, Privacy Salts (Primary + Legacy),
50
+ Authoritative Identity, deletion horizon
51
+ engine.py §7 recursive delegation evaluation, hashed hypotheses,
52
+ multi-salt shared work bound
53
+ challenge.py §8 Strict Consistency Challenge (hashed, multi-salt) +
54
+ signed Freshness Receipts
55
+ verifier.py §5.2, §11.2.4 verify-on-ingest: IssuerKeyset, KeyResolver,
56
+ Keyring, verify_operation()
57
+ delta.py §11.2.4 DeltaReceiver — transport-agnostic receive boundary
58
+ (decode → verify → apply)
59
+ naming.py §8, §11 RNS naming constants (fixed discriminators +
60
+ configurable RFed topic)
61
+ cli/ the `dacar` command-line tool (work doc #2):
62
+ __init__.py argparse dispatch + `main()` entry point
63
+ store.py persistent node store (INI config, identity, HLC clock,
64
+ CRDT state, rnns aliases, plaintext ledger)
65
+ commands.py command implementations + identity/tuple rendering
66
+ transport/ §8, §11.2, §11.3 RNS & LXMF adapters (`rns` is a base dep; `lxmf`
67
+ needs the `transport` extra):
68
+ rns_challenge.py §8 Challenge over an RNS Link (server endpoint + client transport)
69
+ rns_identity.py §3.1, §11.2.4 RnsIdentityResolver (recall → verify key)
70
+ lxmf_sync.py §11.2/§11.3 targeted LXMF Delta delivery + Paper Messages
71
+ tests/ unittest smoketests for every module
72
+ ```
73
+
74
+ ## Quick start
75
+
76
+ ```python
77
+ from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
78
+ from dacar import (
79
+ Action, Clock, Config, Engine, NamespaceHasher,
80
+ Operation, StateVector, Tuple,
81
+ )
82
+
83
+ HASH = b"\x01" * 16 # a 16-byte RNS.Identity hash
84
+ ROOT = b"\x00" * 16 # your Root Trust Anchor
85
+
86
+ hasher = NamespaceHasher() # default salt is FAIL-OPEN; supply a real 32-byte salt!
87
+ state = StateVector()
88
+ clock = Clock()
89
+
90
+ # Bootstrap: the root anchor grants Alice the "read" relation on "sensor:wind".
91
+ state.apply(
92
+ Operation(
93
+ tuple=Tuple.from_plaintext(
94
+ object_id="sensor:wind", relation="read",
95
+ grantee=HASH, issuer=ROOT, hasher=hasher,
96
+ ),
97
+ action=Action.GRANT,
98
+ hlc=clock.now(),
99
+ ).sign(Ed25519PrivateKey.generate()) # in practice, ROOT's private key
100
+ )
101
+
102
+ engine = Engine(Config(root_trust_anchors=frozenset({ROOT})), state)
103
+ assert engine.evaluate("sensor:wind", "read", HASH) is True
104
+ ```
105
+
106
+ ## Verify-on-ingest & identity resolution
107
+
108
+ Every Delta received over the network (RFed, LXMF, or a scanned Paper Message)
109
+ flows through one seam — `DeltaReceiver.apply_payload` — which decodes the
110
+ §5.3 payload, **authenticates it by Ed25519 signature before it may mutate
111
+ state** (§11.2.4), and only then merges it. A `KeyResolver` maps an Operation's
112
+ 16-byte Issuer Hash to the public key(s) needed to check that signature:
113
+
114
+ - **`Keyring`** — a dict-backed resolver for offline / air-gapped / test use; you
115
+ register each Issuer hash → keyset out of band.
116
+ - **`RnsIdentityResolver`** (base; needs `rns`) — resolves a single-identity
117
+ Issuer by **recalling the `RNS.Identity` behind its hash from the network's
118
+ announce store**, with no out-of-band key exchange. Threshold Groups (composite
119
+ IDs RNS cannot recall) and any out-of-band identities fall through to an
120
+ optional inner resolver — RNS is consulted first, then the fallback.
121
+
122
+ ```python
123
+ import RNS
124
+ from dacar import DeltaReceiver, Keyring, Operation, StateVector
125
+ from dacar.transport import RnsIdentityResolver
126
+
127
+ issuer = RNS.Identity() # the Issuer's RNS identity
128
+ state = StateVector()
129
+ resolver = RnsIdentityResolver(fallback=Keyring()) # + registered groups
130
+ rx = DeltaReceiver(state, resolver)
131
+
132
+ op = Operation(...).sign(issuer.sig_prv) # op.issuer is issuer.hash
133
+ rx.apply_payload(op.to_payload()) # recall issuer.hash → verify → merge
134
+ ```
135
+
136
+ For **bulk / full-state convergence** (e.g. RFed catch-up or a periodic sync),
137
+ pack many signed Deltas into one message and ingest them as a batch — each is
138
+ still independently verified-on-ingest, so a forged element is dropped without
139
+ aborting the rest. This is the secure alternative to `StateVector.merge()`,
140
+ which is trusted-local-only (snapshot/restore of a node's own state) and must
141
+ never be fed network bytes:
142
+
143
+ ```python
144
+ batch = DeltaReceiver.pack_payloads([op_a.to_payload(), op_b.to_payload()])
145
+ applied = rx.apply_payloads(batch) # → count of Deltas verified + applied
146
+ ```
147
+
148
+ > **The Issuer Hash must be the canonical RNS identity hash.** RNS defines an
149
+ > identity hash as `SHA-256(P)[:16]` where `P` is the 64-byte public key
150
+ > (`X25519_pub ‖ Ed25519_pub`) — *not* a hash of the Ed25519 signing key alone.
151
+ > Only that hash is recallable, so a single-identity Issuer Hash MUST be
152
+ > `RNS.Identity().hash`; any other value cannot be authenticated and is dropped.
153
+ > (Threshold Group IDs are exempt — they are resolved by explicit keyset
154
+ > registration, not recall.) The quick-start example above uses a placeholder
155
+ > 16-byte hash purely to demonstrate the API; real deployments use RNS identity
156
+ > hashes for Issuer and Grantee.
157
+
158
+ ## Command-line tool (`dacar`)
159
+
160
+ `pip install dacar` provides a `dacar` command for managing authorization
161
+ grants offline-first — no running daemon, no network. It keeps its own RNS
162
+ Identity in its store dir (like `rnid`/`rnx`/`rncp`), signs Grant/Revoke
163
+ operations, ingests received deltas (verify-on-ingest), and evaluates
164
+ permissions locally against the persisted CRDT.
165
+
166
+ ```bash
167
+ dacar init # bootstrap ~/.dacar (random salt, own identity)
168
+ dacar alias add bergie 7f3a9c2b… # name an identity hash (rnns format)
169
+ dacar grant bergie read sensor:wind # sign + apply locally; hex payload on stdout
170
+ dacar grant bergie read sensor:wind --no-apply > delta.hex # export only
171
+ dacar apply delta.hex # ingest a received delta (verify-on-ingest)
172
+ dacar check bergie read sensor:wind # local Engine.evaluate → ALLOW/DENY
173
+ dacar grants # list active grants (plaintext + alias + hash)
174
+ dacar grants --all # include revoked tombstones
175
+ dacar grants --effective # ✔/⚠ whether each issuer traces to an anchor
176
+ dacar revoke bergie read sensor:wind # sign + apply a Revoke
177
+ dacar prune # §9 Time-Horizon Tombstone Pruning
178
+ dacar config show --reveal # show config (salt masked unless --reveal)
179
+ dacar salt new # rotate the Privacy Salt (§10.2)
180
+ ```
181
+
182
+ Global flags on every command: `--store DIR` (default `$DACAR_HOME` or
183
+ `~/.dacar`), `--identity PATH` (override the signing identity), and
184
+ `-v`/`--full-hashes` (show full 32-hex hashes).
185
+
186
+ **Offline verification model:** verify-on-ingest resolves issuer pubkeys from
187
+ the node's own identity (`<store>/identity`) and any `--identity PATH`.
188
+ Issuers RNS cannot resolve offline are dropped (§11.2.4) — not silently
189
+ trusted. Full network recall (`RnsIdentityResolver`) arrives with the
190
+ live-transport phase. `init` bootstraps the node's own identity as the root
191
+ trust anchor (aliased `self`), so locally-issued grants evaluate ALLOW.
192
+
193
+ ## Tests
194
+
195
+ Pure stdlib `unittest` (no `pytest` dependency):
196
+
197
+ ```bash
198
+ cd python
199
+ python -m unittest discover -s tests -v
200
+ ```
@@ -0,0 +1,113 @@
1
+ """Dacar: Decentralized Access Control for Reticulum.
2
+
3
+ Python implementation of Dacar, a Decentralized Access Control system for
4
+ Reticulum: a tuple-based, offline-first authorization policy plane built on an
5
+ LWW-Element-Set CRDT, designed for delay-tolerant mesh networks.
6
+
7
+ Object and relation labels are stored only as salted HMAC-SHA256 hashes
8
+ (§3.3 Namespace Label Privacy), Threshold Groups may act as N-of-M Issuers
9
+ (§4.1), and the state is bounded by Time-Horizon Tombstone Pruning (§9).
10
+ """
11
+
12
+ from dacar.hlc import Clock, MAX_HLC, MAX_LOGICAL, MAX_PHYSICAL, pack, unpack
13
+ from dacar.namespace import (
14
+ DEFAULT_SALT,
15
+ HASH_SIZE,
16
+ MAX_LEGACY_SALTS,
17
+ SALT_SIZE,
18
+ DELIMITER,
19
+ WILDCARD,
20
+ NamespaceHasher,
21
+ covers,
22
+ split,
23
+ )
24
+ from dacar.tuple import MAX_SEGMENTS, Tuple
25
+ from dacar.threshold import ThresholdGroup, group_id
26
+ from dacar.operation import HLC_BYTES, SIGNATURE_SIZE, Action, Operation
27
+ from dacar.verifier import IssuerKeyset, KeyResolver, Keyring, verify_operation
28
+ from dacar.config import Config, DEFAULT_DELETION_HORIZON_DAYS, NullPrivacySaltWarning
29
+ from dacar.crdt import StateVector, TrustedLocalOnlyWarning
30
+ from dacar.delta import DeltaReceiver
31
+ from dacar.naming import (
32
+ APP_NAME,
33
+ CHALLENGE_ASPECTS,
34
+ CHALLENGE_DESTINATION,
35
+ RFED_TOPIC,
36
+ LXMF_DELIVERY_TITLE,
37
+ )
38
+ from dacar.engine import ADMIN_RELATION, DEFAULT_MAX_DEPTH, DEFAULT_MAX_VISITED, Engine
39
+ from dacar.challenge import (
40
+ NONCE_SIZE,
41
+ AuthoritativeServer,
42
+ Challenge,
43
+ ChallengeClient,
44
+ Receipt,
45
+ Transport,
46
+ Verdict,
47
+ )
48
+
49
+ __all__ = [
50
+ # HLC (§5.1)
51
+ "Clock",
52
+ "MAX_HLC",
53
+ "MAX_LOGICAL",
54
+ "MAX_PHYSICAL",
55
+ "pack",
56
+ "unpack",
57
+ # Namespace Label Privacy (§3.3)
58
+ "DEFAULT_SALT",
59
+ "HASH_SIZE",
60
+ "MAX_LEGACY_SALTS",
61
+ "SALT_SIZE",
62
+ "DELIMITER",
63
+ "WILDCARD",
64
+ "NamespaceHasher",
65
+ "covers",
66
+ "split",
67
+ # Tuple (§3.1, §6.1)
68
+ "MAX_SEGMENTS",
69
+ "Tuple",
70
+ # Threshold Groups (§4.1)
71
+ "ThresholdGroup",
72
+ "group_id",
73
+ # Operations (§5.2, §5.3)
74
+ "HLC_BYTES",
75
+ "SIGNATURE_SIZE",
76
+ "Action",
77
+ "Operation",
78
+ # Verify-on-ingest (§11.2.4)
79
+ "IssuerKeyset",
80
+ "KeyResolver",
81
+ "Keyring",
82
+ "verify_operation",
83
+ # Transport-agnostic Delta receive boundary (§11)
84
+ "DeltaReceiver",
85
+ # RNS naming conventions (§8, §11)
86
+ "APP_NAME",
87
+ "CHALLENGE_ASPECTS",
88
+ "CHALLENGE_DESTINATION",
89
+ "RFED_TOPIC",
90
+ "LXMF_DELIVERY_TITLE",
91
+ # Config (§4, §10) + state (§6)
92
+ "Config",
93
+ "DEFAULT_DELETION_HORIZON_DAYS",
94
+ "NullPrivacySaltWarning",
95
+ "StateVector",
96
+ "TrustedLocalOnlyWarning",
97
+ # Engine (§7)
98
+ "ADMIN_RELATION",
99
+ "DEFAULT_MAX_DEPTH",
100
+ "DEFAULT_MAX_VISITED",
101
+ "Engine",
102
+ # Challenge (§8)
103
+ "NONCE_SIZE",
104
+ "AuthoritativeServer",
105
+ "Challenge",
106
+ "ChallengeClient",
107
+ "Receipt",
108
+ "Transport",
109
+ "Verdict",
110
+ ]
111
+
112
+ __version__ = "1.0.0"
113
+ __spec_version__ = "1.0-RC7"