stacker.news/lib
Riccardo Balbo a9a566a79f
Encrypted device sync (#1373)
* user vault

* code cleanup and fixes

* improve ui

* prevent name collisions between users on the same device

* some improvements

* implement storage migration

* comments and cleanup

* make connect button primary instead of warning

* move show passphrase in new line (improvement for small screen devices)

* make show passphrase field readOnly

* fixes

* fix vault key unsync

* implicit migration

* move device sync under  general tab

* fix locally disabled wallets and default wallet selection

* improve text

* remove useless SSR check

* add auth checks

* Rename variables

* Fix missing await

* Refactor local<>vault storage interface

I've changed quite some things here. Attempt of a summary:

* storageKey is now only controlled by useVaultStorageState

I've noticed that dealing with how storage keys are generated (to apply user scope) was handled in two places: the existing wallet code and in the new vault code.

This was confusing and error-prone. I've fixed that by completely relying on the new vault code to generate correct storage keys.

* refactored migration

Migration now simply encrypts any existing local wallets and sends them to the server. On success, the local unencrypted version is deleted.

The previous code seemed to unnecessarily generate new local entries prefixed by 'vault:'.

However, since we either use unencrypted local state OR use the encrypted vault on the server for the data, I didn't see any need for these.

Migration seems to work just as well as before.

* removed unnecessary state

In the <DeviceSync> component, enabled & connected were using a unnecessary combo of useState+useEffect.

They were only using variables that are always available during render so simple assignments were enough.

* other minor changes include:

  * early returns
  * remove unnecessary SSR checks in useEffect or useCallback
  * formatting, comments
  * remove unnecessary me? to expose possible bugs

* Fix missing dependency for useZap

This didn't cause any bugs because useWallet returns everything we need on first render.

This caused a bug with E2EE device sync branch though since there the wallet is loaded async.

This meant that during payment, the wallet config was undefined.

* Assume JSON during encryption and decryption

* Fix stale value from cache served on next fetches

* Add wallet.perDevice field

This adds 'perDevice' as a new wallet field to force local storage. For example, WebLN should not be synced across devices.

* Remove debug buttons

* Rename userVault -> vault

* Update console.log's

* revert some of the migration and key handling changes. restore debug buttons for testing

* Fix existing wallets not loaded

* Pass in localOnly and generate localStorageKey once

* Small refactor of migration

* Fix wallet drag and drop

* Add passphrase copy button

* Fix priorityOnly -> skipTests

* Disable autocompletion for reset confirmation prompt

* Show wrong passphrase as input error

* Move code into components/device-sync.js

* Import/export passphrase via QR code

* Fix modal back button invisible in light mode

* Fix modal closed even on connect error

* Use me-2 for cancel/close button

* Some rephrasing

* Fix wallet detach

* Remove debug buttons

* Fix QR code scan in dark mode

* Don't allow custom passphrases

* More rephrasing

* Only use schema if not enabled

* Fix typo in comment

* Replace 'generate passphrase' button with reload icon

* Add comment about IV reuse in GCM

* Use 600k iterations as recommended by OWASP

* Set extractable to false where not needed

* use-vault fallbacks to local storage only for anonymous users

* fix localStorage reset on logout

* add copy button

* move reset out of modals

* hide server side errors

* hardened passphrase storage

* do not show passphrase even if hardened storage is disabled (ie. indexeddb not supported)

* show qr code button on passphrase creation

* use toast for serverside error

* Move key (de)serialization burden to get/setLocalKey functions

* password textarea and remove qr

* don't print plaintext vault values into console

---------

Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: k00b <k00b@stacker.news>
2024-10-01 14:55:01 -05:00
..
apollo.js batch zap requests (#1424) 2024-09-24 09:38:48 -05:00
badge.js check both `navigator.permissions.query` and `Notification.permission` for permissions (#655) 2023-11-25 11:32:41 -06:00
bip39-words.js add lnc attached wallet (#1104) 2024-04-26 21:22:30 -05:00
bolt11.js add lnc attached wallet (#1104) 2024-04-26 21:22:30 -05:00
clicks.js Revert "Revert "shield your eyes; massive, squashed refactor; nextjs/react/react-dom/apollo upgrades"" 2023-07-23 10:08:43 -05:00
cln.js Support Tor for LNbits recv (#1336) 2024-08-27 11:16:02 -05:00
constants.js allow top sorting by boost 2024-09-21 14:58:25 -05:00
create-prisma.js allow db connection limit and timeout configuration 2024-07-16 13:42:09 -05:00
crypto.js Store hashed and salted email addresses (#1111) 2024-05-04 18:06:15 -05:00
currency.js feat: added NGN currency (#1264) 2024-07-21 11:46:52 -05:00
cursor.js use keyset pagination for notifications (#899) 2024-03-06 13:53:13 -06:00
error.js Encrypted device sync (#1373) 2024-10-01 14:55:01 -05:00
fancy-names.json Add setting to send diagnostics back to SN (#463) 2023-09-18 18:00:16 -05:00
form.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
format.js rethinking boost (#1408) 2024-09-19 13:13:14 -05:00
item.js rethinking boost (#1408) 2024-09-19 13:13:14 -05:00
lnurl.js add NEXT_PUBLIC_URL 2024-04-08 17:54:39 -05:00
macaroon-id.js LND autowithdraw (#806) 2024-02-13 13:17:56 -06:00
macaroon-id.proto LND autowithdraw (#806) 2024-02-13 13:17:56 -06:00
macaroon.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
madness.js reintroduce daily rewards (#1134) 2024-05-01 09:30:36 -05:00
md.js fixes #1395 (#1430) 2024-09-28 16:33:07 -05:00
new-comments.js subtle highlight of new comments 2023-08-06 14:18:40 -05:00
nostr.js Fix nwc error message (#1417) 2024-09-19 15:53:42 -05:00
package.json Convert worker to ESM (#500) 2023-09-23 20:19:35 -05:00
proxy.js Support Tor for LNbits recv (#1336) 2024-08-27 11:16:02 -05:00
rainbow.js Fix upvote hover style not showing for first zap (#1418) 2024-09-20 09:44:15 -05:00
rand.js use rand lightning animation when not logged in 2021-07-16 11:47:18 -05:00
rehype-sn.js don't allow other markup in headings 2024-09-29 11:25:01 -05:00
rss.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
sndev.js dont expect unrun services in dev (#1279) 2024-07-31 19:44:08 -05:00
territory.js fix #951 also retroactively 2024-03-20 20:56:40 -05:00
time.js Fix missing user invoice timeout (#1379) 2024-09-08 17:16:52 -05:00
timedate-scraper.js Attempt to get publication year when auto-titling links (#520) 2023-10-20 19:23:50 -05:00
url.js fixes #1395 (#1430) 2024-09-28 16:33:07 -05:00
url.spec.js Fix missing commentId parsing for item mentions (#1219) 2024-06-03 21:54:42 -05:00
user.js honor mutes when sending push notifications (#1145) 2024-05-12 13:55:56 -05:00
validate.js Encrypted device sync (#1373) 2024-10-01 14:55:01 -05:00
wallet.js Fix inconsistency between walletTypeToResolveType and generateTypeDefName (#1318) 2024-08-19 17:36:07 -05:00
webPush.js Fix duplicate push notification as reply and subscription (#1392) 2024-09-11 16:28:55 -05:00