Skip to content

fix(wallet-sdk): keep the envelope id when bridge re-sends after ready#40

Open
Jr-kenny wants to merge 1 commit into
Abstract-Foundation:mainfrom
Jr-kenny:fix/wallet-sdk-bridge-deferred-id
Open

fix(wallet-sdk): keep the envelope id when bridge re-sends after ready#40
Jr-kenny wants to merge 1 commit into
Abstract-Foundation:mainfrom
Jr-kenny:fix/wallet-sdk-bridge-deferred-id

Conversation

@Jr-kenny

Copy link
Copy Markdown

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 in bridge(). That branch hands the caller back an envelope { id } straight away, but once readyPromise resolves it re-sends through to.send(...), and fromWindow's own send generates 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.send now takes an optional trailing id, fromWindow uses it when given and falls back to a fresh uuid otherwise, and bridge passes 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 bridge test in Messenger.test.ts that queues a send before ready, fires the ready message, then checks the id on the flushed envelope against what send() returned. It fails before this change and passes after.

pnpm --filter @abstract-foundation/wallet-sdk test        # 18 passed
pnpm --filter @abstract-foundation/wallet-sdk typecheck
pnpm --filter @abstract-foundation/wallet-sdk build
pnpm --filter @abstract-foundation/wallet-sdk test:build  # publint + attw clean
pnpm ci:lint

Patch changeset included.

Thanks!

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.
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@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.

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.

wallet-sdk: Messenger.bridge sends a different envelope id than the one returned to the caller

1 participant