Skip to content

refactor(tron-wallet-snap): guarantee local type consistency for networks - #403

Draft
ulissesferreira wants to merge 1 commit into
mainfrom
WPN-2226-guarantee-snap-local-type-consistency-for-networks-in-tron
Draft

ulissesferreira wants to merge 1 commit into
mainfrom
WPN-2226-guarantee-snap-local-type-consistency-for-networks-in-tron

Conversation

@ulissesferreira

@ulissesferreira ulissesferreira commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

The Tron Snap handled scopes and networks coming from untrusted boundaries (RPC request params, the Keyring API, the AssetsController) with forced casts (chainId as Network, scope as Network, assetType as CaipAssetType), silently accepting values the Snap does not control and indexing Networks[...] with them.

This PR replaces those casts with runtime assertions and type-safe helpers so the Network, scope, and CAIP asset types stay consistent within the Snap:

  • Adds isSupportedNetwork (type guard) and assertSupportedNetwork (throws InvalidParamsError) next to Network in constants.
  • Adds parseTronCaipAssetType in utils/caip.ts to parse CAIP asset types into Tron scopes without casts.
  • Validates every incoming scope/asset type at the handler boundaries (client request, keyring, cronjob) with superstruct structs or the assertion helpers.
  • Types internal state, accounts, and asset maps with the narrower local types (TronKeyringAccount, Network-keyed scopes) instead of the broad shared-package types, asserting at the boundary where values come in.
  • Narrows SNAP_OWNED_ASSETS to readonly CaipAssetType[] and derives client network maps from Object.values(Network).

Supersedes #394 / #402 (branch renamed and scope reduced to the type-consistency changes only).

Ticket: WPN-2226

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@ulissesferreira
ulissesferreira force-pushed the WPN-2226-guarantee-snap-local-type-consistency-for-networks-in-tron branch from 5ab0e9c to 6e91079 Compare October 2, 2026 18:08
@ulissesferreira
ulissesferreira force-pushed the WPN-2226-guarantee-snap-local-type-consistency-for-networks-in-tron branch from 6e91079 to ab3162c Compare October 2, 2026 18:14

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.

1 participant