Skip to content

feat(stellar-wallet-snap): Add exportAccount keyring API - #187

Draft
stanleyyconsensys wants to merge 12 commits into
mainfrom
feat/stellar/export-pk
Draft

feat(stellar-wallet-snap): Add exportAccount keyring API#187
stanleyyconsensys wants to merge 12 commits into
mainfrom
feat/stellar/export-pk

Conversation

@stanleyyconsensys

@stanleyyconsensys stanleyyconsensys commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Explanation

Adds support for the Keyring API v2 exportAccount method in @metamask/stellar-wallet-snap, enabling Stellar secret-seed (S…) export in base32 format, with validation and safeguards to reduce the risk of leaking secrets.

Changes:

  • Implement exportAccount in the keyring handler, deriving the wallet from entropy and returning an ExportedAccount payload (base32 only).
  • Add secret-seed validation (StellarSecretKeyStruct) and wire in a single supported export encoding constant.
  • Update permissions, manifest capabilities, docs, tests, and changelog to reflect the new export functionality.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support for the Keyring API v2 exportAccount method in @metamask/stellar-wallet-snap, enabling Stellar secret-seed (S…) export in base32 format, with validation and safeguards to reduce the risk of leaking secrets.

Changes:

  • Implement exportAccount in the keyring handler, deriving the wallet from entropy and returning an ExportedAccount payload (base32 only).
  • Add secret-seed validation (StellarSecretKeyStruct) and wire in a single supported export encoding constant.
  • Update permissions, manifest capabilities, docs, tests, and changelog to reflect the new export functionality.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/stellar-wallet-snap/src/utils/requestResponse.test.ts Extends origin validation test coverage to include ExportAccount.
packages/stellar-wallet-snap/src/services/wallet/Wallet.ts Exposes secret getter for derived keypairs to support exportAccount.
packages/stellar-wallet-snap/src/services/wallet/Wallet.test.ts Adds unit test asserting the derived wallet returns the expected Stellar secret seed.
packages/stellar-wallet-snap/src/permissions.ts Allows keyring_exportAccount for the MetaMask origin.
packages/stellar-wallet-snap/src/handlers/keyring/keyring.ts Implements exportAccount, validates inputs/defaults, derives wallet, validates secret, and wraps errors to avoid leaking secrets.
packages/stellar-wallet-snap/src/handlers/keyring/keyring.test.ts Adds exportAccount behavior tests and verifies secrets are not logged.
packages/stellar-wallet-snap/src/handlers/keyring/exceptions.ts Introduces ExportAccountException to represent export failures without embedding secrets in messages.
packages/stellar-wallet-snap/src/handlers/keyring/api.ts Adds ExportAccountRequestStruct with defaulting + strict encoding validation (base32 only).
packages/stellar-wallet-snap/src/handlers/keyring/api.test.ts Adds tests for ExportAccountRequestStruct acceptance/rejection and defaulting behavior.
packages/stellar-wallet-snap/src/context.ts Injects walletService into KeyringHandler to support wallet derivation for export.
packages/stellar-wallet-snap/src/constants.ts Defines PRIVATE_KEY_EXPORT_ENCODING = 'base32' as the sole supported export encoding.
packages/stellar-wallet-snap/src/api/address.ts Adds StellarSecretKeyStruct for Stellar secret-seed format validation.
packages/stellar-wallet-snap/src/api/address.test.ts Adds unit tests for StellarSecretKeyStruct.
packages/stellar-wallet-snap/snap.manifest.json Declares keyring privateKey.exportFormats support for base32.
packages/stellar-wallet-snap/docs/use-cases/keyring/keyring.md Documents exportAccount behavior and data source (derived, not persisted).
packages/stellar-wallet-snap/CHANGELOG.md Adds an Unreleased changelog entry for exportAccount.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/stellar-wallet-snap/src/handlers/keyring/keyring.test.ts Outdated
Comment thread packages/stellar-wallet-snap/CHANGELOG.md
this.#logger.debug('Keyring request handled', {
origin,
method: request.method,
result: keyringRequestResult,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

remove it for security purpose

privateKey,
};
} catch (error: unknown) {
return rethrowIfInstanceElseThrow(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

return rethrowIfInstanceElseThrow is a exception throw process, the return is just to align the type check on tsc

const { account } = await this.#accountService.resolveAccount({
accountId,
});
const wallet = await this.#walletService.resolveWallet(account);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

both method will auto assert if the address is same, and throw error if

  • account not found
  • address not match
  • fail to derived account

@socket-security

socket-security Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​metamask/​keyring-api@​24.1.01001001009950
Updated@​metamask/​snaps-jest@​10.2.0 ⏵ 10.2.177 +110010096100
Updated@​metamask/​snaps-sdk@​11.2.0 ⏵ 12.0.19910078 +194 -1100

View full report

@socket-security

socket-security Bot commented Aug 27, 2026

Copy link
Copy Markdown

Warning

MetaMask internal reviewing guidelines:

  • Do not ignore-all
  • Each alert has instructions on how to review if you don't know what it means. If lost, ask your Security Liaison or the supply-chain group
  • Copy-paste ignore lines for specific packages or a group of one kind with a note on what research you did to deem it safe.
    @SocketSecurity ignore npm/PACKAGE@VERSION
Action Severity Alert  (click "▶" to expand/collapse)
Warn Low
Potential code anomaly (AI signal): npm @metamask/snaps-simulation is 62.0% likely to have a medium risk anomaly

Notes: The fragment is primarily an orchestration layer for installing/executing MetaMask Snaps and registering internal RPC/action handlers. The main high-impact risk signals are (1) direct execution of snap source code obtained from fetchSnap(), and (2) sensitive key material derivation (mnemonic/seed) from options.secretRecoveryPhrase in a clearly labeled 'withKeyringV2Unsafe' handler that passes mnemonic+seed into an externally provided operation callback. Additionally, SnapController:getSnapFile forwards caller-controlled path/encoding to getSnapFile(auxiliaryFiles, ...)—which could enable unintended file access depending on that helper’s validation. No clear malicious exfiltration or obfuscation is visible in this snippet alone.

Confidence: 0.62

Severity: 0.58

From: packages/bitcoin-wallet-snap/package.jsonnpm/@metamask/snaps-jest@10.2.1npm/@metamask/snaps-simulation@4.3.1

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@metamask/snaps-simulation@4.3.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

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.

2 participants