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",
|
"async-sema": "^3.1.0",
|
||||||
"axios": "0.19.2",
|
"axios": "0.19.2",
|
||||||
"bignumber.js": "9.0.0",
|
"bignumber.js": "9.0.0",
|
||||||
"bnc-onboard": "1.5.0",
|
"bnc-onboard": "^1.7.1",
|
||||||
"connected-react-router": "6.8.0",
|
"connected-react-router": "6.8.0",
|
||||||
"currency-flags": "^2.1.1",
|
"currency-flags": "^2.1.1",
|
||||||
"date-fns": "2.11.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'
|
const ETH_SIGN_NOT_SUPPORTED_ERROR_MSG = 'ETH_SIGN_NOT_SUPPORTED'
|
||||||
|
|
||||||
export const getEthSigner = async ({
|
export const ethSigner = async ({
|
||||||
baseGas,
|
baseGas,
|
||||||
data,
|
data,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
|
|
|
@ -1,19 +1,30 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import { getEIP712Signer } from './EIP712Signer'
|
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
|
// 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)
|
// 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)
|
// 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 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
|
let signature
|
||||||
for (let signingFunc of signingFuncs) {
|
|
||||||
|
const signerByWallet = getSignersByWallet(isHW)
|
||||||
|
for (let signingFunc of signerByWallet) {
|
||||||
try {
|
try {
|
||||||
signature = await signingFunc(txArgs)
|
signature = await signingFunc(txArgs)
|
||||||
|
|
||||||
|
|
|
@ -102,12 +102,9 @@ const createTransaction = ({
|
||||||
// https://github.com/LedgerHQ/ledgerjs/issues/378
|
// https://github.com/LedgerHQ/ledgerjs/issues/378
|
||||||
// Couldn't find an issue for trezor but the error is almost the same
|
// Couldn't find an issue for trezor but the error is almost the same
|
||||||
const canTryOffchainSigning =
|
const canTryOffchainSigning =
|
||||||
!isExecution &&
|
!isExecution && !smartContractWallet && semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES)
|
||||||
!smartContractWallet &&
|
|
||||||
!hardwareWallet &&
|
|
||||||
semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES)
|
|
||||||
if (canTryOffchainSigning) {
|
if (canTryOffchainSigning) {
|
||||||
const signature = await tryOffchainSigning({ ...txArgs, safeAddress })
|
const signature = await tryOffchainSigning({ ...txArgs, safeAddress }, hardwareWallet)
|
||||||
|
|
||||||
if (signature) {
|
if (signature) {
|
||||||
closeSnackbar(beforeExecutionKey)
|
closeSnackbar(beforeExecutionKey)
|
||||||
|
|
|
@ -87,12 +87,9 @@ const processTransaction = ({
|
||||||
// https://github.com/LedgerHQ/ledgerjs/issues/378
|
// https://github.com/LedgerHQ/ledgerjs/issues/378
|
||||||
// Couldn't find an issue for trezor but the error is almost the same
|
// Couldn't find an issue for trezor but the error is almost the same
|
||||||
const canTryOffchainSigning =
|
const canTryOffchainSigning =
|
||||||
!isExecution &&
|
!isExecution && !smartContractWallet && semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES)
|
||||||
!smartContractWallet &&
|
|
||||||
!hardwareWallet &&
|
|
||||||
semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES)
|
|
||||||
if (canTryOffchainSigning) {
|
if (canTryOffchainSigning) {
|
||||||
const signature = await tryOffchainSigning({ ...txArgs, safeAddress })
|
const signature = await tryOffchainSigning({ ...txArgs, safeAddress }, hardwareWallet)
|
||||||
|
|
||||||
if (signature) {
|
if (signature) {
|
||||||
closeSnackbar(beforeExecutionKey)
|
closeSnackbar(beforeExecutionKey)
|
||||||
|
|
Loading…
Reference in New Issue