Commit graph

21 commits

Author SHA1 Message Date
Håvard Kittelsen
34f5bcb6b7 docs: correct the integration test path, note two things easy to get wrong 2026-08-19 08:00:20 +00:00
Håvard Kittelsen
dcda4fce6a fix(wallet): deliver the courtesy disconnect before tearing the relay down
doDisconnect fired the courtesy `disconnect` message without awaiting it, then
tore the relay connection down on the next line:

    conn.client.relay(disconnectMsg).catch(() => {});   // fire and forget
    ...
    conn.cleanup();                                      // closes the pool underneath it

relay() resolves only after `Promise.allSettled(pool.publish(...))` — a real
round trip to every configured relay. cleanup() closed the pool while that
publish was still in flight, so the message usually never left and the dapp went
on believing the wallet was connected until its own liveness timeout fired.
Downstream wallets were patching this out of the published package.

Teardown now splits into two halves with opposite timing requirements.

Registry removal stays synchronous. getConnections() is what a UI renders, and
connect() returns an existing connection for a URI, so leaving this one in the
map while its teardown is pending would hand a caller a dying connection. This
is the one place this differs from !30 and from the downstream patches, which
defer the registry removal along with the teardown.

Relay teardown is deferred until the publish settles, bounded by
DISCONNECT_PUBLISH_TIMEOUT_MS (5s). The bound matters: "the publish never
settles" is exactly the case where a relay is unreachable, and a socket that is
never closed is worse than a courtesy message that is never delivered.

disconnect() keeps its synchronous void signature — not a breaking change.

Why it shipped broken: disconnect.test.ts only covered dapp → wallet. Nothing
exercised wallet → dapp, and the failure is invisible from the wallet's side —
its own state is correct either way, and only the peer notices.
disconnect-delivery.test.ts covers that direction over a live relay, including
the two invariants the deferral must not break (registry cleared immediately,
URI reusable afterwards).

Also fixes a latent hang in the integration harness that the new file exposed.
setupConnection gated both the dapp_ready send and the message handler inside
the keyexchangecomplete callback, so the handshake hung on receiving the wallet's
single wallet_ready for the cycle. Miss it — the dapp's subscription can come up
after the wallet has already published — and key exchange never resolves, the
handler never registers, no dapp_ready is ever sent, and the wallet, guarded by
walletReadySentThisCycle, has nothing prompting it to retry. It now re-announces
dapp_ready(wallet_discovered=false) every 2s until key exchange completes, which
resets that guard and earns another wallet_ready: the recovery path mutual
discovery already specifies, which the harness was not using. Plus retry: 2 on
the integration config, since these tests talk to live relays and a dropped
connection is an environment failure rather than a regression.

docs/wallet.md gains a "Sending disconnect" section for the synchronous/deferred
split and what a caller may rely on. docs/protocol.md gains the sender-side half
of the courtesy-disconnect semantics, which previously read as though "no
acknowledgement" licensed fire-and-forget. That reading is what produced the bug.

The race was diagnosed and first fixed by hantyrram (Ronaldo Ramano) in !30,
which this supersedes — the deferral is their fix; this changes only how it is
scoped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 16:29:34 +02: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
Dagur Valberg Johannsson
22601be42d
Detect stale tcp connections to relay
Enable nostr-tools' internal stale tcp connection detection
2026-04-08 09:47:50 +02:00
Dagur Valberg Johannsson
4bcbef2aae Merge branch 'nicer-react' into 'master'
Add session persistence and refactor dapp manager

See merge request riftenlabs/lib/wizardconnect!19
2026-04-03 15:15:26 +00:00
Dagur Valberg Johannsson
8cd22c34ba
Add session persistence and refactor dapp manager
Keep session persistance by default, such that when reloading a dapp,
the wizardconnect session is kept alive.

Improve signature request interface. Simplify the react API.
2026-04-03 17:11:18 +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
CyberAshven
d1369f5867 docs: standardize extension names to BCR-agreed standard
Replace placeholder 'bip352' / 'bip47_rpa' with the finalized
extension names from the BCR post and BCH Stealth Protocol spec:

- bip352      → bch_stealth_bip352
- bip47_rpa   → rpa_bip47

Add spend_path / scan_path fields to each extension handshake
object, pointing to the hardened gate paths where the wallet
exports xpubs. Dapps derive the non-hardened /0 child locally.

Add rpa_spend / rpa_scan path names alongside stealth_spend /
stealth_scan in all examples. Update known extensions table with
full path information and BCR reference links.

Spec: https://bitcoincashresearch.org/t/ecdh-stealth-addresses-on-bitcoin-cash-implementation-code/1773/5

I have read the CLA Document and I hereby sign the CLA
2026-03-28 22:39:34 +03: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
889dd566d1
Add serialization helpers to @wizardconnect/core
Canonical encoding for BigInt (<bigint: Xn>) and Uint8Array (hex or
<Uint8Array: 0x...>) used in the relay protocol. Provides both
serialization (sourceOutputToRelay, transactionToHex) and deserialization
(parseExtendedJson, toUint8Array, toBigInt) so dapps and wallets
don't have to implement this independently.
2026-03-23 08:59:02 +01:00
Dagur Valberg Johannsson
a22d98a6b2 Merge branch 'doc-xpub' into 'master'
doc: An article on xpub sharing

See merge request riftenlabs/lib/wizardconnect!8
2026-03-23 07:45:38 +00:00
Dagur Valberg Johannsson
8467856975
Persist xpub paths in session storage for offline pubkey derivation
The useWizardConnect hook now saves PathXpub[] from wallet_ready into
the localStorage session. On auto-reconnect, restoreSessionPaths() is
called so getPubkey() works immediately without waiting for the wallet.
Corrupt cached paths are cleared with a warning.
2026-03-23 08:32:17 +01:00
Dagur Valberg Johannsson
add06b6476
Add getSessionPaths() and restoreSessionPaths() to DappConnectionManager
Allows dapps to cache the raw PathXpub[] from wallet_ready and restore
them on subsequent page loads. restoreSessionPaths decodes the xpub strings
and populates pubkeyState so getPubkey() works without waiting for the
wallet to reconnect. Throws on invalid xpub data.
2026-03-23 08:26:12 +01:00
Dagur Valberg Johannsson
45fd9f4cb5
Add 'react' package with QR code and modal dialog
Makes it easier for dapp developers to integrate WizardConnect and have
consistent user interface for it across dapps.
2026-03-18 16:34:41 +01:00
Dagur Valberg Johannsson
55ff82bbec
Document SIGHASH_ALL requirement 2026-03-18 10:31:06 +01:00
Dagur Valberg Johannsson
b40303c52a
doc: An article on xpub sharing 2026-03-17 14:47:04 +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
6fce9b47cb
First commit for WizardConnect 2026-03-06 11:38:09 +01:00