Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/web-crypto-isolate-bundlers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-server-sdk': patch
---

Remove `node:crypto` fallbacks from Web Crypto helpers so isolate/edge bundlers can import the SDK.
2 changes: 1 addition & 1 deletion packages/livekit-server-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@
"vitest": "^4.0.0"
},
"engines": {
"node": ">=18"
"node": ">=19"
}
}
12 changes: 5 additions & 7 deletions packages/livekit-server-sdk/src/crypto/digest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
//
// SPDX-License-Identifier: Apache-2.0

// Use the Web Crypto API if available, otherwise fallback to Node.js crypto
// Web Crypto only — no import('node:crypto') so isolate/edge bundlers can resolve this module
export async function digest(data: string): Promise<ArrayBuffer> {
if (globalThis.crypto?.subtle) {
const encoder = new TextEncoder();
return crypto.subtle.digest('SHA-256', encoder.encode(data));
} else {
const nodeCrypto = await import('node:crypto');
return nodeCrypto.createHash('sha256').update(data).digest();
if (!globalThis.crypto?.subtle) {
throw new Error('Web Crypto API is required (globalThis.crypto.subtle)');
}
const encoder = new TextEncoder();
return crypto.subtle.digest('SHA-256', encoder.encode(data));
}
10 changes: 4 additions & 6 deletions packages/livekit-server-sdk/src/crypto/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
//
// SPDX-License-Identifier: Apache-2.0

// Use the Web Crypto API if available, otherwise fallback to Node.js crypto
// Web Crypto only — no import('node:crypto') so isolate/edge bundlers can resolve this module
export async function getRandomBytes(size: number = 16): Promise<Uint8Array> {
if (globalThis.crypto) {
return crypto.getRandomValues(new Uint8Array(size));
} else {
const nodeCrypto = await import('node:crypto');
return nodeCrypto.getRandomValues(new Uint8Array(size));
if (!globalThis.crypto?.getRandomValues) {
throw new Error('Web Crypto API is required (globalThis.crypto.getRandomValues)');
}
return crypto.getRandomValues(new Uint8Array(size));
}
Loading