Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): use lib0 sha256 when api not available #6454

Merged
merged 1 commit into from
Mar 12, 2024
Merged
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
6 changes: 5 additions & 1 deletion packages/framework/store/src/persistence/blob/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { toBase64 } from 'lib0/buffer.js';
import { digest } from 'lib0/hash/sha256';

export async function sha(input: ArrayBuffer): Promise<string> {
const hash = await crypto.subtle.digest('SHA-256', input);
const hash =
crypto.subtle === undefined // crypto.subtle is not available without a secure context (HTTPS)
? digest(new Uint8Array(input))
: await crypto.subtle.digest('SHA-256', input);

// faster conversion from ArrayBuffer to base64 in browser
return toBase64(new Uint8Array(hash)).replace(/\+/g, '-').replace(/\//g, '_');
Expand Down
Loading