@didit-protocol/sdk-web 0.5.0 → 0.5.3

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Didit SDK for Web v0.5.0
2
+ * Didit SDK for Web v0.5.3
3
3
  * (c) 2026 Didit
4
4
  * @license MIT
5
5
  */
@@ -22,18 +22,20 @@ const CSS_CLASSES = {
22
22
  closeIcon: "didit-close-icon",
23
23
  closeIconLegacy: "didit-close-icon-legacy",
24
24
  flowSized: "didit-flow-sized",
25
+ sizeAnimated: "didit-size-animated",
25
26
  loading: "didit-loading",
26
27
  confirmOverlay: "didit-confirm-overlay",
27
28
  confirmBox: "didit-confirm-box",
28
29
  embedded: "didit-embedded"
29
30
  };
30
- const SDK_VERSION = "0.5.0";
31
+ const SDK_VERSION = "0.5.3";
31
32
  /**
32
33
  * The permissions the verification iframe gets, in a modal and embedded:
33
- * camera and microphone for capture, and clipboard-write for the flow's copy
34
- * buttons.
34
+ * camera and microphone for capture, clipboard-write for the flow's copy
35
+ * buttons, and digital-credentials-get so the flow can ask a digital ID wallet
36
+ * (Google Wallet) through the W3C Digital Credentials API from inside the iframe.
35
37
  */
36
- const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write";
38
+ const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write; digital-credentials-get";
37
39
  /** The verification-URL query parameter each camera option is forwarded as. */
38
40
  const CAMERA_QUERY_PARAMS = {
39
41
  defaultDocumentCamera: "document_camera",
@@ -54,7 +56,7 @@ const PRESENTATION_QUERY_PARAMS = {
54
56
  };
55
57
  /**
56
58
  * Posted by the hosted flow when it lays itself out for the modal, with
57
- * `data: { contentHeight, colorScheme?, dir? }`. The modal then grows to the
59
+ * `data: { contentHeight, colorScheme?, dir?, kind? }` (`kind` is `handoff` or `step`, `step` when missing). The modal then grows to the
58
60
  * handoff card on a computer and follows the content height in a narrow
59
61
  * window. Handled by the modal and never delivered to `onEvent`.
60
62
  */
@@ -688,6 +690,10 @@ function getTranslations(language) {
688
690
  return translationsMap[language] ?? EN;
689
691
  }
690
692
 
693
+ /** The length of the one animation when the flow moves from the handoff card to a step or back. */
694
+ const SIZE_ANIMATION_MS = 300;
695
+ /** How long the modal waits for the first layout before it shows at step size, so it can never hang. */
696
+ const FIRST_LAYOUT_TIMEOUT_MS = 3000;
691
697
  class VerificationModal {
692
698
  constructor(configuration, callbacks) {
693
699
  this.state = {
@@ -705,9 +711,13 @@ class VerificationModal {
705
711
  this.boundHandleKeydown = null;
706
712
  this.boundHandleFocusChange = null;
707
713
  this.confirmationFocusTimeout = null;
714
+ this.firstLayoutTimeout = null;
715
+ this.sizeTimeout = null;
708
716
  this.embedded = false;
709
717
  this.embeddedContainer = null;
710
718
  this.language = "en";
719
+ /** The page's own background colours, kept while a full-screen modal paints over them. */
720
+ this.pageBackground = null;
711
721
  /** body.style.overflow value observed right before this modal locked scroll, restored on close(). */
712
722
  this.previousBodyOverflow = null;
713
723
  this.modalId = generateModalId();
@@ -752,9 +762,9 @@ class VerificationModal {
752
762
  .${CSS_CLASSES.container} {
753
763
  position: relative;
754
764
  width: 100%;
755
- max-width: 500px;
756
- max-height: 90vh;
757
- max-height: 90dvh;
765
+ max-width: 440px;
766
+ height: min(860px, calc(100vh - 2rem));
767
+ height: min(860px, calc(100dvh - 2rem));
758
768
  border-radius: 16px;
759
769
  overflow: hidden;
760
770
  background: transparent;
@@ -766,9 +776,7 @@ class VerificationModal {
766
776
 
767
777
  .${CSS_CLASSES.iframe} {
768
778
  width: 100%;
769
- height: 90vh;
770
- height: 90dvh;
771
- max-height: 700px;
779
+ height: 100%;
772
780
  border: none;
773
781
  display: block;
774
782
  }
@@ -809,6 +817,12 @@ class VerificationModal {
809
817
  z-index: 5;
810
818
  }
811
819
 
820
+ @media (prefers-color-scheme: dark) {
821
+ .${CSS_CLASSES.loading} {
822
+ background: #0b0b0d;
823
+ }
824
+ }
825
+
812
826
  .${CSS_CLASSES.loading}.hidden {
813
827
  display: none;
814
828
  }
@@ -930,6 +944,58 @@ class VerificationModal {
930
944
  outline-offset: 2px;
931
945
  }
932
946
 
947
+ /*
948
+ * Steps are phone-sized (440 x 860, above). On a computer the handoff card is wider
949
+ * (board Start-Embedded): 960 x 660 on a window of 1000px or more, never wider than the
950
+ * window less its margin and never taller than 90% of it. In a narrower window the
951
+ * page stacks and the height follows its content (--didit-content-height, set from the
952
+ * flow's layout message). Until the flow reports what it shows, the modal is the handoff
953
+ * card at its final size with the spinner inside it (the flow stays hidden and lays itself
954
+ * out for that size): it never opens small and grows. The first change of kind (a step
955
+ * instead of the handoff, or the person continues on this computer) animates once.
956
+ */
957
+ @media (min-width: 541px) {
958
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
959
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
960
+ max-width: min(960px, calc(100vw - 2rem));
961
+ height: min(var(--didit-content-height, 660px), calc(100vh * 0.9));
962
+ height: min(var(--didit-content-height, 660px), calc(100dvh * 0.9));
963
+ }
964
+
965
+ .${CSS_CLASSES.container}.${CSS_CLASSES.sizeAnimated} {
966
+ transition: max-width 0.25s ease, height 0.25s ease;
967
+ }
968
+
969
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.iframe} {
970
+ visibility: hidden;
971
+ }
972
+ }
973
+
974
+ /*
975
+ * While pending the card already looks like the first screen (ground, radius, shadow and
976
+ * close button come from the flow-sized rules below, with the device theme); the loader
977
+ * sits inside it on the card's own ground.
978
+ */
979
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.loading} {
980
+ background: transparent;
981
+ }
982
+
983
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} circle {
984
+ stroke: rgba(255, 255, 255, 0.16);
985
+ }
986
+
987
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} path {
988
+ stroke: #f5f5f7;
989
+ }
990
+
991
+ @media (min-width: 1000px) {
992
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
993
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
994
+ height: min(660px, calc(100vh * 0.9));
995
+ height: min(660px, calc(100dvh * 0.9));
996
+ }
997
+ }
998
+
933
999
  @media (max-width: 540px) {
934
1000
  .${CSS_CLASSES.overlay} {
935
1001
  padding: 0;
@@ -937,23 +1003,16 @@ class VerificationModal {
937
1003
 
938
1004
  .${CSS_CLASSES.container} {
939
1005
  max-width: 100%;
940
- max-height: 100vh;
941
- max-height: 100dvh;
942
- border-radius: 0;
943
- }
944
-
945
- .${CSS_CLASSES.iframe} {
946
1006
  height: 100vh;
947
1007
  height: 100dvh;
948
- max-height: none;
1008
+ border-radius: 0;
949
1009
  }
950
1010
  }
951
1011
 
952
1012
  /*
953
- * Once the hosted flow reports its layout (didit:layout), the modal
954
- * grows to the handoff card on a computer (960 x 660, at most 90% of
955
- * the window) and follows the flow's content height in a narrow
956
- * window. Colours are the design system tokens named beside them.
1013
+ * The hosted flow's layout message (didit:layout) brings the modal's size
1014
+ * (see above), theme and direction. Colours are the design system tokens
1015
+ * named beside them.
957
1016
  */
958
1017
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
959
1018
  --didit-ground: #ffffff; /* site-ground */
@@ -963,7 +1022,6 @@ class VerificationModal {
963
1022
  --didit-close-fill: rgba(0, 0, 0, 0.06);
964
1023
  --didit-drop: rgba(17, 24, 39, 0.35);
965
1024
  --didit-ring: rgba(0, 0, 0, 0.06);
966
- max-width: 500px;
967
1025
  background: var(--didit-ground);
968
1026
  box-shadow: 0 30px 80px -24px var(--didit-drop), 0 0 0 1px var(--didit-ring);
969
1027
  }
@@ -978,12 +1036,6 @@ class VerificationModal {
978
1036
  --didit-ring: rgba(255, 255, 255, 0.08); /* c-shadow-pop, dark */
979
1037
  }
980
1038
 
981
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
982
- height: var(--didit-flow-height);
983
- max-height: 90vh;
984
- max-height: 90dvh;
985
- }
986
-
987
1039
  .${CSS_CLASSES.closeIcon} {
988
1040
  display: none;
989
1041
  }
@@ -1048,34 +1100,20 @@ class VerificationModal {
1048
1100
  max-width: max(300px, 18.75rem);
1049
1101
  margin: auto;
1050
1102
  overflow-wrap: anywhere;
1103
+ /* Focusing the dialog scrolls it into view start-aligned; this keeps
1104
+ * the overlay's top padding visible so the title is never clipped. */
1105
+ scroll-margin-top: 1rem;
1051
1106
  }
1052
1107
 
1053
1108
  .${CSS_CLASSES.flowSized} .didit-confirm-actions {
1054
1109
  flex-wrap: wrap;
1055
1110
  }
1056
1111
 
1057
- @media (min-width: 1024px) {
1058
- .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1059
- width: 90vw;
1060
- max-width: 960px;
1061
- }
1062
-
1063
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1064
- height: 660px;
1065
- }
1066
- }
1067
-
1068
1112
  @media (max-width: 540px) {
1069
1113
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1070
1114
  max-width: 100%;
1071
1115
  box-shadow: none;
1072
1116
  }
1073
-
1074
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1075
- height: 100vh;
1076
- height: 100dvh;
1077
- max-height: none;
1078
- }
1079
1117
  }
1080
1118
 
1081
1119
  .${CSS_CLASSES.embedded} {
@@ -1308,12 +1346,13 @@ class VerificationModal {
1308
1346
  */
1309
1347
  readFlowLayout(data) {
1310
1348
  const fields = typeof data === "object" && data !== null ? data : {};
1311
- const { contentHeight, colorScheme, dir } = fields;
1349
+ const { contentHeight, colorScheme, dir, kind } = fields;
1312
1350
  if (typeof contentHeight !== "number" || !Number.isFinite(contentHeight) || contentHeight <= 0) {
1313
1351
  return null;
1314
1352
  }
1315
1353
  const prefersDark = window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
1316
1354
  return {
1355
+ kind: kind === "handoff" ? "handoff" : "step",
1317
1356
  contentHeight: Math.ceil(contentHeight),
1318
1357
  colorScheme: colorScheme === "light" || colorScheme === "dark" ? colorScheme : prefersDark ? "dark" : "light",
1319
1358
  dir: dir === "ltr" || dir === "rtl" ? dir : isRtlLanguage(this.language) ? "rtl" : "ltr"
@@ -1325,18 +1364,113 @@ class VerificationModal {
1325
1364
  return;
1326
1365
  SDKLogger.log("Flow layout:", layout);
1327
1366
  this.container.classList.add(CSS_CLASSES.flowSized);
1328
- this.container.style.setProperty("--didit-flow-height", `${layout.contentHeight}px`);
1329
1367
  this.container.dataset.diditTheme = layout.colorScheme;
1330
1368
  this.container.dataset.diditDir = layout.dir;
1369
+ // The height the person sees now, before the reported content height can change it.
1370
+ const shownHeight = this.container.offsetHeight;
1371
+ this.container.style.setProperty("--didit-content-height", `${layout.contentHeight}px`);
1372
+ this.matchPageBackground(layout.colorScheme);
1373
+ this.setModalKind(layout.kind, layout.kind === "handoff" && this.handoffHeight(layout) === shownHeight);
1374
+ }
1375
+ /** Whether the window is a computer-sized one: a phone is full screen and never waits for a layout. */
1376
+ isPhoneWindow() {
1377
+ return window.matchMedia?.("(max-width: 540px)").matches ?? false;
1331
1378
  }
1332
- /** Back to the fixed 500 x 700 modal until the newly loaded flow reports its layout. */
1379
+ /** The height the handoff card takes for a layout, as the size rules above compute it (rounded like offsetHeight). */
1380
+ handoffHeight(layout) {
1381
+ const cap = window.innerHeight * 0.9;
1382
+ return Math.round(Math.min(window.innerWidth >= 1000 ? 660 : layout.contentHeight, cap));
1383
+ }
1384
+ /**
1385
+ * Sets what the modal is sized for. Leaving "pending" shows the modal at its final size with no
1386
+ * transition; any later change animates once.
1387
+ */
1388
+ setModalKind(kind, sizeUnchanged = false) {
1389
+ if (!this.container)
1390
+ return;
1391
+ const previous = this.container.dataset.diditKind;
1392
+ if (previous === kind)
1393
+ return;
1394
+ if (this.firstLayoutTimeout !== null && kind !== "pending") {
1395
+ window.clearTimeout(this.firstLayoutTimeout);
1396
+ this.firstLayoutTimeout = null;
1397
+ }
1398
+ // Every change of kind animates, the pending card included (it is on screen), and only for the
1399
+ // length of the change, so resizing the window never lags behind.
1400
+ // Pending already is the handoff card: a handoff first layout of the same size moves nothing,
1401
+ // while a different reported height (a narrow window) animates the correction once.
1402
+ const staysPut = previous === "pending" && kind === "handoff" && sizeUnchanged;
1403
+ if (previous !== undefined && !staysPut)
1404
+ this.animateSizeOnce();
1405
+ this.container.dataset.diditKind = kind;
1406
+ // The final size is in place before the loader goes; a flow still loading keeps its loader.
1407
+ if (previous === "pending" && !this.state.isLoading)
1408
+ this.loadingEl?.classList.add("hidden");
1409
+ }
1410
+ animateSizeOnce() {
1411
+ this.container?.classList.add(CSS_CLASSES.sizeAnimated);
1412
+ if (this.sizeTimeout !== null)
1413
+ window.clearTimeout(this.sizeTimeout);
1414
+ this.sizeTimeout = window.setTimeout(() => {
1415
+ this.sizeTimeout = null;
1416
+ this.container?.classList.remove(CSS_CLASSES.sizeAnimated);
1417
+ }, SIZE_ANIMATION_MS);
1418
+ }
1419
+ /** A flow that reports no layout (an older one) still shows, at step size, after a short wait. */
1420
+ waitForFirstLayout() {
1421
+ if (!this.container)
1422
+ return;
1423
+ // The card looks like the first screen from the first frame, in the device's theme.
1424
+ this.container.classList.add(CSS_CLASSES.flowSized);
1425
+ this.container.dataset.diditTheme = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1426
+ this.setModalKind("pending");
1427
+ this.firstLayoutTimeout = window.setTimeout(() => {
1428
+ this.firstLayoutTimeout = null;
1429
+ // A flow that never reported is an older one that paints itself: no card look around it.
1430
+ this.container?.classList.remove(CSS_CLASSES.flowSized);
1431
+ delete this.container?.dataset.diditTheme;
1432
+ this.setModalKind("step");
1433
+ }, FIRST_LAYOUT_TIMEOUT_MS);
1434
+ }
1435
+ /**
1436
+ * On a phone Safari paints the bottom edge of the screen with the page's own background, past
1437
+ * any fixed overlay, and shows it when the keyboard moves the page. A full-screen modal lends
1438
+ * the page its ground colour while it is open, so no strip of the host page shows around it.
1439
+ */
1440
+ matchPageBackground(colorScheme) {
1441
+ if (!window.matchMedia?.("(max-width: 540px)").matches)
1442
+ return;
1443
+ const root = document.documentElement;
1444
+ this.pageBackground ?? (this.pageBackground = { root: root.style.backgroundColor, body: document.body.style.backgroundColor });
1445
+ const ground = colorScheme === "dark" ? "#0b0b0d" : "#ffffff";
1446
+ root.style.backgroundColor = ground;
1447
+ document.body.style.backgroundColor = ground;
1448
+ }
1449
+ restorePageBackground() {
1450
+ if (!this.pageBackground)
1451
+ return;
1452
+ document.documentElement.style.backgroundColor = this.pageBackground.root;
1453
+ document.body.style.backgroundColor = this.pageBackground.body;
1454
+ this.pageBackground = null;
1455
+ }
1456
+ /** Back to the neutral look until the newly loaded flow reports its theme and direction. */
1333
1457
  resetFlowLayout() {
1334
1458
  if (this.embedded || !this.container)
1335
1459
  return;
1336
- this.container.classList.remove(CSS_CLASSES.flowSized);
1337
- this.container.style.removeProperty("--didit-flow-height");
1460
+ this.restorePageBackground();
1461
+ this.container.classList.remove(CSS_CLASSES.flowSized, CSS_CLASSES.sizeAnimated);
1338
1462
  delete this.container.dataset.diditTheme;
1339
1463
  delete this.container.dataset.diditDir;
1464
+ delete this.container.dataset.diditKind;
1465
+ this.container.style.removeProperty("--didit-content-height");
1466
+ if (this.firstLayoutTimeout !== null) {
1467
+ window.clearTimeout(this.firstLayoutTimeout);
1468
+ this.firstLayoutTimeout = null;
1469
+ }
1470
+ if (this.sizeTimeout !== null) {
1471
+ window.clearTimeout(this.sizeTimeout);
1472
+ this.sizeTimeout = null;
1473
+ }
1340
1474
  }
1341
1475
  handleKeydown(event) {
1342
1476
  if (!this.state.isOpen)
@@ -1372,7 +1506,9 @@ class VerificationModal {
1372
1506
  handleIframeLoad() {
1373
1507
  if (this.iframe?.src && this.iframe.src !== "about:blank") {
1374
1508
  this.state.isLoading = false;
1375
- this.loadingEl?.classList.add("hidden");
1509
+ // A modal still waiting for its first layout keeps the loader over the hidden flow.
1510
+ if (this.container?.dataset.diditKind !== "pending")
1511
+ this.loadingEl?.classList.add("hidden");
1376
1512
  this.callbacks.onIframeLoad();
1377
1513
  }
1378
1514
  }
@@ -1461,6 +1597,8 @@ class VerificationModal {
1461
1597
  this.hideConfirmation();
1462
1598
  this.loadingEl?.classList.remove("hidden");
1463
1599
  this.resetFlowLayout();
1600
+ if (!this.embedded && !this.isPhoneWindow())
1601
+ this.waitForFirstLayout();
1464
1602
  if (this.iframe) {
1465
1603
  this.iframe.src = verificationUrl;
1466
1604
  }
@@ -1832,6 +1970,23 @@ async function pollTransactionAfterAction(args) {
1832
1970
  return latest;
1833
1971
  }
1834
1972
 
1973
+ /**
1974
+ * Embedded mode renders inside an element that already exists on the
1975
+ * integrator's page. Without it the modal never shows anything (embedded mode
1976
+ * never activates the overlay), so the launch fails with a message the
1977
+ * integrator can act on instead of silently presenting nothing.
1978
+ */
1979
+ function assertEmbeddedHostExists(configuration) {
1980
+ if (!configuration?.embedded)
1981
+ return;
1982
+ const containerId = configuration.embeddedContainerId;
1983
+ if (!containerId) {
1984
+ throw new Error("Embedded mode requires embeddedContainerId: the id of the element that hosts the verification.");
1985
+ }
1986
+ if (typeof document === "undefined" || !document.getElementById(containerId)) {
1987
+ throw new Error(`Embedded container "#${containerId}" was not found in the page.`);
1988
+ }
1989
+ }
1835
1990
  class DiditSdk {
1836
1991
  static get shared() {
1837
1992
  if (!DiditSdk._instance) {
@@ -1891,17 +2046,20 @@ class DiditSdk {
1891
2046
  this._modal.destroy();
1892
2047
  this._modal = null;
1893
2048
  }
1894
- this._modal = new VerificationModal(config, {
1895
- onClose: () => this.handleModalClose(),
1896
- onCloseConfirmed: () => this.handleModalCloseConfirmed(),
1897
- onMessage: (event) => this.handleVerificationEvent(event),
1898
- onIframeLoad: () => this.handleIframeLoad()
1899
- });
2049
+ // A new launch is not in an error state any more, whatever the last one did.
2050
+ this._errorMessage = undefined;
1900
2051
  try {
1901
2052
  const { url } = options;
1902
2053
  if (!url || typeof url !== "string") {
1903
2054
  throw new Error("Invalid options: url is required");
1904
2055
  }
2056
+ assertEmbeddedHostExists(config);
2057
+ this._modal = new VerificationModal(config, {
2058
+ onClose: () => this.handleModalClose(),
2059
+ onCloseConfirmed: () => this.handleModalCloseConfirmed(),
2060
+ onMessage: (event) => this.handleVerificationEvent(event),
2061
+ onIframeLoad: () => this.handleIframeLoad()
2062
+ });
1905
2063
  this._url = buildVerificationUrl(url, config);
1906
2064
  this.setState("loading");
1907
2065
  this.emitInternalEvent("didit:started", {});
@@ -2018,6 +2176,7 @@ class DiditSdk {
2018
2176
  this._modal?.destroy();
2019
2177
  this._modal = null;
2020
2178
  this.reset();
2179
+ this.setState("idle");
2021
2180
  }
2022
2181
  async runTransactionAction(baseUrl, transactionToken, submitResult, onActionCompleted) {
2023
2182
  const generation = this._actionGeneration;
@@ -2133,6 +2292,7 @@ class DiditSdk {
2133
2292
  const sessionData = this.buildSessionData();
2134
2293
  this._modal?.close();
2135
2294
  this.reset();
2295
+ this.setState("idle");
2136
2296
  const result = {
2137
2297
  type: "cancelled",
2138
2298
  session: sessionData
@@ -2153,6 +2313,11 @@ class DiditSdk {
2153
2313
  }
2154
2314
  handleVerificationEvent(event) {
2155
2315
  SDKLogger.log("Verification event:", event);
2316
+ // Keep the session the flow told us about so a modal the user closes by
2317
+ // hand still reports the session it belongs to in the cancelled result.
2318
+ if (event.data?.sessionId) {
2319
+ this._sessionId = event.data.sessionId;
2320
+ }
2156
2321
  this.onEvent?.(event);
2157
2322
  switch (event.type) {
2158
2323
  case "didit:ready":
@@ -2208,6 +2373,7 @@ class DiditSdk {
2208
2373
  if (this._configuration?.closeModalOnComplete) {
2209
2374
  this._modal?.close();
2210
2375
  this.reset();
2376
+ this.setState("idle");
2211
2377
  }
2212
2378
  const result = {
2213
2379
  type: "completed",
@@ -2220,6 +2386,7 @@ class DiditSdk {
2220
2386
  const sessionData = this.buildSessionData(event.data);
2221
2387
  this._modal?.close();
2222
2388
  this.reset();
2389
+ this.setState("idle");
2223
2390
  const result = {
2224
2391
  type: "cancelled",
2225
2392
  session: sessionData
@@ -2238,10 +2405,14 @@ class DiditSdk {
2238
2405
  else {
2239
2406
  verificationError = createVerificationError("unknown", "An unknown error occurred");
2240
2407
  }
2241
- this._errorMessage = verificationError.message;
2242
- this.setState("error");
2243
2408
  this._modal?.close();
2409
+ this._modal = null;
2410
+ // Clear what the failed launch left behind, then report the error as the
2411
+ // state the SDK is in: reset() alone would leave callers reading "idle"
2412
+ // with no error message right after onStateChange("error").
2244
2413
  this.reset();
2414
+ this._errorMessage = verificationError.message;
2415
+ this.setState("error");
2245
2416
  const result = {
2246
2417
  type: "failed",
2247
2418
  error: verificationError
@@ -2257,7 +2428,6 @@ class DiditSdk {
2257
2428
  }
2258
2429
  }
2259
2430
  reset() {
2260
- this._state = "idle";
2261
2431
  this._sessionId = undefined;
2262
2432
  this._url = undefined;
2263
2433
  this._errorMessage = undefined;