maciejhirsz / uos

Universal Offline Signatures
52 stars 5 forks source link

Examples: QR codes as a reference #2

Open kumavis opened 5 years ago

kumavis commented 5 years ago

Please include some QR codes as a reference, so its clear what the expected result is

kumavis commented 5 years ago

obviously theres parameterization in the QR code that is flexible and not specified in the scope, but great for testing. especially if you provide the private key / seed phrase used to generate the example data.

maciejhirsz commented 5 years ago

I'll do some (minor) tweaks to the spec, split the particulars for each protocol (Eth, Substrate). Adding examples is a really good idea.

xardass commented 5 years ago

I second the need for examples. Apparently IOS has some trouble reading native binary encoded QR (https://stackoverflow.com/questions/32429480/read-binary-qr-code-with-avfoundation).

maciejhirsz commented 5 years ago

@xardass We've run into similar issues on mobile, but solved them now. Once you get the BarcodeRawData you can extract the binary data with some processing. The main catch is that the QR code payload is offset by 4 bits, the JS code in the link is working on a hexencoded string we get in React Native, which makes things a bit clearer (since one hex character is 4 bits), but you can do the same with raw byte buffers. The structure is, in order:

Once you strip the tail padding, the indicator and the terminator you are left with one or two bytes for length, and the payload. It's then easy to match the length to the remainder of the buffer and strip the length prefix (or error if neither matches). This is not a complete decoding process for all QR code encodings, but it is sufficient for this use case.