uor-addr 0.1.0__py3-none-win_amd64.whl

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.
uor_addr/__init__.py ADDED
@@ -0,0 +1,416 @@
1
+ """uor-addr — typed content-addressing Python bindings.
2
+
3
+ Wraps the `uor-addr-c` C ABI dynamic library via `ctypes` (stdlib).
4
+ The bundled native library (`libuor_addr_c.so` on Linux,
5
+ `libuor_addr_c.dylib` on macOS, `uor_addr_c.dll` on Windows) is
6
+ included in the wheel for each supported platform. The produced
7
+ κ-label is byte-for-byte identical to the Rust crate's output
8
+ (cross-validation pinned by CF-C* in CONFORMANCE.md).
9
+
10
+ >>> from uor_addr import kappa
11
+ >>> kappa.json_address(b'{"foo":"bar"}')
12
+ 'sha256:7a38bf81f383f69433ad6e900d35b3e2385593f76a7b7ab5d4355b8ba41ee24b'
13
+
14
+ Why C ABI rather than wasm? wasmtime-py's Component Model API is not
15
+ yet stable as of wasmtime 24.x; once it lands, a follow-on release
16
+ can pivot to the WASM Component Model artifact this repository also
17
+ publishes.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import ctypes
23
+ import importlib.resources
24
+ import platform
25
+ import sys
26
+ from typing import Final
27
+
28
+
29
+ class AddressError(Exception):
30
+ """Raised when a realization's address function fails.
31
+
32
+ Maps the C ABI return codes to one of three kinds:
33
+
34
+ - `'invalid-input'` — input failed the realization's host-boundary
35
+ parser (e.g. malformed JSON, non-DER ASN.1, schema admission
36
+ mismatch).
37
+ - `'too-large'` — input exceeded a typed-input ceiling (depth,
38
+ width, container arity).
39
+ - `'pipeline-failure'` — defensive substrate-level failure;
40
+ unreachable on well-formed input.
41
+ """
42
+
43
+ def __init__(self, kind: str, message: str = "") -> None:
44
+ self.kind = kind
45
+ super().__init__(message or f"uor-addr address failed: {kind}")
46
+
47
+
48
+ # Wire-format width: len("sha256:") + 64-byte lowercase-hex digest.
49
+ ADDRESS_LABEL_BYTES: Final[int] = 71
50
+
51
+ # C ABI return codes (mirror UOR_ADDR_* in uor_addr.h).
52
+ _OK = 0
53
+ _ERR_NULL_POINTER = -1
54
+ _ERR_BUFFER_TOO_SMALL = -2
55
+ _ERR_INVALID_INPUT = -3
56
+ _ERR_TOO_LARGE = -4
57
+ _ERR_PIPELINE = -5
58
+
59
+ _ERR_KIND: Final[dict[int, str]] = {
60
+ _ERR_INVALID_INPUT: "invalid-input",
61
+ _ERR_TOO_LARGE: "too-large",
62
+ _ERR_PIPELINE: "pipeline-failure",
63
+ _ERR_NULL_POINTER: "pipeline-failure",
64
+ _ERR_BUFFER_TOO_SMALL: "pipeline-failure",
65
+ }
66
+
67
+
68
+ def _libname() -> str:
69
+ """Resolve the bundled C ABI library filename for the current OS."""
70
+ system = sys.platform
71
+ if system.startswith("linux"):
72
+ return "libuor_addr_c.so"
73
+ if system == "darwin":
74
+ return "libuor_addr_c.dylib"
75
+ if system in ("win32", "cygwin"):
76
+ return "uor_addr_c.dll"
77
+ raise OSError(f"unsupported platform for uor-addr: {system} {platform.machine()}")
78
+
79
+
80
+ def _load_lib() -> ctypes.CDLL:
81
+ """Locate + load the bundled native library."""
82
+ lib_path = importlib.resources.files(__package__).joinpath(_libname())
83
+ with importlib.resources.as_file(lib_path) as path:
84
+ return ctypes.CDLL(str(path))
85
+
86
+
87
+ # Bind once at import time; subsequent calls reuse the same library
88
+ # handle and the same function-pointer bindings.
89
+ _lib = _load_lib()
90
+
91
+
92
+ def _bind(symbol: str) -> ctypes._NamedFuncPointer:
93
+ """Bind one `uor_addr_*` C function with its argtypes / restype."""
94
+ fn = getattr(_lib, symbol)
95
+ fn.argtypes = [
96
+ ctypes.POINTER(ctypes.c_uint8), # const uint8_t *input
97
+ ctypes.c_size_t, # size_t input_len
98
+ ctypes.POINTER(ctypes.c_uint8), # uint8_t *out_label
99
+ ctypes.c_size_t, # size_t out_label_len
100
+ ctypes.POINTER(ctypes.c_size_t), # size_t *out_written
101
+ ]
102
+ fn.restype = ctypes.c_int32
103
+ return fn
104
+
105
+
106
+ _FUNCS: Final[dict[str, ctypes._NamedFuncPointer]] = {
107
+ "json_address": _bind("uor_addr_json"),
108
+ "sexp_address": _bind("uor_addr_sexp"),
109
+ "xml_address": _bind("uor_addr_xml"),
110
+ "asn1_address": _bind("uor_addr_asn1"),
111
+ "ring_address": _bind("uor_addr_ring"),
112
+ "codemodule_address": _bind("uor_addr_codemodule"),
113
+ "schema_photo_address": _bind("uor_addr_schema_photo"),
114
+ "schema_document_address": _bind("uor_addr_schema_document"),
115
+ "schema_codemodule_signed_address": _bind("uor_addr_schema_codemodule_signed"),
116
+ }
117
+
118
+
119
+ # ─── Grounded handle wrapper (TC-05 replay across the FFI) ─────────
120
+
121
+ # Verify-error codes mirror UOR_ADDR_ERR_VERIFY_* in the C header. All
122
+ # five map to defensive substrate corruption; unreachable for a handle
123
+ # minted via the *_with_witness Python wrappers.
124
+ _ERR_VERIFY_KIND: Final[dict[int, str]] = {
125
+ -10: "empty-trace",
126
+ -11: "out-of-order-event",
127
+ -12: "zero-target",
128
+ -13: "non-contiguous-steps",
129
+ -14: "capacity-exceeded",
130
+ }
131
+
132
+
133
+ # `*_with_witness` ABI: (input, input_len, out_handle) -> i32
134
+ def _bind_with_witness(symbol: str) -> ctypes._NamedFuncPointer:
135
+ fn = getattr(_lib, symbol)
136
+ fn.argtypes = [
137
+ ctypes.POINTER(ctypes.c_uint8), # const uint8_t *input
138
+ ctypes.c_size_t, # size_t input_len
139
+ ctypes.POINTER(ctypes.c_void_p), # UorAddrGrounded **out_handle
140
+ ]
141
+ fn.restype = ctypes.c_int32
142
+ return fn
143
+
144
+
145
+ _WITH_WITNESS_FUNCS: Final[dict[str, ctypes._NamedFuncPointer]] = {
146
+ "json": _bind_with_witness("uor_addr_json_with_witness"),
147
+ "sexp": _bind_with_witness("uor_addr_sexp_with_witness"),
148
+ "xml": _bind_with_witness("uor_addr_xml_with_witness"),
149
+ "asn1": _bind_with_witness("uor_addr_asn1_with_witness"),
150
+ "ring": _bind_with_witness("uor_addr_ring_with_witness"),
151
+ "codemodule": _bind_with_witness("uor_addr_codemodule_with_witness"),
152
+ "schema_photo": _bind_with_witness("uor_addr_schema_photo_with_witness"),
153
+ "schema_document": _bind_with_witness("uor_addr_schema_document_with_witness"),
154
+ "schema_codemodule_signed": _bind_with_witness("uor_addr_schema_codemodule_signed_with_witness"),
155
+ }
156
+
157
+ # Grounded accessor ABIs.
158
+ _lib.uor_addr_grounded_kappa_label.argtypes = [
159
+ ctypes.c_void_p, # const UorAddrGrounded *handle
160
+ ctypes.POINTER(ctypes.c_uint8), # uint8_t *out_label
161
+ ctypes.c_size_t, # size_t out_label_len
162
+ ctypes.POINTER(ctypes.c_size_t), # size_t *out_written
163
+ ]
164
+ _lib.uor_addr_grounded_kappa_label.restype = ctypes.c_int32
165
+
166
+ _lib.uor_addr_grounded_content_fingerprint.argtypes = [
167
+ ctypes.c_void_p,
168
+ ctypes.POINTER(ctypes.c_uint8),
169
+ ctypes.c_size_t,
170
+ ctypes.POINTER(ctypes.c_size_t),
171
+ ]
172
+ _lib.uor_addr_grounded_content_fingerprint.restype = ctypes.c_int32
173
+
174
+ _lib.uor_addr_grounded_verify.argtypes = [
175
+ ctypes.c_void_p,
176
+ ctypes.POINTER(ctypes.c_uint8),
177
+ ctypes.c_size_t,
178
+ ctypes.POINTER(ctypes.c_size_t),
179
+ ]
180
+ _lib.uor_addr_grounded_verify.restype = ctypes.c_int32
181
+
182
+ _lib.uor_addr_grounded_free.argtypes = [ctypes.c_void_p]
183
+ _lib.uor_addr_grounded_free.restype = None
184
+
185
+
186
+ class VerifyError(Exception):
187
+ """Raised when `Grounded.verify()` fails.
188
+
189
+ The `kind` attribute is one of: `'empty-trace'`,
190
+ `'out-of-order-event'`, `'zero-target'`, `'non-contiguous-steps'`,
191
+ `'capacity-exceeded'` — matching the WIT `verify-error` variant.
192
+ All five are defensive against substrate corruption; unreachable
193
+ for a `Grounded` minted through this binding.
194
+ """
195
+
196
+ def __init__(self, kind: str, message: str = "") -> None:
197
+ self.kind = kind
198
+ super().__init__(message or f"uor-addr verify failed: {kind}")
199
+
200
+
201
+ class Grounded:
202
+ """Opaque handle to a Rust-side `Grounded<AddressLabel>` witness.
203
+
204
+ Constructed by any of the `kappa.*_address_with_witness` methods.
205
+ Carries the ψ-pipeline's emitted derivation; verifiable through
206
+ [`verify`] without re-invoking SHA-256.
207
+
208
+ TC-05 conformance: every `Grounded` produced by a
209
+ `*_address_with_witness` call replays through `verify()` to a
210
+ κ-label byte-identical to the one [`kappa_label`] reports
211
+ (QS-05 replay equivalence — bit-identical round-trip).
212
+
213
+ Use as a context manager to deterministically release the
214
+ underlying handle on scope exit; otherwise the handle is freed at
215
+ garbage-collection time via `__del__`.
216
+ """
217
+
218
+ __slots__ = ("_handle",)
219
+
220
+ def __init__(self, handle: int) -> None:
221
+ # `handle` is a raw integer pointer returned by a C ABI
222
+ # `*_with_witness` call. Must be non-zero on success.
223
+ self._handle: int | None = handle
224
+
225
+ def __enter__(self) -> "Grounded":
226
+ return self
227
+
228
+ def __exit__(self, *exc_info: object) -> None:
229
+ self.close()
230
+
231
+ def __del__(self) -> None:
232
+ # Defensive: free the handle on GC if the caller didn't
233
+ # close() it explicitly.
234
+ self.close()
235
+
236
+ def close(self) -> None:
237
+ """Release the underlying handle. After `close()`, further
238
+ method calls raise `RuntimeError`."""
239
+ if self._handle is not None:
240
+ _lib.uor_addr_grounded_free(self._handle)
241
+ self._handle = None
242
+
243
+ def _require(self) -> int:
244
+ if self._handle is None:
245
+ raise RuntimeError("Grounded handle has been closed")
246
+ return self._handle
247
+
248
+ def kappa_label(self) -> str:
249
+ """Return the 71-byte ASCII κ-label this Grounded carries."""
250
+ handle = self._require()
251
+ out_buf = (ctypes.c_uint8 * ADDRESS_LABEL_BYTES)()
252
+ written = ctypes.c_size_t(0)
253
+ rc = _lib.uor_addr_grounded_kappa_label(
254
+ handle, out_buf, ADDRESS_LABEL_BYTES, ctypes.byref(written)
255
+ )
256
+ if rc != _OK:
257
+ raise AddressError(_ERR_KIND.get(rc, "pipeline-failure"))
258
+ return bytes(out_buf).decode("ascii")
259
+
260
+ def content_fingerprint(self) -> bytes:
261
+ """Return the 32-byte SHA-256 content fingerprint."""
262
+ handle = self._require()
263
+ out_buf = (ctypes.c_uint8 * 32)()
264
+ written = ctypes.c_size_t(0)
265
+ rc = _lib.uor_addr_grounded_content_fingerprint(
266
+ handle, out_buf, 32, ctypes.byref(written)
267
+ )
268
+ if rc != _OK:
269
+ raise AddressError(_ERR_KIND.get(rc, "pipeline-failure"))
270
+ return bytes(out_buf)
271
+
272
+ def verify(self) -> str:
273
+ """Replay the derivation through `prism_verify::certify_from_trace`
274
+ and return the recovered κ-label. SHA-256 is **not** re-invoked.
275
+
276
+ Round-trip equivalence: `g.verify() == g.kappa_label()` byte-for-byte
277
+ (QS-05 / CL-R* in CONFORMANCE.md).
278
+ """
279
+ handle = self._require()
280
+ out_buf = (ctypes.c_uint8 * ADDRESS_LABEL_BYTES)()
281
+ written = ctypes.c_size_t(0)
282
+ rc = _lib.uor_addr_grounded_verify(
283
+ handle, out_buf, ADDRESS_LABEL_BYTES, ctypes.byref(written)
284
+ )
285
+ if rc != _OK:
286
+ if rc in _ERR_VERIFY_KIND:
287
+ raise VerifyError(_ERR_VERIFY_KIND[rc])
288
+ raise AddressError(_ERR_KIND.get(rc, "pipeline-failure"))
289
+ return bytes(out_buf).decode("ascii")
290
+
291
+
292
+ def _mint_with_witness(
293
+ realization: str, data: bytes | bytearray | memoryview
294
+ ) -> Grounded:
295
+ buf = bytes(data)
296
+ in_ptr = (ctypes.c_uint8 * len(buf)).from_buffer_copy(buf)
297
+ out_handle = ctypes.c_void_p()
298
+ fn = _WITH_WITNESS_FUNCS[realization]
299
+ rc = fn(in_ptr, len(buf), ctypes.byref(out_handle))
300
+ if rc != _OK:
301
+ kind = _ERR_KIND.get(rc, "pipeline-failure")
302
+ raise AddressError(kind)
303
+ if out_handle.value is None:
304
+ raise AddressError(
305
+ "pipeline-failure",
306
+ "C ABI returned OK without writing a handle",
307
+ )
308
+ return Grounded(out_handle.value)
309
+
310
+
311
+ def _call(fn: ctypes._NamedFuncPointer, data: bytes | bytearray | memoryview) -> str:
312
+ buf = bytes(data)
313
+ in_ptr = (ctypes.c_uint8 * len(buf)).from_buffer_copy(buf)
314
+ out_buf = (ctypes.c_uint8 * ADDRESS_LABEL_BYTES)()
315
+ written = ctypes.c_size_t(0)
316
+ rc = fn(in_ptr, len(buf), out_buf, ADDRESS_LABEL_BYTES, ctypes.byref(written))
317
+ if rc != _OK:
318
+ kind = _ERR_KIND.get(rc, "pipeline-failure")
319
+ raise AddressError(kind)
320
+ if written.value != ADDRESS_LABEL_BYTES:
321
+ raise AddressError(
322
+ "pipeline-failure",
323
+ f"C ABI wrote {written.value} bytes, expected {ADDRESS_LABEL_BYTES}",
324
+ )
325
+ return bytes(out_buf).decode("ascii")
326
+
327
+
328
+ class _Kappa:
329
+ """Bound facade exposing the C ABI realization functions."""
330
+
331
+ def json_address(self, data: bytes) -> str:
332
+ """RFC 8259 JSON under RFC 8785 JCS + Unicode NFC + SHA-256."""
333
+ return _call(_FUNCS["json_address"], data)
334
+
335
+ def sexp_address(self, data: bytes) -> str:
336
+ """Rivest 1997 canonical S-expressions + SHA-256."""
337
+ return _call(_FUNCS["sexp_address"], data)
338
+
339
+ def xml_address(self, data: bytes) -> str:
340
+ """W3C XML-C14N 1.1 (subset) + SHA-256."""
341
+ return _call(_FUNCS["xml_address"], data)
342
+
343
+ def asn1_address(self, data: bytes) -> str:
344
+ """ITU-T X.690 DER + SHA-256."""
345
+ return _call(_FUNCS["asn1_address"], data)
346
+
347
+ def ring_address(self, data: bytes) -> str:
348
+ """UOR-Framework Amendment 43 §2 ring elements + SHA-256."""
349
+ return _call(_FUNCS["ring_address"], data)
350
+
351
+ def codemodule_address(self, data: bytes) -> str:
352
+ """CCMAS canonical AST + SHA-256."""
353
+ return _call(_FUNCS["codemodule_address"], data)
354
+
355
+ def schema_photo_address(self, data: bytes) -> str:
356
+ """schema.org/Photograph admission + JSON canonicalization."""
357
+ return _call(_FUNCS["schema_photo_address"], data)
358
+
359
+ def schema_document_address(self, data: bytes) -> str:
360
+ """schema.org/Article admission + JSON canonicalization."""
361
+ return _call(_FUNCS["schema_document_address"], data)
362
+
363
+ def schema_codemodule_signed_address(self, data: bytes) -> str:
364
+ """in-toto Statement v1 admission + JSON canonicalization."""
365
+ return _call(_FUNCS["schema_codemodule_signed_address"], data)
366
+
367
+ # ─── Witness-bearing entry points (TC-05) ──────────────────────
368
+
369
+ def json_address_with_witness(self, data: bytes) -> Grounded:
370
+ """JSON realization; returns a verifiable [`Grounded`] witness."""
371
+ return _mint_with_witness("json", data)
372
+
373
+ def sexp_address_with_witness(self, data: bytes) -> Grounded:
374
+ """S-expression realization; returns a verifiable [`Grounded`] witness."""
375
+ return _mint_with_witness("sexp", data)
376
+
377
+ def xml_address_with_witness(self, data: bytes) -> Grounded:
378
+ """XML realization; returns a verifiable [`Grounded`] witness."""
379
+ return _mint_with_witness("xml", data)
380
+
381
+ def asn1_address_with_witness(self, data: bytes) -> Grounded:
382
+ """ASN.1 realization; returns a verifiable [`Grounded`] witness."""
383
+ return _mint_with_witness("asn1", data)
384
+
385
+ def ring_address_with_witness(self, data: bytes) -> Grounded:
386
+ """Ring realization; returns a verifiable [`Grounded`] witness."""
387
+ return _mint_with_witness("ring", data)
388
+
389
+ def codemodule_address_with_witness(self, data: bytes) -> Grounded:
390
+ """Code-module realization; returns a verifiable [`Grounded`] witness."""
391
+ return _mint_with_witness("codemodule", data)
392
+
393
+ def schema_photo_address_with_witness(self, data: bytes) -> Grounded:
394
+ """schema.org/Photograph; returns a verifiable [`Grounded`] witness."""
395
+ return _mint_with_witness("schema_photo", data)
396
+
397
+ def schema_document_address_with_witness(self, data: bytes) -> Grounded:
398
+ """schema.org/Article; returns a verifiable [`Grounded`] witness."""
399
+ return _mint_with_witness("schema_document", data)
400
+
401
+ def schema_codemodule_signed_address_with_witness(self, data: bytes) -> Grounded:
402
+ """in-toto Statement v1; returns a verifiable [`Grounded`] witness."""
403
+ return _mint_with_witness("schema_codemodule_signed", data)
404
+
405
+
406
+ # Singleton facade — matches the npm package's `kappa` export shape.
407
+ kappa: Final[_Kappa] = _Kappa()
408
+
409
+
410
+ __all__ = [
411
+ "ADDRESS_LABEL_BYTES",
412
+ "AddressError",
413
+ "Grounded",
414
+ "VerifyError",
415
+ "kappa",
416
+ ]
Binary file
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.4
2
+ Name: uor-addr
3
+ Version: 0.1.0
4
+ Summary: Typed content-addressing — deterministic, verifiable sha256:<64hex> κ-labels from JSON / S-expressions / XML / ASN.1 DER / schema.org / in-toto. Wraps the uor-addr-c native library via ctypes.
5
+ Author-email: The UOR Foundation <engineering@uor.foundation>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/UOR-Foundation/uor-addr
8
+ Project-URL: Repository, https://github.com/UOR-Foundation/uor-addr
9
+ Project-URL: Issues, https://github.com/UOR-Foundation/uor-addr/issues
10
+ Project-URL: Source (Python binding), https://github.com/UOR-Foundation/uor-addr/tree/main/bindings/python
11
+ Keywords: uor,content-addressing,sha256,kappa-label,canonicalization,jcs,json
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Security :: Cryptography
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Dynamic: license-file
25
+
26
+ # uor-addr (Python)
27
+
28
+ Python bindings for [`uor-addr`](https://github.com/UOR-Foundation/uor-addr) — typed content-addressing producing deterministic `sha256:<64hex>` κ-labels from JSON, S-expressions, XML, ASN.1 DER, schema.org, in-toto, and more.
29
+
30
+ Wraps the [`uor-addr-c`](https://github.com/UOR-Foundation/uor-addr/tree/main/crates/uor-addr-c) C ABI dynamic library via `ctypes` (stdlib — **no external dependencies**). The produced κ-label is **byte-for-byte identical** to the Rust crate's output.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install uor-addr
36
+ ```
37
+
38
+ Requires Python 3.10+. Wheels ship per-platform; sdist falls back to building from the workspace.
39
+
40
+ ## Quickstart
41
+
42
+ ```python
43
+ from uor_addr import kappa
44
+
45
+ label = kappa.json_address(b'{"foo":"bar"}')
46
+ print(label)
47
+ # sha256:7a38bf81f383f69433ad6e900d35b3e2385593f76a7b7ab5d4355b8ba41ee24b
48
+ ```
49
+
50
+ ## API
51
+
52
+ Nine `*_address` methods on the `kappa` singleton, one per realization. Each takes `bytes`-like and returns the 71-byte ASCII `sha256:<64-lowercase-hex>` κ-label as `str`. Failures raise `uor_addr.AddressError` carrying one of three `kind` tags (`'invalid-input'` / `'too-large'` / `'pipeline-failure'`).
53
+
54
+ | Method | Realization | Imported spec |
55
+ |---|---|---|
56
+ | `kappa.json_address` | JSON | RFC 8259 + RFC 8785 JCS + UAX #15 NFC |
57
+ | `kappa.sexp_address` | S-expressions | Rivest 1997 canonical form |
58
+ | `kappa.xml_address` | XML | W3C XML-C14N 1.1 (subset) |
59
+ | `kappa.asn1_address` | ASN.1 | ITU-T X.690 DER |
60
+ | `kappa.ring_address` | Ring elements | UOR-Framework Amendment 43 §2 |
61
+ | `kappa.codemodule_address` | Code-module AST | CCMAS |
62
+ | `kappa.schema_photo_address` | schema.org/Photograph | schema.org/Photograph |
63
+ | `kappa.schema_document_address` | schema.org/Article (+ subtypes) | schema.org/Article |
64
+ | `kappa.schema_codemodule_signed_address` | in-toto Statement v1 | in-toto Statement v1 |
65
+
66
+ ## Determinism + canonical-form invariance
67
+
68
+ ```python
69
+ from uor_addr import kappa
70
+
71
+ # JSON: whitespace, key order, NFC vs NFD all collapse.
72
+ a = kappa.json_address(b'{"a":1,"b":2}')
73
+ b = kappa.json_address(b'{ "b" : 2 , "a" : 1 }')
74
+ assert a == b
75
+
76
+ # But typed values that look similar produce distinct κ-labels.
77
+ int_label = kappa.json_address(b"42")
78
+ str_label = kappa.json_address(b'"42"')
79
+ assert int_label != str_label
80
+ ```
81
+
82
+ ## TC-05 replay across the FFI boundary
83
+
84
+ Each `*_address_with_witness` method returns a `Grounded` handle carrying the ψ-pipeline's emitted derivation. Calling `grounded.verify()` replays the derivation through `prism_verify::certify_from_trace` and returns the recovered κ-label **without re-invoking SHA-256**. The verifier reads the trace events the source pipeline emitted and re-packages the certified output (QS-05 replay equivalence; CL-R\* in [CONFORMANCE.md](https://github.com/UOR-Foundation/uor-addr/blob/main/CONFORMANCE.md)).
85
+
86
+ ```python
87
+ from uor_addr import kappa
88
+
89
+ with kappa.json_address_with_witness(b'{"foo":"bar"}') as grounded:
90
+ print(grounded.kappa_label())
91
+ # sha256:7a38bf81f383f69433ad6e900d35b3e2385593f76a7b7ab5d4355b8ba41ee24b
92
+
93
+ assert grounded.verify() == grounded.kappa_label()
94
+ # TC-05 round-trip; SHA-256 was not re-invoked.
95
+
96
+ fingerprint: bytes = grounded.content_fingerprint()
97
+ # 32-byte content fingerprint (distinct from the κ-label hex
98
+ # suffix — it is prism's content-address of the Grounded's full
99
+ # state, used for replay verification).
100
+ ```
101
+
102
+ The `Grounded` handle is freed on `__exit__` of the `with` block; otherwise it is freed at garbage-collection time. Cross-process attestation is not supported (the underlying `Trace<256>` constructor is `pub(crate)` in `uor-foundation`); for that, persist the κ-label itself and re-mint at the verifier side.
103
+
104
+ ## Why C ABI rather than WASM?
105
+
106
+ The `@uor-foundation/uor-addr` npm package wraps the WASM Component Model artifact via [`jco`](https://github.com/bytecodealliance/jco). Python's [`wasmtime-py`](https://pypi.org/project/wasmtime/) does not yet expose the Component Model API (24.x ships core-module support only); pivoting to wasm would require either waiting for upstream or pulling in a less-mature runtime. The C ABI path is faster (native code), more compact (no wasm runtime in the wheel), and produces the same κ-label byte-for-byte. The `uor-addr-c` native library is bundled per-platform in the wheel.
107
+
108
+ ## Byte identity with the Rust crate
109
+
110
+ The κ-label this package produces is **byte-for-byte identical** to `uor_addr::<realization>::address(input).address` from the Rust crate (and to `@uor-foundation/uor-addr` npm's output). Cross-validation is pinned by the **CF-C\*** invariant class in [CONFORMANCE.md](https://github.com/UOR-Foundation/uor-addr/blob/main/CONFORMANCE.md).
111
+
112
+ ## License
113
+
114
+ Apache-2.0.
@@ -0,0 +1,7 @@
1
+ uor_addr/__init__.py,sha256=S2A-b8BaoyTajzwjMKRC0TEdE0d6O3IJ4cMkfcPcJ7c,16461
2
+ uor_addr/uor_addr_c.dll,sha256=aGWkPmkHKn_SVX5dX1-3rut62g0rAAZoWpSvTwCMJow,1574400
3
+ uor_addr-0.1.0.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
4
+ uor_addr-0.1.0.dist-info/METADATA,sha256=-aAavN8IWemdRFHViohiLBYHZw-sR1vuMV9XS1KE-e0,6127
5
+ uor_addr-0.1.0.dist-info/WHEEL,sha256=GjDPPQwEcripVP6P2r3RxLa-h5Lb9ifGB7FYYtbLDT0,98
6
+ uor_addr-0.1.0.dist-info/top_level.txt,sha256=IPXEJJ5q4rSoTfLBnB9ce8KdNxS89vCzQ4qSn1VfuNQ,9
7
+ uor_addr-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
5
+
@@ -0,0 +1,201 @@
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
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1 @@
1
+ uor_addr