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:
Mikhail Mikheev 2020-04-08 19:30:55 +04:00 committed by GitHub
parent e33d9fd9bb
commit b8bfeab588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1016 additions and 1810 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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)

View File

@ -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)

View File

@ -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)

2789
yarn.lock

File diff suppressed because it is too large Load Diff