-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: now using ethers v6 as a dependency which may need extra attention when merging. The output of `eth_signTransaction` algorithms may be slightly different as transactions are by default infered as type 1 (EIP1559)
- Loading branch information
1 parent
977662a
commit f5dcdf2
Showing
26 changed files
with
254 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
import { Web3Provider, ExternalProvider } from '@ethersproject/providers' | ||
import { Wallet } from '@ethersproject/wallet' | ||
import { BrowserProvider, Eip1193Provider, Wallet } from 'ethers' | ||
|
||
export function createEthersProvider(): Web3Provider { | ||
export function createEthersProvider(): BrowserProvider { | ||
const privateKeyHex = '0x1da6847600b0ee25e9ad9a52abbd786dd2502fa4005dd5af9310b7cc7a3b25db' | ||
const wallet = new Wallet(privateKeyHex) | ||
const mockProvider = new MockWeb3Provider(wallet) | ||
const provider = new Web3Provider(mockProvider) | ||
const provider = new BrowserProvider(mockProvider) | ||
return provider | ||
} | ||
|
||
class MockWeb3Provider implements Eip1193Provider { | ||
constructor(private wallet: Wallet) {} | ||
|
||
class MockWeb3Provider implements ExternalProvider { | ||
constructor(private wallet: Wallet){ | ||
|
||
} | ||
async request(request: { method: string; params?: any[] }): Promise<any> { | ||
|
||
switch(request.method) { | ||
case 'personal_sign': | ||
//@ts-ignore | ||
return this.wallet.signMessage(request.params[1]) | ||
break | ||
case 'eth_signTypedData_v4': | ||
//@ts-ignore | ||
case 'eth_signTypedData_v4': | ||
// @ts-ignore | ||
const {domain, types, message} = JSON.parse(request.params[1]) | ||
delete(types.EIP712Domain) | ||
return this.wallet._signTypedData(domain, types, message) | ||
return this.wallet.signTypedData(domain, types, message) | ||
case 'eth_accounts': | ||
return [await this.wallet.getAddress()] | ||
case 'eth_chainId': | ||
return "1337" | ||
break | ||
default: | ||
throw Error(`not_available: method ${request.method}`) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.