Fix bitcore-lib browser test issues#4160
Merged
kajoseph merged 3 commits intobitpay:masterfrom May 8, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses browser test failures caused by transitive dependency changes in elliptic/related packages by avoiding direct access to point coordinate internals and using the Point accessor APIs (getX()) when serializing x-coordinates.
Changes:
- Replace direct
point.xaccess withpoint.getX()when converting x-coordinates to 32-byte buffers for Schnorr/taproot-related logic. - Ensure x-only pubkey serialization is consistently padded to 32 bytes in Schnorr verification and transaction signature checks.
- Update taproot tweak hashing/output key derivation to use accessor-based x-coordinate retrieval.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/bitcore-lib/lib/transaction/transaction.js | Use point.getX() (32-byte padded) when converting PublicKey to x-only pubkey bytes for Schnorr signature checks. |
| packages/bitcore-lib/lib/publickey.js | Use getX() for TapTweak hashing input and tweaked output key serialization (32 bytes). |
| packages/bitcore-lib/lib/privatekey.js | Use getX() when serializing the internal public point x-coordinate for TapTweak hashing. |
| packages/bitcore-lib/lib/crypto/schnorr.js | Use getX() for PublicKey conversion and BIP340 challenge hash construction (32-byte padded). |
Comments suppressed due to low confidence (1)
packages/bitcore-lib/lib/crypto/schnorr.js:89
Schnorr.verifynow convertsPublicKeyinputs viapublicKey.point.getX().toBuffer({ size: 32 }), but the existing BIP340 vector tests only cover the Buffer input path. Add a unit test that callsSchnorr.verifywith aPublicKeyinstance (including a case where the x-coordinate would be <32 bytes without padding) to ensure this code path remains working across elliptic/bn.js dependency changes.
Schnorr.verify = function(publicKey, message, signature) {
if ($.isType(publicKey, 'PublicKey')) {
publicKey = publicKey.point.getX().toBuffer({ size: 32 });
}
if (publicKey.length !== 32) {
throw new Error('Public key should be 32 bytes for schnorr signatures');
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1367
to
1370
| if ($.isType(pubkey, 'PublicKey')) { | ||
| pubkey = pubkey.point.x.toBuffer(); | ||
| pubkey = pubkey.point.getX().toBuffer({ size: 32 }); | ||
| } | ||
| $.checkArgument(pubkey && pubkey.length === 32, 'Schnorr signatures have 32-byte public keys. The caller is responsible for enforcing this.'); |
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.
Description
Locally, when Lodash was removed, it regenerated the package-lock file. Although the elliptic package was pinned, elliptic's dependencies were not pinned, so upon regeneration, elliptic's dependencies transitively caused test failure in browser test.
This was mitigated by updating bitcore-lib to use Point x-coordinate accessors (
point.getX()) instead of directly accessingpoint.x. This issue was latent, and could have happened at any time, so this fix is appropriate.In commit
f68b2ca86f4e520f2458ce4d9f96760ceb9fddb3, benchmark scripts are checked in to the bitcore-lib package, along with a summary of execution (run on a Mac M3). These are then removed in the following commit.Changelog
getXaccessor pattern instead of directly retrieving the point class's x coordinate.Testing Notes
Checklist