From 8fe52fc3a1ad59ff285bd47a5853c7434e9de2e3 Mon Sep 17 00:00:00 2001 From: Maxim Kucherov Date: Tue, 9 Aug 2022 16:23:37 +0300 Subject: [PATCH] Check if toolkit is undefined --- src/ethereum/signers/web3EthereumSigner.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ethereum/signers/web3EthereumSigner.ts b/src/ethereum/signers/web3EthereumSigner.ts index ea0d22a1..c58328f3 100644 --- a/src/ethereum/signers/web3EthereumSigner.ts +++ b/src/ethereum/signers/web3EthereumSigner.ts @@ -23,7 +23,10 @@ export class Web3EthereumSigner implements Signer { } async getAddress(): Promise { - const web3 = await this.atomexContext.providers.blockchainProvider.getReadonlyToolkit(this.blockchain, 'web3') as Web3; + const web3 = await this.atomexContext.providers.blockchainProvider.getReadonlyToolkit(this.blockchain, 'web3') as Web3 | undefined; + if (!web3) + throw new Error('readonly web3 toolkit is unavailable'); + const accounts = await web3.eth.getAccounts(); const address = accounts[0]; if (!address) @@ -38,7 +41,10 @@ export class Web3EthereumSigner implements Signer { async sign(message: string): Promise { const address = await this.getAddress(); - const web3 = await this.atomexContext.providers.blockchainProvider.getToolkit(this.blockchain, address, 'web3') as Web3; + const web3 = await this.atomexContext.providers.blockchainProvider.getToolkit(this.blockchain, address, 'web3') as Web3 | undefined; + if (!web3) + throw new Error('web3 toolkit is unavailable'); + const signatureBytes = await this.signInternal(message, address, web3); const publicKeyBytes = recoverPublicKey(signatureBytes, web3.eth.accounts.hashMessage(message));