uos icon indicating copy to clipboard operation
uos copied to clipboard

Examples: QR codes as a reference

Open kumavis opened this issue 6 years ago • 4 comments

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

kumavis avatar May 03 '19 01:05 kumavis

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.

kumavis avatar May 03 '19 01:05 kumavis

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

maciejhirsz avatar May 06 '19 15:05 maciejhirsz

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).

xardass avatar Aug 02 '19 02:08 xardass

@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:

  • 4 bits for encoding indicator, 0100 if encoding is binary. (this is what causes the offset).
  • 8 or 16 bits for byte length of the payload.
  • payload bits.
  • 4 bits for terminator: 0000.
  • alternating ec and 11 bytes to pad the QR code to capacity it needs to fill up a square.

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.

maciejhirsz avatar Aug 02 '19 13:08 maciejhirsz