Skip to content

[Snyk] Security upgrade near-api-js from 2.1.4 to 4.0.0#10288

Open
revan-zhang wants to merge 8 commits intoxfrom
snyk-fix-aa49a870b8245d2637d59133c6b1428f
Open

[Snyk] Security upgrade near-api-js from 2.1.4 to 4.0.0#10288
revan-zhang wants to merge 8 commits intoxfrom
snyk-fix-aa49a870b8245d2637d59133c6b1428f

Conversation

@revan-zhang
Copy link
Copy Markdown
Contributor

@revan-zhang revan-zhang commented Feb 22, 2026

snyk-top-banner

Snyk has created this PR to fix 1 vulnerabilities in the yarn dependencies of this project.

Snyk changed the following file(s):

  • packages/core/package.json

Note for zero-installs users

If you are using the Yarn feature zero-installs that was introduced in Yarn V2, note that this PR does not update the .yarn/cache/ directory meaning this code cannot be pulled and immediately developed on as one would expect for a zero-install project - you will need to run yarn to update the contents of the ./yarn/cache directory.
If you are not using zero-install you can ignore this as your flow should likely be unchanged.

⚠️ Warning
Failed to update the yarn.lock, please update manually before merging.

Vulnerabilities that will be fixed with an upgrade:

Issue Score
medium severity Infinite loop
SNYK-JS-BNJS-15274301
  620  

Important

  • Check the changes in this PR to ensure they won't cause issues with your project.
  • Max score is 1000. Note that the real score may have changed since the PR was raised.
  • This PR was automatically created by Snyk using the credentials of a real user.

Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open fix PRs.

For more information:
🧐 View latest project report
📜 Customise PR templates
🛠 Adjust project settings
📚 Read about Snyk's upgrade logic


Learn how to fix vulnerabilities with free interactive lessons:

🦉 Learn about vulnerability in an interactive lesson of Snyk Learn.


Open with Devin

@revan-zhang
Copy link
Copy Markdown
Contributor Author

revan-zhang commented Feb 22, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

"js-conflux-sdk": "^2.1.12",
"jsrsasign": "^10.8.6",
"near-api-js": "^2.1.4",
"near-api-js": "^4.0.0",
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.

🔴 Major version bump of near-api-js (v2→v4) breaks all consuming code due to incompatible API changes

Upgrading near-api-js from ^2.1.4 to ^4.0.0 introduces multiple breaking API changes, but none of the consuming code was updated to match.

Root Cause and Detailed Breakdown

1. utils.serialize.deserialize 3-argument API removed (borsh v0.7→v1.0)

near-api-js v2 depends on borsh ^0.7.0 which exposes deserialize(schema, class, buffer). near-api-js v4 depends on borsh 1.0.0 which changed to deserialize(schema, buffer) returning a plain object. The code at packages/core/src/chains/near/CoreChainSoftware.ts:80-84 and packages/kit-bg/src/vaults/impls/near/utils.ts:85-89 both call:

utils.serialize.deserialize(
    transactions.SCHEMA,
    transactions.Transaction,
    buffer,
);

This 3-argument form will fail at runtime with v4.

2. transactions.SCHEMA format completely changed

In v2, SCHEMA was a Map compatible with borsh v0.7. In v4, SCHEMA is a plain object with struct/enum definitions for borsh v1.0. Even if the deserialize call were fixed, passing the old-style schema would produce incorrect results.

3. SignedTransaction/Signature constructor changes

The code at packages/core/src/chains/near/CoreChainSoftware.ts:114-120 constructs transactions.SignedTransaction and transactions.Signature — the v4 constructors use Assignable with a different initialization pattern.

4. Import path near-api-js/lib/transaction may be removed

Both packages/core/src/chains/near/CoreChainSoftware.ts:31-33 and packages/kit-bg/src/vaults/impls/near/utils.ts:8,13 import from near-api-js/lib/transaction — a deep internal path that may not exist in v4's restructured package layout.

5. bn.js removed as a dependency

packages/kit-bg/src/vaults/impls/near/utils.ts:2 imports BN from 'bn.js' which was a transitive dependency of near-api-js v2 but is no longer a dependency of v4 (replaced by @noble/curves).

Impact: Once the yarn.lock is regenerated (as the PR warns is needed), all NEAR chain operations — transaction building, signing, deserialization, and broadcasting — will break at runtime, making the NEAR wallet completely non-functional.

Prompt for agents
The near-api-js upgrade from v2 to v4 is a breaking change that requires updating all consuming code. The files that need changes are:

1. packages/core/src/chains/near/CoreChainSoftware.ts:
   - Line 5: The import `{ transactions, utils }` from 'near-api-js' needs to be verified against v4 exports.
   - Lines 30-33: The import from 'near-api-js/lib/transaction' needs to be changed to use the new package structure (likely import directly from 'near-api-js' or '@near-js/transactions').
   - Lines 80-84: The `utils.serialize.deserialize(transactions.SCHEMA, transactions.Transaction, buffer)` call must be updated to use the new borsh v1.0 API. In v4, use `transactions.Transaction.decode(buffer)` or `decodeTransaction(buffer)` from '@near-js/transactions'.
   - Lines 114-120: The `new transactions.SignedTransaction({transaction, signature: new transactions.Signature(...)})` construction needs to be verified against the v4 Assignable-based constructors.

2. packages/kit-bg/src/vaults/impls/near/utils.ts:
   - Line 7-8: Imports from 'near-api-js' and 'near-api-js/lib/transaction' need updating.
   - Lines 85-89: Same `utils.serialize.deserialize` 3-argument call needs updating to use `Transaction.decode(buffer)` or the new deserialization API.
   - Line 2: Verify that 'bn.js' is still available as it was removed as a transitive dependency of near-api-js v4.

Alternatively, if the goal is just to fix the bn.js vulnerability, consider whether a more targeted approach (e.g., using yarn resolutions to override the bn.js version) would be safer than a major version bump.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@socket-security
Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​aptos-labs/​ts-sdk@​1.39.09710010050100
Added@​babel/​plugin-proposal-class-properties@​7.18.61001006550100
Added@​babel/​plugin-proposal-class-static-block@​7.21.01001007150100
Added@​babel/​plugin-proposal-nullish-coalescing-operator@​7.18.61001007050100
Added@​babel/​plugin-proposal-private-methods@​7.18.61001006550100
Added@​babel/​plugin-proposal-private-property-in-object@​7.21.111001007350100
Added@​mymonero/​mymonero-keyimage-cache@​3.0.0691005982100
Added@​onekeyfe/​cross-inpage-provider-injected@​2.2.6365100879790
Added@​babel/​plugin-transform-numeric-separator@​7.25.91001006793100
Added@​onekeyfe/​cross-inpage-provider-types@​2.2.6382100689790
Added@​expo/​plist@​0.1.3741007199100
Added@​onekeyfe/​cross-inpage-provider-errors@​2.2.6384100719790
Added@​onekeyfe/​extension-bridge-hosted@​2.2.6380100719790
Added@​onekeyfe/​hd-transport-electron@​1.1.24811007297100
Added@​magiceden-oss/​open_creator_protocol@​0.3.5921007281100
Added@​types/​node-fetch@​2.6.91001007281100
Added@​aptos-labs/​siwa@​0.4.0771007387100
Added@​mymonero/​mymonero-app-bridge@​3.0.0821007381100
Added@​onekeyfe/​hd-shared@​1.1.24831007397100
Added@​onekeyfe/​cross-inpage-provider-core@​2.2.6384100739790
Added@​babel/​preset-typescript@​7.27.11001007394100
Addedesbuild@​0.27.2911007391100
Added@​keystonehq/​keystone-sdk@​0.4.1841007490100
Updated@​babel/​plugin-transform-optional-chaining@​7.27.1 ⏵ 7.25.9100 +110074 +194100
Added@​formatjs/​intl-pluralrules@​4.3.31001007497100
Addedexpo-keep-awake@​14.1.47410082100100
Added@​formatjs/​intl-locale@​2.4.471001007591100
Added@​formatjs/​intl-getcanonicallocales@​1.9.21001007691100
Added@​babel/​preset-env@​7.28.6971007795100
Added@​glif/​filecoin-rpc-client@​3.0.27710010081100
Added@​benfen/​bfc.js@​0.2.7821007789100
Added@​alephium/​web3@​1.5.292100779670
Added@​onekeyfe/​bitcoinforksjs-lib@​7.0.0-rc.0791009979100
See 31 more rows in the dashboard

View full report

@socket-security
Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm @emurgo/cardano-message-signing-asmjs is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?npm/@onekeyfe/cardano-coin-selection-asmjs@1.1.10-alpha.8npm/@emurgo/cardano-message-signing-asmjs@1.0.1

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@emurgo/cardano-message-signing-asmjs@1.0.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @onekeyfe/cross-inpage-provider-injected is 98.0% likely obfuscated

Confidence: 0.98

Location: Package overview

From: package.jsonnpm/@onekeyfe/cross-inpage-provider-injected@2.2.63

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@onekeyfe/cross-inpage-provider-injected@2.2.63. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @onekeyfe/cross-inpage-provider-injected is 85.0% likely obfuscated

Confidence: 0.85

Location: Package overview

From: package.jsonnpm/@onekeyfe/cross-inpage-provider-injected@2.2.63

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@onekeyfe/cross-inpage-provider-injected@2.2.63. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

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.

4 participants