Skip to content

Support TON hex signatures#688

Open
SergeyG-Solicy wants to merge 1 commit intotestnetfrom
feature/add-ton-network
Open

Support TON hex signatures#688
SergeyG-Solicy wants to merge 1 commit intotestnetfrom
feature/add-ton-network

Conversation

@SergeyG-Solicy
Copy link
Contributor

@SergeyG-Solicy SergeyG-Solicy commented Mar 13, 2026

Summary by CodeRabbit

  • Improvements
    • Hex string validation has been enhanced to accept strings with and without the "0x" prefix, providing greater flexibility when processing hexadecimal input data. This improvement streamlines data conversion workflows by accepting a wider range of valid input formats while maintaining compatibility with existing functionality.

@SergeyG-Solicy SergeyG-Solicy requested a review from tcsenpai March 13, 2026 11:25
@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Support TON hex signatures without 0x prefix

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Support hex strings without 0x prefix in signature validation
• Improve hex string detection logic and validation
• Maintain backward compatibility with 0x-prefixed hex strings
Diagram
flowchart LR
  input["Input string"] --> check{"Has 0x prefix?"}
  check -->|Yes| remove["Remove 0x prefix"]
  check -->|No| use["Use as-is"]
  remove --> validate["Validate hex format"]
  use --> validate
  validate --> isValid{"Valid hex?"}
  isValid -->|Yes| convert["Convert to Uint8Array"]
  isValid -->|No| passthrough["Return unchanged"]
Loading

Grey Divider

File Changes

1. src/utilities/validateUint8Array.ts ✨ Enhancement +5/-5

Support hex strings without 0x prefix

• Modified hex string detection to accept strings with or without 0x prefix
• Simplified conditional logic by using ternary operator for prefix handling
• Improved hex validation regex to require at least one character
• Reordered validation checks for better readability

src/utilities/validateUint8Array.ts


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 13, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Empty hex not parsed 🐞 Bug ✓ Correctness
Description
validateIfUint8Array no longer converts the empty-hex string "0x" to an empty byte buffer because
the new hex regex requires at least one hex character. Codepaths that normalize empty byte arrays to
"0x" will now receive a string instead of bytes, potentially causing downstream type/format
failures.
Code

src/utilities/validateUint8Array.ts[R9-13]

+        const hexString = input.startsWith("0x") ? input.slice(2) : input
+        const isHex = /^[0-9a-fA-F]+$/.test(hexString) && hexString.length % 2 === 0
+        if (isHex) {
            return Buffer.from(hexString, "hex")
        }
Evidence
The updated validator requires one-or-more hex chars ("+") so "0x" (which becomes an empty string
after prefix stripping) is no longer considered hex, and the function returns the original string.
Elsewhere, the codebase explicitly normalizes empty hex values to "0x" and encodes them by stripping
the prefix and calling Buffer.from(...,"hex"), which supports empty strings—indicating "0x" is a
legitimate empty-bytes representation in this repo.

src/utilities/validateUint8Array.ts[7-16]
src/libs/omniprotocol/serialization/consensus.ts[7-13]
src/libs/omniprotocol/serialization/consensus.ts[15-18]
src/libs/blockchain/transaction.ts[356-369]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`validateIfUint8Array("0x")` now returns the string `"0x"` instead of an empty byte array because the regex was tightened from `*` to `+`. In this codebase, empty byte sequences are normalized/represented as `"0x"`, so this is a behavioral regression and can cause downstream type/format errors when bytes are expected.

## Issue Context
Other serializers/encoders normalize empty hex to `"0x"` and then strip the prefix and use `Buffer.from(..., "hex")` (which supports empty strings), so `"0x"` should be accepted as a valid hex encoding for empty bytes.

## Fix Focus Areas
- src/utilities/validateUint8Array.ts[7-16]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a503d1cc-df54-4bbd-9d47-81f07f1259c0

📥 Commits

Reviewing files that changed from the base of the PR and between 06c44ff and db03667.

📒 Files selected for processing (1)
  • src/utilities/validateUint8Array.ts

Walkthrough

The validateUint8Array utility function's hex string handling was updated to accept hex strings regardless of "0x" prefix presence. The validation logic now uses a single isHex check and converts via Buffer.from(hexString, "hex"), while preserving existing behavior for non-string and object inputs.

Changes

Cohort / File(s) Summary
Hex String Validation
src/utilities/validateUint8Array.ts
Expanded hex string validation to accept strings with or without "0x" prefix; replaced prefix-specific logic with unified isHex check; conversion updated to use Buffer.from(hexString, "hex").

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A hex string's prefix need not be,
With or without, accepted we see!
The rabbit hops 'round validation's gate,
Now strings of hex are all first-rate! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Support TON hex signatures' is partially related to the changeset, which enhances hex string validation in validateUint8Array.ts by accepting hex strings with or without '0x' prefix. However, the title is vague about the specific technical improvement and doesn't clearly convey that this is about improving hex string handling in validation logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/add-ton-network
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

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.

1 participant