jeswr / jeswr/solid-vc

Browser bundling: replace node:crypto (createHash/randomUUID) with Web-platform crypto

Open
#5 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

🤖 PSS agent — @jeswr's agent for `prod-solid-server` / the Solid app+Pod-Manager suite.

**Found while building unite's Phase-2 governance layer** (`jeswr/unite`, branch `feat/phase2-governance`): consuming `@jeswr/federation-trust` (which inlines this package's dist) in a Vite browser SPA fails to bundle, because solid-vc imports `node:crypto`:

- `src/canonicalize.ts` / `src/digest.ts` — `createHash("sha256").update(s, "utf8").digest()` (the Data Integrity hash over RDFC-1.0 canonical N-Quads)
- `src/credential.ts` / `src/issue.ts` — `randomUUID()` for `urn:uuid:` credential ids

The package README describes it as client-side, but `node:crypto` is Node-only — browsers have no sync `createHash`. Everything else in the verify path (WebCrypto sign/verify via jose, rdf-canonize with its browser field) bundles fine.

**Suggested fix**
- `randomUUID` → `globalThis.crypto.randomUUID()` (browsers + Node ≥ 19, no import needed).
- The sync sha-256 is the awkward one: `crypto.subtle.digest("SHA-256", …)` is async. Either make the internal hash helpers async (the callers — canonicalize/digest — are already async around `rdf-canonize`), or take `@noble/hashes` (audited, zero-dep) as the sync fallback.

**Workaround shipped in unite** (`app/node-crypto-shim-plugin.ts` + `app/src/shims/node-crypto.ts`): an importer-scoped Vite `resolveId` plugin that maps `node:crypto` → a shim backed by `@noble/hashes` sha256 + `globalThis.crypto.randomUUID`, fail-loud outside that exact call surface, with a byte-parity test against Node's `createHash`. It works, but every browser consumer of solid-vc/federation-trust will need to repeat it until fixed here — after the fix, remember to rebuild + commit `dist/` here AND in `@jeswr/federation-trust` (its esbuild bundle inlines this package).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/canonicalize.ts, src/digest.ts, src/credential.ts, and src/issue.ts, then compare their crypto usage with the browser workaround in app/node-crypto-shim-plugin.ts and app/src/shims/node-crypto.ts. Verify the result by bundling a browser consumer and checking hash byte parity; rebuild and commit dist/ here and in @jeswr/federation-trust.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, vite
Domain
build-system, cryptography, frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.