Skip to content

Comments

feat: export private key#721

Merged
kvhnuke merged 2 commits intoenkryptcom:feat/export-private-keysfrom
nikicat:feat/export-private-key
Sep 10, 2025
Merged

feat: export private key#721
kvhnuke merged 2 commits intoenkryptcom:feat/export-private-keysfrom
nikicat:feat/export-private-key

Conversation

@nikicat
Copy link

@nikicat nikicat commented Jun 21, 2025

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

    • Added the ability to export the private key for user accounts via a new "Export" action in the accounts menu.
    • Introduced an export account dialog where users can enter their password to securely view and copy their private key.
  • UI Updates

    • Added an "Export" option to the accounts list item menu, visible for exportable accounts.
    • Improved account management with a dedicated export account form and enhanced menu actions.

@coderabbitai
Copy link

coderabbitai bot commented Jun 21, 2025

"""

Walkthrough

This 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

Files/Groups Change Summary
.../src/libs/background/index.ts, .../src/libs/background/internal/index.ts, .../internal/get-private-key.ts Add internal background handler and export for getPrivateKey method; implement async retrieval logic.
.../src/libs/keyring/keyring.ts, .../keyring/src/index.ts Add getPrivateKey method to keyring classes for retrieving private keys using account info and password.
.../src/types/messenger.ts Add getPrivateKey to InternalMethods enum for message routing.
.../ui/action/views/accounts/components/accounts-list-item-menu.vue, .../accounts-list-item.vue Add "Export" menu action and prop wiring for exportable accounts.
.../ui/action/views/accounts/components/export-account-form.vue New component: export private key dialog with password input and result display.
.../ui/action/views/accounts/index.vue Integrate export account action and dialog into accounts view, with state management for export flow.

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
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Add option to export private keys of individual accounts (#297)
Allow export for both imported private key and mnemonic-based accounts (#297)
Require password validation before exporting private key (#297)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested reviewers

  • SemajaM
    """

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ac8cc8 and e83b189.

📒 Files selected for processing (2)
  • packages/extension/src/libs/background/internal/get-private-key.ts (1 hunks)
  • packages/extension/src/ui/action/views/accounts/components/export-account-form.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/extension/src/ui/action/views/accounts/components/export-account-form.vue
  • packages/extension/src/libs/background/internal/get-private-key.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ccbae8f and 2ac8cc8.

📒 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 getPrivateKey internal 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 getPrivateKey functionality 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 exportable boolean 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 getPrivateKey method 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 exportable prop is set to true for 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($$$) {
  $$$
}'

@kvhnuke kvhnuke changed the base branch from main to feat/export-private-keys September 10, 2025 20:40
@kvhnuke kvhnuke merged commit 36944a4 into enkryptcom:feat/export-private-keys Sep 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Export Private Keys Option

3 participants