Skip to content

fix(orders): resolve 64-hex order ids directly without re-hashing in dispatch and refund (closes #67) - #298

Open
Ranjeet2063 wants to merge 1 commit into
Movalabs-crew:mainfrom
Ranjeet2063:fix/admin-order-id-hash-resolution
Open

Ranjeet2063 wants to merge 1 commit into
Movalabs-crew:mainfrom
Ranjeet2063:fix/admin-order-id-hash-resolution

Conversation

@Ranjeet2063

Copy link
Copy Markdown
Contributor

Summary of Changes

This PR resolves issue #67 where dispatchOrder and refundOrder (and readOrder) in lib/stellar/orders.ts unconditionally ran await hashOrderId(orderId). When called from app/admin/orders/page.tsx, the order ID is already the 32-byte event-derived SHA-256 hash formatted as a 64-character hex string. Re-hashing the 64-hex ASCII string produced a completely different SHA-256 digest, resulting in contract calls failing with OrderNotFound.

Key Changes

  1. Helper resolveOrderIdHash in lib/stellar/orders.ts:
    • Pure, robust resolver that checks if orderId matches a 64-character hex string (^[0-9a-fA-F]{64}$, with optional 0x prefix and trimmed whitespace).
    • If already a 64-hex hash, it converts it directly via hexToBytes without re-hashing.
    • If a short raw pre-image (e.g. "SS-2024-0001"), it computes SHA-256 via hashOrderId.
  2. Usage in Order Management Operations:
    • Used in dispatchOrder, refundOrder, and readOrder in lib/stellar/orders.ts.
    • Leaves app/admin/orders/page.tsx passing the indexer event-derived hex ID unmodified.
  3. Comprehensive Unit Tests:
    • tests/lib/stellar/orders.test.ts: Verifies 64-hex bypass (lower/upper/mixed case, 0x prefix, whitespace) and SHA-256 computation for raw pre-images.
    • tests/app/admin/orders-dispatch.test.tsx: Asserts the admin page passes the event-derived hex ID directly to dispatchOrder and refundOrder without modification.

Verification (2x Verified)

  • npx vitest run tests/lib/stellar/orders.test.ts tests/app/admin/orders-dispatch.test.tsx (8/8 tests pass, 0 warnings)
  • npm run type-check (0 errors)
  • npm run lint (0 errors)
  • npx prettier --check (100% formatted)

Closes #67

Copilot AI lite review requested due to automatic review settings September 4, 2026 21:36
@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

@Ranjeet2063 is attempting to deploy a commit to the Oluremi's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

[Bounty: $100] Admin dispatch/refund re-hash the event-derived order id so they can never match the on-chain order

2 participants