diff --git a/packages/eth-keyring-ledger/src/LedgerKeyring.ts b/packages/eth-keyring-ledger/src/LedgerKeyring.ts index fdbafafce..ad708586a 100644 --- a/packages/eth-keyring-ledger/src/LedgerKeyring.ts +++ b/packages/eth-keyring-ledger/src/LedgerKeyring.ts @@ -4,7 +4,7 @@ import { TransactionFactory, FeeMarketEIP1559Transaction, } from '@ethereumjs/tx'; -import LedgerEth from '@ledgerhq/hw-app-eth'; +import LedgerEth, { ledgerService } from '@ledgerhq/hw-app-eth'; import type Transport from '@ledgerhq/hw-transport'; import { addressUtils } from '@rabby-wallet/base-utils'; import { eventBus } from '@rabby-wallet/keyring-utils'; @@ -409,7 +409,12 @@ class LedgerKeyring { const hdPath = await this.unlockAccountByAddress(address); await this.makeApp(true); try { - const res = await this.app!.signTransaction(hdPath, rawTxHex); + const resolution = await ledgerService.resolveTransaction( + rawTxHex, + {}, + {}, + ); + const res = await this.app!.signTransaction(hdPath, rawTxHex, resolution); const newOrMutatedTx = handleSigning(res); const valid = newOrMutatedTx.verifySignature(); if (valid) { @@ -500,43 +505,26 @@ class LedgerKeyring { try { await this.makeApp(true); - let res: { - v: number; - s: string; - r: string; - }; - - // https://github.com/LedgerHQ/ledger-live/blob/5bae039273beeeb02d8640d778fd7bf5f7fd3776/libs/coin-evm/src/hw-signMessage.ts#L68C7-L79C10 - try { - res = await this.app!.signEIP712Message(hdPath, data); - } catch (e: any) { - const shouldFallbackOnHashedMethod = - 'statusText' in e && e.statusText === 'INS_NOT_SUPPORTED'; - if (!shouldFallbackOnHashedMethod) { - throw e; - } - - const { domain, types, primaryType, message } = - sigUtil.TypedDataUtils.sanitizeData(data); - const domainSeparatorHex = sigUtil.TypedDataUtils.hashStruct( - 'EIP712Domain', - domain, - types, - isV4, - ).toString('hex'); - const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct( - primaryType as string, - message, - types, - isV4, - ).toString('hex'); - - res = await this.app!.signEIP712HashedMessage( - hdPath, - domainSeparatorHex, - hashStructMessageHex, - ); - } + const { domain, types, primaryType, message } = + sigUtil.TypedDataUtils.sanitizeData(data); + const domainSeparatorHex = sigUtil.TypedDataUtils.hashStruct( + 'EIP712Domain', + domain, + types, + isV4, + ).toString('hex'); + const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct( + primaryType as string, + message, + types, + isV4, + ).toString('hex'); + + const res = await this.app!.signEIP712HashedMessage( + hdPath, + domainSeparatorHex, + hashStructMessageHex, + ); let v = res.v.toString(16); if (v.length < 2) {