mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-18 21:53:13 +00:00
* test: specify encryption method Makes debugging easier. * Fix log typo * Remove ecies-geth Start removal of elliptic dependency and move towards exclusive usage to CryptoSubtle.
30 lines
664 B
TypeScript
30 lines
664 B
TypeScript
import nodeCrypto from "crypto";
|
|
|
|
// IE 11
|
|
declare global {
|
|
interface Window {
|
|
msCrypto?: Crypto;
|
|
}
|
|
|
|
interface Crypto {
|
|
webkitSubtle?: SubtleCrypto;
|
|
}
|
|
}
|
|
|
|
const crypto = window.crypto || window.msCrypto || nodeCrypto.webcrypto;
|
|
const subtle: SubtleCrypto = crypto.subtle || crypto.webkitSubtle;
|
|
|
|
if (subtle === undefined) {
|
|
throw new Error("crypto and/or subtle api unavailable");
|
|
}
|
|
|
|
export { crypto, subtle };
|
|
|
|
export function randomBytes(size: number): Uint8Array {
|
|
return crypto.getRandomValues(new Uint8Array(size));
|
|
}
|
|
|
|
export function sha256(msg: ArrayBufferLike): Promise<ArrayBuffer> {
|
|
return subtle.digest({ name: "SHA-256" }, msg);
|
|
}
|