@didit-protocol/sdk-web 0.5.0 → 0.5.1

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.
package/README.md CHANGED
@@ -295,6 +295,8 @@ DiditSdk.shared.startVerification({
295
295
 
296
296
  If the host element has no resolved height, the embedded iframe also has no usable height. Resize the host element when your layout changes; the SDK continues to fill it automatically.
297
297
 
298
+ If `embeddedContainerId` is missing or no element carries it, the launch fails with the `failed` result (and the `error` state) instead of silently rendering nothing: embedded mode never falls back to the modal overlay.
299
+
298
300
  ## Verification Results
299
301
 
300
302
  The SDK returns three types of results:
@@ -579,6 +581,18 @@ The `codeSize` field in `code_sent` indicates the OTP code length (e.g., 4 or 6
579
581
  - Edge 79+
580
582
 
581
583
 
584
+ ## Releasing
585
+
586
+ Each release starts from a tag pushed to a commit on `master`. The workflow checks that the tag matches the package versions and that each package's `CHANGELOG.md` has a section for that version, then creates the GitHub release and publishes to npm with trusted publishing.
587
+
588
+ | Tag | Publishes | Workflow |
589
+ | --- | --- | --- |
590
+ | `signals-v<version>` | `@didit-protocol/signals` | `release-signals.yml` |
591
+ | `auth-v<version>` | `@didit-protocol/auth`, then `@didit-protocol/auth-react`, then `@didit-protocol/auth-nextjs`, all at the same version | `release-auth.yml` |
592
+ | `v<version>` | `@didit-protocol/sdk-web` | `release.yml` |
593
+
594
+ When versions depend on each other, release in this order and wait for each to reach npm: signals, then auth, then sdk-web. The auth and sdk-web workflows stop before publishing if the `@didit-protocol/signals` version they depend on is not on npm yet. `@didit-protocol/auth-nextjs` pins `@didit-protocol/auth` and `@didit-protocol/auth-react` at exactly its own version, so bump all three together; `npm run test:release` checks that before a tag does.
595
+
582
596
  ## License
583
597
 
584
598
  Copyright © 2026 Didit. All rights reserved.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Didit SDK for Web v0.5.0
2
+ * Didit SDK for Web v0.5.1
3
3
  * (c) 2026 Didit
4
4
  * @license MIT
5
5
  */
@@ -27,13 +27,14 @@ const CSS_CLASSES = {
27
27
  confirmBox: "didit-confirm-box",
28
28
  embedded: "didit-embedded"
29
29
  };
30
- const SDK_VERSION = "0.5.0";
30
+ const SDK_VERSION = "0.5.1";
31
31
  /**
32
32
  * 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.
33
+ * camera and microphone for capture, clipboard-write for the flow's copy
34
+ * buttons, and digital-credentials-get so the flow can ask a digital ID wallet
35
+ * (Google Wallet) through the W3C Digital Credentials API from inside the iframe.
35
36
  */
36
- const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write";
37
+ const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write; digital-credentials-get";
37
38
  /** The verification-URL query parameter each camera option is forwarded as. */
38
39
  const CAMERA_QUERY_PARAMS = {
39
40
  defaultDocumentCamera: "document_camera",
@@ -1048,6 +1049,9 @@ class VerificationModal {
1048
1049
  max-width: max(300px, 18.75rem);
1049
1050
  margin: auto;
1050
1051
  overflow-wrap: anywhere;
1052
+ /* Focusing the dialog scrolls it into view start-aligned; this keeps
1053
+ * the overlay's top padding visible so the title is never clipped. */
1054
+ scroll-margin-top: 1rem;
1051
1055
  }
1052
1056
 
1053
1057
  .${CSS_CLASSES.flowSized} .didit-confirm-actions {
@@ -1832,6 +1836,23 @@ async function pollTransactionAfterAction(args) {
1832
1836
  return latest;
1833
1837
  }
1834
1838
 
1839
+ /**
1840
+ * Embedded mode renders inside an element that already exists on the
1841
+ * integrator's page. Without it the modal never shows anything (embedded mode
1842
+ * never activates the overlay), so the launch fails with a message the
1843
+ * integrator can act on instead of silently presenting nothing.
1844
+ */
1845
+ function assertEmbeddedHostExists(configuration) {
1846
+ if (!configuration?.embedded)
1847
+ return;
1848
+ const containerId = configuration.embeddedContainerId;
1849
+ if (!containerId) {
1850
+ throw new Error("Embedded mode requires embeddedContainerId: the id of the element that hosts the verification.");
1851
+ }
1852
+ if (typeof document === "undefined" || !document.getElementById(containerId)) {
1853
+ throw new Error(`Embedded container "#${containerId}" was not found in the page.`);
1854
+ }
1855
+ }
1835
1856
  class DiditSdk {
1836
1857
  static get shared() {
1837
1858
  if (!DiditSdk._instance) {
@@ -1891,17 +1912,20 @@ class DiditSdk {
1891
1912
  this._modal.destroy();
1892
1913
  this._modal = null;
1893
1914
  }
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
- });
1915
+ // A new launch is not in an error state any more, whatever the last one did.
1916
+ this._errorMessage = undefined;
1900
1917
  try {
1901
1918
  const { url } = options;
1902
1919
  if (!url || typeof url !== "string") {
1903
1920
  throw new Error("Invalid options: url is required");
1904
1921
  }
1922
+ assertEmbeddedHostExists(config);
1923
+ this._modal = new VerificationModal(config, {
1924
+ onClose: () => this.handleModalClose(),
1925
+ onCloseConfirmed: () => this.handleModalCloseConfirmed(),
1926
+ onMessage: (event) => this.handleVerificationEvent(event),
1927
+ onIframeLoad: () => this.handleIframeLoad()
1928
+ });
1905
1929
  this._url = buildVerificationUrl(url, config);
1906
1930
  this.setState("loading");
1907
1931
  this.emitInternalEvent("didit:started", {});
@@ -2018,6 +2042,7 @@ class DiditSdk {
2018
2042
  this._modal?.destroy();
2019
2043
  this._modal = null;
2020
2044
  this.reset();
2045
+ this.setState("idle");
2021
2046
  }
2022
2047
  async runTransactionAction(baseUrl, transactionToken, submitResult, onActionCompleted) {
2023
2048
  const generation = this._actionGeneration;
@@ -2133,6 +2158,7 @@ class DiditSdk {
2133
2158
  const sessionData = this.buildSessionData();
2134
2159
  this._modal?.close();
2135
2160
  this.reset();
2161
+ this.setState("idle");
2136
2162
  const result = {
2137
2163
  type: "cancelled",
2138
2164
  session: sessionData
@@ -2153,6 +2179,11 @@ class DiditSdk {
2153
2179
  }
2154
2180
  handleVerificationEvent(event) {
2155
2181
  SDKLogger.log("Verification event:", event);
2182
+ // Keep the session the flow told us about so a modal the user closes by
2183
+ // hand still reports the session it belongs to in the cancelled result.
2184
+ if (event.data?.sessionId) {
2185
+ this._sessionId = event.data.sessionId;
2186
+ }
2156
2187
  this.onEvent?.(event);
2157
2188
  switch (event.type) {
2158
2189
  case "didit:ready":
@@ -2208,6 +2239,7 @@ class DiditSdk {
2208
2239
  if (this._configuration?.closeModalOnComplete) {
2209
2240
  this._modal?.close();
2210
2241
  this.reset();
2242
+ this.setState("idle");
2211
2243
  }
2212
2244
  const result = {
2213
2245
  type: "completed",
@@ -2220,6 +2252,7 @@ class DiditSdk {
2220
2252
  const sessionData = this.buildSessionData(event.data);
2221
2253
  this._modal?.close();
2222
2254
  this.reset();
2255
+ this.setState("idle");
2223
2256
  const result = {
2224
2257
  type: "cancelled",
2225
2258
  session: sessionData
@@ -2238,10 +2271,14 @@ class DiditSdk {
2238
2271
  else {
2239
2272
  verificationError = createVerificationError("unknown", "An unknown error occurred");
2240
2273
  }
2241
- this._errorMessage = verificationError.message;
2242
- this.setState("error");
2243
2274
  this._modal?.close();
2275
+ this._modal = null;
2276
+ // Clear what the failed launch left behind, then report the error as the
2277
+ // state the SDK is in: reset() alone would leave callers reading "idle"
2278
+ // with no error message right after onStateChange("error").
2244
2279
  this.reset();
2280
+ this._errorMessage = verificationError.message;
2281
+ this.setState("error");
2245
2282
  const result = {
2246
2283
  type: "failed",
2247
2284
  error: verificationError
@@ -2257,7 +2294,6 @@ class DiditSdk {
2257
2294
  }
2258
2295
  }
2259
2296
  reset() {
2260
- this._state = "idle";
2261
2297
  this._sessionId = undefined;
2262
2298
  this._url = undefined;
2263
2299
  this._errorMessage = undefined;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Didit SDK for Web v0.5.0
2
+ * Didit SDK for Web v0.5.1
3
3
  * (c) 2026 Didit
4
4
  * @license MIT
5
5
  */
@@ -27,13 +27,14 @@ const CSS_CLASSES = {
27
27
  confirmBox: "didit-confirm-box",
28
28
  embedded: "didit-embedded"
29
29
  };
30
- const SDK_VERSION = "0.5.0";
30
+ const SDK_VERSION = "0.5.1";
31
31
  /**
32
32
  * 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.
33
+ * camera and microphone for capture, clipboard-write for the flow's copy
34
+ * buttons, and digital-credentials-get so the flow can ask a digital ID wallet
35
+ * (Google Wallet) through the W3C Digital Credentials API from inside the iframe.
35
36
  */
36
- const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write";
37
+ const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write; digital-credentials-get";
37
38
  /** The verification-URL query parameter each camera option is forwarded as. */
38
39
  const CAMERA_QUERY_PARAMS = {
39
40
  defaultDocumentCamera: "document_camera",
@@ -1048,6 +1049,9 @@ class VerificationModal {
1048
1049
  max-width: max(300px, 18.75rem);
1049
1050
  margin: auto;
1050
1051
  overflow-wrap: anywhere;
1052
+ /* Focusing the dialog scrolls it into view start-aligned; this keeps
1053
+ * the overlay's top padding visible so the title is never clipped. */
1054
+ scroll-margin-top: 1rem;
1051
1055
  }
1052
1056
 
1053
1057
  .${CSS_CLASSES.flowSized} .didit-confirm-actions {
@@ -1832,6 +1836,23 @@ async function pollTransactionAfterAction(args) {
1832
1836
  return latest;
1833
1837
  }
1834
1838
 
1839
+ /**
1840
+ * Embedded mode renders inside an element that already exists on the
1841
+ * integrator's page. Without it the modal never shows anything (embedded mode
1842
+ * never activates the overlay), so the launch fails with a message the
1843
+ * integrator can act on instead of silently presenting nothing.
1844
+ */
1845
+ function assertEmbeddedHostExists(configuration) {
1846
+ if (!configuration?.embedded)
1847
+ return;
1848
+ const containerId = configuration.embeddedContainerId;
1849
+ if (!containerId) {
1850
+ throw new Error("Embedded mode requires embeddedContainerId: the id of the element that hosts the verification.");
1851
+ }
1852
+ if (typeof document === "undefined" || !document.getElementById(containerId)) {
1853
+ throw new Error(`Embedded container "#${containerId}" was not found in the page.`);
1854
+ }
1855
+ }
1835
1856
  class DiditSdk {
1836
1857
  static get shared() {
1837
1858
  if (!DiditSdk._instance) {
@@ -1891,17 +1912,20 @@ class DiditSdk {
1891
1912
  this._modal.destroy();
1892
1913
  this._modal = null;
1893
1914
  }
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
- });
1915
+ // A new launch is not in an error state any more, whatever the last one did.
1916
+ this._errorMessage = undefined;
1900
1917
  try {
1901
1918
  const { url } = options;
1902
1919
  if (!url || typeof url !== "string") {
1903
1920
  throw new Error("Invalid options: url is required");
1904
1921
  }
1922
+ assertEmbeddedHostExists(config);
1923
+ this._modal = new VerificationModal(config, {
1924
+ onClose: () => this.handleModalClose(),
1925
+ onCloseConfirmed: () => this.handleModalCloseConfirmed(),
1926
+ onMessage: (event) => this.handleVerificationEvent(event),
1927
+ onIframeLoad: () => this.handleIframeLoad()
1928
+ });
1905
1929
  this._url = buildVerificationUrl(url, config);
1906
1930
  this.setState("loading");
1907
1931
  this.emitInternalEvent("didit:started", {});
@@ -2018,6 +2042,7 @@ class DiditSdk {
2018
2042
  this._modal?.destroy();
2019
2043
  this._modal = null;
2020
2044
  this.reset();
2045
+ this.setState("idle");
2021
2046
  }
2022
2047
  async runTransactionAction(baseUrl, transactionToken, submitResult, onActionCompleted) {
2023
2048
  const generation = this._actionGeneration;
@@ -2133,6 +2158,7 @@ class DiditSdk {
2133
2158
  const sessionData = this.buildSessionData();
2134
2159
  this._modal?.close();
2135
2160
  this.reset();
2161
+ this.setState("idle");
2136
2162
  const result = {
2137
2163
  type: "cancelled",
2138
2164
  session: sessionData
@@ -2153,6 +2179,11 @@ class DiditSdk {
2153
2179
  }
2154
2180
  handleVerificationEvent(event) {
2155
2181
  SDKLogger.log("Verification event:", event);
2182
+ // Keep the session the flow told us about so a modal the user closes by
2183
+ // hand still reports the session it belongs to in the cancelled result.
2184
+ if (event.data?.sessionId) {
2185
+ this._sessionId = event.data.sessionId;
2186
+ }
2156
2187
  this.onEvent?.(event);
2157
2188
  switch (event.type) {
2158
2189
  case "didit:ready":
@@ -2208,6 +2239,7 @@ class DiditSdk {
2208
2239
  if (this._configuration?.closeModalOnComplete) {
2209
2240
  this._modal?.close();
2210
2241
  this.reset();
2242
+ this.setState("idle");
2211
2243
  }
2212
2244
  const result = {
2213
2245
  type: "completed",
@@ -2220,6 +2252,7 @@ class DiditSdk {
2220
2252
  const sessionData = this.buildSessionData(event.data);
2221
2253
  this._modal?.close();
2222
2254
  this.reset();
2255
+ this.setState("idle");
2223
2256
  const result = {
2224
2257
  type: "cancelled",
2225
2258
  session: sessionData
@@ -2238,10 +2271,14 @@ class DiditSdk {
2238
2271
  else {
2239
2272
  verificationError = createVerificationError("unknown", "An unknown error occurred");
2240
2273
  }
2241
- this._errorMessage = verificationError.message;
2242
- this.setState("error");
2243
2274
  this._modal?.close();
2275
+ this._modal = null;
2276
+ // Clear what the failed launch left behind, then report the error as the
2277
+ // state the SDK is in: reset() alone would leave callers reading "idle"
2278
+ // with no error message right after onStateChange("error").
2244
2279
  this.reset();
2280
+ this._errorMessage = verificationError.message;
2281
+ this.setState("error");
2245
2282
  const result = {
2246
2283
  type: "failed",
2247
2284
  error: verificationError
@@ -2257,7 +2294,6 @@ class DiditSdk {
2257
2294
  }
2258
2295
  }
2259
2296
  reset() {
2260
- this._state = "idle";
2261
2297
  this._sessionId = undefined;
2262
2298
  this._url = undefined;
2263
2299
  this._errorMessage = undefined;