Commit graph

14 commits

Author SHA1 Message Date
Håvard Kittelsen
a919735874 fix(wallet): bound the deferral, keep the registry synchronous, add tests
Builds on the previous commit, which correctly identified the race and the shape
of the answer. Three things needed to change before it could ship, and the reason
each matters is easy to miss.

DEFER THE TEARDOWN, NOT THE REGISTRY

The previous commit moved everything into clean(), including
this.connections.delete() and the connectionsChanged emit. That leaves the
connection in the map until the publish settles, so after disconnect() returns:

  - getConnections() still lists a connection the user just disconnected;
  - connect() matches by URI at the top of the function, so reconnecting to the
    same URI hands back the dying connection — which clean() then deletes,
    leaving the caller holding an id for something already gone.

Registry removal is now synchronous and only conn.cleanup() — the transport
teardown, the part that was killing the in-flight publish — is deferred.

BOUND THE WAIT

There was no timeout: if relay() never settles, clean() never runs and the
interval, the socket and the map entry leak permanently. That is not a corner
case. relay() enqueues rather than publishes when the client is not ready, so
disconnecting while the relay is unreachable — precisely when a user reaches for
disconnect — can hang forever. DISCONNECT_PUBLISH_TIMEOUT_MS bounds it: an
undelivered courtesy message is a smaller problem than a socket that never
closes.

RESTORE THE TYPES

doDisconnect had lost its parameter annotations and its `private` modifier, and
the message literal its DisconnectMessage type. Under "strict": true that is
TS7006 on both parameters — the package does not compile — and dropping `private`
widened the public API by accident. Formatting is back to the repo's prettier
config.

TESTS

None of the above is visible from the wallet's side: its own state is correct
either way and only the peer notices, which is how the original bug shipped.
disconnect.test.ts only ever covered dapp -> wallet.

disconnect-delivery.test.ts covers wallet -> dapp over a live relay. Verified by
reverting the fix: the two delivery tests time out after 20s, and the two
invariant tests — immediate registry removal, and reconnecting on the same URI —
pass either way, which is precisely why they are there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-14 08:45:16 +02:00
hantyrram
d907c2c1b0 fix(wizardconnect): defer connection cleanup until relay disconnect completes
- `conn.cleanup()` calls `client.disconnect()` which closes the WebSocket
transport.
- In the old code, cleanup ran synchronously right after `conn.client.relay(disconnectMsg)`, so the transport was torn down before the async relay message could be transmitted. The error was silently swallowed by `.catch(() => {})` — the disconnect message was never actually sent to the dapp.
2026-05-25 14:03:14 +08:00
jakobsn
443acccb80 Active reconnect. 2026-04-29 09:06:53 +00:00
Dagur Valberg Johannsson
b96cb8e151
Add chunk transport extension for oversized messages
Splits ProtocolMessages exceeding NIP-44's 65,535-byte plaintext ceiling
across multiple gift-wrapped events. Symmetric (both directions),
fire-and-forget, backward-compatible via a new transport-level
\`extensions\` field on \`dapp_ready\` and \`wallet_ready\`. Resolves the
\"Failed to swap: invalid plaintext size\" error on aggregated swap
requests and enables signed-tx responses up to the 1 MB BCH consensus
limit (~2 MB hex).
2026-04-21 14:58:12 +02:00
Dagur Valberg Johannsson
ef56fb198c
Add additional default relay
For improved reliability, this adds an additional relay as a redundancy.
2026-04-14 08:42:34 +02:00
jakobsn
e852e70a8e Dedup connection: conn.dappDiscovered = false; 2026-04-03 12:35:50 +00:00
Dagur Valberg Johannsson
08ea3da6aa
Re-send signature request on ready
User may need some time to open their wallet to approve signature
request and miss it.

If we have a active request, re-send it if we see a
wallet_ready signal, suggesting the wallet was just opened.
2026-04-03 13:22:40 +02:00
Dagur Valberg Johannsson
4d1ba8e207
Add 'extensions' to hdwalletv1 protocol
This backward compatible change allows wallets/dapps to add additional
features outside the basic transaction signature support to the
hdwalletv1 protocol.
2026-03-26 10:50:40 +01:00
Dagur Valberg Johannsson
81a67825fe
Don't require input path for all inputs
Not all inputs need a signature; only require it for the input paths
that do.
2026-03-16 16:54:32 +01:00
Dagur Valberg Johannsson
8ef04218b4
Add input paths for a signature request
This solves an issue where wallet has to scan address ranges for each
derivation path and match it to locking script to figure out what
private key to use for signature.

This is a waste of effort and unnecessary complex for wallet
implementations since the dapp side already knows what inputs its using.
2026-03-16 15:27:18 +01:00
Dagur Valberg Johannsson
0e54217929
Second attempt at trusted publishing 2026-03-09 17:05:45 +01:00
Dagur Valberg Johannsson
c681983883
Add uri to relay private key generation
Making private key deterministic allows for easy session restoration
2026-03-09 15:36:52 +01:00
Dagur Valberg Johannsson
c564492473
Add CI/CD 2026-03-06 15:15:17 +01:00
Dagur Valberg Johannsson
6fce9b47cb
First commit for WizardConnect 2026-03-06 11:38:09 +01:00