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

Copy link
Copy Markdown
Contributor

Explanation

The Tron Snap handled scopes and networks coming from untrusted boundaries (RPC request params, the Keyring API) with forced casts (chainId as Network, scope as Network), 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 isNetwork (type guard) and assertNetwork (throws InvalidParamsError) next to Network in constants.
  • Adds parseTronCaipAssetType in utils/caip.ts to parse CAIP asset types into Tron scopes without casts.
  • Derives client network maps from Object.values(Network) and asserts supported networks at handler boundaries.
  • Renames the Tron keyring account entity type for local type consistency.

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

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