diff --git a/src/crypto/index.js b/src/crypto/index.js index d078e40..ce4037c 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -42,5 +42,7 @@ export { } from './provider.js'; // Backends (for direct access / testing) +// Note: WasmCryptoBackend is NOT re-exported here because it uses import.meta +// which is incompatible with React Native/Hermes. Import it directly: +// import { WasmCryptoBackend } from 'salvium-js/src/crypto/backend-wasm.js'; export { JsCryptoBackend } from './backend-js.js'; -export { WasmCryptoBackend } from './backend-wasm.js'; diff --git a/src/crypto/provider.js b/src/crypto/provider.js index 81e3d1e..7184191 100644 --- a/src/crypto/provider.js +++ b/src/crypto/provider.js @@ -28,10 +28,15 @@ export async function setCryptoBackend(type) { currentBackend = new JsCryptoBackend(); await currentBackend.init(); } else if (type === 'wasm') { - // Dynamic import to avoid loading WASM unless requested - const { WasmCryptoBackend } = await import('./backend-wasm.js'); - currentBackend = new WasmCryptoBackend(); - await currentBackend.init(); + // Dynamic import() is not supported in React Native/Hermes. + // In Node/Bun, import backend-wasm.js directly: + // import { WasmCryptoBackend } from './backend-wasm.js'; + // const backend = new WasmCryptoBackend(); await backend.init(); + throw new Error( + "WASM backend cannot be loaded via setCryptoBackend() — dynamic import() " + + "is not available in all runtimes (e.g. Hermes). In Node/Bun, import " + + "WasmCryptoBackend from './crypto/backend-wasm.js' directly." + ); } else { throw new Error(`Unknown crypto backend: ${type}. Use 'js' or 'wasm'.`); }