Skip to content

Commit

Permalink
fix: Properly update wallet engine private key on account change (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
skambalin authored Mar 25, 2024
1 parent 66bd068 commit 1f73742
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/wallet-engine/src/engine/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider';

import { Engine, EngineEventTarget } from './engine';
import { ChainConfig } from '../types';
import { getKeyPair } from '../accounts';

export type BiconomyOptions = {
apiKey: string;
Expand All @@ -28,7 +27,6 @@ const createBiconomyProvider = async (provider: providers.ExternalProvider, opti
contractAddresses: [],
});

console.log('Biconomy', options);
await biconomyInstance.init();

return biconomyInstance.provider;
Expand Down Expand Up @@ -65,10 +63,14 @@ export const createEthereumEngine = ({
const getProvider = async () => {
const privateKey = getPrivateKey();

if (!providerFactory.provider && privateKey) {
const { secretKey } = getKeyPair({ type: 'ethereum', privateKey });
if (!privateKey) {
throw new Error('Ethereum provider is not ready. Empty private key!');
}

await providerFactory.setupProvider(secretKey.toString('hex'));
if (providerFactory.provider) {
await providerFactory.updateAccount({ privateKey });
} else {
await providerFactory.setupProvider(privateKey);
}

if (!providerFactory.provider) {
Expand Down

0 comments on commit 1f73742

Please sign in to comment.