import * as ethers from "ethers"; import { Networkish } from "@ethersproject/networks"; import { ConnectionInfo } from "@ethersproject/web"; import { Web3Provider } from "../../src/web3/web3.provider"; import { IProvider, SignedDataStruct } from "../../src/web3/provider"; import { config } from "../config"; export class TestHelperTypes { static wallet(): ethers.Wallet { return new ethers.Wallet(this.privateKey()); } static privateKey(): string { return "0xc652107d70e7022e5ac598eac3eb82f92d2da28411b9462f793eb4257806d2ed"; } /** * This returns the options required to instantiate * an ethers.providers.JsonRpcProvider. * @returns providerOptions */ static providerOptions(): { network: Networkish, connection: ConnectionInfo } { return { network: { name: "rinkeby", chainId: 4, }, connection: { url: `https://rinkeby.infura.io/v3/${config().INFURA_API_KEY}`, headers: { 'Authorization': `Basic ${Buffer.from(config().INFURA_PROJECT_SECRET).toString('base64')}` } } } } /** * This returns a web3Provider instance using * an ethers.providers.JsonRpcProvider as the * implementation of the provider attribute. * @returns web3Provider */ static provider(): Web3Provider { const ethersWeb3Provider = new ethers.providers.JsonRpcProvider(this.providerOptions().connection, this.providerOptions().network); const wallet = new ethers.Wallet(this.privateKey(), ethersWeb3Provider); const testProvider: IProvider = { network: ethersWeb3Provider.network, send: ethersWeb3Provider.send, signTypedData_v4: async (account: string, data: SignedDataStruct) => { const types: any = {}; types[data.primaryType] = data.types[data.primaryType]; return await wallet._signTypedData(data.domain, types, data.message); }, }; return new Web3Provider(testProvider); } }