cryptoadvance / specter-diy

DIY airgapped hardware wallet that uses QR codes for communication with the host
MIT License
441 stars 73 forks source link

qr code animations #56

Closed gorazdko closed 4 years ago

gorazdko commented 4 years ago

Abstract

I did a proof of concept for scanning animated qrs automatically (without buttons): https://github.com/gorazdko/specter-diy/tree/animiated_qr_video

Results

Its feasible, though results arent nearly as good as in https://divan.dev/posts/animatedqr/ where

The best result was 1.4 secs, which is almost 9KB/s! This result has been recorded at a rate of 11 frames per second and chunk size of 850 bytes with Medium recovery level

Here, one setting that works ok is 250 ms interval with 100 byte frames. For optimal settings one should play with parameters

Should we prefer this method over the one with buttons?

stepansnigirev commented 4 years ago

Sounds amazing! I think it's the right way to go. So awesome what you are doing!

I tried it out, specter-desktop part works great, but I wasn't able to scan it with specter-diy. Not sure why yet, I need to look into your code and understand the logic. Looks like it doesn't even try to scan multiple codes, not sure why.

I will get back to it later tonight and look carefully.

stepansnigirev commented 4 years ago

Ok I was stupid... Frozen firmware ignored python files )))

Works like a charm!!! Beeps a few times and imports the wallet - very nice feeling! I like it!

gorazdko commented 4 years ago

I tried it out, specter-desktop part works great

the qrcode library is not ok. it has a bug: https://github.com/davidshimjs/qrcodejs/issues/220

You will notice it when changing max_len when having QRCode.CorrectLevel.H

I need to look into your code and understand the logic

i will write a couple of sentences later about how this works, the limitations and other things i noticed...

gorazdko commented 4 years ago

How it works

Example:

interval of animating 300ms, 200byte frames , qrCorrectionLevel=L

Downsides:

If our hand is not still and PSBT transaction is very large we can wait several rounds (and one round can get big, perhaps even 20 frames) until all the frames are scanned. Bad UX, can get frustrating. Also, if the scanner is not focused accurately on the qr code, the scanning speed can slow down dramatically.

Deployment

I can make this into a PR if we decide we want this. It still has some bugs that i need to fix (e.g. buffer overflow when scanning multiple rounds etc.) and do some code cleanup. But it would also break the support for the other scanner (which i dont have) which specter diy uses.

Regarding specter desktop, i can find a better frontend qrcode library and push the changes without buttons. The current backend qr library is not suitable as the qr code animation is a frontend process.

stepansnigirev commented 4 years ago

I think we should use animated QR codes only when it is super necessary - rare transactions with many inputs and outputs, very large multisig wallets.

With current PSBT optimizations even a large multisig fits in one QR codes if there are not too many inputs and outputs. And if people want to make a huge transaction, they should be ready to hold their wallet still for quite some time )))

Let's make it into a pull request. For specter-desktop I suggest to add a checkbox or button animate QR code. So normally QR code is large and shows full data, but if you check the checkbox it becomes smaller and animated.

The same for signed psbt QR code in specter-diy - we have enough space to add a checkbox that would animate the QR code. By default let's keep it static.