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; + }, + }); +}