Skip to content

fix(sdk): toJSON returns empty object#2995

Merged
shumkov merged 15 commits into
v3.0-devfrom
refactor/sdk/param-types
Jan 16, 2026
Merged

fix(sdk): toJSON returns empty object#2995
shumkov merged 15 commits into
v3.0-devfrom
refactor/sdk/param-types

Conversation

@shumkov

@shumkov shumkov commented Jan 15, 2026

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Multiple issues with toJSON methods in Evo SDK

What was done?

  • Fixed JS value to JSON value conversion (proofs data to JSON)
  • Replaced duplicate struct to IdentityPublicKeyWasm
  • Other minor fixes

How Has This Been Tested?

Implemented tests for JS value to JSON value conversion

Breaking Changes

Identity queries now return IdentityPublicKey instead of IdentityKeyInfo

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • Tests

    • Added comprehensive JS→JSON conversion tests (Maps, BigInt, Uint8Array, toJSON, nested structures).
  • New Features

    • Exposed a JS-accessible JSON-normalization helper for complex JS/WASM values.
    • Platform addresses and address-info now support JSON serialization.
    • Network inputs accept numeric enum values.
  • Refactor

    • Unified and expanded serialization bridges across WASM bindings for more consistent JS interop.
  • API

    • Identity key endpoints now return public key objects instead of legacy key-info objects.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@shumkov has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 42052fb and 8d5e399.

📒 Files selected for processing (1)
  • packages/wasm-dpp2/src/serialization/conversions.rs
📝 Walkthrough

Walkthrough

Adds JS→JSON normalization utilities and tests (Map/toJSON/BigInt/Uint8Array handling), implements Serialize for PlatformAddressWasm with bech32m/hex parsing fallback, updates many wasm serde conversion macro usages to pair wrapper types with internal Rust types, and extends NetworkLike to accept numeric literals.

Changes

Cohort / File(s) Summary
JSON conversion & helpers
packages/wasm-dpp2/src/serialization/conversions.rs
Added testJsValueToJson wasm export and helpers: js_value_to_json, try_call_to_json, normalize_js_value_for_json, normalize_map_for_json, map_key_to_string. Handles Map→object, toJSON(), BigInt→string, Uint8Array→array, and recursive normalization.
JSON conversion tests
packages/wasm-dpp2/tests/unit/js-value-to-json.spec.mjs
Added comprehensive tests covering Map key types (string/number/BigInt/Identifier/WASM object), nested maps/arrays/objects, BigInt handling, Uint8Array conversion, toJSON behavior, ordering, and large inputs.
Platform address serialization & parsing
packages/wasm-dpp2/src/platform_address/address.rs
Implemented impl Serialize for PlatformAddressWasm; serialization emits hex for human-readable serializers and raw bytes for binary. Parsing now tries bech32m first, falls back to hex, and returns clear errors on invalid input.
Address query types & returns
packages/wasm-sdk/src/queries/address.rs
Derived Serialize/Deserialize for PlatformAddressInfoWasm (camelCase), added From<AddressInfo>, wasm getters, and return paths converting items to JS objects via to_object() with undefined for missing entries.
Identity queries & public key types
packages/wasm-sdk/src/queries/identity.rs, packages/js-evo-sdk/src/identities/facade.ts
Replaced public usage of IdentityKeyInfoWasm with IdentityPublicKeyWasm across bindings and SDK facade; updated constructors/getters and return types to use IdentityPublicKeyWasm/IdentityPublicKey.
WASM serde conversion pairing
packages/wasm-sdk/src/queries/protocol.rs, packages/wasm-sdk/src/queries/system.rs, packages/wasm-sdk/src/queries/token.rs, packages/wasm-sdk/src/wallet/*.rs
Converted many impl_wasm_serde_conversions!(TypeWasm) calls to paired form impl_wasm_serde_conversions!(TypeWasm, Type) to bind wasm wrappers to internal Rust types.
Network parsing enhancement
packages/wasm-dpp2/src/core/network.rs
Extended TS NetworkLike to accept numeric literals (`0
Tests & minor formatting
packages/wasm-dpp2/tests/unit/*.spec.mjs
Minor formatting/assertion simplifications across unit tests (BatchTransition, DataContract, Identity, PlatformAddress, PlatformAddressOutput).

Sequence Diagram(s)

sequenceDiagram
    participant JS as JavaScript
    participant WASM as WASM Module
    participant Norm as Normalizer

    JS->>WASM: testJsValueToJson(jsValue)
    WASM->>Norm: js_value_to_json(jsValue)
    Norm->>Norm: detect type (Map, BigInt, Uint8Array, Array, Object, primitive)
    alt has toJSON()
        Norm->>WASM: try_call_to_json(obj)
        Norm->>Norm: normalize returned value recursively
    else Map
        Norm->>Norm: map_key_to_string() for each key
        Norm->>Norm: normalize_map_for_json() values recursively
    else BigInt
        Norm->>Norm: convert to string
    else Uint8Array
        Norm->>Norm: convert to Array of numbers
    else Array/Object
        Norm->>Norm: recursively normalize elements/properties
    end
    Norm-->>WASM: normalized JS-friendly structure
    WASM-->>JS: return normalized JsValue
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • QuantumExplorer

Poem

🐰
I hop through Maps and nibble keys,
Turn BigInts into stringy peas,
Hex and bech32m I sniff with care,
Normalize the forest everywhere,
A little hop for serialized trees!

🚥 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 title 'fix(sdk): toJSON returns empty object' directly describes the main problem being fixed - toJSON methods returning empty objects - which aligns with the core fix in the js_value_to_json conversion logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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


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.

@shumkov shumkov changed the title Refactor/sdk/param-types fix(sdk): toJSON returns empty object Jan 15, 2026
@github-actions github-actions Bot added this to the v3.0.0 milestone Jan 15, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@packages/wasm-dpp2/src/core/network.rs`:
- Around line 45-57: The code that handles numeric enum values (using
value.as_f64() and casting to u32) silently truncates fractional inputs (e.g.,
1.9 becomes 1); update the logic in the numeric branch that returns
NetworkWasm::Mainnet/Testnet/Devnet/Regtest so that it first verifies the f64 is
an integer and non-negative (e.g., check num.fract() == 0.0 and num >= 0.0 and
within u32 range) before casting to u32, and if the value is not an integer
return a WasmDppError::invalid_argument with a message rejecting non-integer
network values; keep the existing match on the validated integer to return the
appropriate NetworkWasm::* variant.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f6361d and 83d03cc.

📒 Files selected for processing (2)
  • packages/wasm-dpp2/src/core/network.rs
  • packages/wasm-dpp2/src/platform_address/address.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Rust code must pass cargo clippy --workspace linter checks
Rust code must be formatted using cargo fmt --all

**/*.rs: Use 4-space indent for Rust files
Follow rustfmt defaults and keep code clippy-clean for Rust modules
Use snake_case for Rust module names
Use PascalCase for Rust type names
Use SCREAMING_SNAKE_CASE for Rust constants

Files:

  • packages/wasm-dpp2/src/platform_address/address.rs
  • packages/wasm-dpp2/src/core/network.rs
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WebAssembly as a bridge between Rust and JavaScript implementations
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code

Applied to files:

  • packages/wasm-dpp2/src/platform_address/address.rs
  • packages/wasm-dpp2/src/core/network.rs
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WebAssembly as a bridge between Rust and JavaScript implementations

Applied to files:

  • packages/wasm-dpp2/src/platform_address/address.rs
🧬 Code graph analysis (1)
packages/wasm-dpp2/src/core/network.rs (1)
packages/wasm-sdk/src/error.rs (1)
  • invalid_argument (75-77)
🔇 Additional comments (3)
packages/wasm-dpp2/src/core/network.rs (2)

6-16: LGTM! TypeScript type extension is well-documented.

The NetworkLike type alias correctly extends to include numeric literals 0-3, aligning with the NetworkWasm enum discriminants. Documentation clearly describes acceptable input formats.


59-61: LGTM! Error message correctly reflects the expanded input options.

The updated error message accurately describes both string and numeric input options available to the caller.

packages/wasm-dpp2/src/platform_address/address.rs (1)

8-9: LGTM!

The imports are correctly added to support the new Serialize implementation.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread packages/wasm-dpp2/src/core/network.rs
Comment thread packages/wasm-dpp2/src/platform_address/address.rs
@shumkov shumkov self-assigned this Jan 15, 2026
@shumkov shumkov moved this to In review / testing in Platform team Jan 15, 2026
@shumkov
shumkov merged commit f030a1f into v3.0-dev Jan 16, 2026
31 of 32 checks passed
@shumkov
shumkov deleted the refactor/sdk/param-types branch January 16, 2026 11:21
@github-project-automation github-project-automation Bot moved this from In review / testing to Done in Platform team Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants