UR Implementation in Python -- ported from the C++ Reference Implementation by Blockchain Commons
URs ("Uniform Resources") are a method for encoding structured binary data for transport in URIs and QR Codes. They are described in BCR-2020-005.
There is also another reference implementation in Swift: URKit, and a demo app that uses it to display and read multi-part animated QR codes: URDemo.
The code is not yet available in a package format, so just copy the files into your project.
Either hashlib
in a normal Python environment or uhashlib
in MicroPython must be available.
-
Include the source folder in your Python project
-
Import the encoder and decoder:
from ur.ur_encoder import UREncoder from ur.ur_decoder import URDecoder
-
Write some test code:
ur = make_message_ur(32767) max_fragment_len = 1000 first_seq_num = 100 encoder = UREncoder(ur, max_fragment_len, first_seq_num) decoder = URDecoder() while True: part = encoder.next_part() decoder.receive_part(part) if decoder.is_complete(): break if decoder.is_success(): assert(decoder.result == ur) else: print('{}'.format(decoder.result)) assert(False)
Before accepting a PR that can affect build or unit tests, make sure the following command succeeds:
python test.py
Ensure that you add new unit tests for new or modified functionality.
Unless otherwise noted (either in this /README.md or in the file's header comments) the contents of this repository are Copyright © 2020 Foundation Devices, Inc., and are licensed under the spdx:BSD-2-Clause Plus Patent License.
This code is a Python port of the original C++ reference implementation by Blockchain Commons. See Blockchain Commons UR Library for the original version.
TBD
We encourage public contributions through issues and pull-requests! Please review CONTRIBUTING.md for details on our development process. All contributions to this repository require a GPG signed Contributor License Agreement.
If you have questions or problems, please use this repository's issues feature.
The following people directly contributed to this repository. You can add your name here by getting involved — the first step is to learn how to contribute from our CONTRIBUTING.md documentation.
Name | Role | Github | GPG Fingerprint | |
---|---|---|---|---|
Ken Carpenter | Initial Port | @FoundationKen | <[email protected]> | TBD |
We want to keep all our software safe for everyone. If you have discovered a security vulnerability, we appreciate your help in disclosing it to us in a responsible manner. We are unfortunately not able to offer bug bounties at this time.
We do ask that you offer us good faith and use best efforts not to leak information or harm any user, their data, or our developer community. Please give us a reasonable amount of time to fix the issue before you publish it. Do not defraud our users or us in the process of discovery. We promise not to bring legal action against researchers who point out a problem provided they do their best to follow the these guidelines.
Please report suspected security vulnerabilities in private via email to [email protected] (do not use this email for support). Please do NOT create publicly viewable issues for suspected security vulnerabilities.
The following keys may be used to communicate sensitive information to developers:
Name | Fingerprint |
---|---|
[email protected] | Coming Soon.. |
You can import a key by running the following command with that individual’s fingerprint: gpg --recv-keys "<fingerprint>"
Ensure that you put quotes around fingerprints that contain spaces.
- Initial testing release.