fix(batchService): expose hash+notes on public batch so Track Batch verification works - #1353
Open
saidai-bhuvanesh wants to merge 1 commit into
Conversation
|
@openhands-agent is attempting to deploy a commit to the Nitya Gosain's projects Team on Vercel. A member of the Team first needs to authorize it. |
…erification works toPublicBatch stripped the hash (and notes) from each update when building the public /batches/public/:id response. The client's verifyHashChain() treats a missing hash as a break in the ledger (return false), so every public batch was flagged as 'LEDGER INTEGRITY BREACH: TAMPERING DETECTED' even when legitimate. notes is also part of the hash serialization on both server (calculateUpdateHash) and client (verifyHashChain), so stripping it made verification impossible even with the hash. notes is provenance text the timeline already renders as each update's description, and hash is the tamper-evident chain hash consumers verify. Update the public-batch test to assert notes/hash are present. Closes Nitya-003#1338
saidai-bhuvanesh
force-pushed
the
fix/1338-public-batch-hash-chain-verification
branch
from
August 15, 2026 03:41
de3a471 to
a10c15c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1338
The public Track Batch page (
/track-batch) flags every legitimate batch as "LEDGER INTEGRITY BREACH: TAMPERING DETECTED", making the tracking page unusable:Every public batch is flagged as tampered.
toPublicBatch(backend/services/batchService.js) stripped thehashfield from each update when building the public response. The client'sverifyHashChain()(frontend/src/utils/crypto.ts) treats a missinghashas a break in the ledger (return false), sosetIsTampered(true)fires for every public batch — consumers scanning a QR code see a false tamper banner even though the batch is legitimate.Hash-chain verification can never succeed even with the hash.
calculateUpdateHash(server) andverifyHashChain(client) both serializenotesinto the hash input. SincetoPublicBatchalso strippednotes, the client would recompute the hash withnotes=""while the server used the real notes → guaranteed mismatch.Fix
backend/services/batchService.js—toPublicBatchnow exposesnotesandhashon each public update:updates: (batchData.updates || []).map((update) => ({ stage: update.stage, actor: update.actor, location: update.location, timestamp: update.timestamp, + notes: update.notes, // part of hash serialization + rendered as the update description + hash: update.hash, // required by client verifyHashChain() })),Why exposing
notes/hashpublicly is correctnotesis supply-chain provenance text (e.g. "Initial harvest recorded", "Arrived at mandi") that the Track Batch timeline already renders as each update's description (description: update.notes || ...). It is intentionally public provenance, not private data.hashis a SHA-256 of the public update fields + previous hash. Exposing it is the entire point of a tamper-evident ledger — consumers verify the chain client-side._id,farmerId,farmerAddress,farmerWalletAddress,blockchainHash,syncStatus,pendingApprovalId,approvalHistory) remain stripped.Test
backend/tests/batch.test.js— the public-batch test previously assertedupdates[0]has nonotes(encoding the buggy behavior). Updated to assertnotesandhashare present, and the mock update now carries ahashreflecting the real schema.Scope / related
This PR is scoped strictly to the
toPublicBatchhash/notes defect (#1338). A separate pre-existingSyntaxErrorinbackend/services/batchService.js(an orphaned EOF.catch) is tracked by #1227 and fixed in PR #1274; once #1274 lands,node --checkpasses on this file and the full Jest suite for the public-batch test runs end-to-end. This PR's hunk applies cleanly on top of #1274 (no overlap).Files
backend/services/batchService.jsbackend/tests/batch.test.jsThis PR was created by an AI agent (OpenHands) on behalf of @saidai-bhuvanesh.