socket-function 0.8.23 → 0.8.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/misc.ts +8 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.8.23",
3
+ "version": "0.8.25",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
package/src/misc.ts CHANGED
@@ -10,6 +10,14 @@ export function convertErrorStackToError(error: string): Error {
10
10
  export function sha256Hash(buffer: Buffer) {
11
11
  return crypto.createHash("sha256").update(buffer).digest("hex");
12
12
  }
13
+ /** Async, but works both clientside and serverside. */
14
+ export async function sha256HashPromise(buffer: Buffer) {
15
+ if (isNode()) {
16
+ return crypto.createHash("sha256").update(buffer).digest("hex");
17
+ } else {
18
+ return window.crypto.subtle.digest("SHA-256", buffer);
19
+ }
20
+ }
13
21
 
14
22
 
15
23
  export function arrayEqual(a: unknown[], b: unknown[]) {