Conversation
|
|
Please review, Should not have any breaking issues. |
|
I think this might cause race-conditions in some cases. For example, if I have a NodeJS script that immediately attempts to execute a hashing operation at its entry point like so: node index.js import { hexToBin, sha256 } from '@bitauth/libauth';
// 32 byte hex payload
const hexPayload = '00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff';
// I'm not sure if we have a guarantee that sha256 will be instantiated at this point because the crypto WASM promises may not have resolved
sha256.hash(hexToBin(hexPayload));You might be able to get around this by setting your tsconfig.json I think this would also break the typing where the WASM functions are injected automatically as arguments to other functions too (because There's a bit of cross-over that might help here (that shows, roughly, how to configure Vite): |
e72ba49 to
60aec23
Compare
The latest React projects complains the existing code has a top level await. This proposed change returns the same variables but not as promises.
The code may look a little "hacky" but the traditional way of solving is issue using IIFE doesn't work.
ie: this doesn't work:
(async() => {
const [sha1, sha256, sha512, ripemd160, secp256k1] = await Promise.all([
instantiateSha1(),
instantiateSha256(),
instantiateSha512(),
instantiateRipemd160(),
instantiateSecp256k1(),
]);
})();
export { ripemd160, secp256k1, sha1, sha256, sha512 };