● Remove Hermes-incompatible WASM imports from crypto module
Drop static re-export of WasmCryptoBackend from crypto/index.js
(import.meta breaks React Native/Hermes) and replace dynamic
import() in setCryptoBackend('wasm') with a thrown error pointing
to direct import for Node/Bun environments.
This commit is contained in:
+3
-1
@@ -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';
|
||||
|
||||
@@ -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'.`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user