Add browser global CDN build to idkit-core#288
Conversation
…azer to drop in new IDKit configs
…ed atest file to stress test concurrent requests and more
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
reminder to remove dist/idkit.global.js and dist/idkit_wasm_bg.wasm from the branch entirely before we merge this |
|
@codex review |
Takaros999
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
we don't need another example here
There was a problem hiding this comment.
same, we should remove this
There was a problem hiding this comment.
why are we commiting this?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
what is the purpose of this test?
| "./idkit.global.js": "./dist/idkit.global.js", | ||
| "./idkit_wasm_bg.wasm": "./dist/idkit_wasm_bg.wasm" |
There was a problem hiding this comment.
do we really need this? what's the purpose?
| * it from document.currentScript because classic scripts do not have | ||
| * import.meta.url. | ||
| */ | ||
| export function setWasmInput( |
There was a problem hiding this comment.
can we try without this first? it might not be needed
…instead read only expose connected unpkg url
…an retry instead of reusing a stale rejected promise.
…build because of possible race condition
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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, |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 097d3d2. Configure here.
|
@codex review |
There was a problem hiding this comment.
💡 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"], |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
lgtm can you check the last comment from codex to see if it's valid
| import { IDKit } from "@worldcoin/idkit-core"; | ||
|
|
||
| const CDN_IDKIT_SCRIPT_URL = | ||
| "https://unpkg.com/@worldcoin/idkit-core/dist/idkit.global.js"; |
There was a problem hiding this comment.
| "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
…ts there once published)
Takaros999
left a comment
There was a problem hiding this comment.
LGTM, tbh I would change the browser index.html to only use the CDN script you can


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-coreso partners can load IDKit 4.x via unpkg/jsdelivr without a separate standalone package.A new
src/browser.tsentry assigns the existing clientIDKitnamespace towindow.IDKitand deliberately omits RP signing (still/signingon the server).tsupnow runs a second minified IIFE build todist/idkit.global.js, withunpkg/jsdelivrinpackage.jsonpointing at that file; WASM copy todist/idkit_wasm_bg.wasmis shared with the ESM/CJS build via a refactoredcopyWasmToDist.js/packages/core/README.mddocuments CDN usage and a minimalwindow.IDKitexample. The browser example gains a Use CDN version toggle that dynamically loads the unpkg package root and runs the same verification flow throughwindow.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.