From 6cc15997f8868cbde82033890dc2eaf075db3280 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 4 Apr 2023 06:30:22 -0400 Subject: [PATCH] *add webcrypto polyfill fork --- build.js | 2 +- package.json | 1 + polyfill.js | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 polyfill.js diff --git a/build.js b/build.js index d0f4f54..447a53a 100644 --- a/build.js +++ b/build.js @@ -10,5 +10,5 @@ esbuild.buildSync({ define: { global: "self", }, - inject:['timers.js'] + inject: ["timers.js", "polyfill.js"], }); diff --git a/package.json b/package.json index eadd0bb..fbec70b 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@libp2p/utils": "^3.0.6", "@lumeweb/kernel-swarm-client": "git+https://git.lumeweb.com/LumeWeb/kernel-swarm-client.git", "@multiformats/mafmt": "^11.1.2", + "@peculiar/webcrypto": "git+https://git.lumeweb.com/LumeWeb/webcrypto.git", "b4a": "^1.6.3", "blockstore-idb": "^1.1.0", "buffer": "^6.0.3", diff --git a/polyfill.js b/polyfill.js new file mode 100644 index 0000000..892bd4d --- /dev/null +++ b/polyfill.js @@ -0,0 +1,13 @@ +import { Crypto } from "@peculiar/webcrypto"; +import { Buffer } from "buffer"; + +let globalCrypto = self.crypto; +if (!globalCrypto.subtle) { + let subtleCrypto = new Crypto().subtle; + Object.defineProperty(globalCrypto, "subtle", { + get() { + return subtleCrypto; + }, + }); +} +export { Buffer };