Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
feat(eip1559): enable EIP-1559 transaction signing on Ledger HW
Browse files Browse the repository at this point in the history
  • Loading branch information
onyb committed Sep 16, 2021
1 parent e7ddbc6 commit 67d953c
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 27 deletions.
12 changes: 7 additions & 5 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/app/helpers/co
import { NETWORK_TYPE_TO_ID_MAP } from '../network/enums'
import { hasEIP1559GasFields } from '../../../../ui/app/helpers/utils/transactions.util'
import TrezorKeyring from 'eth-trezor-keyring'
import LedgerBridgeKeyring from '@metamask/eth-ledger-bridge-keyring'

const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send.
const MAX_MEMSTORE_TX_LIST_SIZE = 100 // Number of transactions (by unique nonces) to keep in memory
Expand Down Expand Up @@ -153,21 +152,24 @@ export default class TransactionController extends EventEmitter {
const keyring = await this.getKeyringForAccount(fromAddress)

// TODO (@onyb): remove this when hardware wallet support for EIP-1559 is available.
return ![TrezorKeyring.type, LedgerBridgeKeyring.type].includes(keyring.type)
return ![TrezorKeyring.type].includes(keyring.type)
}

/**
* Gets a configuration object compatible with @ethereumjs/tx to be used
* while creating unsigned transactions. It works for both default networks
* as well as EVM-compatible chains.
*
* The preferEIP1559 argument can be used to switch to the London fork, when
* when the account supports both legacy as well as EIP-1559 transactions.
*
* @returns {Common} The configuration object to be passed to TransactionFactory.
*/
async makeConfig (fromAddress) {
async makeConfig (fromAddress, preferEIP1559) {
const { type: networkType, chainId: configChainId, nickname: name } = this.getProviderConfig()

const accountSupportsEIP1559 = await this.getEIP1559Compatibility(fromAddress)
const hardfork = accountSupportsEIP1559 ? Hardfork.London : Hardfork.Berlin
const hardfork = accountSupportsEIP1559 && preferEIP1559 ? Hardfork.London : Hardfork.Berlin

// Not a custom RPC network. Obtain the canonical chain ID corresponding to
// the network type, and return the Common configuration object.
Expand Down Expand Up @@ -613,7 +615,7 @@ export default class TransactionController extends EventEmitter {

// prepare unsigned tx
const fromAddress = txParams.from
const common = await this.makeConfig(fromAddress)
const common = await this.makeConfig(fromAddress, isEIP1559Transaction)
const unsignedEthTx = TransactionFactory.fromTxData(txParams, { common })

// sign tx
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@material-ui/core": "^4.11.0",
"@metamask/contract-metadata": "^1.25.0",
"@metamask/controllers": "^8.0.0",
"@metamask/eth-ledger-bridge-keyring": "github:brave/eth-ledger-bridge-keyring#43de9dd395eac55febb1519e4c233ea030bbfde7",
"@metamask/eth-ledger-bridge-keyring": "github:brave/eth-ledger-bridge-keyring#c559e6f426aabf9b2a29a00ed93c7fd55dda08af",
"@metamask/etherscan-link": "^1.1.0",
"@metamask/inpage-provider": "^6.1.0",
"@popperjs/core": "^2.4.0",
Expand Down
2 changes: 1 addition & 1 deletion ui/app/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export function isEIP1559Network (state) {
case 'Ledger Hardware':
// Ledger supports EIP-1559, but requires a major version upgrade of
// ledgerjs.
keyringSupportsEIP1559 = false
keyringSupportsEIP1559 = true
break
case 'Simple Key Pair':
default:
Expand Down
Loading

0 comments on commit 67d953c

Please sign in to comment.