feat: add native Bitcoin HD keyring with BIP-84 derivation#601
Open
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
Open
feat: add native Bitcoin HD keyring with BIP-84 derivation#601devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
Conversation
Implements a native Bitcoin keyring for P2WPKH (native SegWit) address derivation using BIP-84. The keyring is conditionally registered in the Engine behind the 'bitcoin' feature flag. Changes: - Add BitcoinKeyring class with BIP-84 key derivation using @metamask/key-tree - Generate P2WPKH addresses via @noble/hashes (SHA-256 + RIPEMD-160) and bech32 - Support mainnet (bc1) and testnet (tb1) address generation - Add 'bitcoin' entry to ExtendedKeyringTypes enum - Register bitcoinKeyringBuilder in Engine (behind ONLY_INCLUDE_IF(bitcoin)) - Add comprehensive unit tests (18 tests covering all keyring operations) - Transaction/message signing marked as TODOs (throw not-implemented) Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Devin Review
|
| .split('/') | ||
| .map((part) => { | ||
| const hardened = part.endsWith("'"); | ||
| const index = parseInt(part.replace("'", ''), 10); |
…moveAccount Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
…ialize after removeAccount Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a native Bitcoin HD keyring with BIP-84 derivation for P2WPKH (native SegWit) addresses. Registers it conditionally in Engine behind the
bitcoinpreprocessor flag.New module
app/core/BitcoinKeyring/:types.ts—BitcoinKeyringState,BitcoinKeyringAccount,BitcoinNetworkenumBitcoinKeyring.ts— Keyring using@metamask/key-tree(BIP-84),@noble/hashes(SHA-256 + RIPEMD-160), andbech32for P2WPKH addresses. Supports serialize/deserialize, addAccounts, getAccounts, exportAccount, removeAccount. Signing stubs throw (TODO).index.ts— Exports +bitcoinKeyringBuilder()factoryBitcoinKeyring.test.ts— 19 unit testsModified files:
app/constants/keyringTypes.ts— Addedbitcoin = 'Bitcoin HD Key Tree'app/core/Engine/Engine.ts— Conditional import + registration of Bitcoin keyring builderReview & Testing Checklist for Human
abandon abandon...about) — cross-reference with a known BIP-84 derivation toolremoveAccountfollowed byaddAccountsproduces unique addresses (no index collision) — covered by test but worth manual verificationbech32import resolves correctly at runtime (it's a transitive dep viabitcoin-address-validation, pinned in resolutions)///: BEGIN:ONLY_INCLUDE_IF(bitcoin)preprocessor directives in Engine.ts are correctly placed and don't break non-bitcoin buildsNotes
#nextDeriveIndextracks BIP-84 derivation index independently of#accountsarray length, preventing duplicate derivation afterremoveAccount(fix for Devin Review finding)nextDeriveIndexis persisted in serialized state with backward-compatible fallback tonumberOfAccountsreact-native-tcpGitHub tarball returns 404, blockingyarn installin all CI jobs. Not caused by this PR.yarn lint,tsc --noEmit(zero errors), 19/19 unit testsLink to Devin session: https://app.devin.ai/sessions/e42aa97910c14dd69abbaae28747b0e6
Requested by: @dr-phil