diff --git a/package.json b/package.json index bbd67b3..4e61539 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,8 @@ "it-stream-types": "^2.0.1", "protons-runtime": "^5.0.0", "uint8arraylist": "^2.4.3", - "uint8arrays": "^4.0.4" + "uint8arrays": "^4.0.4", + "wherearewe": "^2.0.1" }, "devDependencies": { "@chainsafe/libp2p-yamux": "^5.0.0", diff --git a/src/crypto/index.ts b/src/crypto/index.ts index a00634d..448dbdc 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -1,6 +1,7 @@ import crypto from 'node:crypto' import { newInstance, ChaCha20Poly1305 } from '@chainsafe/as-chacha20poly1305' import { digest } from '@chainsafe/as-sha256' +import { isElectronMain } from 'wherearewe' import { pureJsCrypto } from './js.js' import type { ICryptoInterface } from '../crypto.js' @@ -77,3 +78,9 @@ export const defaultCrypto: ICryptoInterface = { return nodeCrypto.chaCha20Poly1305Decrypt(ciphertext, nonce, ad, k, dst) } } + +// no chacha20-poly1305 in electron https://github.com/electron/electron/issues/24024 +if (isElectronMain) { + defaultCrypto.chaCha20Poly1305Encrypt = asCrypto.chaCha20Poly1305Encrypt + defaultCrypto.chaCha20Poly1305Decrypt = asCrypto.chaCha20Poly1305Decrypt +}