Skip to content

feat(near): port baseline NEAR transaction parser - #426

Draft
shahan-khatchadourian-anchorage wants to merge 1 commit into
shahankhatchadourian/near-a1-depsfrom
shahankhatchadourian/near-a2-chain
Draft

feat(near): port baseline NEAR transaction parser#426
shahan-khatchadourian-anchorage wants to merge 1 commit into
shahankhatchadourian/near-a1-depsfrom
shahankhatchadourian/near-a2-chain

Conversation

@shahan-khatchadourian-anchorage

@shahan-khatchadourian-anchorage shahan-khatchadourian-anchorage commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Second PR of the NEAR-consolidation stack (stacked on #425). Ports baseline NEAR transaction parsing from an existing, already-built and already-tested reference implementation into this crate's conventions.

Stack: A1 (#425) -> A2 (this) -> A3 (intents preset) -> A4 (signature verification) -> B (identity + wiring) -> C (docs site).

What this PR does

Adds baseline NEAR chain decoding to chain_parsers/visualsign-near:

  • tx.rs: borsh-decodes a NEAR Transaction/SignedTransaction from hex or base64 input.
  • actions.rs: renders each Action variant (Transfer, FunctionCall with a fail-closed JSON args decoder for ft_transfer/ft_transfer_call/ft_withdraw, generic label fallback for the rest).
  • convert.rs: assembles the final payload (Network/From/To + per-action fields) via NearVisualSignConverter.
  • fmt.rs/networks.rs: yoctoNEAR/Tgas decimal formatting, Mainnet/Testnet display.

This is a port, not new development -- the source repo's code is the reference implementation. Two deliberate deviations from a verbatim port:

  • tx.rs's input decoding uses this repo's shared visualsign::encodings::SupportedEncodings::detect + decode_hex convention (matching visualsign-solana's own from_string) instead of the source repo's hand-rolled 0x-prefix stripping -- this repo's convention is to reuse the shared mechanism rather than hand-roll per chain. Added a regression test for the 0x-prefixed case.
  • convert.rs omits the source repo's near-intents-feature-gated execute_intents decoding -- that code depends on presets/intents/, which lands in A3, compiled unconditionally there (no feature gate in the final design, since every other preset in this repo is unconditional too).

A1's placeholder NearParserError enum is removed as dead code now that the real port uses visualsign::vsptrait::TransactionParseError directly, matching the source repo; the now-unused thiserror dependency is dropped with it.

Verification

  • cargo test -p visualsign-near -- 20/20 pass (all of the source repo's original cases preserved, plus the new 0x-prefix test).
  • cargo clippy -p visualsign-near --all-targets -- -D warnings, cargo fmt --check -- clean.
  • cargo check/clippy -p parser_app --no-default-features --features near -- clean (narrow-build variant).
  • make -C src lint, make -C src test -- clean (default features; stock builds unaffected).
  • Internal code review and security review both run against this diff; no findings above minor/informational (one dead-dependency cleanup already folded in).

@shahan-khatchadourian-anchorage shahan-khatchadourian-anchorage changed the title shahankhatchadourian/near a2 chain feat(near): port baseline NEAR transaction parser Jul 30, 2026
@shahan-khatchadourian-anchorage
shahan-khatchadourian-anchorage force-pushed the shahankhatchadourian/near-a2-chain branch from a23f854 to f9246e6 Compare July 30, 2026 19:17
Ports the baseline chain-parsing code: borsh Transaction/SignedTransaction
decode via near-primitives (tx.rs), per-action rendering plus a
fail-closed args decoder for ft_transfer/ft_transfer_call/ft_withdraw
(actions.rs), the NearVisualSignConverter (convert.rs), and
yoctoNEAR/Tgas formatting (fmt.rs, networks.rs).

Two deliberate deviations from a verbatim port:
- tx.rs decodes hex/base64 input via the shared
  visualsign::encodings::SupportedEncodings::detect + decode_hex
  convention (matching visualsign-solana) instead of hand-rolled
  0x-prefix stripping.
- convert.rs omits near-intents-feature-gated execute_intents decoding;
  that depends on presets/intents/, which lands in a later PR, compiled
  unconditionally rather than behind a feature flag.

A1's placeholder NearParserError is removed as dead code now that this
PR uses visualsign::vsptrait::TransactionParseError directly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

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.

Pull request overview

Ports a baseline NEAR chain parser into the workspace’s VisualSign conventions by adding NEAR transaction envelope decoding, per-action rendering, and a NearVisualSignConverter that assembles NEAR transactions into SignablePayload fields.

Changes:

  • Added NEAR transaction decoding from hex/base64 (including 0x-prefixed hex) into a NearTransaction wrapper.
  • Implemented baseline NEAR action rendering (Transfer + FunctionCall with fail-closed decoding for select NEP-141 methods) and payload assembly via NearVisualSignConverter.
  • Removed now-dead NEAR-specific error type and dropped the thiserror dependency.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/chain_parsers/visualsign-near/src/tx.rs Adds NEAR borsh decoding from hex/base64 into NearTransaction + regression tests.
src/chain_parsers/visualsign-near/src/actions.rs Renders NEAR Action variants into VisualSign fields; includes selective JSON args decoding for common FT methods.
src/chain_parsers/visualsign-near/src/convert.rs Converts NearTransaction into SignablePayload with network/from/to headers and per-action fields.
src/chain_parsers/visualsign-near/src/fmt.rs Adds yoctoNEAR + Tgas fixed-decimal formatting helpers and tests.
src/chain_parsers/visualsign-near/src/networks.rs Introduces NearNetwork enum and display names + tests.
src/chain_parsers/visualsign-near/src/lib.rs Exposes NEAR modules and re-exports NearVisualSignConverter/NearTransaction; removes dead error enum.
src/chain_parsers/visualsign-near/Cargo.toml Drops thiserror dependency from the NEAR chain crate.
src/Cargo.lock Removes thiserror from the NEAR crate dependency list.

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

Comment on lines +26 to +32
impl NearVisualSignConverter {
/// Construct a converter for mainnet (the default for wallet display).
#[must_use]
pub fn new() -> Self {
Self::default()
}
}
@@ -0,0 +1,65 @@
//! yoctoNEAR, Tgas, base58 formatting helpers.
@@ -0,0 +1,39 @@
//! NearNetwork enum and system-account recognition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants