● 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:
Matt Hess
2026-02-09 06:27:06 +00:00
parent 7bb66ac1ac
commit ba691182a0
2 changed files with 12 additions and 5 deletions
+3 -1
View File
@@ -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';
+9 -4
View File
@@ -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'.`);
}