@rhinestone/1auth 0.6.5 → 0.6.7

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.
@@ -283,55 +283,19 @@ interface IntentTokenRequest {
283
283
  /** Amount in base units (use parseUnits for decimals) */
284
284
  amount: bigint;
285
285
  }
286
- /**
287
- * A signed intent request from a backend.
288
- * This provides XSS protection by ensuring calls were constructed server-side.
289
- */
290
- interface DeveloperSignedIntent {
291
- /** Developer ID (clientId). Mapped to merchantId for the API. */
292
- developerId?: string;
293
- /** Wire field used by the API (same value as developerId) */
294
- merchantId?: string;
295
- /** Target chain ID */
296
- targetChain: number;
297
- /** Calls to execute (signed by developer) */
298
- calls: IntentCall[];
299
- /** Username of the signer */
300
- username?: string;
301
- /** Alternative to username: account address */
302
- accountAddress?: string;
303
- /** Unique nonce for replay protection */
304
- nonce: string;
305
- /** Expiry timestamp (Unix ms) */
306
- expiresAt: number;
307
- /** Ed25519 signature over the canonical message (base64) */
308
- signature: string;
309
- /** Optional client ID */
310
- clientId?: string;
311
- /** Optional token requests */
312
- tokenRequests?: IntentTokenRequest[];
313
- }
314
- type IntentSigner = (params: {
315
- username: string;
316
- accountAddress?: string;
317
- targetChain: number;
318
- calls: IntentCall[];
319
- tokenRequests?: IntentTokenRequest[];
320
- sourceAssets?: string[];
321
- }) => Promise<DeveloperSignedIntent>;
322
286
  /**
323
287
  * Options for sendIntent
324
288
  */
325
289
  interface SendIntentOptions {
326
- /** Username of the signer (for unsigned requests) */
290
+ /** Username of the signer */
327
291
  username?: string;
328
- /** Account address of the signer (alternative to username for unsigned requests) */
292
+ /** Account address of the signer (alternative to username) */
329
293
  accountAddress?: string;
330
- /** Target chain ID (for unsigned requests) */
294
+ /** Target chain ID */
331
295
  targetChain?: number;
332
- /** Calls to execute on the target chain (for unsigned requests) */
296
+ /** Calls to execute on the target chain */
333
297
  calls?: IntentCall[];
334
- /** Optional token requests (for unsigned requests) */
298
+ /** Optional token requests */
335
299
  tokenRequests?: IntentTokenRequest[];
336
300
  /**
337
301
  * Constrain which tokens can be used as input/payment.
@@ -347,11 +311,6 @@ interface SendIntentOptions {
347
311
  sourceChainId?: number;
348
312
  /** When to close the dialog and return success. Defaults to "preconfirmed" */
349
313
  closeOn?: CloseOnStatus;
350
- /**
351
- * Pre-signed intent from developer backend (XSS protected)
352
- * If provided, username/targetChain/calls/tokenRequests are ignored
353
- */
354
- signedIntent?: DeveloperSignedIntent;
355
314
  /**
356
315
  * Wait for a transaction hash before resolving.
357
316
  * Defaults to false to preserve existing behavior.
@@ -792,23 +751,58 @@ interface RequestConsentResult {
792
751
  declare class OneAuthClient {
793
752
  private config;
794
753
  private theme;
754
+ /**
755
+ * Create a new OneAuthClient.
756
+ *
757
+ * Normalizes the config (filling in default URLs), then immediately injects
758
+ * `<link rel="preconnect">` tags for the passkey domain so that DNS lookup
759
+ * and TLS handshake start before the first dialog is opened, shaving
760
+ * noticeable latency from the first user interaction.
761
+ *
762
+ * @param config - Client configuration including optional providerUrl, dialogUrl,
763
+ * clientId, theme, and redirect settings.
764
+ */
795
765
  constructor(config: PasskeyProviderConfig);
796
766
  /**
797
767
  * Update the theme configuration at runtime
798
768
  */
799
769
  setTheme(theme: ThemeConfig): void;
800
770
  /**
801
- * Build theme URL parameters
771
+ * Serialize the active theme into URL query parameters for the dialog.
772
+ *
773
+ * Merges the instance-level theme (set via constructor or `setTheme`) with any
774
+ * per-call override, so callers can temporarily change the appearance for a
775
+ * single dialog invocation without mutating shared state.
776
+ *
777
+ * @param overrideTheme - One-shot theme values that take precedence over the
778
+ * instance theme for this call only.
779
+ * @returns A URL-encoded query string (e.g. `"theme=dark&accent=%230090ff"`),
780
+ * or an empty string if no theme properties are set.
802
781
  */
803
782
  private getThemeParams;
804
783
  /**
805
- * Get the dialog URL (Vite app URL)
806
- * Defaults to providerUrl if dialogUrl is not set
784
+ * Resolve the URL of the dialog app (the Vite/Next.js frontend that renders
785
+ * the WebAuthn UI inside the iframe).
786
+ *
787
+ * `dialogUrl` is a separate config option to support split deployments where
788
+ * the API server and the dialog frontend run at different origins. Falls back
789
+ * to `providerUrl` when not explicitly configured — the common case.
790
+ *
791
+ * @returns The base URL used when constructing all dialog endpoint paths.
807
792
  */
808
793
  private getDialogUrl;
809
794
  /**
810
- * Get the origin for message validation
811
- * Uses dialogUrl origin if set, otherwise providerUrl origin
795
+ * Extract the trusted origin used to validate incoming postMessage events.
796
+ *
797
+ * All `window.addEventListener("message", ...)` handlers in this class check
798
+ * `event.origin` against this value to prevent cross-origin spoofing. Wraps
799
+ * `getDialogUrl()` in a `new URL()` parse so that paths and query strings are
800
+ * stripped — only the scheme + host + port are compared.
801
+ *
802
+ * Falls back to the raw dialog URL string if URL parsing fails (e.g. during
803
+ * unit tests with non-standard URL formats).
804
+ *
805
+ * @returns The scheme + host + optional port of the dialog app (e.g. `"https://passkey.1auth.box"`).
812
806
  */
813
807
  private getDialogOrigin;
814
808
  /**
@@ -819,6 +813,24 @@ declare class OneAuthClient {
819
813
  * Get the configured client ID
820
814
  */
821
815
  getClientId(): string | undefined;
816
+ /**
817
+ * Poll the intent status endpoint until a transaction hash appears or the
818
+ * intent reaches a terminal failure state.
819
+ *
820
+ * This is used after `sendIntent` resolves (with `waitForHash: true`) to
821
+ * continue waiting for the on-chain hash even after the dialog has been
822
+ * dismissed. It is intentionally separate from the in-dialog polling loop so
823
+ * callers that don't need the hash can skip it entirely.
824
+ *
825
+ * Errors during individual poll attempts are swallowed so that transient
826
+ * network issues don't abort the wait prematurely.
827
+ *
828
+ * @param intentId - The Rhinestone intent ID returned by the execute endpoint.
829
+ * @param options.timeoutMs - Maximum wait time in milliseconds (default 120 000).
830
+ * @param options.intervalMs - Time between polls in milliseconds (default 2 000).
831
+ * @returns The transaction hash string, or `undefined` if the deadline was
832
+ * reached or the intent failed/expired before a hash was produced.
833
+ */
822
834
  private waitForTransactionHash;
823
835
  /**
824
836
  * Open the authentication modal (sign in + sign up).
@@ -1027,42 +1039,169 @@ declare class OneAuthClient {
1027
1039
  */
1028
1040
  private sendTransactionStatus;
1029
1041
  /**
1030
- * Wait for the signing result without closing the modal
1042
+ * Listen for a signing result that belongs to a specific `requestId`.
1043
+ *
1044
+ * Used by legacy server-side signing request flows (popup/embed/modal) where
1045
+ * the dialog was pre-loaded with a signing request created via the API. The
1046
+ * `requestId` filter is needed because multiple dialogs may be open or there
1047
+ * may be stale messages from a previous dialog in the queue.
1048
+ *
1049
+ * Resolves on `PASSKEY_SIGNING_RESULT` matching `requestId`, or on
1050
+ * `PASSKEY_CLOSE` (user dismissed the dialog).
1051
+ *
1052
+ * @param requestId - The signing request ID to match against incoming messages.
1053
+ * @param dialog - The `<dialog>` element (opened before this call) used to
1054
+ * `showModal()` so the dialog becomes interactive.
1055
+ * @param _iframe - Unused; kept for signature consistency with other wait helpers.
1056
+ * @param cleanup - Idempotent teardown function that closes and removes the dialog.
1057
+ * @returns A `SigningResult` discriminated union.
1031
1058
  */
1032
1059
  private waitForIntentSigningResponse;
1033
1060
  /**
1034
- * Wait for signing result (simplified - no requestId matching)
1061
+ * Listen for a signing result from the currently open modal dialog.
1062
+ *
1063
+ * Unlike `waitForIntentSigningResponse`, this variant does not filter by
1064
+ * `requestId` because the inline intent flow (sendIntent / signMessage /
1065
+ * signTypedData) owns the dialog exclusively — there is no risk of collisions
1066
+ * from other dialogs.
1067
+ *
1068
+ * Handles two result shapes:
1069
+ * - New "secure flow": dialog executed the intent server-side and returns
1070
+ * only an `intentId` (no signature exposed to the SDK).
1071
+ * - Legacy flow: dialog returns a raw `WebAuthnSignature` for the SDK to
1072
+ * forward to the execute endpoint.
1073
+ *
1074
+ * @param dialog - The `<dialog>` element wrapping the signing iframe.
1075
+ * @param _iframe - Unused; kept for signature consistency with other wait helpers.
1076
+ * @param cleanup - Idempotent teardown that closes and removes the dialog.
1077
+ * @returns A `SigningResult` extended with an optional `signedHash` field
1078
+ * populated when the dialog performs message signing.
1035
1079
  */
1036
1080
  private waitForSigningResponse;
1037
1081
  /**
1038
- * Wait for signing result with auto-refresh support
1039
- * This method handles both signing results and quote refresh requests from the dialog
1082
+ * Listen for a signing result while also handling quote-refresh requests.
1083
+ *
1084
+ * Quotes from the Rhinestone orchestrator have a short TTL (typically ~60 s).
1085
+ * When the user takes too long to review and the quote expires, the dialog
1086
+ * sends `PASSKEY_REFRESH_QUOTE`. This method intercepts that message, calls
1087
+ * the provided `onRefresh` callback to fetch a new quote, and replies with
1088
+ * either `PASSKEY_REFRESH_COMPLETE` (success) or `PASSKEY_REFRESH_ERROR`
1089
+ * (failure) — allowing the dialog to stay open and show the updated fees
1090
+ * without requiring a full restart.
1091
+ *
1092
+ * Once the user confirms or rejects, the promise resolves with the signing
1093
+ * result exactly as `waitForSigningResponse` would.
1094
+ *
1095
+ * @param dialog - The `<dialog>` element wrapping the signing iframe.
1096
+ * @param iframe - The iframe element; used to post refresh messages back.
1097
+ * @param cleanup - Idempotent teardown that closes and removes the dialog.
1098
+ * @param dialogOrigin - Trusted origin for message validation (passed in to
1099
+ * avoid redundant `getDialogOrigin()` calls from the hot path).
1100
+ * @param onRefresh - Async callback that fetches a fresh quote and returns the
1101
+ * updated intent fields, or `null` if the refresh failed.
1102
+ * @returns A `SigningResult` extended with an optional `signedHash`.
1040
1103
  */
1041
1104
  private waitForSigningWithRefresh;
1042
1105
  /**
1043
- * Wait for the dialog to be closed
1106
+ * Wait for the dialog to be explicitly closed by the user or the iframe.
1107
+ *
1108
+ * Resolves on either:
1109
+ * - `PASSKEY_CLOSE` postMessage from the iframe (user clicked the X button
1110
+ * or the dialog programmatically closed itself after showing a result).
1111
+ * - The native `<dialog> close` event (escape key or `dialog.close()` call).
1112
+ *
1113
+ * Calling `cleanup()` before awaiting this is safe — both resolution paths
1114
+ * call `cleanup()` internally but it is idempotent. The primary use case is
1115
+ * keeping the dialog open while the SDK polls for a transaction hash, then
1116
+ * showing the final success/error state before letting the user dismiss.
1117
+ *
1118
+ * @param dialog - The `<dialog>` element to watch.
1119
+ * @param cleanup - Idempotent teardown that closes and removes the dialog.
1044
1120
  */
1045
1121
  private waitForDialogClose;
1046
1122
  /**
1047
- * Inject a preconnect link tag to pre-warm DNS + TLS for a given URL.
1123
+ * Inject a `<link rel="preconnect">` tag for the given URL's origin.
1124
+ *
1125
+ * Browsers use preconnect hints to resolve DNS, perform the TCP handshake,
1126
+ * and negotiate TLS before a resource is actually requested, reducing
1127
+ * time-to-first-byte when the dialog iframe loads. The tag is deduplicated —
1128
+ * if one already exists for the same origin it will not be added again.
1129
+ *
1130
+ * Only called in browser environments (guarded by `typeof document` in the
1131
+ * constructor). Invalid URLs are silently ignored.
1132
+ *
1133
+ * @param url - Any URL whose origin should be preconnected to.
1048
1134
  */
1049
1135
  private injectPreconnect;
1050
1136
  /**
1051
- * Wait for the dialog iframe to signal ready without sending init data.
1052
- * Returns a sendInit function the caller uses once prepare data is available.
1137
+ * Wait for the dialog iframe to signal ready, but defer sending `PASSKEY_INIT`
1138
+ * until the caller decides the time is right.
1139
+ *
1140
+ * This is the deferred variant of `waitForDialogReady`, used by flows that run
1141
+ * the dialog and a background API call in parallel (the "two-phase" approach).
1142
+ * Rather than blocking until both the iframe is ready AND the API call is done,
1143
+ * this method resolves as soon as `PASSKEY_READY` arrives and returns a
1144
+ * `sendInit` callback. The caller invokes `sendInit` once prepare data is
1145
+ * available, which may happen before or after the iframe is ready.
1146
+ *
1147
+ * Timeout: if the iframe never signals ready within 10 seconds (e.g. network
1148
+ * error, origin mismatch), resolves with `{ ready: false }` and calls cleanup.
1149
+ *
1150
+ * @param dialog - The `<dialog>` element wrapping the iframe.
1151
+ * @param iframe - The iframe element that will receive `PASSKEY_INIT`.
1152
+ * @param cleanup - Idempotent teardown that closes and removes the dialog.
1153
+ * @returns `{ ready: true, sendInit }` when the iframe is ready, or
1154
+ * `{ ready: false }` if the dialog was closed or timed out first.
1053
1155
  */
1054
1156
  private waitForDialogReadyDeferred;
1055
1157
  /**
1056
- * Prepare an intent by calling the orchestrator for a quote.
1057
- * Returns the prepare response and the origin tier from the response header.
1158
+ * Call the passkey service to obtain a Rhinestone orchestrator quote for an
1159
+ * intent (a single target-chain transaction or swap).
1160
+ *
1161
+ * The service contacts the Rhinestone orchestrator, which returns a signed
1162
+ * `intentOp` structure containing the quote, fees, and a WebAuthn challenge
1163
+ * the user must sign to authorize execution.
1164
+ *
1165
+ * The `X-Origin-Tier` response header is forwarded to the dialog so it can
1166
+ * display tier-specific UI (e.g. "Free" vs "Premium" badge).
1167
+ *
1168
+ * Side effect: if the server returns "User not found", the cached user entry
1169
+ * is removed from `localStorage` to force re-authentication.
1170
+ *
1171
+ * @param requestBody - Serialized intent options (bigint amounts converted to
1172
+ * strings before this call).
1173
+ * @returns On success: `{ success: true, data: PrepareIntentResponse, tier }`.
1174
+ * On failure: `{ success: false, error: { code, message } }`.
1058
1175
  */
1059
1176
  private prepareIntent;
1060
1177
  /**
1061
- * Prepare a batch intent by calling the orchestrator for quotes on all intents.
1178
+ * Call the passkey service to obtain orchestrator quotes for all intents in a
1179
+ * batch, returning a single shared WebAuthn challenge.
1180
+ *
1181
+ * The service prepares each intent independently and assembles a merkle tree
1182
+ * whose root becomes the challenge. Signing that root once authorizes every
1183
+ * intent in the batch. Partially-failed batches are supported: the response
1184
+ * includes both `intents` (succeeded) and `failedIntents` (per-intent errors),
1185
+ * so the dialog can still show the successful subset for signing.
1186
+ *
1187
+ * Side effect: same "User not found" localStorage cleanup as `prepareIntent`.
1188
+ *
1189
+ * @param requestBody - Serialized batch options (bigint amounts converted to
1190
+ * strings before this call).
1191
+ * @returns On success: `{ success: true, data: PrepareBatchIntentResponse, tier }`.
1192
+ * On failure: `{ success: false, error, failedIntents? }`.
1062
1193
  */
1063
1194
  private prepareBatchIntent;
1064
1195
  /**
1065
- * Send a prepare error message to the dialog iframe.
1196
+ * Forward a prepare-phase error to the dialog iframe so it can display a
1197
+ * human-readable failure message instead of hanging on the loading state.
1198
+ *
1199
+ * The dialog listens for `PASSKEY_PREPARE_ERROR` and transitions to an error
1200
+ * view. The user can then dismiss the dialog, at which point
1201
+ * `waitForDialogClose` resolves and the SDK returns the error to the caller.
1202
+ *
1203
+ * @param iframe - The iframe element to post the error to.
1204
+ * @param error - Human-readable error message from the prepare response.
1066
1205
  */
1067
1206
  private sendPrepareError;
1068
1207
  /**
@@ -1200,7 +1339,34 @@ declare class OneAuthClient {
1200
1339
  signWithPopup(options: SigningRequestOptions): Promise<SigningResult>;
1201
1340
  signWithRedirect(options: SigningRequestOptions, redirectUrl?: string): Promise<void>;
1202
1341
  signWithEmbed(options: SigningRequestOptions, embedOptions: EmbedOptions): Promise<SigningResult>;
1342
+ /**
1343
+ * Create and append a signing iframe to a caller-supplied container element.
1344
+ *
1345
+ * Used by the `signWithEmbed` flow where the integrator wants the signing UI
1346
+ * to appear inline on their page rather than in a modal overlay. The iframe
1347
+ * loads a pre-created signing request URL and fires `options.onReady` once
1348
+ * the page has loaded.
1349
+ *
1350
+ * @param requestId - The signing request ID; used to construct the iframe src
1351
+ * and give it a stable DOM id for later removal via `removeEmbed`.
1352
+ * @param options - Embed configuration including the container element,
1353
+ * optional dimensions, and lifecycle callbacks.
1354
+ * @returns The created `<iframe>` element (already appended to the container).
1355
+ */
1203
1356
  private createEmbed;
1357
+ /**
1358
+ * Listen for a signing result from an embedded (inline) signing iframe.
1359
+ *
1360
+ * Matches incoming `PASSKEY_SIGNING_RESULT` messages against `requestId`
1361
+ * to avoid reacting to messages from other iframes on the page. On resolution
1362
+ * (success or failure), the iframe is removed from the DOM and
1363
+ * `embedOptions.onClose` is invoked.
1364
+ *
1365
+ * @param requestId - The signing request ID to match against incoming messages.
1366
+ * @param iframe - The embedded signing iframe.
1367
+ * @param embedOptions - Embed configuration; `onClose` is called after cleanup.
1368
+ * @returns A `SigningResult` discriminated union.
1369
+ */
1204
1370
  private waitForEmbedResponse;
1205
1371
  removeEmbed(requestId: string): void;
1206
1372
  handleRedirectCallback(): Promise<SigningResult>;
@@ -1208,33 +1374,203 @@ declare class OneAuthClient {
1208
1374
  * Fetch passkeys for a user from the auth provider
1209
1375
  */
1210
1376
  getPasskeys(username: string): Promise<PasskeyCredential[]>;
1377
+ /**
1378
+ * Register a signing request with the passkey service and receive a
1379
+ * short-lived `requestId`.
1380
+ *
1381
+ * Used by the legacy popup, redirect, and embed flows. The passkey service
1382
+ * stores the challenge and metadata server-side so the dialog page can fetch
1383
+ * them by `requestId` without relying on URL parameters alone. This avoids
1384
+ * exposing potentially large challenge payloads in query strings.
1385
+ *
1386
+ * @param options - The signing options (challenge, username, description, etc.).
1387
+ * @param mode - How the dialog will be opened (`"popup"`, `"redirect"`, or `"embed"`).
1388
+ * @param redirectUrl - Only required for `"redirect"` mode; the URL the dialog
1389
+ * will navigate back to after signing.
1390
+ * @returns The created signing request with its unique `requestId`.
1391
+ * @throws If the API call fails.
1392
+ */
1211
1393
  private createSigningRequest;
1394
+ /**
1395
+ * Open a centered popup window for the signing or auth dialog.
1396
+ *
1397
+ * Positions the popup near the top of the current window (50px from the top)
1398
+ * and horizontally centered relative to the browser window. Uses `popup=true`
1399
+ * to request a minimal chrome popup (no address bar) on browsers that support
1400
+ * the Window Management API.
1401
+ *
1402
+ * @param url - The full URL to open in the popup.
1403
+ * @returns The popup `Window` reference, or `null` if the browser blocked it.
1404
+ */
1212
1405
  private openPopup;
1213
1406
  /**
1214
- * Wait for the dialog iframe to signal ready, then send init data.
1215
- * Also handles early close (X button, escape, backdrop) during the ready phase.
1216
- * Returns true if dialog is ready, false if it was closed before becoming ready.
1407
+ * Wait for the dialog iframe to signal ready, then immediately send init data.
1408
+ *
1409
+ * This is the synchronous-init variant: `initMessage` is available at call
1410
+ * time, so it can be posted as soon as `PASSKEY_READY` arrives. Use
1411
+ * `waitForDialogReadyDeferred` when init data depends on an in-flight API call.
1412
+ *
1413
+ * Also handles early close (X button, escape key, backdrop click) during the
1414
+ * ready phase so those paths resolve cleanly without leaking event listeners.
1415
+ *
1416
+ * Timeout: resolves `false` after 10 seconds if the iframe never signals ready
1417
+ * (e.g. origin mismatch or network error loading the dialog app).
1418
+ *
1419
+ * @param dialog - The `<dialog>` element wrapping the iframe.
1420
+ * @param iframe - The iframe element that will receive `PASSKEY_INIT`.
1421
+ * @param cleanup - Idempotent teardown that closes and removes the dialog.
1422
+ * @param initMessage - The `PASSKEY_INIT` payload to send when ready.
1423
+ * @returns `true` if the dialog is ready and init was sent; `false` if the
1424
+ * dialog was closed or timed out before becoming ready.
1217
1425
  */
1218
1426
  private waitForDialogReady;
1219
1427
  /**
1220
- * Create a modal dialog with a full-viewport iframe inside.
1221
- * All visual chrome (backdrop, positioning, animations) is rendered
1222
- * by the passkey app inside the iframe the SDK just provides
1223
- * a transparent full-screen container.
1428
+ * Create and open a full-viewport `<dialog>` containing a passkey iframe.
1429
+ *
1430
+ * The SDK owns only the transparent outer shell; all visible UI (backdrop,
1431
+ * card, animations, close button) is rendered by the passkey app inside the
1432
+ * iframe. This approach means design changes can be shipped server-side
1433
+ * without updating SDK consumers.
1434
+ *
1435
+ * Lifecycle:
1436
+ * 1. A themed "Loading…" overlay is injected and shown immediately while the
1437
+ * iframe loads, matching the exact visual structure of the passkey app's
1438
+ * TitleBar + IndeterminateLoader so the transition is seamless.
1439
+ * 2. When the iframe sends `PASSKEY_RENDERED`, the overlay fades out and
1440
+ * the iframe becomes fully visible.
1441
+ * 3. The returned `cleanup` function tears down all event listeners,
1442
+ * disconnects the MutationObserver, closes the `<dialog>`, and removes
1443
+ * it from the DOM. It is idempotent — safe to call multiple times.
1444
+ *
1445
+ * Browser quirks handled:
1446
+ * - The 1Password extension sets `inert` on the `<dialog>`, making it
1447
+ * non-interactive. A MutationObserver removes the attribute immediately.
1448
+ * - Password managers may also set `inert` on dialog siblings; cleanup
1449
+ * restores those as well.
1450
+ * - The iframe sandbox includes `allow-popups-to-escape-sandbox` so that
1451
+ * 1Password's popup UI can render outside the sandboxed context.
1452
+ *
1453
+ * @param url - The full URL (including query params) to load in the iframe.
1454
+ * @returns References to the dialog, iframe, and a cleanup function.
1224
1455
  */
1225
1456
  private createModalDialog;
1457
+ /**
1458
+ * Listen for the auth result from the modal dialog.
1459
+ *
1460
+ * Waits for `PASSKEY_READY` before processing any other messages to avoid
1461
+ * acting on stale `PASSKEY_CLOSE` events that may still be in the event queue
1462
+ * from a previously closed dialog.
1463
+ *
1464
+ * Also handles the `PASSKEY_RETRY_POPUP` message: sent by the dialog when a
1465
+ * password manager (e.g. Bitwarden) intercepts the WebAuthn call inside the
1466
+ * iframe. In that case the SDK seamlessly re-opens a standalone popup window,
1467
+ * where WebAuthn works without cross-origin iframe restrictions, and waits
1468
+ * for the result from there instead.
1469
+ *
1470
+ * @param _dialog - Unused; kept for signature consistency.
1471
+ * @param iframe - The iframe element; used to send `PASSKEY_INIT` on ready.
1472
+ * @param cleanup - Idempotent teardown for the modal dialog.
1473
+ * @returns An `AuthResult` discriminated union.
1474
+ */
1226
1475
  private waitForModalAuthResponse;
1227
1476
  /**
1228
1477
  * Open a popup for auth and wait for the result.
1229
1478
  * Used when iframe mode fails (e.g., due to password manager interference).
1230
1479
  */
1231
1480
  private waitForPopupAuthResponse;
1481
+ /**
1482
+ * Listen for the authenticate result from the modal dialog.
1483
+ *
1484
+ * The authenticate flow combines sign-in/sign-up with optional off-chain
1485
+ * challenge signing. The dialog sends `PASSKEY_AUTHENTICATE_RESULT` on
1486
+ * completion with both user details and, if a challenge was requested, the
1487
+ * WebAuthn signature and the hashed challenge value for server-side
1488
+ * verification.
1489
+ *
1490
+ * @param _dialog - Unused; kept for signature consistency.
1491
+ * @param _iframe - Unused; kept for signature consistency.
1492
+ * @param cleanup - Idempotent teardown for the modal dialog.
1493
+ * @returns An `AuthenticateResult` discriminated union.
1494
+ */
1232
1495
  private waitForAuthenticateResponse;
1496
+ /**
1497
+ * Listen for the connect result from the connect dialog.
1498
+ *
1499
+ * The connect flow is a lightweight "are you still you?" confirmation that
1500
+ * does not require a new passkey ceremony. On success, the dialog returns the
1501
+ * user's username, address, and an `autoConnected` flag indicating whether the
1502
+ * user had previously enabled auto-connect (in which case no UI was shown).
1503
+ *
1504
+ * On failure with `action: "switch"`, the caller should redirect to the full
1505
+ * auth flow because the user has no cached session to confirm.
1506
+ *
1507
+ * @param _dialog - Unused; kept for signature consistency.
1508
+ * @param _iframe - Unused; kept for signature consistency.
1509
+ * @param cleanup - Idempotent teardown for the modal dialog.
1510
+ * @returns A `ConnectResult` discriminated union.
1511
+ */
1233
1512
  private waitForConnectResponse;
1513
+ /**
1514
+ * Listen for the consent result from the consent dialog.
1515
+ *
1516
+ * The consent dialog shows the user which data fields an app is requesting
1517
+ * access to and lets them approve or deny. On approval, `data` contains the
1518
+ * consented field values (e.g. email address, device names) and `grantedAt`
1519
+ * records when consent was given.
1520
+ *
1521
+ * A `PASSKEY_CLOSE` without a prior `PASSKEY_CONSENT_RESULT` is treated as an
1522
+ * explicit user cancellation (distinct from denial, though both yield
1523
+ * `success: false`).
1524
+ *
1525
+ * @param _dialog - Unused; kept for signature consistency.
1526
+ * @param _iframe - Unused; kept for signature consistency.
1527
+ * @param cleanup - Idempotent teardown for the modal dialog.
1528
+ * @returns A `RequestConsentResult` discriminated union.
1529
+ */
1234
1530
  private waitForConsentResponse;
1531
+ /**
1532
+ * Listen for a signing result from a server-request-based modal dialog.
1533
+ *
1534
+ * Similar to `waitForIntentSigningResponse` but intended for the older
1535
+ * `signWithModal` path that pre-creates a signing request via the API (rather
1536
+ * than inlining all data in `PASSKEY_INIT`). Filters by `requestId` to handle
1537
+ * the case where stale messages from a previous dialog may still be in flight.
1538
+ *
1539
+ * @param requestId - The signing request ID to match against incoming messages.
1540
+ * @param _dialog - Unused; kept for signature consistency.
1541
+ * @param _iframe - Unused; kept for signature consistency.
1542
+ * @param cleanup - Idempotent teardown that closes and removes the dialog.
1543
+ * @returns A `SigningResult` discriminated union.
1544
+ */
1235
1545
  private waitForModalSigningResponse;
1546
+ /**
1547
+ * Listen for a signing result from a popup window.
1548
+ *
1549
+ * Polls for popup closure every 500 ms as a fallback to detect when the user
1550
+ * closes the popup without completing the signing flow (no `PASSKEY_CLOSE`
1551
+ * message is fired in that case because the popup's unload event cannot
1552
+ * reliably postMessage to the opener on all browsers).
1553
+ *
1554
+ * On success or cancellation, the popup is programmatically closed and the
1555
+ * interval is cleared.
1556
+ *
1557
+ * @param requestId - The signing request ID to match against incoming messages.
1558
+ * @param popup - The popup `Window` reference returned by `openPopup`.
1559
+ * @returns A `SigningResult` discriminated union.
1560
+ */
1236
1561
  private waitForPopupResponse;
1562
+ /**
1563
+ * Fetch the completed signing result from the passkey service by request ID.
1564
+ *
1565
+ * Used by the redirect flow: after the passkey service redirects back to
1566
+ * `redirectUrl`, the integrator calls `handleRedirectCallback()`, which
1567
+ * extracts `requestId` from the URL query params and delegates here to
1568
+ * retrieve the full signature from the server.
1569
+ *
1570
+ * @param requestId - The signing request ID from the redirect callback URL.
1571
+ * @returns A `SigningResult` discriminated union.
1572
+ */
1237
1573
  private fetchSigningResult;
1238
1574
  }
1239
1575
 
1240
- export { type RequestConsentResult as $, type AuthResult as A, type BalanceRequirement as B, type CreateSigningRequestResponse as C, type DeveloperSignedIntent as D, type EmbedOptions as E, type CloseOnStatus as F, type PrepareIntentResponse as G, type ExecuteIntentResponse as H, type IntentSigner as I, type IntentHistoryOptions as J, type IntentHistoryItem as K, type IntentHistoryResult as L, type SendSwapOptions as M, type SendSwapResult as N, OneAuthClient as O, type PasskeyProviderConfig as P, type SwapQuote as Q, type ThemeConfig as R, type SendIntentResult as S, type TransactionAction as T, type UserPasskeysResponse as U, type ConsentField as V, type WebAuthnSignature as W, type ConsentData as X, type CheckConsentOptions as Y, type CheckConsentResult as Z, type RequestConsentOptions as _, type IntentCall as a, type BatchIntentItem as a0, type SendBatchIntentOptions as a1, type SendBatchIntentResult as a2, type BatchIntentItemResult as a3, type PreparedBatchIntent as a4, type PrepareBatchIntentResponse as a5, type SigningRequestOptions as b, type SigningResult as c, type SigningSuccess as d, type SigningError as e, type SigningErrorCode as f, type SigningRequestStatus as g, type PasskeyCredential as h, type ConnectResult as i, type AuthenticateOptions as j, type AuthenticateResult as k, type SigningResultBase as l, type SignMessageOptions as m, type SignMessageResult as n, type SignTypedDataOptions as o, type SignTypedDataResult as p, type EIP712Domain as q, type EIP712Types as r, type EIP712TypeField as s, type TransactionFees as t, type TransactionDetails as u, type IntentTokenRequest as v, type SendIntentOptions as w, type IntentQuote as x, type IntentStatus as y, type OrchestratorStatus as z };
1576
+ export { type SendBatchIntentOptions as $, type AuthResult as A, type BalanceRequirement as B, type CreateSigningRequestResponse as C, type PrepareIntentResponse as D, type EmbedOptions as E, type ExecuteIntentResponse as F, type IntentHistoryOptions as G, type IntentHistoryItem as H, type IntentCall as I, type IntentHistoryResult as J, type SendSwapOptions as K, type SendSwapResult as L, type SwapQuote as M, type ThemeConfig as N, OneAuthClient as O, type PasskeyProviderConfig as P, type ConsentField as Q, type ConsentData as R, type SendIntentResult as S, type TransactionAction as T, type UserPasskeysResponse as U, type CheckConsentOptions as V, type WebAuthnSignature as W, type CheckConsentResult as X, type RequestConsentOptions as Y, type RequestConsentResult as Z, type BatchIntentItem as _, type SigningRequestOptions as a, type SendBatchIntentResult as a0, type BatchIntentItemResult as a1, type PreparedBatchIntent as a2, type PrepareBatchIntentResponse as a3, type SigningResult as b, type SigningSuccess as c, type SigningError as d, type SigningErrorCode as e, type SigningRequestStatus as f, type PasskeyCredential as g, type ConnectResult as h, type AuthenticateOptions as i, type AuthenticateResult as j, type SigningResultBase as k, type SignMessageOptions as l, type SignMessageResult as m, type SignTypedDataOptions as n, type SignTypedDataResult as o, type EIP712Domain as p, type EIP712Types as q, type EIP712TypeField as r, type TransactionFees as s, type TransactionDetails as t, type IntentTokenRequest as u, type SendIntentOptions as v, type IntentQuote as w, type IntentStatus as x, type OrchestratorStatus as y, type CloseOnStatus as z };