fix: validate Horizon and Soroban RPC responses - #177
Open
jeremytsng wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens packages/snap network integrations by validating the specific Horizon and Soroban RPC response fields the Snap consumes, so malformed payloads fail early with NetworkServiceException instead of leaking undefined deeper into mapping logic.
Changes:
- Added a reusable
assertNetworkResponsehelper that wraps Superstruct validation errors asNetworkServiceException. - Introduced Superstruct schemas for the consumed Horizon/RPC response shapes and enforced them across
NetworkServiceread paths. - Expanded
NetworkServicetest coverage to ensure malformed responses surface the new validation errors.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/snap/src/services/network/utils.ts | Adds a shared response-validation helper used by network calls. |
| packages/snap/src/services/network/NetworkService.ts | Applies response validation to Horizon/RPC calls before mapping/consuming fields. |
| packages/snap/src/services/network/NetworkService.test.ts | Adds tests ensuring malformed responses throw the intended validation errors. |
| packages/snap/src/services/network/api.ts | Defines Superstruct schemas for Horizon and Soroban RPC response subsets used by the Snap. |
| packages/snap/snap.manifest.json | Updates Snap bundle shasum for the new build output. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| response: unknown, | ||
| struct: Struct<Validated>, | ||
| message: string, | ||
| ): void { |
| num_sponsoring: optional(number()), | ||
| num_sponsored: optional(number()), | ||
| data_attr: optional(record(string(), string())), | ||
| balances: optional(array(HorizonBalanceLineStruct)), |
Adds superstruct validation for the fields the snap consumes from Horizon and Soroban RPC responses, so malformed payloads fail fast with a NetworkServiceException instead of propagating undefined values into account, fee, transaction and asset mapping.
jeremytsng
force-pushed
the
fix/horizon-api-response-validation
branch
from
August 11, 2026 08:33
cc9bf3f to
40558fe
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.
Adds superstruct validation for the fields the snap consumes from Horizon and Soroban RPC responses, so malformed payloads fail fast with a NetworkServiceException instead of propagating undefined values into account, fee, transaction and asset mapping.
Explanation
References
Checklist