foundation-devices / foundation-ur-py Goto Github PK
View Code? Open in Web Editor NEWUR Implementation in Python ported from Blockchain Commons C++ Reference Implementation
License: Other
UR Implementation in Python ported from Blockchain Commons C++ Reference Implementation
License: Other
Hi!
Thanks for implementing this in Python!
Have you considered publishing the package on pypi.org?
Occasionally UR decoding fails to decode a fragment when it shouldn't. It fails to decode the fragment because the checksum included in the body does not match the calculated checksum. I believe the issue is that the calculated checksum is the wrong byte size. Here is an example fragment that reproduces the issue. Other UR libs appear to decode this fragment successfully.
fragment = "UR:CRYPTO-PSBT/20-29/LPBBCSCACFCMCPCYBBRSPTSKHDSSDTSBTKDECHRHPKHKVWMDMNKSGDAOAEAEAEAEAECHPTBBEODKPLETLBLDAMJOPMBNPEPLWMFZLTZTHGOEQZTELTLGAYCHAEAEAEAEAECHPTBBFXSAWKIDLTENBSKPJLFEFLMNCLPKEMTPWPMHMHIOLTKECSAMAEAEAEAEAECHPTBBINTKMWZMYNKNKEZCBGKTHDFEZOPAYNPRMEFTHPKGLTAEAEAEAEADADDNEMMDAAAEAEAEAEAECPAECXHDGWFDVTSPHDOLBNKIGETEECLKOSOXLPJSSNFXSGCLAHESJSVTURDYJZCWSRKNDTADAHTKGHCLAOFSTDLNUYSAASIESFDNRKHSMNJZTONLPSLDWFTDMNINOXEHHNKOTODRWPCHRORHDACLAEETWDVL"
ur_decoder = URDecoder()
status = ur_decoder.receive_part(fragment)
Bytewords.decode throws the exception 'Invalid Bytewords.' because the calculated crc32 checksum does not match the checksum on the body of the fragment. I believe the issue is that the calculated checksum is not returning from crc32_bytes
as a 32 bit integer.
For the above example the checksum included in the fragment is 0038eae3
in hex. But the checksum returned by crc32_bytes
is 38eae3
. So on line 110 of bytewords.py the check if checksum != body_checksum:
is false.
When I hard code the byte length in the crc32n
function to be 4 bytes this seems to fix the issue, but I don't know what the "correct" way would be to handle this.
I changed:
return n.to_bytes((bit_length(n) + 7) // 8, 'big')
to:
return n.to_bytes(4, 'big')
and this makes this issue go away as far as I can tell
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.