Skip to content

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

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

feat(stellar-wallet-snap): Add exportAccount keyring API#187
stanleyyconsensys wants to merge 3 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

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