mirror of https://github.com/waku-org/js-waku.git
Use `@noble/secp2156k1`'s sha3 util
This commit is contained in:
parent
9829cc2cab
commit
50fa2d881d
|
@ -1,7 +1,6 @@
|
|||
import nodeCrypto from "crypto";
|
||||
|
||||
import * as secp from "@noble/secp256k1";
|
||||
import { concat } from "uint8arrays/concat";
|
||||
|
||||
declare const self: Record<string, any> | undefined;
|
||||
const crypto: { node?: any; web?: any } = {
|
||||
|
@ -22,17 +21,4 @@ export function getSubtle(): SubtleCrypto {
|
|||
}
|
||||
|
||||
export const randomBytes = secp.utils.randomBytes;
|
||||
|
||||
export async function sha256(...messages: Uint8Array[]): Promise<Uint8Array> {
|
||||
if (crypto.web) {
|
||||
const buffer = await crypto.web.subtle.digest("SHA-256", concat(messages));
|
||||
return new Uint8Array(buffer);
|
||||
} else if (crypto.node) {
|
||||
const { createHash } = crypto.node;
|
||||
const hash = createHash("sha256");
|
||||
messages.forEach((m) => hash.update(m));
|
||||
return Uint8Array.from(hash.digest());
|
||||
} else {
|
||||
throw new Error("The environment doesn't have sha256 function");
|
||||
}
|
||||
}
|
||||
export const sha256 = secp.utils.sha256;
|
||||
|
|
Loading…
Reference in New Issue