Adjust assert inside withWasm (#363)

This commit is contained in:
Jaco
2022-06-18 13:26:50 +03:00
committed by GitHub
parent ed438e8877
commit 03030ae93f
2 changed files with 10 additions and 3 deletions
+7
View File
@@ -1,5 +1,12 @@
# CHANGELOG
## master
Changes:
- Adjust assert inside `withWasm`
## 6.1.1 May 13, 2022
Changes:
+3 -3
View File
@@ -3,8 +3,6 @@
import type { WasmCryptoInstance } from '@polkadot/wasm-crypto-init/types';
import { assert } from '@polkadot/util';
import { bridge, initBridge } from './init';
export { packageInfo } from './packageInfo';
@@ -34,7 +32,9 @@ type PopFirst<T extends unknown[]> =
*/
function withWasm <T, F extends (wasm: WasmCryptoInstance, ...params: never[]) => T> (fn: F): (...params: PopFirst<Parameters<F>>) => ReturnType<F> {
return (...params: PopFirst<Parameters<F>>): ReturnType<F> => {
assert(bridge.wasm, 'The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
if (!bridge.wasm) {
throw new Error('The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
}
return fn(bridge.wasm, ...params) as ReturnType<F>;
};