feat(stellar-wallet-snap): Add exportAccount keyring API - #187
feat(stellar-wallet-snap): Add exportAccount keyring API#187stanleyyconsensys wants to merge 3 commits into
exportAccount keyring API#187Conversation
There was a problem hiding this comment.
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
exportAccountin the keyring handler, deriving the wallet from entropy and returning anExportedAccountpayload (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.
| this.#logger.debug('Keyring request handled', { | ||
| origin, | ||
| method: request.method, | ||
| result: keyringRequestResult, |
There was a problem hiding this comment.
remove it for security purpose
| privateKey, | ||
| }; | ||
| } catch (error: unknown) { | ||
| return rethrowIfInstanceElseThrow( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
both method will auto assert if the address is same, and throw error if
- account not found
- address not match
- fail to derived account
Explanation
Adds support for the Keyring API v2
exportAccountmethod in@metamask/stellar-wallet-snap, enabling Stellar secret-seed (S…) export inbase32format, with validation and safeguards to reduce the risk of leaking secrets.Changes:
exportAccountin the keyring handler, deriving the wallet from entropy and returning anExportedAccountpayload (base32 only).StellarSecretKeyStruct) and wire in a single supported export encoding constant.References
Checklist