anchorage_layer_simple/features/userwallet-key-protection.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

2.7 KiB
Raw Permalink Blame History

UserWallet Protection des clés par mot de passe

Author: Équipe 4NK
Date: 2026-01-26

Objectif

Chiffrer la clé privée au repos avec un mot de passe utilisateur. Déverrouillage requis pour signer (login, iframe auth). Verrouillage possible pour vider la session sans toucher au stockage.

Impacts

  • Fonctionnels : Activation/désactivation de la protection, déverrouillage au démarrage si protégé, verrouillage manuel. Export inclut la clé seulement si déverrouillé.
  • Techniques : keyProtection (PBKDF2 + AES-GCM), sessionUnlockedKey, extension de identity (enable/disable/unlock/lock). LocalIdentity.privateKey optionnel. Gate applicatif (UnlockScreen) quand protégé et non déverrouillé.

Modifications

Nouveaux fichiers

  • utils/keyProtection.ts : encryptPrivateKey, decryptPrivateKey, EncryptedPayload. PBKDF2 100k itérations, AES-GCM, salt/iv aléatoires.
  • utils/sessionUnlockedKey.ts : getUnlockedPrivateKey, setUnlockedPrivateKey (module-level).
  • components/UnlockScreen.tsx : Formulaire mot de passe, appel à unlock, affichage erreur.

identity.ts

  • isProtectionEnabled, enableProtection, disableProtection, unlock, lock.
  • Stockage : userwallet_identity_encrypted (ciphertext, iv, salt). Identité stockée sans privateKey quand protection activée.

useIdentity

  • isProtected, isUnlocked, enableProtection, disableProtection, unlock, lock, refreshIdentity.
  • Identité renvoyée : stockée + privateKey de session si protégé et déverrouillé.

App

  • AppGate : Si identity && isProtected && !isUnlockedUnlockScreen, sinon AppContent.

UI

  • HomeScreen : Bouton « Verrouiller » si protégé et déverrouillé.
  • DataExportImportScreen : Section « Protection par mot de passe » (activer / désactiver / verrouiller). Gestion erreurs export si verrouillé.

Autres

  • useChannel : Si identity sans privateKey → erreur « Identité verrouillée ».
  • LoginScreen : Vérification identity.privateKey avant signature.
  • exportImport : Export utilise la clé de session si protégé ; sinon throw « Déverrouillez… ».

Types

  • LocalIdentity.privateKey : optionnel.

Modalités de déploiement

  • Rebuild frontend, déploiement des assets. Aucune migration.

Modalités danalyse

  • Activer la protection → recharger → UnlockScreen. Déverrouiller → accès normal. Verrouiller → UnlockScreen à nouveau.
  • Exporter sans déverrouiller (si contournement du gate) → erreur. Exporter après déverrouillage → JSON contient identity.privateKey.
  • Désactiver la protection → identité de nouveau en clair ; userwallet_identity_encrypted supprimé.