OpenBazaar / openbazaar-desktop

OpenBazaar 2.0 Desktop Client (talks to openbazaar-go server daemon)
MIT License
648 stars 186 forks source link

QR code adjustments to accommodate those long Monero addresses #1772

Closed rbrunner7 closed 5 years ago

rbrunner7 commented 5 years ago

The addition of Monero as a supported coin results in a problem with QR codes in the OpenBazaar desktop client because Monero addresses are considerably longer than the addresses of the coins supported so far: Normal Monero addresses are 95 characters long, and so-called integrated addresses even 106 characters. Example of a Monero address:

44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A

There are 2 places in the OpenBazaar desktop client where QR codes are generated and displayed. (A 3rd one for donations does not matter for the issue at hand.)

The first place is the ReceiveMoney view as part of the wallet. The code line in question:

qrDataUri = qr(walletCur.qrCodeText(address), { type: 6, size: 5, level: 'Q' });

type specifies the overal size of the whole QR code, size is the size of the dots, and Q is the ECC level, where Q gives a redundancy of about 25%, meaning 25% of the dots could come in wrong when scanning the code and the content would still read correctly.

The qrCodeText method prepends the name of the coin to the address. In the case of BTC the QR code thus encodes something like this:

bitcoin:1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2

The second place is the Payment view for purchases. The code line in question:

return qr(URL, { type: 8, size: 5, level: 'Q' });

Here an amount parameter is added. An example for an encoded text:

bitcoin:1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2?amount=12.12345678

The type and the level parameters together decide how many characters those QR codes can encode. You can consult the tables on this page. Look for the Version List 1-10 button, and use the Binary column in the table, not the Alphanumeric column, because with characters like : and ? we go beyond mere letters and digits.

So how many characters do we need for Monero? If we want to play it safe, i.e. allow for the longer integrated addresses, allow for large amounts of XMR, and throw in 5 extra characters for spare, e.g. for being able to go from monero: to monero:// as some wallets may prefer without going over the question of QR codes all over again, we arrive at 118 characters for a receiving QR code and 144 for a purchase payment QR code.

If we stick with ECC level Q we need to up from type 6 to 9 for receiving and from 8 to 10 for purchase payment.

If we lower the ECC level from Q to M (about 15% redundancy instead of 25%) we only need to go up from 6 to 7 for receiving, and we can even stay with 8 for purchase payment.

I think lowering the ECC level is perfectly ok for our use case, mostly reading QR codes with smartphone cameras off PC screens, where everything is neat and sharp. See also the comment about those levels from here:

L is selected for dirt-free environments, M is most common, and Q & H should be used in factory environments where the QR Code label is subject to wear and tear.

If we stick with level Q some optical changes are needed in the views to accommodate the considerably larger QR codes, or the size of the dots needs a reduction from 5 to 4.

Personally, I propose to lower the ECC level to M and just make the receiving QR code a little bigger (type 7 instead of 6).