Skip to content

Conversation

@HinsonSIDAN
Copy link
Member

Summary

This PR adds a static method MeshValue.sortValue() to sort Cardano Value (JSON representation) by policy ID and token name using byte ordering. It also simplifies the internal compareByteOrder function from a complex byte-by-byte parsing loop to a simple string comparison, leveraging the fact that hex digits 0-9, a-f are in ascending ASCII order.

Changes:

  • Simplified compareByteOrder from 13 lines to 2 lines
  • Added MeshValue.sortValue(plutusValue: Value): Value static method
  • Added test cases for sortValue

Affect components

  • @meshsdk/common
  • @meshsdk/contract
  • @meshsdk/core
  • @meshsdk/core-csl
  • @meshsdk/core-cst
  • @meshsdk/hydra
  • @meshsdk/provider
  • @meshsdk/react
  • @meshsdk/svelte
  • @meshsdk/transaction
  • @meshsdk/wallet
  • Mesh playground (i.e. https://meshjs.dev/)
  • Mesh CLI

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Bug fix (non-breaking change which fixes an issue)
  • Code refactoring (improving code quality without changing its behavior)
  • Documentation update (adding or updating documentation related to the project)

Related Issues

N/A

Checklist

  • My code is appropriately commented and includes relevant documentation, if necessary
  • I have added tests to cover my changes, if necessary
  • I have updated the documentation, if necessary
  • All new and existing tests pass (i.e. npm run test)
  • The build is pass (i.e. npm run build)

Additional Information

The sortValue method is useful for ensuring consistent ordering of assets in Value when deserializing or constructing values from various sources. Cardano requires values to be sorted by policy ID then token name for transaction validity.

@HinsonSIDAN HinsonSIDAN merged commit e07a8ff into main Jan 13, 2026
1 check passed
@HinsonSIDAN HinsonSIDAN deleted the feat/mesh-value-deser-ordering branch January 13, 2026 15:58
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.

2 participants