Initialize ECC library eagerly so Taproot sends work#450
Open
j0ntz wants to merge 1 commit into
Open
Conversation
`initEccLib(secp256k1)` was only called lazily inside `getECPair()`, but Taproot (p2tr) address parsing in `addressToScriptPubkey` (via `payments.p2tr`) needs the ECC library too — and that path can run before any ECPair/signing operation, e.g. when `makeSpend` converts a Taproot recipient address to a scriptPubkey. As a result, sending to a `bc1p…` address failed with "No ECC Library provided". Segwit v0 (`bc1q…`) sends were unaffected because they don't require ECC for address conversion. Initialize the ECC library once at module load so Taproot address handling works regardless of call order. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
initEccLib(secp256k1)was only called lazily, insidegetECPair(). But Taproot (p2tr) address handling inaddressToScriptPubkey→guessAddressTypeFromAddress→payments.p2tralso requires the ECC library, and that path can run before any ECPair/signing operation — most notably whenmakeSpendconverts a Taproot recipient address to a scriptPubkey.As a result, sending to a
bc1p…(Taproot / bech32m) address failed:payments.p2trthrew"No ECC Library provided. You must call initEccLib()", whichguessAddressTypeFromAddressswallowed, surfacing asunable to convert address … to script pubkey. SegWit v0 (bc1q…) sends were unaffected because they don't need ECC for address conversion.Fix: initialize the ECC library once at module load (using the already-present
@bitcoinerlab/secp256k1dep), so Taproot address handling works regardless of call order. The existing lazy init ingetECPair()is left in place (idempotent).How it was found
Integrating the Breez SDK - Spark for Bitcoin Lightning sends in edge-react-gui (EdgeApp/edge-react-gui#6017). Spark deposit addresses are Taproot (
bc1p…), so funding a Spark wallet from an Edge BTC wallet requires sending to one — which failed until this fix.Testing
Verified on iOS: with this change,
makeSpendto a Taproot address succeeds and broadcasts a valid P2TR-output transaction (confirmed on mainnet), which the prior code could not do. Isolated repro:payments.p2tr({ address: 'bc1p…', network })throws withoutinitEccLib, succeeds with it.Asana: https://app.asana.com/0/1215088146871429/1215168882923123
🤖 Generated with Claude Code
Note
Low Risk
Single startup init using an existing dependency; no auth or transaction-logic changes beyond enabling p2tr address parsing.
Overview
Fixes Taproot (
bc1p…) sends by callinginitEccLibwith@bitcoinerlab/secp256k1whenkeymanagerloads, instead of relying only on lazy init insidegetECPair().Spend building can run
addressToScriptPubkey/guessAddressTypeFromAddress/payments.p2trbefore any signing path runs; without ECC registered, that failed with No ECC Library provided and surfaced as unable to convert the address to script pubkey. SegWit v0 (bc1q…) was unaffected. LazygetECPair()init is unchanged and remains idempotent.Reviewed by Cursor Bugbot for commit c1717cb. Bugbot is set up for automated code reviews on this repo. Configure here.