Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const networkId = Number(this.state.ethereum.networkId)
const rpcUrl = this.state.ethereum.endpoint
const engine = new ProviderEngine()
const transport = await this.transport()
const ledger = createLedgerSubprovider(
() => transport, {
networkId,
accountsLength: 1,
path,
})
ledger.signMessage = ledger.signPersonalMessage
engine.addProvider(ledger)
engine.addProvider(
// new RpcSubprovider({ rpcUrl }),
new FetchSubprovider({
rpcUrl,
}),
)
engine.start()
// @ts-ignore
// const web3account = (await .web3!.eth.getAccounts())[0]
// console.assert(web3account === selectedAddress,
// `Expected web3 to be initialized with ${selectedAddress} but got ${web3account}`)
// @ts-ignore
ethereumModule.setProvider(engine)
}
async switchToLedgerWallet(accountsOffset = 0, accountsQuantity = 6) {
const engine = new ProviderEngine();
this.getLedgerTransport = () => HWTransportNodeHid.create();
const ledger = Web3SubProvider(this.getLedgerTransport, {
networkId: CONFIG.chainId,
accountsLength: accountsQuantity,
accountsOffset: accountsOffset
});
const subscriptionSubprovider = new SubscriptionSubprovider();
subscriptionSubprovider.on('data', (err, notification) => {
engine.emit('data', err, notification);
});
engine.addProvider(ledger);
engine.addProvider(subscriptionSubprovider);
engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));
engine.start();
this.web3 = new Web3(engine);
this.web3.transactionConfirmationBlocks = 1;
}
this.trezorWalletSubProvider = await TrezorWalletSubProviderFactory(
CONFIG.chainId,
accountsOffset,
accountsQuantity,
eventEmitter
);
const engine = new ProviderEngine();
const subscriptionSubprovider = new SubscriptionSubprovider();
subscriptionSubprovider.on('data', (err, notification) => {
engine.emit('data', err, notification);
});
engine.addProvider(this.trezorWalletSubProvider);
engine.addProvider(subscriptionSubprovider);
engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));
engine.start();
this.web3 = new Web3(engine);
this.web3.transactionConfirmationBlocks = 1;
}
return new Promise(async (resolve, reject) => {
const engine = new ProviderEngine()
const getTransport = () => TransportU2F.create()
const ledger = createLedgerSubprovider(getTransport, {
networkId: 1,
accountsLength: 5,
})
ledger.getAccounts = () => ["123"]
ledger.signMessage = ledger.signPersonalMessage
engine.addProvider(ledger)
engine.addProvider(
new FetchSubprovider({
rpcUrl: "https://mainnet.infura.io/5Ic91y0T9nLh6qUg33K0",
}),
)
engine.start()
resolve(new Web3(engine))
})
}
export function getProvider() {
const ethNet = appConfig().network;
const networkId = appConfig().networkId;
const rpcUrl = getNodeUrl(ethNet);
const engine = new ProviderEngine();
const getTransport = async () => TransportU2F.create();
const ledger = createLedgerSubprovider(getTransport, {
networkId,
accountsLength: 5,
});
engine.addProvider(ledger);
engine.addProvider(new FetchSubprovider({ rpcUrl }));
engine.start();
return engine;
}
createWeb3(accountsOffset, accountsQuantity) {
accountsOffset = accountsOffset || 0;
accountsQuantity = accountsQuantity || 6;
const engine = new ProviderEngine();
const getTransport = () => HWTransportNodeHid.create();
const ledger = Web3SubProvider(getTransport, {
networkId: chainId,
accountsLength: accountsQuantity,
accountsOffset
});
engine.addProvider(ledger);
engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));
engine.start();
return new Web3(engine);
}
signTransaction(args) {
async defaultWallet() {
const engine = new ProviderEngine();
engine.addProvider(this.getWalletEthTxSubprovider());
engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));
engine.start();
this.web3 = new Web3(engine);
this.web3.transactionConfirmationBlocks = 1;
}
export const getReadOnlyWeb3 = async () => {
const engine = new ProviderEngine();
engine.addProvider(new FetchSubprovider({ rpcUrl }));
engine.start();
return new Web3(engine);
};