From c1717cb2d5e35521c78c3a1d9cdc7168b124093c Mon Sep 17 00:00:00 2001 From: Jonathan Tzeng Date: Wed, 27 May 2026 17:01:36 -0700 Subject: [PATCH] Initialize ECC library eagerly so Taproot sends work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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) --- src/common/utxobased/keymanager/keymanager.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/utxobased/keymanager/keymanager.ts b/src/common/utxobased/keymanager/keymanager.ts index 17a84718..b8b7f90e 100644 --- a/src/common/utxobased/keymanager/keymanager.ts +++ b/src/common/utxobased/keymanager/keymanager.ts @@ -32,6 +32,15 @@ import { InsufficientFundsErrorPlus } from './types' import * as utxopicker from './utxopicker' import * as pickerUtils from './utxopicker/utils' +// Eagerly initialize the ECC library at module load. Taproot (p2tr) address +// parsing in `addressToScriptPubkey` (via `payments.p2tr`) requires the ECC +// library, and that code path can run before any ECPair/signing operation +// triggers the lazy `getECPair` init below — e.g. when `makeSpend` converts a +// Taproot recipient address to a scriptPubkey. Without this, sending to a +// `bc1p…` address fails with "No ECC Library provided". +// eslint-disable-next-line @typescript-eslint/no-var-requires +initEccLib(require('@bitcoinerlab/secp256k1')) + let ECPairCache: ECPairAPI const getECPair = (): ECPairAPI => { if (ECPairCache != null) return ECPairCache