feat(python): add a CPython binding + build for the uUR module#10
Open
kdmukAI-bot wants to merge 1 commit into
Open
feat(python): add a CPython binding + build for the uUR module#10kdmukAI-bot wants to merge 1 commit into
kdmukAI-bot wants to merge 1 commit into
Conversation
Adds a CPython counterpart to the MicroPython uUR.c wrapper so the native BC-UR encoder/decoder is importable as `uUR` on CPython (e.g. Raspberry Pi), mirroring the ESP32 firmware's native module. Same module surface as the MicroPython side, so host business logic that does `import uUR` works on both runtimes. - python/uUR.c: the full uUR surface via the CPython C-API — UR, URDecoder, UREncoder, FountainEncoder, the Types CBOR-codec namespace, and the DECODER_* state constants. Wraps the ur_decoder_get_state() state-machine API. The FountainEncoder view is returned uncached to avoid a parent<->view reference cycle (behaviorally identical to the cached MicroPython view; leak-free under refcounting). - setup.py + pyproject.toml: a pip-installable build of the `uUR` extension from the portable core (envelope + types + bundled SHA-256; no OpenSSL). `py-modules = []` stops setuptools from misreading the C `src/` dir as a Python src-layout package. - .gitignore: ignore the CPython build artifacts (*.so, egg-info, dist). Host build uses the bundled src/sha256/sha256.c (UR_USE_MBEDTLS_SHA256 unset), so there is no external crypto dependency. Co-Authored-By: kdmukai <934746+kdmukai@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a CPython binding for the
uURmoduleThis adds a CPython counterpart to the existing MicroPython
uUR.cwrapper, so the native BC-UR encoder/decoder is importable asuURon host/desktop CPython (e.g. Raspberry Pi), mirroring the module the ESP32/MicroPython firmware already exposes. Business logic that doesimport uURthen works identically on both runtimes.What's here
python/uUR.c— the fulluURsurface via the CPython C-API:UR,URDecoder,UREncoder,FountainEncoder, theTypesCBOR-codec namespace (bytes/psbt/bip39/output+ tag/type constants), and theDECODER_*state constants. It wraps theur_decoder_get_state()state-machine API and returns theFountainEncoderview uncached (leak-free under refcounting; avoids a parent↔view reference cycle — behaviorally identical to the cached MicroPython view).setup.py+pyproject.toml— a pip-installable build of theuURextension from the portable core (envelope +types+ the bundled SHA-256; no OpenSSL/mbedTLS).py-modules = []keeps setuptools from misreading the Csrc/dir as a Python src-layout package..gitignore— ignore the CPython build artifacts.Notes
src/sha256/sha256.c(UR_USE_MBEDTLS_SHA256unset), so there's no external crypto dependency.uUR.cso the two runtimes present one API.Validation
pip install .builds + imports cleanly; a full multi-part fountain encode→decode roundtrip plus theTypescodecs pass on x86-64 CPython 3.13 and, on-device, on ARMv6 CPython 3.10 (Raspberry Pi Zero).🤖 Generated with Claude Code