-
Notifications
You must be signed in to change notification settings - Fork 7
feat(ocap-kernel): add BIP39 mnemonic support for kernel identity seed recovery #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
grypez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early review to keep up with the PR.
5e68dcc to
0222bc0
Compare
Add @scure/bip39 for BIP39 mnemonic phrase support in kernel identity seed recovery. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add BIP39 mnemonic phrase support for kernel identity seed recovery: - Add isValidMnemonic() to validate BIP39 mnemonic phrases - Add mnemonicToSeed() to derive a 32-byte seed from a mnemonic - Add seedToMnemonic() to export a seed as a 12-word mnemonic - Extend RemoteCommsOptions with optional 'mnemonic' parameter - Update initRemoteComms to use mnemonic for seed derivation when provided - Export new utility functions from package index This enables users to backup and recover their kernel identity using a standard BIP39 mnemonic phrase. The same mnemonic will always produce the same peer ID, allowing identity recovery on new hosts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add unit tests for the new BIP39 mnemonic functionality: - isValidMnemonic: validation of 12/24-word mnemonics, checksums, and edge cases - mnemonicToSeed: conversion, determinism, and error handling - seedToMnemonic: conversion and round-trip validation - initRemoteComms with mnemonic option: seed derivation, peer ID consistency, existing identity preservation, and error cases Also fix seedToMnemonic to validate hex string length before conversion. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add end-to-end tests for the BIP39 mnemonic functionality: - BIP39 Utility Functions tests: validation, seed conversion, round-trip - BIP39 Identity Recovery tests: - Same mnemonic produces same peer ID (deterministic) - Different mnemonic produces different peer ID - Existing identity is preserved (mnemonic ignored) - Invalid mnemonic throws error Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive documentation for BIP39 mnemonic-based identity backup and recovery: - Create docs/identity-backup-recovery.md with: - Overview of kernel identity and BIP39 support - API reference for utility functions - Usage scenarios (first-time setup, backup, recovery, verification) - Security best practices - Error handling examples - Update docs/usage.md with: - Add Identity Backup and Recovery to table of contents - Add brief section with link to the detailed guide Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move BIP39 mnemonic utilities from remote-comms.ts to a dedicated utils/bip39.ts module for better separation of concerns: - Create src/utils/bip39.ts with isValidMnemonic, mnemonicToSeed, seedToMnemonic functions - Create src/utils/bip39.test.ts with unit tests for the utilities - Update remote-comms.ts to import mnemonicToSeed from utils - Update index.ts to export from utils/bip39.ts - Remove duplicate BIP39 utility tests from remote-comms.test.ts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…eeds - Replace non-standard entropy doubling with proper PBKDF2-HMAC-SHA512 - Remove seedToMnemonic (PBKDF2 is one-way, cannot reverse) - Add generateMnemonic for creating new random mnemonics - Support all valid BIP39 mnemonic lengths (12, 15, 18, 21, 24 words) - Add test vector verification for standard BIP39 compliance - Update documentation to reflect new backup/recovery workflow BREAKING: Users must now generate a mnemonic first if they want backup capability. Random seeds cannot be backed up as mnemonics. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Allow passing mnemonic directly to Kernel.make for cleaner API:
const kernel = await Kernel.make(platformServices, db, { mnemonic });
await kernel.initRemoteComms({ relays });
The mnemonic can still be passed to initRemoteComms for backwards
compatibility, and takes precedence if provided in both places.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…dentity Instead of silently ignoring the mnemonic parameter when an identity already exists, throw an error to prevent using a different identity than expected. Users must use resetStorage: true to clear existing identity before using a mnemonic for recovery. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The resetStorage option preserves identity fields by design. When combined with mnemonic for recovery, also clear identity fields so the new mnemonic can be used. Adds test to verify the recovery workflow works correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove reference to non-existent seedToMnemonic function in usage.md - Update example to show correct workflow: generate mnemonic first, then use for initialization and recovery - Fix RemoteCommsOptions.mnemonic JSDoc to clarify that an error is thrown when identity exists, not silently ignored Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
d212604 to
f27b0e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
| this.#kernelStore.kv.delete('keySeed'); | ||
| this.#kernelStore.kv.delete('peerId'); | ||
| this.#kernelStore.kv.delete('ocapURLKey'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid mnemonic causes irreversible identity loss before validation
High Severity
When resetStorage: true and mnemonic are provided to Kernel.make(), the identity keys (keySeed, peerId, ocapURLKey) are deleted immediately based only on whether options.mnemonic is truthy. The mnemonic is only validated later in initRemoteComms() when mnemonicToSeed() is called. If the mnemonic is invalid (typo, wrong checksum, etc.), the user's original identity is already irreversibly deleted, and the kernel cannot proceed with the invalid mnemonic either, resulting in data loss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting enough to punt to the backlog, but not really in the kernel's contract.
Closes #778
Summary
Implements BIP39 mnemonic phrase support for kernel identity seed recovery, addressing #778.
Changes:
@scure/bip39dependency (audited, secure BIP39 implementation)generateMnemonic()to create new random mnemonics (12 or 24 words)isValidMnemonic()to validate BIP39 mnemonic phrasesmnemonicToSeed()to derive a 32-byte seed using standard PBKDF2 derivationmnemonicoption toKernel.make()(recommended) andinitRemoteComms()resetStorage: true)Usage:
Implementation Notes
Acceptance Criteria from Issue
Test plan
generateMnemonic()- generates valid 12/24-word mnemonicsisValidMnemonic()- validates all BIP39 lengths, rejects invalid checksumsmnemonicToSeed()- deterministic PBKDF2 conversion, test vector verificationinitRemoteCommswith mnemonic option - seed derivation, peer ID consistency🤖 Generated with Claude Code
Note
Adds recoverable kernel identities via BIP39 mnemonics and integrates them into initialization flows.
generateMnemonic(),isValidMnemonic(),mnemonicToSeed()(exported fromindex.ts) using@scure/bip39Kernel.makeandinitRemoteCommsaccept optionalmnemonic;initRemoteCommsderiveskeySeedfrom it and logs usagemnemonicwhen an identity exists throws a clear error;resetStorage: trueenables recovery;initRemoteCommsoption takes precedence over constructorRemoteManagerplumbsmnemonic;remote-comms.tssupports mnemonic-based seed derivation and preserves known relays behaviordocs/identity-backup-recovery.md;docs/usage.mdupdated with quick-start and linkremote-commsmnemonic paths; Node E2E tests verify peer ID stability, conflicts, invalid mnemonics, and recovery@scure/bip39dependency; adjust public exports and expected exports testWritten by Cursor Bugbot for commit f27b0e4. This will update automatically on new commits. Configure here.