-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run
chomp prettier
on codebase (#401)
- Loading branch information
Showing
18 changed files
with
323 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
let _nodeCrypto; | ||
|
||
export async function getIntegrityNodeLegacy(buf: Uint8Array | string): Promise<`sha384-${string}`> { | ||
const hash = (_nodeCrypto || (_nodeCrypto = (await (0, eval)('import("node:crypto")')))).createHash("sha384"); | ||
export async function getIntegrityNodeLegacy( | ||
buf: Uint8Array | string | ||
): Promise<`sha384-${string}`> { | ||
const hash = ( | ||
_nodeCrypto || (_nodeCrypto = await (0, eval)('import("node:crypto")')) | ||
).createHash("sha384"); | ||
hash.update(buf); | ||
return `sha384-${hash.digest("base64")}`; | ||
} | ||
|
||
export let getIntegrity = async function getIntegrity(buf: Uint8Array | string): Promise<`sha384-${string}`> { | ||
export let getIntegrity = async function getIntegrity( | ||
buf: Uint8Array | string | ||
): Promise<`sha384-${string}`> { | ||
const data = typeof buf === "string" ? new TextEncoder().encode(buf) : buf; | ||
const hashBuffer = await crypto.subtle.digest("SHA-384", data); | ||
const hashArray = Array.from(new Uint8Array(hashBuffer)); | ||
const hashBase64 = btoa(String.fromCharCode(...hashArray)); | ||
return `sha384-${hashBase64}`; | ||
} | ||
}; | ||
|
||
if (typeof crypto === 'undefined') | ||
getIntegrity = getIntegrityNodeLegacy; | ||
if (typeof crypto === "undefined") getIntegrity = getIntegrityNodeLegacy; |
Oops, something went wrong.