Skip to content

Add browser global CDN build to idkit-core#288

Merged
Takaros999 merged 15 commits into
mainfrom
kartike/add-cdn-idkit
Jun 23, 2026
Merged

Add browser global CDN build to idkit-core#288
Takaros999 merged 15 commits into
mainfrom
kartike/add-cdn-idkit

Conversation

@kchaw2005

@kchaw2005 kchaw2005 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

The Issue

Currently Razer uses a drop in CDN script-tag to implement a deprecated version of @worldcoin/idkit-js (also now deprecated). The src for the exact unpkg endpoint they use can be found here. We needed a drop in way for them to implement new IDKit 4.0 sessions and features without reviving @worldcoin/idkit-standalone or creating another package.

The Fix

Create a browser entrypoint at browser.ts and build it as a CDN-friendly IIFE artifact from the existing @worldcoin/idkit-core.
The new script-tag build exposes the existing core client namespace as window.IDKit.

This keeps the existing npm import API unchanged while adding a browser-global artifact at:

dist/idkit.global.js

The build also copies the WASM artifact into dist/ so the CDN script can automatically load:

dist/idkit_wasm_bg.wasm

Release Note

This requires publishing a new @worldcoin/idkit-core package version before the npm CDN URL
works. After publish, partners can load:

<script src="https://unpkg.com/@worldcoin/idkit-core@<version>/dist/idkit.global.js"></script>


Note

Low Risk
Additive packaging and documentation; client npm exports unchanged and signing is not exposed on the browser global.

Overview
Adds a script-tag / CDN path for @worldcoin/idkit-core so partners can load IDKit 4.x via unpkg/jsdelivr without a separate standalone package.

A new src/browser.ts entry assigns the existing client IDKit namespace to window.IDKit and deliberately omits RP signing (still /signing on the server). tsup now runs a second minified IIFE build to dist/idkit.global.js, with unpkg / jsdelivr in package.json pointing at that file; WASM copy to dist/idkit_wasm_bg.wasm is shared with the ESM/CJS build via a refactored copyWasmToDist.

js/packages/core/README.md documents CDN usage and a minimal window.IDKit example. The browser example gains a Use CDN version toggle that dynamically loads the unpkg package root and runs the same verification flow through window.IDKit (presets resolved by name on the loaded namespace).

Reviewed by Cursor Bugbot for commit 741b5d5. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
idkit-js-example Ready Ready Preview, Comment Jun 22, 2026 11:26pm

Request Review

@kchaw2005

Copy link
Copy Markdown
Contributor Author

reminder to remove dist/idkit.global.js and dist/idkit_wasm_bg.wasm from the branch entirely before we merge this

@Takaros999

Copy link
Copy Markdown
Contributor

@codex review

@Takaros999 Takaros999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high level:

  • instead of adding 2 examples, feel free to edit the existing browser/index.html we have
  • in order to test this e2e, you can publish the package with a different name (from your computer) and try to use it in a real example
  • remove the new dist entries

Comment thread js/examples/browser/legacy-cdn.html Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need another example here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, we should remove this

Comment thread js/packages/core/dist/idkit.global.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we commiting this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WASM context right now there is a script that builds wasm file into js/packages/core/wasm/... then the typescript copies that into js/packages/core/dist to include in the final npm package. this seems redundant and we shouldn't commit it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of this test?

Comment thread js/packages/core/package.json Outdated
Comment on lines +32 to +33
"./idkit.global.js": "./dist/idkit.global.js",
"./idkit_wasm_bg.wasm": "./dist/idkit_wasm_bg.wasm"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this? what's the purpose?

Comment thread js/packages/core/src/lib/wasm.ts Outdated
* it from document.currentScript because classic scripts do not have
* import.meta.url.
*/
export function setWasmInput(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we try without this first? it might not be needed

Comment thread js/examples/browser/index.html Fixed
Comment thread js/examples/browser/index.html Outdated
…instead read only expose connected unpkg url
Comment thread js/examples/browser/index.html Outdated
Comment thread js/examples/browser/index.html
Comment thread js/packages/core/tsup.config.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 097d3d2. Configure here.

clean: moduleCleanPaths,
treeshake: true,
outDir: "dist",
onSuccess: copyWasmToDist,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial clean keeps stale WASM

Medium Severity

The module build switched from wiping all of dist to selective globs that never remove idkit_wasm_bg.wasm. When copyWasmToDist skips because wasm/idkit_wasm_bg.wasm is missing, an older binary can remain alongside freshly built JS, including idkit.global.js, so CDN and npm consumers may load mismatched WASM.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 097d3d2. Configure here.

@Takaros999

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 097d3d27b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

},
{
entry: { idkit: "src/browser.ts" },
format: ["iife"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve WASM URL resolution in the global build

When this entrypoint is emitted as an IIFE, it still bundles src/lib/wasm.ts; every IDKit.request(...).preset/constraints path calls initIDKit(), which invokes the wasm-pack loader without an explicit URL. That loader resolves idkit_wasm_bg.wasm from import.meta.url, but an IIFE/classic script has no module URL, so CDN consumers will fail during WASM initialization instead of loading the sibling .wasm file. Capture/pass a script-relative WASM URL for the global build or avoid bundling the wasm glue into an IIFE.

Useful? React with 👍 / 👎.

Takaros999
Takaros999 previously approved these changes Jun 22, 2026

@Takaros999 Takaros999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm can you check the last comment from codex to see if it's valid

Comment thread js/examples/browser/index.html Outdated
import { IDKit } from "@worldcoin/idkit-core";

const CDN_IDKIT_SCRIPT_URL =
"https://unpkg.com/@worldcoin/idkit-core/dist/idkit.global.js";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"https://unpkg.com/@worldcoin/idkit-core/dist/idkit.global.js";
"https://unpkg.com/@worldcoin/idkit-core";

because you added the unpckg field in package.json it will default to that and we can skip the dist/idkit.global.js part

@Takaros999 Takaros999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tbh I would change the browser index.html to only use the CDN script you can

@Takaros999 Takaros999 merged commit 83e2878 into main Jun 23, 2026
19 checks passed
@Takaros999 Takaros999 deleted the kartike/add-cdn-idkit branch June 23, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants