Skip to content

Fix: Correct response data indexing for saveShards function#137

Merged
ravish1729 merged 1 commit intomainfrom
v0.4.3
Sep 27, 2025
Merged

Fix: Correct response data indexing for saveShards function#137
ravish1729 merged 1 commit intomainfrom
v0.4.3

Conversation

@aakash-taneja
Copy link
Collaborator

@aakash-taneja aakash-taneja commented Sep 27, 2025

PR Type

Bug fix


Description

  • Fix response data indexing in saveShards function call

  • Change from responseData.Hash to responseData[0].Hash


Diagram Walkthrough

flowchart LR
  A["Response Data"] --> B["Incorrect: responseData.Hash"]
  A --> C["Correct: responseData[0].Hash"]
  C --> D["saveShards Function"]
Loading

File Walkthrough

Relevant files
Bug fix
browser.ts
Fix response data array indexing                                                 

src/Lighthouse/uploadEncrypted/encrypt/text/browser.ts

  • Fix indexing of response data from responseData.Hash to
    responseData[0].Hash
  • Correct array access pattern for hash extraction
+1/-1     

@codiumai-pr-agent-free
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Type Safety

The code uses as any for the response data which bypasses TypeScript's type checking. Consider defining a proper interface for the response structure to improve type safety and prevent similar indexing errors in the future.

const responseData = (await response.json()) as any

@codiumai-pr-agent-free
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Add validation for API response

Add validation for the responseData from the API. Check that it is a non-empty
array and contains the expected Hash property before accessing
responseData[0].Hash to prevent potential runtime errors.

src/Lighthouse/uploadEncrypted/encrypt/text/browser.ts [50-57]

 const responseData = (await response.json()) as any
+
+if (!Array.isArray(responseData) || responseData.length === 0 || !responseData[0].Hash) {
+  throw new Error('Invalid response data from Lighthouse node.')
+}
 
 const { error } = await saveShards(
   publicKey,
   responseData[0].Hash,
   signedMessage,
   keyShards
 )

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential runtime error introduced by the PR's change. Adding validation for the API response responseData before accessing its elements is a good practice that improves the code's robustness.

Medium
  • More

@ravish1729 ravish1729 merged commit 7f8f69a into main Sep 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants