Skip to content

Remove lodash from bitcore-lib#4149

Open
MichaelAJay wants to merge 115 commits into
bitpay:masterfrom
MichaelAJay:rm-lodash
Open

Remove lodash from bitcore-lib#4149
MichaelAJay wants to merge 115 commits into
bitpay:masterfrom
MichaelAJay:rm-lodash

Conversation

@MichaelAJay
Copy link
Copy Markdown
Contributor

@MichaelAJay MichaelAJay commented Apr 27, 2026

Description

Remove lodash from bitcore-lib. Also some general cleanup, and especially 'forEach' fixing.

Changelog

  • Replace lodash in bitcore-lib with plain JS implementations

Testing Notes


Checklist

  • I have read CONTRIBUTING.md and verified that this PR follows the guidelines and requirements outlined in it.

@MichaelAJay MichaelAJay changed the title WIP remove lodash Remove lodash from bitcore-lib May 11, 2026
@MichaelAJay MichaelAJay marked this pull request as ready for review May 11, 2026 18:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request removes the lodash runtime dependency from packages/bitcore-lib by replacing lodash helpers with equivalent native JavaScript implementations across the library and its test suite.

Changes:

  • Replaced lodash type checks, collection helpers, cloning, and object extension with native JS (typeof, Array.isArray, map/filter/reduce, Object.assign, etc.).
  • Updated transaction sorting/shuffling and various loops to avoid .forEach and lodash utilities.
  • Removed lodash from bitcore-lib dependencies and stopped exporting it via bitcore.deps._.

Reviewed changes

Copilot reviewed 45 out of 46 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/bitcore-lib/test/transaction/unspentoutput.js Drops lodash usage in tests; uses structuredClone for deep copy.
packages/bitcore-lib/test/transaction/transaction.js Replaces lodash shuffle stubbing with Math.random stubbing; minor test cleanups.
packages/bitcore-lib/test/transaction/signature.js Removes unused lodash/chai should imports from test file.
packages/bitcore-lib/test/transaction/output.js Removes unused imports (expect/lodash/errors) after cleanup.
packages/bitcore-lib/test/transaction/input/publickeyhash.js Removes lodash/chai imports (relies on existing test environment setup).
packages/bitcore-lib/test/transaction/input/multisigscripthash.js Replaces lodash-based assertions with native array mapping + chai members checks.
packages/bitcore-lib/test/transaction/input/multisig.js Replaces lodash checks with native array mapping + chai members checks.
packages/bitcore-lib/test/transaction/input/input.js Replaces lodash iteration with for...of; adds lint suppressions for bitwise ops.
packages/bitcore-lib/test/script/interpreter.js Removes lodash and replaces array checks/iteration with native constructs.
packages/bitcore-lib/test/opcode.js Replaces _.size with Object.keys(...).length.
packages/bitcore-lib/test/hdpublickey.js Removes lodash/assert usage; modernizes to const + chai deep equality.
packages/bitcore-lib/test/hdprivatekey.js Removes lodash/assert usage; replaces lodash iteration with for...of.
packages/bitcore-lib/test/hdkeys.js Replaces _.each with for...of; removes unused imports.
packages/bitcore-lib/test/crypto/signature.js Replaces lodash iteration with loops; updates fixture runner implementation.
packages/bitcore-lib/package.json Removes lodash dependency; pins elliptic to an exact version.
packages/bitcore-lib/package-lock.json Updates lockfile to reflect dependency removal and related resolution changes.
packages/bitcore-lib/lib/util/preconditions.js Replaces lodash string checks with typeof.
packages/bitcore-lib/lib/util/js.js Replaces lodash checks and forEach with native checks/loops; simplifies try/catch.
packages/bitcore-lib/lib/uri.js Removes lodash; switches to Object.assign and native loops; replaces URL variable usage.
packages/bitcore-lib/lib/unit.js Removes lodash; replaces object checks and iteration with native constructs.
packages/bitcore-lib/lib/transaction/unspentoutput.js Removes lodash; replaces undefined/number/object checks with native equivalents.
packages/bitcore-lib/lib/transaction/transaction.js Removes lodash; replaces sum/difference/without/shuffle with native implementations.
packages/bitcore-lib/lib/transaction/output.js Removes lodash type checks; adds bitwise lint suppression and minor cleanup.
packages/bitcore-lib/lib/transaction/input/multisigscripthash.js Replaces _.sortBy with explicit array copy + comparator sort.
packages/bitcore-lib/lib/transaction/input/multisig.js Replaces lodash collection helpers with native map/filter/reduce/sort and loops.
packages/bitcore-lib/lib/transaction/input/input.js Removes lodash; replaces type checks; adds bitwise lint suppressions.
packages/bitcore-lib/lib/script/script.js Removes lodash; replaces object checks and sorting with native equivalents.
packages/bitcore-lib/lib/script/interpreter.js Removes lodash; replaces undefined checks with nullish checks; adds JSUtil usage.
packages/bitcore-lib/lib/publickey.js Removes lodash; replaces isUndefined patterns with explicit === undefined checks.
packages/bitcore-lib/lib/privatekey.js Removes lodash; replaces null/undefined and string/object checks with native checks.
packages/bitcore-lib/lib/opcode.js Removes lodash; replaces type checks and _.extend with Object.assign.
packages/bitcore-lib/lib/message.js Removes lodash; replaces string checks with typeof.
packages/bitcore-lib/lib/hdpublickey.js Removes lodash; replaces collection/type helpers with native equivalents.
packages/bitcore-lib/lib/hdprivatekey.js Removes lodash; replaces includes/some/every/type checks with native equivalents.
packages/bitcore-lib/lib/errors/index.js Removes lodash; replaces _.each and type checks with native equivalents.
packages/bitcore-lib/lib/encoding/bufferreader.js Removes lodash; replaces undefined/string/object checks with native equivalents.
packages/bitcore-lib/lib/encoding/base58check.js Removes lodash; replaces string checks with typeof.
packages/bitcore-lib/lib/encoding/base58.js Removes lodash; rewrites validCharacters with native checks/iteration.
packages/bitcore-lib/lib/crypto/signature.js Removes lodash; introduces helper for DER sign-bit checks; adjusts strict defaulting.
packages/bitcore-lib/lib/crypto/point.js Removes unused catch variable; minor import order tweak.
packages/bitcore-lib/lib/crypto/bn.js Removes lodash; replaces type checks; adds bitwise lint suppressions.
packages/bitcore-lib/lib/block/merkleblock.js Removes lodash; replaces extend/array checks/undefined checks with native equivalents.
packages/bitcore-lib/lib/block/blockheader.js Removes lodash; replaces type checks; replaces noop setter.
packages/bitcore-lib/lib/block/block.js Removes lodash; replaces extend and array building with native equivalents.
packages/bitcore-lib/lib/address.js Removes lodash; replaces array/object/number checks and mapping with native equivalents.
packages/bitcore-lib/index.js Stops exporting lodash via bitcore.deps._.
Files not reviewed (1)
  • packages/bitcore-lib/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)

packages/bitcore-lib/test/crypto/signature.js:262

  • Inside the for loop, non-hex fixture vectors should be skipped, but return; exits test_sigs early and prevents generating the rest of the fixture tests. This changes the semantics compared to the prior forEach callback (where return only skipped the current element).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +508 to 510
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
Interpreter.SCRIPT_VERIFY_CLEANSTACK = (1 << 8),

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.

2 participants