Skip to content

Commit

Permalink
try other method to force exclusion of dynamic import as we have to s…
Browse files Browse the repository at this point in the history
…upport node 18
  • Loading branch information
janfjohannes committed Mar 21, 2024
1 parent 56ed7c2 commit 70d6ea0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lix/source-code/client/src/hash.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
export async function hash(inputStr: string) {
if (!globalThis?.crypto) {
let usedCrypto
// @ts-ignore
if (typeof crypto === "undefined" && typeof process !== "undefined" && process?.versions?.node) {
const modName = "crypto"
usedCrypto = await import(`node:${modName}`)
} else if (typeof crypto !== "undefined") {
usedCrypto = crypto
}
if (!usedCrypto) {
throw new Error("Could not find crypto features in runtime")
}

const idDigest = await globalThis.crypto.subtle.digest(
"SHA-256",
new TextEncoder().encode(inputStr)
)
const idDigest = await usedCrypto.subtle.digest("SHA-256", new TextEncoder().encode(inputStr))
return [...new Uint8Array(idDigest)].map((b) => ("00" + b.toString(16)).slice(-2)).join("")
}

0 comments on commit 70d6ea0

Please sign in to comment.