feat: export private key#721
Conversation
|
""" WalkthroughThis change introduces an "Export Private Key" feature, allowing users to export the private keys of individual accounts via the UI. It adds new UI components, background methods, and keyring logic to handle private key retrieval, password validation, and secure export, covering both mnemonic and imported private key accounts. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant AccountsView (UI)
participant ExportAccountForm (UI)
participant BackgroundHandler
participant KeyRingBase
participant KeyRing
User->>AccountsView (UI): Clicks "Export" on account
AccountsView (UI)->>ExportAccountForm (UI): Opens export dialog
User->>ExportAccountForm (UI): Enters password, submits
ExportAccountForm (UI)->>BackgroundHandler: Sends getPrivateKey request
BackgroundHandler->>KeyRingBase: Calls getPrivateKey(account, password)
KeyRingBase->>KeyRing: Delegates getPrivateKey(options, password)
KeyRing->>KeyRingBase: Returns private key string
KeyRingBase->>BackgroundHandler: Returns private key
BackgroundHandler->>ExportAccountForm (UI): Returns private key
ExportAccountForm (UI)->>User: Displays private key
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/extension/src/ui/action/views/accounts/components/export-account-form.vue (2)
131-136: Clean up duplicate CSS properties.There are duplicate CSS declarations that should be consolidated.
.title { font-style: normal; - font-weight: bold; font-weight: bold; font-size: 16px; line-height: 24px; - color: @primaryLabel; color: black; margin-bottom: 6px; }
68-87: Private key exposure follows expected functionality but consider user warnings.The implementation correctly retrieves and displays the private key as intended. Consider adding user warnings about the security implications of exposing private keys.
Consider adding a warning message to inform users about the security risks:
<div v-if="isDone" class="privkey"> + <p class="warning">⚠️ Keep your private key secure. Never share it with anyone.</p> <p class="title">Private Key:</p> <span class="word">{{ privKey }}</span> </div>
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
packages/extension/src/libs/background/index.ts(2 hunks)packages/extension/src/libs/background/internal/get-private-key.ts(1 hunks)packages/extension/src/libs/background/internal/index.ts(2 hunks)packages/extension/src/libs/keyring/keyring.ts(1 hunks)packages/extension/src/types/messenger.ts(1 hunks)packages/extension/src/ui/action/views/accounts/components/accounts-list-item-menu.vue(2 hunks)packages/extension/src/ui/action/views/accounts/components/accounts-list-item.vue(2 hunks)packages/extension/src/ui/action/views/accounts/components/export-account-form.vue(1 hunks)packages/extension/src/ui/action/views/accounts/index.vue(6 hunks)packages/keyring/src/index.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/extension/src/libs/background/index.ts (1)
packages/keyring/src/index.ts (1)
getPrivateKey(318-340)
packages/keyring/src/index.ts (2)
packages/types/src/index.ts (2)
SignOptions(198-198)Errors(185-185)packages/keyring/src/utils.ts (1)
pathParser(3-18)
🪛 Biome (1.9.4)
packages/extension/src/libs/background/internal/get-private-key.ts
[error] 26-26: This code is unreachable
... because either this statement, ...
... this statement, ...
... or this statement will return from the function beforehand
(lint/correctness/noUnreachable)
🔇 Additional comments (12)
packages/keyring/src/index.ts (2)
322-327: LGTM - Hardware wallet protection.The assertion properly prevents private key export for hardware wallets, which is a critical security measure.
333-333: Fix syntax error.Missing semicolon after the
await this.#getMnemonic(keyringPassword)statement.- const mnemonic = await this.#getMnemonic(keyringPassword) + const mnemonic = await this.#getMnemonic(keyringPassword);Likely an incorrect or invalid review comment.
packages/extension/src/types/messenger.ts (1)
38-38: LGTM - Enum addition follows convention.The new
getPrivateKeyinternal method follows the established naming pattern and integrates properly with the messaging system.packages/extension/src/libs/background/internal/index.ts (1)
9-9: LGTM - Standard module export pattern.The import and export additions properly expose the new
getPrivateKeyfunctionality following the established pattern.Also applies to: 19-19
packages/extension/src/ui/action/views/accounts/components/accounts-list-item.vue (1)
34-34: LGTM - Standard Vue prop implementation.The
exportableboolean prop is properly declared and passed down to the child component, following Vue best practices.Also applies to: 82-82
packages/extension/src/libs/keyring/keyring.ts (1)
100-102: LGTM - Proper delegation pattern.The wrapper method correctly delegates to the internal keyring instance with matching parameters and return type.
packages/extension/src/libs/background/index.ts (1)
28-28: Integration follows established patterns correctly.The import and handler integration for the new
getPrivateKeymethod correctly follows the existing architectural pattern used by other internal methods.Also applies to: 171-172
packages/extension/src/ui/action/views/accounts/components/accounts-list-item-menu.vue (1)
13-19: UI integration follows established patterns.The export menu item implementation correctly mirrors the existing delete functionality pattern with appropriate conditional rendering, event emission, and styling.
Also applies to: 26-26, 30-30, 34-34, 91-93
packages/extension/src/libs/background/internal/get-private-key.ts (1)
6-20: Core logic is sound with proper validation and error handling.The function correctly validates input parameters, handles the keyring interaction, and provides appropriate error responses following the established patterns in the codebase.
packages/extension/src/ui/action/views/accounts/components/export-account-form.vue (1)
57-57: Consider security implications of password prefill in production.The
__PREFILL_PASSWORD__appears to be a development convenience that could pose security risks if not properly handled in production builds.Verify that this development convenience is properly stripped in production builds:
#!/bin/bash # Check if __PREFILL_PASSWORD__ is used elsewhere and how it's handled in build process rg -A 3 -B 3 "__PREFILL_PASSWORD__"packages/extension/src/ui/action/views/accounts/index.vue (2)
26-26: Export integration follows established patterns correctly.The export functionality integration mirrors the existing rename and delete patterns perfectly, maintaining consistency with the established UI flow and state management approach.
Also applies to: 29-29, 105-110, 126-126, 147-147, 168-168, 200-206
26-26: Verify hardware wallet private key export handling.The
exportableprop is set totruefor all accounts, but hardware wallets typically don't allow private key export. Ensure this is properly handled at the keyring level.Check how hardware wallets are handled in the keyring's getPrivateKey method:
#!/bin/bash # Verify hardware wallet handling in keyring implementation ast-grep --pattern 'getPrivateKey($$$) { $$$ }'
This PR adds functionality to export (i.e., display) the private key for any account. I'm not entirely confident that the UI is consistent with the rest of the project, but it works. Closes #297.
Summary by CodeRabbit
New Features
UI Updates