Skip to content

fix: use globalThis.crypto.randomUUID for cross-runtime compat#5

Open
orveth wants to merge 3 commits into
feat/storage-provider-cleanfrom
fix/global-this-crypto-randomuuid
Open

fix: use globalThis.crypto.randomUUID for cross-runtime compat#5
orveth wants to merge 3 commits into
feat/storage-provider-cleanfrom
fix/global-this-crypto-randomuuid

Conversation

@orveth

@orveth orveth commented May 27, 2026

Copy link
Copy Markdown

Stacked on #4.

window.crypto is browser-only; Node 19+, Bun, and Deno expose the same WebCrypto interface at globalThis.crypto. Swap the three randomUUID() callsites (getAttestation.ts, main.tsx, developer.tsx) so the SDK can generate attestation nonces on non-browser runtimes.

3 lines changed across 3 files. Rebase target moves from feat/storage-provider-clean to master once #4 merges.

gudnuf added 2 commits May 27, 2026 10:49
…orage })

Introduces a StorageProvider interface and a `browserStorage` helper. Every
SDK consumer now passes a storage provider explicitly via configure() — no
silent localStorage fallback, no hidden environment branching.

Browser apps import the bundled helper:
  import { configure, browserStorage } from "@agicash/opensecret-sdk";
  configure({ apiUrl, clientId, storage: browserStorage });

Non-browser consumers (React Native, Node, Bun, CLI, MCP) implement the
two-namespace interface against their own backing store. browserStorage
uses getters so importing it in a non-browser context is safe — window is
only referenced if the provider is actually accessed.

Updates the test setup to pass browserStorage so existing integration test
fixtures keep working.
Swap all 43 direct window.localStorage / window.sessionStorage / bare
localStorage / bare sessionStorage callsites across api.ts, encryptedApi.ts,
ai.ts, getAttestation.ts, platformApi.ts, main.tsx, and developer.tsx for
getStorage().persistent.* / getStorage().session.*.

OpenSecretProvider — the React DOM component — wires the SDK's internal
configure() call with the bundled browserStorage helper, since the provider
is intrinsically browser-only.
@orveth orveth force-pushed the feat/storage-provider-clean branch from db1e111 to 3c38f16 Compare May 27, 2026 17:49
window.crypto is browser-only; Node 19+, Bun, and Deno expose the same
WebCrypto interface at globalThis.crypto. Swap the three randomUUID()
callsites (getAttestation.ts, main.tsx, developer.tsx) so the SDK can
generate attestation nonces on non-browser runtimes.
@orveth orveth force-pushed the fix/global-this-crypto-randomuuid branch from a015dfd to 11adae4 Compare May 27, 2026 17:49
@gudnuf gudnuf requested review from jbojcic1 and pmilic021 May 27, 2026 19:13
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