Skip to content

Migrate from elliptic to @noble/curves & Remove bitcoinjs-message#26

Merged
ACken2 merged 16 commits intomainfrom
feature/migrate-to-noble-curves
Nov 23, 2025
Merged

Migrate from elliptic to @noble/curves & Remove bitcoinjs-message#26
ACken2 merged 16 commits intomainfrom
feature/migrate-to-noble-curves

Conversation

@ACken2
Copy link
Owner

@ACken2 ACken2 commented Nov 22, 2025

Description:

🛡️ Security Fix & Dependency Migration

This PR addresses Issue #25 regarding the critical security vulnerabilities and lack of maintenance in the elliptic package.

To resolve this, we have completely removed the dependency tree rooted in elliptic (including bitcoinjs-message and the legacy secp256k1 node wrapper) and migrated to @noble/curves, which is modern, audited, and constant-time.

🔄 Changes

  1. Removed Dependencies:

    • bitcoinjs-message: Replaced with an internal, lightweight implementation.
    • secp256k1: Replaced with @noble/curves.
    • elliptic: Removed entirely (except its use in unit tests).
  2. New Implementation (src/helpers/BitcoinMessage.ts):

    • Implemented a robust, drop-in replacement for Bitcoin Message signing and verification.
    • Full Support: Handles Legacy (P2PKH), Nested Segwit (P2SH-P2WPKH), and Native Segwit (P2WPKH) signature headers.
    • Network Agnostic: The verify function automatically detects the network (Mainnet, Testnet, or Regtest) of the provided address.
  3. Refactor:

    • Updated src/helpers/Key.ts to use noble-curves for key compression and decompression.
    • Updated src/helpers/BIP137.ts to use noble-curves for public key recovery.

🧪 Testing & Verification

We have added a comprehensive test suite to ensure zero regressions:

  • Cross-Verification: A new test suite (test/BitcoinMessage.test.ts) generates signatures using the old bitcoinjs-message library and asserts that our new implementation generates the exact same byte-for-byte output.
  • Round-Trip Tests: Verifies that signatures generated by the new code can be verified by the old library, and vice-versa.
  • Coverage: Tests cover all address types (compressed/uncompressed) and all networks (Mainnet, Testnet, Regtest).
  • Magic Hash: Added specific vectors to verify the double-SHA256 message hashing logic against standard OpenSSL outputs.

⚠️ Breaking Changes

🔗 Related Issues

Closes #25

@gemini-code-assist
Copy link

Summary of Changes

Hello @ACken2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the project's security posture and maintainability by replacing outdated and vulnerable cryptographic dependencies with modern, well-audited alternatives. It introduces an internal, feature-rich implementation for Bitcoin message signing and verification, ensuring continued compatibility and robustness while streamlining the dependency footprint. The changes are thoroughly tested to guarantee functional equivalence and reliability.

Highlights

  • Security & Dependency Migration: The elliptic package, identified as having critical security vulnerabilities and lacking maintenance, has been completely removed from the dependency tree. This addresses Issue Dependency "elliptic" has unfixed security issues #25.
  • New Cryptography Library: The project has migrated to @noble/curves, a modern, audited, and constant-time cryptographic library, replacing elliptic and the legacy secp256k1 node wrapper.
  • Internal Bitcoin Message Implementation: The external bitcoinjs-message dependency has been replaced with a new, robust, and lightweight internal implementation located at src/helpers/BitcoinMessage.ts. This new implementation provides full support for Legacy (P2PKH), Nested Segwit (P2SH-P2WPKH), and Native Segwit (P2WPKH) signature headers.
  • Network Agnostic Verification: The verify function in the new BitcoinMessage implementation automatically detects the network (Mainnet, Testnet, or Regtest) of the provided Bitcoin address, simplifying usage.
  • Refactoring for noble-curves: Key utility functions in src/helpers/Key.ts (for public key compression/decompression) and src/helpers/BIP137.ts (for public key recovery) have been updated to leverage the @noble/curves library.
  • Comprehensive Testing: A new, extensive test suite (test/BitcoinMessage.test.ts) has been added to ensure zero regressions. This includes cross-verification with the old bitcoinjs-message library for byte-for-byte output equality, round-trip tests, and coverage for all address types and networks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coveralls
Copy link

coveralls commented Nov 22, 2025

Pull Request Test Coverage Report for Build 19595927260

Details

  • 79 of 79 (100.0%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 19595886310: 0.0%
Covered Lines: 434
Relevant Lines: 434

💛 - Coveralls

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent security enhancement, migrating from the unmaintained elliptic and bitcoinjs-message packages to the modern and audited @noble/curves. The new BitcoinMessage helper is a well-crafted replacement, and the comprehensive test suite, including cross-verification against the old library, is a great example of ensuring a safe migration. I've identified a critical bug in the new sign method due to incorrect API usage, which would lead to a runtime error. I have also included a suggestion to improve code clarity in the verify method. After addressing these points, this will be a very strong contribution to the project's security and maintainability.

@ACken2 ACken2 merged commit 698f2ad into main Nov 23, 2025
5 checks passed
@ACken2 ACken2 deleted the feature/migrate-to-noble-curves branch November 23, 2025 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dependency "elliptic" has unfixed security issues

2 participants