fix(wallet-sdk): keep the envelope id when bridge re-sends after ready#40
Open
Jr-kenny wants to merge 1 commit into
Open
fix(wallet-sdk): keep the envelope id when bridge re-sends after ready#40Jr-kenny wants to merge 1 commit into
Jr-kenny wants to merge 1 commit into
Conversation
bridge() in waitForReady mode returned one id to the caller but put a fresh uuid on the wire, so envelope-id correlation never matched. Thread the original id through to.send instead of regenerating it.
|
@Jr-kenny is attempting to deploy a commit to the Abstract Foundation Team on Vercel. A member of the Team first needs to authorize it. |
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.
Fixes #39.
Problem
When a bridge is created with
waitForReady: true(what the iframe transport uses), every non-ready send goes through the deferred branch inbridge(). That branch hands the caller back an envelope{ id }straight away, but oncereadyPromiseresolves it re-sends throughto.send(...), andfromWindow's ownsendgenerates a fresh uuid for the envelope. So the id the caller gets is never the id that actually goes out on the wire. The comment right there ("Re-send with the same id so request/response correlation holds") says what it's meant to do, the code just regenerates the id instead.The current EIP-1193 flow doesn't notice because it correlates on the JSON-RPC request id inside the payload, not the envelope id. But the messenger exposes
on(topic, listener, id)for correlating by envelope id, and that path can't match today.Fix
Let the id flow through instead of regenerating it.
Messenger.sendnow takes an optional trailingid,fromWindowuses it when given and falls back to a fresh uuid otherwise, andbridgepasses the id it already returned into the deferred re-send. The new param is optional and last so nothing else has to change.Testing
Added a
bridgetest inMessenger.test.tsthat queues a send before ready, fires the ready message, then checks the id on the flushed envelope against whatsend()returned. It fails before this change and passes after.Patch changeset included.
Thanks!