From 21feb9fa17e25fa75d2e1cc66b3e5e6fac720462 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 4 Apr 2023 06:08:30 -0400 Subject: [PATCH] *Add crypto subtle polyfill --- build.js | 2 +- package.json | 1 + polyfill.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 polyfill.js diff --git a/build.js b/build.js index b9ba69d..b768292 100644 --- a/build.js +++ b/build.js @@ -10,5 +10,5 @@ esbuild.buildSync({ define: { global: "self", }, - inject: ["process.js"], + inject: ["process.js", "polyfill.js"], }); diff --git a/package.json b/package.json index 7057709..1f86f0d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "dependencies": { "@lumeweb/hyperswarm-web": "git+https://git.lumeweb.com/LumeWeb/hyperswarm-web.git", "@noble/ed25519": "^1.7.3", + "@peculiar/webcrypto": "^1.4.3", "b4a": "^1.6.3", "eventemitter2": "^6.4.9", "hyperswarm": "^4.4.0", diff --git a/polyfill.js b/polyfill.js new file mode 100644 index 0000000..6767dc3 --- /dev/null +++ b/polyfill.js @@ -0,0 +1,11 @@ +import { Crypto } from "@peculiar/webcrypto"; + +let globalCrypto = self.crypto; +if (!globalCrypto.subtle) { + let subtleCrypto = new Crypto().subtle; + Object.defineProperty(globalCrypto, "subtle", { + get() { + return subtleCrypto; + }, + }); +}