@aztec/wallet-sdk 0.0.1-commit.fff30aa → 0.0.1-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dest/base-wallet/base_wallet.d.ts +10 -2
  2. package/dest/base-wallet/base_wallet.d.ts.map +1 -1
  3. package/dest/base-wallet/base_wallet.js +19 -4
  4. package/dest/extension/handlers/background_connection_handler.d.ts +12 -2
  5. package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -1
  6. package/dest/extension/handlers/background_connection_handler.js +44 -8
  7. package/dest/extension/handlers/content_script_connection_handler.d.ts +2 -1
  8. package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -1
  9. package/dest/extension/handlers/content_script_connection_handler.js +19 -0
  10. package/dest/extension/handlers/internal_message_types.d.ts +3 -1
  11. package/dest/extension/handlers/internal_message_types.d.ts.map +1 -1
  12. package/dest/extension/handlers/internal_message_types.js +3 -1
  13. package/dest/extension/provider/extension_wallet.d.ts +26 -3
  14. package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
  15. package/dest/extension/provider/extension_wallet.js +78 -7
  16. package/dest/iframe/handlers/iframe_connection_handler.d.ts +6 -2
  17. package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -1
  18. package/dest/iframe/handlers/iframe_connection_handler.js +16 -4
  19. package/dest/iframe/provider/iframe_wallet.d.ts +20 -3
  20. package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -1
  21. package/dest/iframe/provider/iframe_wallet.js +77 -8
  22. package/dest/types.d.ts +52 -2
  23. package/dest/types.d.ts.map +1 -1
  24. package/dest/types.js +25 -0
  25. package/package.json +8 -8
  26. package/src/base-wallet/base_wallet.ts +19 -2
  27. package/src/extension/handlers/background_connection_handler.ts +42 -9
  28. package/src/extension/handlers/content_script_connection_handler.ts +18 -0
  29. package/src/extension/handlers/internal_message_types.ts +2 -0
  30. package/src/extension/provider/extension_wallet.ts +92 -6
  31. package/src/iframe/handlers/iframe_connection_handler.ts +19 -5
  32. package/src/iframe/provider/iframe_wallet.ts +101 -7
  33. package/src/types.ts +59 -0
package/src/types.ts CHANGED
@@ -25,6 +25,13 @@ export enum WalletMessageType {
25
25
  SECURE_RESPONSE = 'aztec-wallet-secure-response',
26
26
  /** Session disconnected notification */
27
27
  SESSION_DISCONNECTED = 'aztec-wallet-session-disconnected',
28
+ /** Liveness probe sent by the dApp while a request is in flight */
29
+ PING = 'aztec-wallet-ping',
30
+ /** Liveness response from the wallet. Any inbound message (including a regular
31
+ * encrypted response) is treated as proof of liveness, so a missing PONG alone
32
+ * never trips disconnect — the dApp also resets its liveness timer on traffic.
33
+ */
34
+ PONG = 'aztec-wallet-pong',
28
35
  }
29
36
 
30
37
  /**
@@ -143,3 +150,55 @@ export interface KeyExchangeResponse {
143
150
  * Callback invoked when a wallet connection is disconnected.
144
151
  */
145
152
  export type DisconnectCallback = () => void;
153
+
154
+ /**
155
+ * Default heartbeat tuning shared by both transports.
156
+ *
157
+ * - `intervalMs`: how often the dApp sends PING probes while a request is in flight.
158
+ * - `deadAfterMs`: how long the channel can stay silent (no PONG, no encrypted
159
+ * response, no DISCONNECT) before the dApp declares the wallet unreachable
160
+ * and rejects all in-flight requests. Generous enough that long-running
161
+ * operations (proveTx, sendTx) on legacy wallets that don't reply to PING
162
+ * still succeed — any inbound traffic resets the timer.
163
+ */
164
+ export const DEFAULT_HEARTBEAT_INTERVAL_MS = 5_000;
165
+ export const DEFAULT_HEARTBEAT_DEAD_AFTER_MS = 300_000;
166
+
167
+ /** Override knobs for the heartbeat — mostly useful for tests. */
168
+ export interface HeartbeatOptions {
169
+ /** How often to send PING probes while a request is in flight (ms). */
170
+ intervalMs?: number;
171
+ /** Idle ceiling before declaring disconnect (ms). */
172
+ deadAfterMs?: number;
173
+ }
174
+
175
+ /**
176
+ * Minimal logger surface used by the wallet SDK.
177
+ *
178
+ * Defined locally so that wallet hosts (browser extensions, iframe wallet pages)
179
+ * can pass a simple `console`-backed logger without pulling in the full
180
+ * `@aztec/foundation` logging runtime, which is non-trivial to bundle in those
181
+ * contexts. Structurally compatible with `Logger` from `@aztec/foundation/log`,
182
+ * so dApp-side callers can pass that type directly.
183
+ */
184
+ export interface WalletSdkLogger {
185
+ /** Diagnostic messages — typically discarded in production. */
186
+ debug: (message: string, data?: unknown) => void;
187
+ /** Informational messages — significant lifecycle events. */
188
+ info: (message: string, data?: unknown) => void;
189
+ /** Recoverable problems — channel decryption failure, missed heartbeats, etc. */
190
+ warn: (message: string, data?: unknown) => void;
191
+ /** Errors that prevent normal operation. */
192
+ error: (message: string, errOrData?: unknown, data?: unknown) => void;
193
+ }
194
+
195
+ /**
196
+ * No-op logger used as the default when callers don't provide one. Discards all
197
+ * messages — wallet hosts that want diagnostics should pass their own logger.
198
+ */
199
+ export const NOOP_LOGGER: WalletSdkLogger = {
200
+ debug: () => {},
201
+ info: () => {},
202
+ warn: () => {},
203
+ error: () => {},
204
+ };