Feature: Use eth_sign for hardware wallets connected via onboard.js (#742)
* Use eth_sign for hardware wallets * install onboard.js with fix from forked repo * rebuild yarn.lock to fix cached onboard * update bnc-onboard
This commit is contained in:
parent
e33d9fd9bb
commit
b8bfeab588
|
@ -52,7 +52,7 @@
|
|||
"async-sema": "^3.1.0",
|
||||
"axios": "0.19.2",
|
||||
"bignumber.js": "9.0.0",
|
||||
"bnc-onboard": "1.5.0",
|
||||
"bnc-onboard": "^1.7.1",
|
||||
"connected-react-router": "6.8.0",
|
||||
"currency-flags": "^2.1.1",
|
||||
"date-fns": "2.11.1",
|
||||
|
|
|
@ -4,7 +4,7 @@ import { getWeb3 } from '~/logic/wallets/getWeb3'
|
|||
|
||||
const ETH_SIGN_NOT_SUPPORTED_ERROR_MSG = 'ETH_SIGN_NOT_SUPPORTED'
|
||||
|
||||
export const getEthSigner = async ({
|
||||
export const ethSigner = async ({
|
||||
baseGas,
|
||||
data,
|
||||
gasPrice,
|
||||
|
|
|
@ -1,19 +1,30 @@
|
|||
// @flow
|
||||
|
||||
import { getEIP712Signer } from './EIP712Signer'
|
||||
import { getEthSigner } from './ethSigner'
|
||||
import { ethSigner } from './ethSigner'
|
||||
|
||||
// 1. we try to sign via EIP-712 if user's wallet supports it
|
||||
// 2. If not, try to use eth_sign (Safe version has to be >1.1.1)
|
||||
// If eth_sign, doesn't work continue with the regular flow (on-chain signatures, more in createTransaction.js)
|
||||
|
||||
const signingFuncs = [getEIP712Signer('v3'), getEIP712Signer('v4'), getEIP712Signer(), getEthSigner]
|
||||
const SIGNERS = {
|
||||
EIP712_V3: getEIP712Signer('v3'),
|
||||
EIP712_V4: getEIP712Signer('v4'),
|
||||
EIP712: getEIP712Signer(),
|
||||
ETH_SIGN: ethSigner,
|
||||
}
|
||||
|
||||
// hardware wallets support eth_sign only
|
||||
const getSignersByWallet = (isHW: boolean): Array<$Values<SIGNERS>> =>
|
||||
isHW ? [SIGNERS.ETH_SIGN] : [SIGNERS.EIP712_V3, SIGNERS.EIP712_V4, SIGNERS.EIP712, SIGNERS.ETH_SIGN]
|
||||
|
||||
export const SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES = '>=1.1.1'
|
||||
|
||||
export const tryOffchainSigning = async (txArgs) => {
|
||||
export const tryOffchainSigning = async (txArgs, isHW: boolean): Promise<string> | typeof undefined => {
|
||||
let signature
|
||||
for (let signingFunc of signingFuncs) {
|
||||
|
||||
const signerByWallet = getSignersByWallet(isHW)
|
||||
for (let signingFunc of signerByWallet) {
|
||||
try {
|
||||
signature = await signingFunc(txArgs)
|
||||
|
||||
|
|
|
@ -102,12 +102,9 @@ const createTransaction = ({
|
|||
// https://github.com/LedgerHQ/ledgerjs/issues/378
|
||||
// Couldn't find an issue for trezor but the error is almost the same
|
||||
const canTryOffchainSigning =
|
||||
!isExecution &&
|
||||
!smartContractWallet &&
|
||||
!hardwareWallet &&
|
||||
semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES)
|
||||
!isExecution && !smartContractWallet && semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES)
|
||||
if (canTryOffchainSigning) {
|
||||
const signature = await tryOffchainSigning({ ...txArgs, safeAddress })
|
||||
const signature = await tryOffchainSigning({ ...txArgs, safeAddress }, hardwareWallet)
|
||||
|
||||
if (signature) {
|
||||
closeSnackbar(beforeExecutionKey)
|
||||
|
|
|
@ -87,12 +87,9 @@ const processTransaction = ({
|
|||
// https://github.com/LedgerHQ/ledgerjs/issues/378
|
||||
// Couldn't find an issue for trezor but the error is almost the same
|
||||
const canTryOffchainSigning =
|
||||
!isExecution &&
|
||||
!smartContractWallet &&
|
||||
!hardwareWallet &&
|
||||
semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES)
|
||||
!isExecution && !smartContractWallet && semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES)
|
||||
if (canTryOffchainSigning) {
|
||||
const signature = await tryOffchainSigning({ ...txArgs, safeAddress })
|
||||
const signature = await tryOffchainSigning({ ...txArgs, safeAddress }, hardwareWallet)
|
||||
|
||||
if (signature) {
|
||||
closeSnackbar(beforeExecutionKey)
|
||||
|
|
Loading…
Reference in New Issue