anchorage_layer_simple/features/userwallet-indexeddb-hash-cache.md
ncantu 5689693507 UserWallet: Multiple feature implementations and updates
**Motivations:**
- Implement BIP39 mnemonic import for identity creation
- Add password-based key protection for enhanced security
- Improve pairing workflow with QR code and URL display
- Migrate hash cache from LocalStorage to IndexedDB for better scalability
- Update signet-dashboard and mempool components

**Root causes:**
- N/A (feature implementations)

**Correctifs:**
- N/A (no bug fixes in this commit)

**Evolutions:**
- BIP39 mnemonic import: Support for 12/24 word English mnemonics with BIP32 derivation path m/44'/0'/0'/0/0
- Key protection: Password-based encryption of private keys at rest with unlock/lock functionality
- Pairing workflow: QR code and URL display for device pairing, form-based word exchange between devices
- IndexedDB migration: Hash cache moved from LocalStorage to IndexedDB to avoid size limitations
- Global action bar: URL parameter support for navigation
- Pairing connection: Enhanced pairing status management

**Pages affectées:**
- userwallet/src/utils/identity.ts
- userwallet/src/utils/keyProtection.ts
- userwallet/src/utils/sessionUnlockedKey.ts
- userwallet/src/utils/indexedDbStorage.ts
- userwallet/src/utils/cache.ts
- userwallet/src/utils/pairing.ts
- userwallet/src/components/UnlockScreen.tsx
- userwallet/src/components/PairingDisplayScreen.tsx
- userwallet/src/components/PairingSetupBlock.tsx
- userwallet/src/components/GlobalActionBar.tsx
- userwallet/src/components/HomeScreen.tsx
- userwallet/src/components/ImportIdentityScreen.tsx
- userwallet/src/components/DataExportImportScreen.tsx
- userwallet/src/hooks/useIdentity.ts
- userwallet/src/hooks/usePairingConnected.ts
- userwallet/src/services/syncService.ts
- userwallet/src/services/pairingConfirm.ts
- userwallet/src/App.tsx
- userwallet/package.json
- userwallet/docs/specs.md
- userwallet/docs/storage.md
- userwallet/docs/synthese.md
- signet-dashboard/public/*.html
- signet-dashboard/public/app.js
- signet-dashboard/public/styles.css
- mempool (submodule updates)
- hash_list.txt, hash_list_cache.txt, utxo_list.txt, utxo_list_cache.txt, fees_list.txt
- features/*.md (documentation files)
2026-01-26 10:23:34 +01:00

56 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UserWallet IndexedDB pour hash_cache
**Author:** Équipe 4NK
**Date:** 2026-01-26
## Objectif
Stocker le cache des hash vus (`userwallet_hash_cache`) dans IndexedDB au lieu de LocalStorage, pour éviter les limites de taille et permettre un volume plus important sans dégradation.
## Impacts
- **Fonctionnels** : Comportement identique (déduplication des messages sync). Pruning à 10k entrées conservé.
- **Techniques** : Nouveau module `indexedDbStorage` (idbGet, idbSet, idbRemove). `HashCache` utilise IndexedDB, `init()` async, `markSeenBatch` async. `SyncService` init avant sync, collecte des nouveaux hashes puis un seul `markSeenBatch`. Export/import lisent/écrivent `hash_cache` via IndexedDB (export/import async).
## Modifications
### utils/indexedDbStorage.ts (nouveau)
- DB `userwallet`, version 1, store `kv` (keyPath `key`).
- `idbGet(key)`, `idbSet(key, value)`, `idbRemove(key)`. Toutes async.
### utils/cache.ts
- `HashCache` : plus de chargement dans le constructeur. `async init()` charge depuis IndexedDB (et migre depuis localStorage si présent).
- `markSeen` : en mémoire uniquement. `markSeenBatch(hashes)` : ajoute + persiste via IndexedDB.
- `clear()` async, utilise `idbRemove`.
- Sauvegarde avec pruning à 10k entrées.
### services/syncService.ts
- `async init()` : délègue à `hashCache.init()`.
- Dans `sync()` : collecte des `newHashes`, puis `await hashCache.markSeenBatch(newHashes)` en fin de sync.
### Composants
- **SyncScreen**, **ServiceListScreen** : `await syncService.init()` avant `sync()`.
### exportImport
- `exportUserWalletData` async : lit `hash_cache` via `idbGet`.
- `importUserWalletData` async : écrit `hash_cache` via `idbSet`.
- **DataExportImportScreen** : `handleExport` async, `handleImportFile` onload async.
### Migration
- Au premier `HashCache.init()`, si IndexedDB na pas `userwallet_hash_cache` et que localStorage la, copie vers IndexedDB puis suppression du localStorage.
## Modalités de déploiement
- Rebuild frontend, déploiement des assets. Migration automatique au premier sync.
## Modalités danalyse
- Effectuer une sync : vérifier quaucune régression. Exporter puis réimporter : vérifier que `hash_cache` est bien présent après import.
- Vérifier en DevTools (Application → IndexedDB → userwallet) la présence du store `kv` et de la clé `userwallet_hash_cache`.