Skip to content

Conversation

@shumkov
Copy link
Collaborator

@shumkov shumkov commented Nov 3, 2025

Issue being fixed or feature implemented

Different entities has different naming for to/from methods (toValue, toObject, ...)

What was done?

  • Rename methods.
  • Make sure fromObject / toObject are returning plain JS Object

How Has This Been Tested?

With existing tests

Breaking Changes

Many methods are renamed

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

Release Notes

  • New Features

    • Added JSON and object-based constructors (fromJSON, fromObject) for enhanced serialization support across assets, identities, and data contracts.
  • API Changes

    • Standardized method naming for consistency: base58()toBase58() and base64()toBase64() across all classes.
    • Improved parameter type handling for network-related methods.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

Walkthrough

This pull request refactors WebAssembly bindings to improve API consistency, including renaming JS binding methods to camelCase conventions (e.g., base64toBase64), adding fromJSON/fromObject constructors for deserialization, removing js_ parameter prefixes, and updating tests to use the new API surface.

Changes

Cohort / File(s) Summary
Manifest
packages/wasm-dpp2/Cargo.toml
Updated package version from fixed 1.0.5 to workspace-managed version; added "identity-json-conversion" feature flag to dpp dependency.
JS Binding Name Updates (toBase64)
packages/wasm-dpp2/src/asset_lock_proof/outpoint.rs, src/core_script.rs, src/data_contract/transitions/create.rs, src/data_contract/transitions/update.rs, src/identity/transitions/credit_withdrawal_transition.rs, src/identity/transitions/identity_credit_transfer_transition.rs, src/identity/transitions/top_up_transition.rs, src/identity/transitions/update_transition.rs, src/state_transitions/base/state_transition.rs, src/state_transitions/batch/batch_transition.rs
Renamed wasm_bindgen js_name attribute from "base64" to "toBase64" across multiple classes, aligning JS API to camelCase convention.
New JSON/Object Deserialization
packages/wasm-dpp2/src/asset_lock_proof/proof.rs, src/data_contract/model.rs, src/identity/model.rs, src/tokens/configuration/localization.rs
Added fromJSON and fromObject public constructors (wasm_bindgen-exposed) to enable deserialization from JS values and JSON-like objects; includes new imports for serde_wasm_bindgen, JsonValue, and value conversion utilities.
Parameter Naming & Type Annotations
packages/wasm-dpp2/src/core_script.rs, src/identity/public_key.rs, src/private_key.rs
Removed js_ prefix from parameters (e.g., js_networknetwork, js_key_hashkey_hash); added unchecked_param_type attributes to network/enum parameters for improved JS type hints; updated internal variable naming for consistency.
Identifier API Renames
packages/wasm-dpp2/src/identifier.rs
Renamed public getters from get_base58()/get_base64() to to_base58()/to_base64(); updated wasm_bindgen js_name from "base58" to "toBase58" and "base64" to "toBase64"; removed js_ prefix from constructor parameter.
Internal Method Updates
packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs, src/tokens/configuration/pre_programmed_distribution.rs, src/epoch/finalized_epoch_info.rs
Updated internal calls from get_base58() to to_base58(); renamed internal variables for consistency (e.g., js_block_proposersblock_proposers).
Data Contract Serialization
packages/wasm-dpp2/src/data_contract/model.rs
Introduced JSON-first serialization path with fromJSON/fromObject constructors; replaced toValue with toObject; updated base58 extraction from get_base58() to to_base58(); shifted serializer from json_compatible to default.
Identity Serialization
packages/wasm-dpp2/src/identity/model.rs
Added fromJSON and fromObject public constructors; refactored toObject to use manual Reflect/Object construction; introduced BigInt and Array handling utilities; added helper functions for platform value conversion.
New Serialization Tests
packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs, Identity.spec.mjs, TokenConfigurationLocalization.spec.mjs, OutPoint.spec.mjs
Added round-trip tests for fromJSON/fromObject and corresponding serialization methods; verifies object/JSON conversion integrity.
API Usage Updates in Tests
packages/wasm-dpp2/tests/unit/{AuthorizedActionTakers,BatchTransition,CoreScript,DataContract,DataContractCreateStateTransition,DataContractUpdateStateTransition,Document,DocumentTransition,DocumentsTransitions,Identifier,IdentityCreateTransition,IdentityCreditTransferTransition,IdentityCreditWithdrawalTransition,IdentityTopUpTransition,IdentityUpdateTransition,TokenBaseTransition,TokenDistributionRecipient,TokenDistributionRules,TokensTransitions}.spec.mjs
Updated test assertions to use renamed methods: base58()toBase58(), base64()toBase64(); replaced fromValue with fromJSON; added round-trip tests for base64 serialization; introduced fromObject test coverage.
Documentation & SDK
packages/wasm-sdk/src/queries/token.rs, packages/wasm-sdk/tests/unit/data-contract.spec.mjs
Updated documentation example from base58() to toBase58(); updated SDK test fixtures to use fromJSON/fromObject and renamed identifier methods.

Sequence Diagram(s)

sequenceDiagram
    participant JS as JavaScript Consumer
    participant WASM as Wasm Module
    participant Rust as Rust Core

    Note over JS,Rust: Old API Flow
    JS->>WASM: fromValue(jsObject)
    WASM->>WASM: serde_json parse
    WASM->>Rust: construct DataContract
    Rust-->>WASM: result
    WASM->>JS: toValue() / .base58()
    
    Note over JS,Rust: New API Flow
    JS->>WASM: fromJSON(jsObject) or fromObject(jsObject)
    WASM->>WASM: serde_wasm_bindgen::from_value
    WASM->>Rust: deserialize via JsonValue
    Rust-->>WASM: result
    WASM->>JS: toObject() / .toBase58()
    
    rect rgba(100, 200, 150, 0.3)
        Note over WASM: New methods preserve<br/>semantic meaning<br/>(to_* for conversion)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Files with logic changes: packages/wasm-dpp2/src/data_contract/model.rs, src/identity/model.rs introduce new JSON deserialization pathways and serialization handling that require verification of conversion correctness.
  • Parameter annotation changes: src/core_script.rs, src/identity/public_key.rs, src/private_key.rs involve new type hint attributes (unchecked_param_type) that need validation for JS interop accuracy.
  • Widespread test updates: Large volume of test files with systematic method renames (repetitive pattern reduces per-file complexity but breadth requires verification of consistency).
  • Areas requiring attention:
    • packages/wasm-dpp2/src/data_contract/model.rs — validates JSON deserialization flow and serializer changes
    • packages/wasm-dpp2/src/identity/model.rs — verifies BigInt handling, platform value conversion helpers, and manual object construction logic
    • packages/wasm-dpp2/src/asset_lock_proof/proof.rs — confirms new fromJSON/fromObject error handling matches existing patterns
    • Test coverage for round-trip serialization (new tests in AssetLockProof, Identity, OutPoint, TokenConfigurationLocalization) to ensure data integrity across conversions

Poem

🐰 Hopping through the WASM garden, we rename with care,
From base64 to toBase64, camelCase everywhere,
fromJSON, fromObject—new paths to explore,
Method names now crystal-clear, predictable and more,
No js_ prefixes needed, the API feels so right!

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'refactor(sdk): conventional naming to/from methods' accurately summarizes the main objective of this changeset. The PR standardizes naming conventions for to/from methods across SDK entities, replacing inconsistent method names with conventional ones like toBase64, toBase58, fromJSON, and fromObject. This is the primary and most significant change throughout the entire changeset affecting numerous files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch methods

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.

Base automatically changed from feat/sdk/entities to v2.2-dev November 3, 2025 08:42
# Conflicts:
#	packages/wasm-dpp2/src/asset_lock_proof/outpoint.rs
#	packages/wasm-dpp2/src/asset_lock_proof/proof.rs
#	packages/wasm-dpp2/src/core_script.rs
#	packages/wasm-dpp2/src/data_contract/contract_bounds.rs
#	packages/wasm-dpp2/src/data_contract/document/methods.rs
#	packages/wasm-dpp2/src/data_contract/model.rs
#	packages/wasm-dpp2/src/data_contract/transitions/create.rs
#	packages/wasm-dpp2/src/data_contract/transitions/update.rs
#	packages/wasm-dpp2/src/epoch/finalized_epoch_info.rs
#	packages/wasm-dpp2/src/identifier.rs
#	packages/wasm-dpp2/src/identity/model.rs
#	packages/wasm-dpp2/src/identity/public_key.rs
#	packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs
#	packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition.rs
#	packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs
#	packages/wasm-dpp2/src/identity/transitions/update_transition.rs
#	packages/wasm-dpp2/src/private_key.rs
#	packages/wasm-dpp2/src/state_transitions/base/state_transition.rs
#	packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs
#	packages/wasm-dpp2/src/state_transitions/batch/batched_transition.rs
#	packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs
#	packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs
#	packages/wasm-dpp2/src/tokens/configuration/localization.rs
#	packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs
#	packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs
#	packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs
#	packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs
#	packages/wasm-dpp2/tests/unit/DataContract.spec.mjs
#	packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/Document.spec.mjs
#	packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs
#	packages/wasm-dpp2/tests/unit/Identifier.spec.mjs
#	packages/wasm-dpp2/tests/unit/Identity.spec.mjs
#	packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs
#	packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs
#	packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs
#	packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs
#	packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs
#	packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs
#	packages/wasm-sdk/src/queries/token.rs
#	packages/wasm-sdk/tests/unit/data-contract.spec.mjs
@shumkov shumkov marked this pull request as draft November 3, 2025 16:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (1)

136-146: <!-- [scratchpad_start]
[task verification 1/1 COMPLETE]

[observations]

  • DataContractWasm exported methods in wasm-dpp2/src/data_contract/model.rs:
    • fromJSON (line 200)
    • fromObject (line 225)
    • fromBytes (line 246)
    • fromHex (line 266)
    • fromBase64 (line 278)
  • Zero matches for "from_value" or "fromValue" as an actual exported method
  • Second grep shows only internal usage of Value type and serde_wasm_bindgen, not a fromValue method

[analysis]

  • fromValue does NOT exist in the exported API
  • Test uses fromValue at lines 136, 179, 187, 195 - all 4 are invalid
  • This is a definite error, not intentional testing of multiple surfaces
  • The test is calling a non-existent method that will fail at runtime

[done]

  • Verification complete: fromValue is NOT a valid exported method
  • This is an oversight that requires fixes
  • Likely should be fromJSON or one of the other from* methods

Remove fromValue() calls—not an exported method on DataContract.

The verification confirms fromValue() is not a valid exported method. The DataContract Wasm API only exports: fromJSON, fromObject, fromBytes, fromHex, and fromBase64. The test at line 136 (and lines 179, 187, 195) must be updated to use one of the valid methods, likely fromJSON() based on the surrounding test patterns.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dee924e and aa0d6e4.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (46)
  • packages/wasm-dpp2/Cargo.toml (2 hunks)
  • packages/wasm-dpp2/src/asset_lock_proof/outpoint.rs (1 hunks)
  • packages/wasm-dpp2/src/asset_lock_proof/proof.rs (2 hunks)
  • packages/wasm-dpp2/src/core_script.rs (2 hunks)
  • packages/wasm-dpp2/src/data_contract/model.rs (5 hunks)
  • packages/wasm-dpp2/src/data_contract/transitions/create.rs (1 hunks)
  • packages/wasm-dpp2/src/data_contract/transitions/update.rs (1 hunks)
  • packages/wasm-dpp2/src/epoch/finalized_epoch_info.rs (1 hunks)
  • packages/wasm-dpp2/src/identifier.rs (1 hunks)
  • packages/wasm-dpp2/src/identity/model.rs (4 hunks)
  • packages/wasm-dpp2/src/identity/public_key.rs (1 hunks)
  • packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs (1 hunks)
  • packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition.rs (1 hunks)
  • packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs (1 hunks)
  • packages/wasm-dpp2/src/identity/transitions/update_transition.rs (1 hunks)
  • packages/wasm-dpp2/src/private_key.rs (2 hunks)
  • packages/wasm-dpp2/src/state_transitions/base/state_transition.rs (1 hunks)
  • packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs (1 hunks)
  • packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs (1 hunks)
  • packages/wasm-dpp2/src/tokens/configuration/localization.rs (1 hunks)
  • packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs (1 hunks)
  • packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs (3 hunks)
  • packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/DataContract.spec.mjs (4 hunks)
  • packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs (6 hunks)
  • packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs (6 hunks)
  • packages/wasm-dpp2/tests/unit/Document.spec.mjs (3 hunks)
  • packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/Identifier.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/Identity.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs (3 hunks)
  • packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs (3 hunks)
  • packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs (3 hunks)
  • packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs (3 hunks)
  • packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs (2 hunks)
  • packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs (1 hunks)
  • packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs (6 hunks)
  • packages/wasm-sdk/src/queries/token.rs (1 hunks)
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs (12 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
packages/**/tests/**

📄 CodeRabbit inference engine (AGENTS.md)

Place unit and integration tests alongside each package in packages//tests

Files:

  • packages/wasm-dpp2/tests/unit/Identifier.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs
  • packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs
  • packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs
  • packages/wasm-dpp2/tests/unit/Identity.spec.mjs
  • packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs
  • packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
  • packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs
  • packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/Document.spec.mjs
  • packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs
  • packages/wasm-dpp2/tests/unit/DataContract.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Format Rust code with cargo fmt
Run Clippy linter for Rust code

Files:

  • packages/wasm-dpp2/src/data_contract/transitions/update.rs
  • packages/wasm-dpp2/src/state_transitions/base/state_transition.rs
  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs
  • packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition.rs
  • packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs
  • packages/wasm-dpp2/src/asset_lock_proof/outpoint.rs
  • packages/wasm-dpp2/src/data_contract/transitions/create.rs
  • packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs
  • packages/wasm-dpp2/src/identity/transitions/update_transition.rs
  • packages/wasm-dpp2/src/asset_lock_proof/proof.rs
  • packages/wasm-dpp2/src/identity/public_key.rs
  • packages/wasm-dpp2/src/identifier.rs
  • packages/wasm-dpp2/src/epoch/finalized_epoch_info.rs
  • packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs
  • packages/wasm-dpp2/src/private_key.rs
  • packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs
  • packages/wasm-dpp2/src/identity/model.rs
  • packages/wasm-dpp2/src/data_contract/model.rs
  • packages/wasm-dpp2/src/core_script.rs
  • packages/wasm-dpp2/src/tokens/configuration/localization.rs
packages/wasm-sdk/**

📄 CodeRabbit inference engine (CLAUDE.md)

Keep WASM SDK docs in sync (run generate_docs.py) when updating the WASM SDK

Files:

  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
🧠 Learnings (40)
📓 Common learnings
Learnt from: thephez
Repo: dashpay/platform PR: 2754
File: packages/wasm-sdk/api-definitions.json:1285-1285
Timestamp: 2025-09-03T19:33:21.688Z
Learning: In packages/wasm-sdk/api-definitions.json, thephez prefers to keep the existing "ripemd160hash20bytes1234" placeholder for ECDSA_HASH160 data field in documentation examples rather than using a valid base64-encoded format, maintaining consistency with the previous documentation approach.
📚 Learning: 2025-09-03T19:33:21.688Z
Learnt from: thephez
Repo: dashpay/platform PR: 2754
File: packages/wasm-sdk/api-definitions.json:1285-1285
Timestamp: 2025-09-03T19:33:21.688Z
Learning: In packages/wasm-sdk/api-definitions.json, thephez prefers to keep the existing "ripemd160hash20bytes1234" placeholder for ECDSA_HASH160 data field in documentation examples rather than using a valid base64-encoded format, maintaining consistency with the previous documentation approach.

Applied to files:

  • packages/wasm-dpp2/tests/unit/Identifier.spec.mjs
  • packages/wasm-dpp2/src/data_contract/transitions/update.rs
  • packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs
  • packages/wasm-dpp2/src/state_transitions/base/state_transition.rs
  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition.rs
  • packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs
  • packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs
  • packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs
  • packages/wasm-dpp2/src/asset_lock_proof/outpoint.rs
  • packages/wasm-dpp2/src/data_contract/transitions/create.rs
  • packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs
  • packages/wasm-dpp2/src/identity/transitions/update_transition.rs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
  • packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs
  • packages/wasm-dpp2/tests/unit/Document.spec.mjs
  • packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs
  • packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs
  • packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs
  • packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs
  • packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs
  • packages/wasm-dpp2/src/identity/model.rs
  • packages/wasm-dpp2/tests/unit/DataContract.spec.mjs
  • packages/wasm-dpp2/src/core_script.rs
  • packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs
📚 Learning: 2025-09-12T13:18:08.661Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-09-12T13:18:08.661Z
Learning: Applies to packages/**/tests/**/*.{js,ts,jsx,tsx,rs} : Name tests descriptively, starting with “should …”

Applied to files:

  • packages/wasm-dpp2/tests/unit/Identifier.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs
📚 Learning: 2024-11-06T07:27:01.722Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2314
File: packages/wallet-contract/test/bootstrap.js:14-16
Timestamp: 2024-11-06T07:27:01.722Z
Learning: In `packages/wallet-contract/test/bootstrap.js`, for Mocha tests in Node.js, async functions like `loadWasmDpp` can be assigned directly to `beforeAll` without wrapping them in another async function.

Applied to files:

  • packages/wasm-dpp2/tests/unit/Identifier.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs
  • packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
  • packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs
  • packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/DataContract.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs
📚 Learning: 2024-10-09T00:22:57.778Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2201
File: packages/rs-platform-version/src/version/v2.rs:1186-1188
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the `IdentityTransitionVersions` structure within `packages/rs-platform-version/src/version/v2.rs`, the field `credit_withdrawal` does not need the `identity_` prefix since it is already encompassed within identity state transitions.

Applied to files:

  • packages/wasm-dpp2/src/data_contract/transitions/update.rs
  • packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs
  • packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition.rs
  • packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs
  • packages/wasm-dpp2/src/data_contract/transitions/create.rs
  • packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs
  • packages/wasm-dpp2/src/identity/transitions/update_transition.rs
  • packages/wasm-dpp2/src/identifier.rs
  • packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs
  • packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs
  • packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs
  • packages/wasm-dpp2/src/identity/model.rs
📚 Learning: 2024-10-24T04:59:20.436Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2270
File: packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js:75-77
Timestamp: 2024-10-24T04:59:20.436Z
Learning: Tenderdash's `tx` RPC method accepts transaction hashes in base64 encoding, or in hex encoding if prefixed with `0x`. Therefore, in `packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js`, it's acceptable to use `stHash.toString('base64')` when calling `requestTenderRpc('tx', { hash: stHash.toString('base64') })`.

Applied to files:

  • packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs
📚 Learning: 2025-06-18T03:44:14.385Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2673
File: packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_update/mod.rs:1164-1197
Timestamp: 2025-06-18T03:44:14.385Z
Learning: QuantumExplorer determined that a CodeRabbit suggestion about fixing signable_bytes calculation in identity update tests with contract-bound keys was incorrect - the code flow is working as intended without the suggested changes.

Applied to files:

  • packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs
  • packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs
  • packages/wasm-dpp2/tests/unit/Identity.spec.mjs
  • packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
  • packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs
📚 Learning: 2025-07-28T20:00:08.502Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/AI_REFERENCE.md:771-783
Timestamp: 2025-07-28T20:00:08.502Z
Learning: In packages/wasm-sdk/AI_REFERENCE.md, the documentation correctly shows the actual SDK method signatures (including identityCreate and identityTopUp with their full parameter lists), which may differ from the UI inputs shown in fixed_definitions.json. The UI may collect fewer parameters from users while handling additional requirements internally.

Applied to files:

  • packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs
  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition.rs
  • packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs
  • packages/wasm-dpp2/tests/unit/Identity.spec.mjs
  • packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs
  • packages/wasm-dpp2/src/identity/public_key.rs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
  • packages/wasm-dpp2/src/identifier.rs
  • packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs
  • packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs
  • packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs
  • packages/wasm-dpp2/src/identity/model.rs
  • packages/wasm-dpp2/src/core_script.rs
  • packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs
📚 Learning: 2025-09-03T14:41:16.196Z
Learnt from: thephez
Repo: dashpay/platform PR: 2754
File: packages/wasm-sdk/AI_REFERENCE.md:766-766
Timestamp: 2025-09-03T14:41:16.196Z
Learning: In packages/wasm-sdk/, the AI_REFERENCE.md file is auto-generated from api-definitions.json. Any documentation fixes should be made in api-definitions.json rather than directly in AI_REFERENCE.md, as manual changes to AI_REFERENCE.md would be overwritten during regeneration.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
📚 Learning: 2025-07-28T20:00:24.323Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/docs.html:2359-2383
Timestamp: 2025-07-28T20:00:24.323Z
Learning: In packages/wasm-sdk/docs.html, QuantumExplorer confirmed that placeholder private keys in documentation examples are acceptable as they are not real keys, though field name accuracy for the SDK API should still be maintained.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-09-03T14:42:29.958Z
Learnt from: thephez
Repo: dashpay/platform PR: 2754
File: packages/wasm-sdk/docs.html:1970-1971
Timestamp: 2025-09-03T14:42:29.958Z
Learning: In packages/wasm-sdk/, the docs.html file is auto-generated from api-definitions.json. Any documentation fixes should be made in api-definitions.json rather than directly in docs.html, as manual changes to docs.html would be overwritten during regeneration.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
  • packages/wasm-dpp2/tests/unit/Document.spec.mjs
📚 Learning: 2024-10-29T14:40:54.727Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/rs-sdk/src/core/transaction.rs:0-0
Timestamp: 2024-10-29T14:40:54.727Z
Learning: In `packages/rs-sdk/src/platform/document_query.rs` and `packages/rs-sdk/src/core/transaction.rs`, certain places don't implement `IntoInner`, so direct error mappings cannot be simplified using `IntoInner`. A TODO comment has been added to address this in a future PR.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-09-02T13:30:17.703Z
Learnt from: thephez
Repo: dashpay/platform PR: 2739
File: packages/wasm-sdk/test/ui-automation/tests/state-transitions.spec.js:1-171
Timestamp: 2025-09-02T13:30:17.703Z
Learning: In packages/wasm-sdk/index.html, state transition definitions are loaded dynamically from api-definitions.json via the loadApiDefinitions() function that fetches './api-definitions.json'. The UI doesn't have hardcoded transition definitions - instead it populates categories, types, inputs, and labels from this JSON configuration file at runtime.

Applied to files:

  • packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs
  • packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs
📚 Learning: 2025-02-10T11:26:36.709Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.

Applied to files:

  • packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
  • packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs
📚 Learning: 2025-10-01T08:37:27.687Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2790
File: packages/rs-drive/src/drive/document/index_uniqueness/validate_document_transfer_transition_action_uniqueness/mod.rs:64-0
Timestamp: 2025-10-01T08:37:27.687Z
Learning: In v1 validators for document transitions that change ownership (transfer, purchase), the owner_id parameter should be omitted from the method signature and extracted internally from the transition's document() accessor, since the owner_id is being changed by the transition itself.

Applied to files:

  • packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs
  • packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs
📚 Learning: 2024-10-30T11:19:59.163Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/rs-sdk/tests/fetch/config.rs:233-233
Timestamp: 2024-10-30T11:19:59.163Z
Learning: In the Rust SDK's `rs-sdk/tests` integration tests (e.g., in `packages/rs-sdk/tests/fetch/config.rs`), we cannot create objects during tests because there is no support for object creation in this context. Therefore, hardcoded values for test identities must be used.

Applied to files:

  • packages/wasm-dpp2/tests/unit/Identity.spec.mjs
  • packages/wasm-dpp2/src/identity/model.rs
📚 Learning: 2025-08-28T14:06:02.805Z
Learnt from: thephez
Repo: dashpay/platform PR: 2739
File: packages/wasm-sdk/test/ui-automation/fixtures/test-data.js:711-723
Timestamp: 2025-08-28T14:06:02.805Z
Learning: The tokenDestroyFrozen operation destroys the entire identity balance for that token and does not require an amount parameter.

Applied to files:

  • packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs
📚 Learning: 2025-08-05T13:55:39.147Z
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.

Applied to files:

  • packages/wasm-dpp2/src/asset_lock_proof/proof.rs
  • packages/wasm-dpp2/src/identity/public_key.rs
📚 Learning: 2024-12-10T10:56:26.215Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2030
File: packages/rs-sdk/tests/vectors/test_asset_lock_proof/quorum_pubkey-100-4ce7fd81273c2b394c0f32367374fc5b09ba912e017aacb366d2171e9ca6f9d5.json:1-1
Timestamp: 2024-12-10T10:56:26.215Z
Learning: In the `packages/rs-sdk/tests/vectors/test_asset_lock_proof/` directory, files with the `.json` extension are mock data that may not follow standard JSON format; this is intentional and acceptable within the project's testing framework.

Applied to files:

  • packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs
📚 Learning: 2024-10-09T00:22:57.778Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2182
File: packages/strategy-tests/src/transitions.rs:182-247
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In test code, input validation in functions like `instant_asset_lock_proof_transaction_fixture_with_dynamic_amount` is not required.

Applied to files:

  • packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs
📚 Learning: 2024-11-20T16:05:40.200Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2257
File: packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/for_saving.rs:148-151
Timestamp: 2024-11-20T16:05:40.200Z
Learning: In `packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/for_saving.rs`, when converting public keys from `QuorumForSavingV0` to `VerificationQuorum`, it's acceptable to use `.expect()` for public key conversion, as the conversion has been verified and panics are acceptable in this context.

Applied to files:

  • packages/wasm-dpp2/src/identity/public_key.rs
  • packages/wasm-dpp2/src/private_key.rs
📚 Learning: 2024-11-20T10:01:50.837Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2257
File: packages/rs-drive-abci/src/platform_types/platform_state/v0/old_structures/mod.rs:94-94
Timestamp: 2024-11-20T10:01:50.837Z
Learning: In `packages/rs-drive-abci/src/platform_types/platform_state/v0/old_structures/mod.rs`, when converting with `PublicKey::try_from`, it's acceptable to use `.expect()` to handle potential conversion errors.

Applied to files:

  • packages/wasm-dpp2/src/identity/public_key.rs
  • packages/wasm-dpp2/src/private_key.rs
📚 Learning: 2024-10-21T01:03:42.458Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2227
File: packages/rs-dpp/src/core_types/validator_set/v0/mod.rs:299-299
Timestamp: 2024-10-21T01:03:42.458Z
Learning: In the `test_serialize_deserialize_validator_set_v0` test within `packages/rs-dpp/src/core_types/validator_set/v0/mod.rs`, deterministic BLS keys cannot be easily used; therefore, using `BlsPublicKey::generate()` is acceptable.

Applied to files:

  • packages/wasm-dpp2/src/identity/public_key.rs
📚 Learning: 2024-10-09T00:22:57.778Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2182
File: packages/rs-drive/src/util/grove_operations/batch_insert_if_not_exists_return_existing_element/mod.rs:46-50
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In this codebase, match statements for versions are intentionally designed to handle known versions and treat unknown versions as mismatches.

Applied to files:

  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
📚 Learning: 2024-09-27T08:25:11.059Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2139
File: packages/rs-drive-proof-verifier/src/types.rs:0-0
Timestamp: 2024-09-27T08:25:11.059Z
Learning: Build failures are intended when new versions are added to the `Version` enum in `TryFrom` implementations, so that developers are forced to handle them explicitly. Therefore, it's acceptable not to include a wildcard arm for `Some(_)` when matching on `response.version`.

Applied to files:

  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
📚 Learning: 2024-10-21T01:03:42.458Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2139
File: packages/rs-drive-proof-verifier/src/types.rs:638-666
Timestamp: 2024-10-21T01:03:42.458Z
Learning: When matching on `response.version`, prefer the code to fail when a new version enum is introduced, and avoid adding a wildcard arm to handle unexpected versions.

Applied to files:

  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
📚 Learning: 2024-11-25T07:49:05.419Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2345
File: packages/wallet-utils-contract/schema/v1/wallet-utils-contract-documents.json:49-55
Timestamp: 2024-11-25T07:49:05.419Z
Learning: In the schema definitions for the `wallet-utils-contract` (file `packages/wallet-utils-contract/schema/v1/wallet-utils-contract-documents.json`), the `$createdAt` field is a system field augmented by DPP and does not need to be defined explicitly in the schema's properties.

Applied to files:

  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
📚 Learning: 2025-09-02T13:30:17.703Z
Learnt from: thephez
Repo: dashpay/platform PR: 2739
File: packages/wasm-sdk/test/ui-automation/tests/state-transitions.spec.js:1-171
Timestamp: 2025-09-02T13:30:17.703Z
Learning: In packages/wasm-sdk/index.html, state transition definitions are loaded dynamically from api-definitions.json rather than being hardcoded in the HTML file. The UI loads transition categories, types, inputs, and labels from this JSON configuration file.

Applied to files:

  • packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs
📚 Learning: 2024-10-09T00:22:57.778Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2215
File: packages/rs-drive-abci/src/execution/engine/run_block_proposal/mod.rs:105-105
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In `run_block_proposal` in `packages/rs-drive-abci/src/execution/engine/run_block_proposal/mod.rs`, when retrieving `last_block_time_ms`, it's acceptable to use `platform_state` instead of `block_platform_state`, even after updating the protocol version.

Applied to files:

  • packages/wasm-dpp2/src/epoch/finalized_epoch_info.rs
📚 Learning: 2025-02-21T13:43:33.462Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2449
File: packages/dapi/lib/externalApis/drive/fetchProofForStateTransitionFactory.js:110-112
Timestamp: 2025-02-21T13:43:33.462Z
Learning: The getRecipientId() method has different signatures for mint and transfer token transitions - mint requires tokenConfiguration parameter while transfer does not, due to their different logic and states.

Applied to files:

  • packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs
📚 Learning: 2024-11-20T20:43:41.185Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2257
File: packages/rs-drive-abci/tests/strategy_tests/masternodes.rs:212-220
Timestamp: 2024-11-20T20:43:41.185Z
Learning: In `packages/rs-drive-abci/tests/strategy_tests/masternodes.rs`, the pattern of generating a `PrivateKey`, converting it to bytes, and reconstructing a `BlsPrivateKey` from those bytes is intentional. Avoid suggesting to simplify this code in future reviews.

Applied to files:

  • packages/wasm-dpp2/src/private_key.rs
📚 Learning: 2025-07-28T20:04:48.458Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/index.html:4360-4416
Timestamp: 2025-07-28T20:04:48.458Z
Learning: In packages/wasm-sdk, the wallet helper `derive_key_from_seed_with_path` (Rust function in src/wallet/key_derivation.rs) is synchronous; its JS wrapper returns a value immediately, so `await` is unnecessary.

Applied to files:

  • packages/wasm-dpp2/src/private_key.rs
📚 Learning: 2024-10-09T00:22:57.778Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2186
File: packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/mod.rs:48-54
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the identity credit withdrawal transition code, the field `platform_version.drive_abci.validation_and_processing.state_transitions.identity_credit_withdrawal_state_transition.transform_into_action` is not an `Option` type, so handling `None` cases is unnecessary.

Applied to files:

  • packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs
📚 Learning: 2024-10-29T10:42:00.521Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/rs-dapi-client/Cargo.toml:22-22
Timestamp: 2024-10-29T10:42:00.521Z
Learning: In `packages/rs-dapi-client/Cargo.toml`, `backon` will not work without the `tokio-sleep` feature in our setup, so it's unnecessary to declare `tokio-sleep` as a separate feature in the `[features]` section.

Applied to files:

  • packages/wasm-dpp2/Cargo.toml
📚 Learning: 2024-10-18T15:39:51.172Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2254
File: packages/rs-sdk/src/sdk.rs:585-585
Timestamp: 2024-10-18T15:39:51.172Z
Learning: The 'platform' project uses Rust version 1.80, so code in 'packages/rs-sdk' can use features available in Rust 1.80, such as the `abs_diff()` method.

Applied to files:

  • packages/wasm-dpp2/Cargo.toml
  • packages/wasm-dpp2/src/data_contract/model.rs
📚 Learning: 2025-09-03T16:37:11.605Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2756
File: packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_masternode_list/update_state_masternode_list/v0/mod.rs:11-11
Timestamp: 2025-09-03T16:37:11.605Z
Learning: In packages/rs-dpp/Cargo.toml, the abci feature already includes core_rpc_client, and core_rpc_client is defined as ["dep:dashcore-rpc"]. This means rs-drive-abci can access dashcore-rpc types through dpp when using the abci feature.

Applied to files:

  • packages/wasm-dpp2/Cargo.toml
📚 Learning: 2025-09-07T22:18:50.883Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-07T22:18:50.883Z
Learning: Applies to packages/wasm-sdk/** : Keep WASM SDK docs in sync (run generate_docs.py) when updating the WASM SDK

Applied to files:

  • packages/wasm-dpp2/Cargo.toml
📚 Learning: 2025-04-11T09:08:05.652Z
Learnt from: pauldelucia
Repo: dashpay/platform PR: 2523
File: packages/rs-drive/src/drive/contract/update/update_contract/v1/update_description/v1/mod.rs:147-151
Timestamp: 2025-04-11T09:08:05.652Z
Learning: Description length validation for data contracts is already handled in the data contract validation process, specifically in packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs.

Applied to files:

  • packages/wasm-dpp2/src/data_contract/model.rs
📚 Learning: 2025-02-14T04:31:17.170Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2449
File: packages/rs-drive-abci/src/execution/platform_events/initialization/create_genesis_state/test/tokens.rs:35-38
Timestamp: 2025-02-14T04:31:17.170Z
Learning: In test scenarios, it's acceptable for different types of identifiers (e.g., identity IDs and contract IDs) to share the same byte values since they operate in different scopes and contexts.

Applied to files:

  • packages/wasm-dpp2/tests/unit/DataContract.spec.mjs
📚 Learning: 2024-11-28T13:49:17.301Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2317
File: packages/rs-dapi-client/src/address_list.rs:175-180
Timestamp: 2024-11-28T13:49:17.301Z
Learning: In Rust code in `packages/rs-dapi-client/src/address_list.rs`, do not change the interface of deprecated methods like `add_uri`, even to fix potential panics.

Applied to files:

  • packages/wasm-dpp2/src/core_script.rs
🧬 Code graph analysis (24)
packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs (1)
packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs (1)
  • localization (86-86)
packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs (1)
packages/wasm-dpp2/tests/unit/Identifier.spec.mjs (11)
  • identifier (18-18)
  • identifier (24-24)
  • identifier (30-30)
  • identifier (36-36)
  • identifier (42-42)
  • identifier (49-49)
  • identifier (55-55)
  • identifier (63-63)
  • identifier (69-69)
  • identifier (75-75)
  • identifier (81-81)
packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs (1)
packages/wasm-dpp2/tests/unit/DataContract.spec.mjs (18)
  • dataContract (24-24)
  • dataContract (32-32)
  • dataContract (38-38)
  • dataContract (46-46)
  • dataContract (91-91)
  • dataContract (105-105)
  • dataContract (113-113)
  • dataContract (119-119)
  • dataContract (125-125)
  • dataContract (131-131)
  • dataContract (137-137)
  • dataContract (145-145)
  • dataContract (153-153)
  • dataContract (161-161)
  • dataContract (169-169)
  • dataContract (181-181)
  • wasm (5-5)
  • PlatformVersion (6-6)
packages/wasm-dpp2/src/asset_lock_proof/proof.rs (3)
packages/wasm-dpp2/src/data_contract/model.rs (4)
  • from_object (226-244)
  • from (40-42)
  • from (46-48)
  • from_json (201-223)
packages/wasm-dpp2/src/identity/model.rs (5)
  • from_object (250-254)
  • js_value (317-317)
  • value (343-344)
  • from (32-34)
  • from_json (240-247)
packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs (3)
  • from_object (68-77)
  • from (26-28)
  • from (32-34)
packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs (1)
packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs (9)
  • instantLockProof (13-13)
  • instantLockProof (19-19)
  • instantLockProof (37-37)
  • instantLockProof (45-45)
  • instantLockProof (51-51)
  • instantLockProof (57-57)
  • instantLockProof (63-63)
  • instantLockProof (71-71)
  • instantLockProof (79-79)
packages/wasm-dpp2/src/identity/public_key.rs (1)
packages/wasm-dpp2/src/enums/network.rs (1)
  • try_from (16-46)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (4)
packages/wasm-sdk/tests/unit/fixtures/data-contract-v0-crypto-card-game.mjs (1)
  • contract (1-96)
packages/wasm-sdk/tests/unit/fixtures/data-contract-v1-with-docs-tokens-groups.mjs (1)
  • contract (1-281)
packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs (1)
  • objectRepresentation (64-64)
packages/wasm-dpp2/tests/unit/DataContract.spec.mjs (1)
  • objectRepresentation (77-77)
packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs (2)
packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs (3)
  • wasm (3-3)
  • base64 (28-28)
  • bytes (29-29)
packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs (5)
  • wasm (3-3)
  • base64 (56-56)
  • bytes (21-21)
  • bytes (48-48)
  • bytes (57-57)
packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs (1)
packages/wasm-dpp2/tests/unit/DataContract.spec.mjs (18)
  • dataContract (24-24)
  • dataContract (32-32)
  • dataContract (38-38)
  • dataContract (46-46)
  • dataContract (91-91)
  • dataContract (105-105)
  • dataContract (113-113)
  • dataContract (119-119)
  • dataContract (125-125)
  • dataContract (131-131)
  • dataContract (137-137)
  • dataContract (145-145)
  • dataContract (153-153)
  • dataContract (161-161)
  • dataContract (169-169)
  • dataContract (181-181)
  • wasm (5-5)
  • PlatformVersion (6-6)
packages/wasm-dpp2/tests/unit/Document.spec.mjs (2)
packages/wasm-dpp2/tests/unit/DataContract.spec.mjs (18)
  • dataContract (24-24)
  • dataContract (32-32)
  • dataContract (38-38)
  • dataContract (46-46)
  • dataContract (91-91)
  • dataContract (105-105)
  • dataContract (113-113)
  • dataContract (119-119)
  • dataContract (125-125)
  • dataContract (131-131)
  • dataContract (137-137)
  • dataContract (145-145)
  • dataContract (153-153)
  • dataContract (161-161)
  • dataContract (169-169)
  • dataContract (181-181)
  • wasm (5-5)
  • PlatformVersion (6-6)
packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs (11)
  • wasm (6-6)
  • documentInstance (16-16)
  • documentInstance (30-30)
  • documentInstance (47-47)
  • documentInstance (87-87)
  • documentInstance (98-98)
  • documentInstance (109-109)
  • documentInstance (120-120)
  • documentInstance (133-133)
  • documentInstance (144-144)
  • documentInstance (155-155)
packages/wasm-dpp2/src/identifier.rs (3)
packages/wasm-dpp2/tests/unit/Identifier.spec.mjs (11)
  • identifier (18-18)
  • identifier (24-24)
  • identifier (30-30)
  • identifier (36-36)
  • identifier (42-42)
  • identifier (49-49)
  • identifier (55-55)
  • identifier (63-63)
  • identifier (69-69)
  • identifier (75-75)
  • identifier (81-81)
packages/wasm-dpp2/src/asset_lock_proof/outpoint.rs (1)
  • to_base64 (81-85)
packages/wasm-dpp2/src/core_script.rs (1)
  • to_base64 (101-103)
packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs (3)
packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs (9)
  • transition (15-15)
  • transition (26-26)
  • transition (44-44)
  • transition (53-53)
  • transition (62-62)
  • wasm (3-3)
  • base64 (28-28)
  • bytes (29-29)
  • restored (33-33)
packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs (4)
  • wasm (3-3)
  • base64 (36-36)
  • bytes (37-37)
  • restored (41-41)
packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs (4)
  • wasm (3-3)
  • base64 (29-29)
  • bytes (30-30)
  • restored (34-34)
packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs (1)
packages/wasm-dpp2/tests/unit/Identifier.spec.mjs (13)
  • identifier (18-18)
  • identifier (24-24)
  • identifier (30-30)
  • identifier (36-36)
  • identifier (42-42)
  • identifier (49-49)
  • identifier (55-55)
  • identifier (63-63)
  • identifier (69-69)
  • identifier (75-75)
  • identifier (81-81)
  • wasm (3-3)
  • identifier2 (43-43)
packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs (1)
packages/wasm-dpp2/src/identifier.rs (1)
  • to_base58 (122-124)
packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs (3)
packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs (4)
  • transition (70-70)
  • wasm (6-6)
  • base64 (54-54)
  • bytes (55-55)
packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs (9)
  • transition (12-12)
  • transition (21-21)
  • transition (29-29)
  • transition (44-44)
  • transition (50-50)
  • wasm (3-3)
  • base64 (31-31)
  • bytes (32-32)
  • restored (36-36)
packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs (3)
  • wasm (3-3)
  • base64 (44-44)
  • bytes (45-45)
packages/wasm-dpp2/src/private_key.rs (2)
packages/wasm-dpp2/src/enums/network.rs (1)
  • try_from (16-46)
packages/wasm-dpp2/src/error.rs (1)
  • invalid_argument (50-52)
packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs (3)
packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs (5)
  • outpoint (13-13)
  • outpoint (44-44)
  • outpoint (83-83)
  • outpoint (94-94)
  • wasm (4-4)
packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs (3)
  • wasm (6-6)
  • base64 (54-54)
  • bytes (55-55)
packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs (3)
  • wasm (3-3)
  • base64 (44-44)
  • bytes (45-45)
packages/wasm-dpp2/src/identity/model.rs (3)
packages/wasm-dpp2/src/asset_lock_proof/proof.rs (8)
  • from (23-25)
  • from (29-31)
  • from (35-37)
  • from (41-43)
  • from (47-52)
  • from (56-61)
  • from_object (156-162)
  • to_string (170-174)
packages/wasm-dpp2/src/identifier.rs (5)
  • value (63-63)
  • value (79-79)
  • try_from (39-51)
  • try_from (56-91)
  • try_from (96-98)
packages/wasm-dpp2/src/utils.rs (2)
  • error_message (26-26)
  • error_message (30-47)
packages/wasm-dpp2/src/data_contract/model.rs (4)
packages/wasm-dpp2/src/asset_lock_proof/proof.rs (9)
  • from (23-25)
  • from (29-31)
  • from (35-37)
  • from (41-43)
  • from (47-52)
  • from (56-61)
  • from_json (165-167)
  • from_object (156-162)
  • to_object (147-153)
packages/wasm-dpp2/src/identity/model.rs (5)
  • from (32-34)
  • from_json (240-247)
  • js_value (317-317)
  • from_object (250-254)
  • to_object (181-231)
packages/wasm-dpp2/src/error.rs (1)
  • serialization (54-56)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (9)
  • contract (24-24)
  • contract (51-55)
  • contract (81-85)
  • contract (116-120)
  • contract (136-140)
  • contract (224-228)
  • contract (246-250)
  • contract (268-272)
  • contract (336-336)
packages/wasm-dpp2/tests/unit/DataContract.spec.mjs (3)
packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs (10)
  • dataContract (16-16)
  • dataContract (25-25)
  • dataContract (40-40)
  • dataContract (54-54)
  • dataContract (62-62)
  • dataContract (70-70)
  • dataContract (83-83)
  • dataContract (97-97)
  • wasm (5-5)
  • PlatformVersion (6-6)
packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs (10)
  • dataContract (16-16)
  • dataContract (25-25)
  • dataContract (40-40)
  • dataContract (54-54)
  • dataContract (62-62)
  • dataContract (70-70)
  • dataContract (83-83)
  • dataContract (97-97)
  • wasm (5-5)
  • PlatformVersion (6-6)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (1)
  • objectRepresentation (273-273)
packages/wasm-dpp2/src/core_script.rs (2)
packages/wasm-dpp2/src/private_key.rs (1)
  • from_bytes (37-51)
packages/wasm-dpp2/src/enums/network.rs (1)
  • try_from (16-46)
packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs (3)
packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs (9)
  • wasm (3-3)
  • transition (12-12)
  • transition (21-21)
  • transition (29-29)
  • transition (44-44)
  • transition (50-50)
  • base64 (31-31)
  • bytes (32-32)
  • restored (36-36)
packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs (4)
  • wasm (3-3)
  • base64 (28-28)
  • bytes (29-29)
  • restored (33-33)
packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs (4)
  • wasm (3-3)
  • base64 (29-29)
  • bytes (30-30)
  • restored (34-34)
packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs (3)
packages/wasm-dpp2/tests/unit/Document.spec.mjs (18)
  • documentInstance (21-21)
  • documentInstance (31-31)
  • documentInstance (38-38)
  • documentInstance (50-50)
  • documentInstance (56-56)
  • documentInstance (62-62)
  • documentInstance (68-68)
  • documentInstance (74-74)
  • documentInstance (82-82)
  • documentInstance (90-90)
  • documentInstance (98-98)
  • documentInstance (108-108)
  • documentInstance (116-116)
  • documentInstance (126-126)
  • documentInstance (136-136)
  • documentInstance (146-146)
  • wasm (7-7)
  • identifier (29-29)
packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs (18)
  • wasm (6-6)
  • documentTransition (27-27)
  • documentTransition (38-38)
  • documentTransition (52-52)
  • documentTransition (89-89)
  • documentTransition (100-100)
  • batchTransition (40-40)
  • batchTransition (54-54)
  • batchTransition (102-102)
  • batchTransition (116-116)
  • batchTransition (164-164)
  • batchTransition (178-178)
  • batchTransition (226-226)
  • batchTransition (240-240)
  • batchTransition (288-288)
  • batchTransition (302-302)
  • batchTransition (350-350)
  • batchTransition (364-364)
packages/wasm-dpp2/tests/unit/Identifier.spec.mjs (12)
  • wasm (3-3)
  • identifier (18-18)
  • identifier (24-24)
  • identifier (30-30)
  • identifier (36-36)
  • identifier (42-42)
  • identifier (49-49)
  • identifier (55-55)
  • identifier (63-63)
  • identifier (69-69)
  • identifier (75-75)
  • identifier (81-81)
packages/wasm-dpp2/src/tokens/configuration/localization.rs (2)
packages/wasm-dpp2/src/asset_lock_proof/proof.rs (2)
  • from_object (156-162)
  • from_json (165-167)
packages/wasm-dpp2/src/identity/model.rs (3)
  • from_object (250-254)
  • js_value (317-317)
  • from_json (240-247)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Rust packages (wasm-dpp2) / Tests
  • GitHub Check: Rust packages (wasm-sdk) / Tests
  • GitHub Check: Rust packages (wasm-sdk) / Formatting
  • GitHub Check: Rust packages (wasm-sdk) / Unused dependencies
  • GitHub Check: Rust packages (wasm-sdk) / Linting
  • GitHub Check: Rust packages (wasm-dpp2) / Linting
  • GitHub Check: Build Docker images (RS-DAPI, rs-dapi, rs-dapi) / Build RS-DAPI image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit

Comment on lines +45 to 52
pub fn new_p2pkh(key_hash: Vec<u8>) -> Self {
let mut key_hash_bytes = [0u8; 20];
let bytes = key_hash.as_slice();
let len = bytes.len().min(32);
key_hash[..len].copy_from_slice(&bytes[..len]);
key_hash_bytes[..len].copy_from_slice(&bytes[..len]);

CoreScriptWasm(CoreScript::new_p2pkh(key_hash))
CoreScriptWasm(CoreScript::new_p2pkh(key_hash_bytes))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix array bounds issue to prevent panic.

The code uses .min(32) but key_hash_bytes is only a 20-byte array. If the input key_hash has a length between 21-32 bytes, len will exceed 20, causing key_hash_bytes[..len] to panic at runtime.

Apply this diff to fix the bounds check:

     pub fn new_p2pkh(key_hash: Vec<u8>) -> Self {
         let mut key_hash_bytes = [0u8; 20];
         let bytes = key_hash.as_slice();
-        let len = bytes.len().min(32);
+        let len = bytes.len().min(20);
         key_hash_bytes[..len].copy_from_slice(&bytes[..len]);
 
         CoreScriptWasm(CoreScript::new_p2pkh(key_hash_bytes))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn new_p2pkh(key_hash: Vec<u8>) -> Self {
let mut key_hash_bytes = [0u8; 20];
let bytes = key_hash.as_slice();
let len = bytes.len().min(32);
key_hash[..len].copy_from_slice(&bytes[..len]);
key_hash_bytes[..len].copy_from_slice(&bytes[..len]);
CoreScriptWasm(CoreScript::new_p2pkh(key_hash))
CoreScriptWasm(CoreScript::new_p2pkh(key_hash_bytes))
}
pub fn new_p2pkh(key_hash: Vec<u8>) -> Self {
let mut key_hash_bytes = [0u8; 20];
let bytes = key_hash.as_slice();
let len = bytes.len().min(20);
key_hash_bytes[..len].copy_from_slice(&bytes[..len]);
CoreScriptWasm(CoreScript::new_p2pkh(key_hash_bytes))
}
🤖 Prompt for AI Agents
In packages/wasm-dpp2/src/core_script.rs around lines 45 to 52, the code
computes len with .min(32) but copies into a 20-byte array which can panic for
input lengths 21–32; change the bounds calculation to use the destination length
(e.g., bytes.len().min(key_hash_bytes.len()) or .min(20)) so you only copy at
most 20 bytes, then copy that many bytes and construct CoreScriptWasm with the
fixed key_hash_bytes.

Comment on lines +55 to 68
pub fn new_p2sh(script_hash: Vec<u8>) -> Self {
let mut script_hash_bytes = [0u8; 20];
let bytes = script_hash.as_slice();
let len = bytes.len().min(32);
script_hash[..len].copy_from_slice(&bytes[..len]);
script_hash_bytes[..len].copy_from_slice(&bytes[..len]);

let mut bytes = vec![
opcodes::all::OP_HASH160.to_u8(),
opcodes::all::OP_PUSHBYTES_20.to_u8(),
];
bytes.extend_from_slice(&script_hash);
bytes.extend_from_slice(&script_hash_bytes);
bytes.push(opcodes::all::OP_EQUAL.to_u8());
Self::from_bytes(bytes)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix array bounds issue to prevent panic.

Same issue as new_p2pkh: the code uses .min(32) but script_hash_bytes is only a 20-byte array. If the input script_hash has a length between 21-32 bytes, this will panic at runtime.

Apply this diff to fix the bounds check:

     pub fn new_p2sh(script_hash: Vec<u8>) -> Self {
         let mut script_hash_bytes = [0u8; 20];
         let bytes = script_hash.as_slice();
-        let len = bytes.len().min(32);
+        let len = bytes.len().min(20);
         script_hash_bytes[..len].copy_from_slice(&bytes[..len]);
 
         let mut bytes = vec![
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn new_p2sh(script_hash: Vec<u8>) -> Self {
let mut script_hash_bytes = [0u8; 20];
let bytes = script_hash.as_slice();
let len = bytes.len().min(32);
script_hash[..len].copy_from_slice(&bytes[..len]);
script_hash_bytes[..len].copy_from_slice(&bytes[..len]);
let mut bytes = vec![
opcodes::all::OP_HASH160.to_u8(),
opcodes::all::OP_PUSHBYTES_20.to_u8(),
];
bytes.extend_from_slice(&script_hash);
bytes.extend_from_slice(&script_hash_bytes);
bytes.push(opcodes::all::OP_EQUAL.to_u8());
Self::from_bytes(bytes)
}
pub fn new_p2sh(script_hash: Vec<u8>) -> Self {
let mut script_hash_bytes = [0u8; 20];
let bytes = script_hash.as_slice();
let len = bytes.len().min(20);
script_hash_bytes[..len].copy_from_slice(&bytes[..len]);
let mut bytes = vec![
opcodes::all::OP_HASH160.to_u8(),
opcodes::all::OP_PUSHBYTES_20.to_u8(),
];
bytes.extend_from_slice(&script_hash_bytes);
bytes.push(opcodes::all::OP_EQUAL.to_u8());
Self::from_bytes(bytes)
}
🤖 Prompt for AI Agents
In packages/wasm-dpp2/src/core_script.rs around lines 55 to 68, the code sets
script_hash_bytes as a 20-byte array but calculates len with .min(32), which can
cause a panic when script_hash is 21–32 bytes; change the length cap to 20 (or
use script_hash_bytes.len()) before copy_from_slice so you only copy up to the
20 bytes available, then proceed to build the P2SH byte vector and call
Self::from_bytes(bytes).

Comment on lines +185 to +230
&object,
&JsValue::from_str("id"),
&JsValue::from(IdentifierWasm::from(self.0.id())),
)
.map_err(|err| {
WasmDppError::serialization(format!(
"unable to set identity id: {}",
err.error_message()
))
})?;

let public_keys = Array::new();
for public_key in self.0.public_keys().values() {
public_keys.push(&JsValue::from(IdentityPublicKeyWasm::from(
public_key.clone(),
)));
}
Reflect::set(
&object,
&JsValue::from_str("publicKeys"),
&public_keys.into(),
)
.map_err(|err| {
WasmDppError::serialization(format!(
"unable to set identity publicKeys: {}",
err.error_message()
))
})?;

let balance = big_int_from_u64(self.0.balance())?;
Reflect::set(&object, &JsValue::from_str("balance"), &balance.into()).map_err(|err| {
WasmDppError::serialization(format!(
"unable to set identity balance: {}",
err.error_message()
))
})?;

let revision = big_int_from_u64(self.0.revision())?;
Reflect::set(&object, &JsValue::from_str("revision"), &revision.into()).map_err(|err| {
WasmDppError::serialization(format!(
"unable to set identity revision: {}",
err.error_message()
))
})?;

Ok(object.into())
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

toObject/fromObject still expose WASM classes instead of plain JS objects

toObject() is now expected to hand back a plain JavaScript structure, but this implementation copies IdentifierWasm/IdentityPublicKeyWasm instances directly into the result. JSON.stringify(identity.toObject()) (or spreading it to clone) will still carry wasm pointers rather than literals. Symmetrically, fromObject() insists each publicKeys entry be an IdentityPublicKeyWasm via .to_wasm, so a caller that supplies a plain POJO (the advertised goal) immediately trips the “identity publicKeys must contain IdentityPublicKey instances” error.

Please convert the shape both ways: emit only primitives/POJOs (e.g., base58/base64 strings, arrays, BigInt) in toObject(), and have fromObject() accept that shape by deserializing through serde_wasm_bindgen/identity_from_platform_value instead of requiring wasm-bound classes. That keeps the API consistent with the PR objective and aligns with DataContract’s toObject/fromObject.

Also applies to: 333-398

🤖 Prompt for AI Agents
In packages/wasm-dpp2/src/identity/model.rs around lines 185-230 (and similarly
for lines 333-398), toObject currently embeds
IdentifierWasm/IdentityPublicKeyWasm instances instead of plain JS values and
fromObject requires wasm classes; change to emit only primitives/POJOs in
toObject (serialize identifier as a string, publicKeys as plain JS
objects/arrays of primitives, balance/revision as JS BigInt or number/string as
existing convention) by converting each wasm type into its platform
representation before Reflect::set, and update fromObject to accept plain POJOs
by deserializing inputs via serde_wasm_bindgen/identity_from_platform_value (or
equivalent deserializer) instead of calling .to_wasm/.expect; ensure error
mapping remains but validate and convert plain structures into internal types
during deserialization so callers can supply plain objects/JSON.

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.

3 participants