Skip to content

Commit

Permalink
Check if toolkit is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
maxima-net committed Aug 11, 2022
1 parent cf7f7b4 commit 8fe52fc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ethereum/signers/web3EthereumSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export class Web3EthereumSigner implements Signer {
}

async getAddress(): Promise<string> {
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)
Expand All @@ -38,7 +41,10 @@ export class Web3EthereumSigner implements Signer {

async sign(message: string): Promise<AtomexSignature> {
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));

Expand Down

0 comments on commit 8fe52fc

Please sign in to comment.