generated from MetaMask/metamask-module-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Description
Problem
Currently, the kernel generates a new random seed on startup if none exists. There's no mechanism for users to backup or recover their kernel identity using a mnemonic phrase.
File: packages/ocap-kernel/src/remotes/kernel/remote-comms.ts:135-137
// XXX TODO: Instead of generating a new random seed unconditionally,
// this function should accept an optional BIP39 keyphrase parameterWhy This Matters
- Identity Loss: If kernel storage is lost/corrupted, the peer ID changes permanently
- No Backup: Users cannot backup their kernel identity
- No Portability: Cannot move kernel identity between devices
- OCAP URLs Break: URLs issued by the old identity become invalid
Expected Behavior
- Support BIP39 mnemonic phrase (12 or 24 words) for seed generation
- Allow seed export as mnemonic for backup
- Deterministic key derivation from mnemonic
- Backward compatible with existing random seed generation
Implementation
Files to Modify
| File | Changes |
|---|---|
kernel/remote-comms.ts |
Add BIP39 support to generateKeyInfo() |
remotes/types.ts |
Extend RemoteCommsOptions with mnemonic option |
Kernel.ts |
Pass mnemonic option through to remote comms |
Approach
-
Add BIP39 dependency
yarn add bip39 -
Update
generateKeyInfo()inremote-comms.tsexport async function generateKeyInfo( kernelStore: KernelStore, mnemonic?: string, ): Promise<KeyInfo> { let seed: Uint8Array; if (mnemonic) { // Derive seed from mnemonic seed = bip39.mnemonicToSeedSync(mnemonic).slice(0, 32); } else { // Check for existing seed or generate new random one const existingSeed = kernelStore.getRemoteCommsSeed(); seed = existingSeed ?? crypto.getRandomValues(new Uint8Array(32)); } // ... rest of key generation }
-
Add seed export functionality
export function exportSeedAsMnemonic(seed: Uint8Array): string { return bip39.entropyToMnemonic(seed); }
-
Extend
RemoteCommsOptionstype RemoteCommsOptions = { // ... existing options mnemonic?: string; // BIP39 mnemonic for seed recovery };
Security Considerations
- Mnemonic should never be logged
- Consider memory protection for seed material
- Validate mnemonic checksum before use
- Document secure backup practices for users
Acceptance Criteria
- BIP39 mnemonic accepted for seed generation
- Same mnemonic always produces same peer ID
- Seed can be exported as mnemonic for backup
- Existing random seed generation still works (backward compatible)
- Mnemonic validation (checksum verification)
- Unit tests for mnemonic-based key derivation
- Documentation for backup/recovery procedures
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels