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