Skip to content

fix: commonjs compatibility#1877

Merged
gagdiez merged 9 commits into
near:masterfrom
fastnear:commonjs-compatibility
Mar 8, 2026
Merged

fix: commonjs compatibility#1877
gagdiez merged 9 commits into
near:masterfrom
fastnear:commonjs-compatibility

Conversation

@mikedotexe

@mikedotexe mikedotexe commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • Commit messages follow the conventional commits spec
  • If this is a code change: I have written unit tests. (Same tests)
  • If this changes code in a published package: I have run pnpm changeset to create a changeset JSON document appropriate for this change.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

near-api-js is a powerful library for connecting and interacting with the NEAR blockchain. Currently, there are some places where we can make small gains by removing the EcmaScript APIs (like Buffer) with safe and modern APIs.

More information on motivation located in issue #1876

Test Plan

Same tests, all passing, none added

Related issues/PRs

Issue #1876


Some screenshots that might help understand, or at least helped me…

Buffer swap

Screenshot 2026-02-26 at 4 50 36 PM Screenshot 2026-02-26 at 4 51 07 PM

Removal of dependency in favor of native and secure API

Screenshot 2026-02-26 at 4 54 40 PM

and so on.

Note: some of these screenshots are before pushing up the merge conflicts, but they illustrate what's happening here.

@changeset-bot

changeset-bot Bot commented Feb 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1954977

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
near-api-js Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

mikedotexe and others added 3 commits February 26, 2026 17:35
# Conflicts:
#	packages/accounts/src/account.ts
#	packages/accounts/src/interface.ts
#	packages/accounts/src/local-view-execution/index.ts
#	packages/accounts/src/local-view-execution/runtime.ts
#	packages/accounts/src/local-view-execution/types.ts
#	packages/accounts/src/utils.ts
#	packages/accounts/test/account.test.ts
#	packages/client/src/view.ts
#	packages/cookbook/transactions/batch-transactions.ts
#	packages/crypto/package.json
#	packages/near-api-js/package.json
#	packages/near-api-js/tsup.config.ts
#	packages/providers/src/failover-rpc-provider.ts
#	packages/providers/src/json-rpc-provider.ts
#	packages/tokens/package.json
#	packages/utils/src/provider.ts
#	pnpm-lock.yaml
#	src/crypto/key_pair_ed25519.ts
#	src/crypto/key_pair_secp256k1.ts
#	src/crypto/public_key.ts
#	src/transactions/action_creators.ts
#	src/utils/format.ts
#	test/unit/transactions/transaction.test.ts
- Use prehash: false since NEAR provides pre-hashed messages
- Reorder recovered signature bytes from [recovery, r, s] to [r, s, recovery]
  to match NEAR's expected 65-byte format
- Replace Buffer.from(hex) with Uint8Array in tests

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment thread .changeset/moody-squids-stick.md Outdated
@@ -0,0 +1,5 @@
---
"near-api-js": major

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this would release near-api-js v8, maybe lets change it to "minor" so we release near-api-js 7.2.0 instead

thought, it could even be a patch, because there is no change in interfaces, only external things

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, yeah I had the wrong idea about semver here. fixed in f8543dd

@gagdiez

gagdiez commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

nice, I think that we do actually need this, and I do not have any major concerns with the code changes.

Want to hear also @denbite's opinion as he created most of the v7

@gagdiez gagdiez closed this Mar 5, 2026
@github-project-automation github-project-automation Bot moved this from NEW❗ to Shipped 🚀 in DevTools Mar 5, 2026
@gagdiez gagdiez reopened this Mar 5, 2026
@github-project-automation github-project-automation Bot moved this from Shipped 🚀 to NEW❗ in DevTools Mar 5, 2026
@gagdiez gagdiez changed the title Commonjs compatibility fix: commonjs compatibility Mar 5, 2026
@mikedotexe

Copy link
Copy Markdown
Contributor Author

I want to share this because it's astonishing what can happen with compilations after doing these kinds of things suggested in this pull request:

Screenshot 2026-03-05 at 4 32 27 PM copy

More details about how this fit into shrinking the wallet compilations here azbang/near-connect#73

@denbite

denbite commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

@mikedotexe overall this PR is looking good

I’ve also been meaning to migrate from secp256k1 to @noble/curves/secp256k1, so I’m glad to see this happening

one thing I wanted to highlight though, is that we try to follow our changeset rules quite closely
they encourage small, atomic, and well-documented updates so versioning stays clean and changes are easy to reason about or revert if needed

right now this PR seems to be doing two separate things:

  1. replacing the secp256k1 library with @noble/curves/secp256k1
  2. replacing Buffer with Uint8Array

ideally these would be implemented as two separate PRs
however, to avoid the extra time spent rebasing and splitting this up, I’d suggest at least adding two separate changeset files in this PR (one for each change) with the descriptions that briefly explain what was changed, rather than the goal behind the change

if we do that, this LGTM from my side

@gagdiez gagdiez enabled auto-merge March 7, 2026 16:19
gagdiez
gagdiez previously approved these changes Mar 7, 2026
auto-merge was automatically disabled March 8, 2026 12:47

Head branch was pushed to by a user without write access

@gagdiez gagdiez enabled auto-merge March 8, 2026 12:52
@gagdiez gagdiez merged commit dc80b96 into near:master Mar 8, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from NEW❗ to Shipped 🚀 in DevTools Mar 8, 2026
@github-actions github-actions Bot mentioned this pull request Mar 7, 2026
@mikedotexe mikedotexe deleted the commonjs-compatibility branch March 8, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Shipped 🚀

Development

Successfully merging this pull request may close these issues.

4 participants