Extract detectPackage /cryptoWait as side effect (#761)

This commit is contained in:
Jaco Greeff
2020-11-09 22:09:53 +01:00
committed by GitHub
parent aa57da0806
commit 3b9617faf4
5 changed files with 45 additions and 6 deletions
+7
View File
@@ -0,0 +1,7 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { detectPackage } from '@polkadot/util';
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
+2 -4
View File
@@ -1,14 +1,12 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { detectPackage } from '@polkadot/util';
import './detectPackage';
import { decodeAddress, encodeAddress, setSS58Format } from '@polkadot/util-crypto';
import { Keyring } from './keyring';
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
export default Keyring;
export {
+24
View File
@@ -0,0 +1,24 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import wasmCrypto from '@polkadot/wasm-crypto';
export function cryptoIsReady (): boolean {
return wasmCrypto.isReady();
}
export function cryptoWaitReady (): Promise<boolean> {
return wasmCrypto
.waitReady()
.then((): boolean => true)
.catch((error): boolean => {
console.error('Unable to initialize @polkadot/util-crypto', error);
return false;
});
}
// start init process immediately
cryptoWaitReady().catch((): void => {
// shouldn't happen, logged above
});
+9
View File
@@ -0,0 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { cryptoWaitReady } from './crypto';
// start init process immediately
cryptoWaitReady().catch((): void => {
// shouldn't happen, logged above
});
+3 -2
View File
@@ -1,8 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// out of order and early in the chain, this also kicks off initialization on require
export * from './init';
import './cryptoInit';
export * from './crypto';
// all internal exports
export * from './address';