From 85000d4737edb3417ca9518cc3bc87d7b7ad87a2 Mon Sep 17 00:00:00 2001 From: Cody Miller Date: Mon, 2 Oct 2023 20:02:56 -0400 Subject: [PATCH] fix: polyfill crypto --- package.json | 1 + src/util/crypto.ts | 4 ++++ src/util/webhooks.ts | 2 ++ yarn.lock | 8 ++++++++ 4 files changed, 15 insertions(+) create mode 100644 src/util/crypto.ts diff --git a/package.json b/package.json index 7fbb80ff..7523029a 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "dependencies": { "@onehop/json-methods": "^1.2.0", "cross-fetch": "^3.1.5", + "uncrypto": "^0.1.3", "zod": "^3.21.4" } } diff --git a/src/util/crypto.ts b/src/util/crypto.ts new file mode 100644 index 00000000..51745385 --- /dev/null +++ b/src/util/crypto.ts @@ -0,0 +1,4 @@ +import * as cryptoPonyfill from 'uncrypto'; + +export const HAS_NATIVE_CRYPTO = typeof globalThis.crypto !== 'undefined'; +export const crypto = HAS_NATIVE_CRYPTO ? globalThis.crypto : cryptoPonyfill; diff --git a/src/util/webhooks.ts b/src/util/webhooks.ts index e20c0c13..f98ed53e 100644 --- a/src/util/webhooks.ts +++ b/src/util/webhooks.ts @@ -1,3 +1,5 @@ +import {crypto} from './crypto'; + export const POSSIBLE_EVENTS = { Channels: [ { diff --git a/yarn.lock b/yarn.lock index ea418f79..ac0361e8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -559,6 +559,7 @@ __metadata: typedoc-plugin-markdown: 3.14.0 typedoc-plugin-missing-exports: 1.0.0 typescript: ^5.0.2 + uncrypto: ^0.1.3 zod: ^3.21.4 languageName: unknown linkType: soft @@ -3955,6 +3956,13 @@ __metadata: languageName: node linkType: hard +"uncrypto@npm:^0.1.3": + version: 0.1.3 + resolution: "uncrypto@npm:0.1.3" + checksum: 07160e08806dd6cea16bb96c3fd54cd70fc801e02fc3c6f86980144d15c9ebbd1c55587f7280a207b3af6cd34901c0d0b77ada5a02c2f7081a033a05acf409e2 + languageName: node + linkType: hard + "unique-filename@npm:^2.0.0": version: 2.0.1 resolution: "unique-filename@npm:2.0.1"