Skip to content

feat(wallet): session based mechanism to handle wallet's keys #995

@JulesFiliot

Description

@JulesFiliot

Objective

  • Implement a session based mechanism to access the encrypted seed stored in the vault in order to sign transactions without having to ask the user's password each time during a session.
  • User should enter his password once, then for each transaction that he has to sign, he shouldn't have to enter his password again during this session. A session is active as long as the user is not idle for more than 15 minutes (TBD) (i.e. not using the wallet's UI). A session is automatically ended if the user closes his browser. Starting a new session means prompting the user's password again.

Architecture

Storage strategy
  • Persistent layer (chrome.storage.local): Stores the vault. This includes the encrypted seed, a unique random salt, and the initialization vector.
  • Ephemeral layer (chrome.storage.session): Stores the master encryption key derived via PBKDF2. This is a RAM-only storage area that survives service worker sleep cycles but is wiped when the browser is closed.
Key lifecycle & session management
  • Unlock: Upon password entry, we will derive the master encryption key using PBKDF2 (user's password + salt). We verify that we can decrypt the vault with this key, then we persist the key in chrome.storage.session.
  • Transaction Signing: The service worker retrieves the master encryption key from chrome.storage.session to decrypt the seed phrase only at the moment of signing. All raw secrets are wiped from memory immediately after the signature is generated.
  • Auto-lock: We will implement the chrome.alarms API to call chrome.storage.session.clear() after 15 minutes of inactivity, which will wipe the master encryption key from the storage, thus "locking" the wallet.
TrustWallet refactor

To optimize performance and security we should refactor how we use @trustwallet/wallet-core.

  • Current:
    • TrustWallet's KeyStore is used for both storage and blockchain operations.
  • After refactor:
    • Vault management: Use browser-passworder library (AES-GCM) for initial vault encryption/decryption. This avoids, for every session, initializing TrustWallet's Wasm binary just to check a password or unlock a UI feature.
    • Signing engine: Use TrustWallet strictly as a "signing engine". It will be initialized only when a transaction is pending, taking the decrypted seed phrase to derive chain specific private keys (we only use ethereum for now) and sign payloads.
  • Security benefits:
    • No raw seed phrases or master keys are ever written to the hard drive.
    • No user password stored in RAM. If we used TrustWallet only to implement this feature, it would require us to store the user's password in RAM as TrustWallet's KeyStore requires the original password to be decrypted.

References


Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions