Skip to content

fix(core): drop ulid package; implement ULID via Web Crypto (#57)#59

Merged
paperhurts merged 1 commit into
mainfrom
fix/drop-ulid-dep
Jun 19, 2026
Merged

fix(core): drop ulid package; implement ULID via Web Crypto (#57)#59
paperhurts merged 1 commit into
mainfrom
fix/drop-ulid-dep

Conversation

@paperhurts

Copy link
Copy Markdown
Owner

Closes #57. Supersedes the insufficient #58.

The real bug: importing the ulid package runs export const ulid = factory() at module load, which calls detectPrng() and throws secure crypto unusable, insecure Math.random not allowed in the crxjs MV3 service-worker context — before any of our code runs. So #58 (binding a PRNG via factory()) couldn't help: the throw fires on import. The SW stayed Inactive; the entire background (reconcile, native-tree sync, poll) never ran.

Fix: remove the ulid dependency and implement newUlid() directly — 48-bit ms timestamp + 80 bits from crypto.getRandomValues, Crockford base32, 26 chars, time-sortable. Verified detectPrng/detectRoot/etc. are gone from both shells' built bundles.

Docs: added a "Creating your GitHub token (PAT)" section to the root README (how to make the fine-grained token, which was only documented in the Chrome package README); gitignored .env* (e2e throwaway-repo creds); corrected test counts (core 82→83, total 310→311).

Tests: core 83, extension-shared 119, web 109 — all pass; both shell builds clean.

🤖 Generated with Claude Code

The previous fix (#58) was insufficient: importing the `ulid` package runs its
module-level `export const ulid = factory()` → `detectPrng()` AT IMPORT TIME,
which throws "secure crypto unusable, insecure Math.random not allowed" under
crxjs MV3 service-worker bundling — before any of our code runs. So the SW kept
crashing (registration failed, "Inactive") and the whole background never ran.

Remove the `ulid` dependency entirely and implement newUlid() directly:
48-bit ms timestamp + 80 bits from crypto.getRandomValues, Crockford base32,
26 chars, time-sortable. crypto.getRandomValues is present in the SW, extension
pages, the web UI, and Node 19+. Verified: detectPrng/detectRoot/etc. no longer
appear in either shell's built bundle.

docs: add a "Creating your GitHub token (PAT)" section to the root README (how
to actually make the fine-grained token, not just revoke it); gitignore .env*
(e2e throwaway-repo credentials); correct test counts (core 82->83, total
310->311).

Closes #57

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@paperhurts paperhurts merged commit 6712626 into main Jun 19, 2026
1 check passed
@paperhurts paperhurts deleted the fix/drop-ulid-dep branch June 19, 2026 22:44
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.

MV3 service worker crashes on load: ulid 'secure crypto unusable' — background never runs

1 participant