Skip to content

Commit

Permalink
Feat: natively support clear signing with Ledger (#4416)
Browse files Browse the repository at this point in the history
* fix: natively support clear signing with Ledger

* Use correct type

* Enable typed data signing support

* Fix module resolution imports

* Remove Jest setup

* Update packages

* Fix type issues

* Fix insufficient funds bug

* Update comment

* Facilitate toggling module

* Fix lock file

* Remove logs

* Get instead of converting to bytes

* Build ethers rejection error from error code

* Remove log
  • Loading branch information
iamacook authored Dec 17, 2024
1 parent b942226 commit 1a3188b
Show file tree
Hide file tree
Showing 18 changed files with 1,462 additions and 240 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ updates:
directory: '/'
schedule:
interval: 'weekly'
groups:
ledger:
patterns:
- '@ledgerhq/*'

- package-ecosystem: 'github-actions'
directory: '/'
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.13.5",
"@gnosis.pm/zodiac": "^4.0.3",
"@ledgerhq/context-module": "^1.1.0",
"@ledgerhq/device-management-kit": "^0.5.1",
"@ledgerhq/device-signer-kit-ethereum": "^1.1.0",
"@mui/icons-material": "^6.1.6",
"@mui/material": "^6.1.6",
"@mui/x-date-pickers": "^7.22.1",
Expand Down
5 changes: 4 additions & 1 deletion src/components/safe-apps/AppFrame/useAppCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import type {
SafeInfoExtended,
} from '@safe-global/safe-apps-sdk'
import { Methods, RPC_CALLS } from '@safe-global/safe-apps-sdk'
import type { Permission, PermissionRequest } from '@safe-global/safe-apps-sdk/dist/types/types/permissions'
import type {
Permission,
PermissionRequest,
} from 'node_modules/@safe-global/safe-apps-sdk/dist/types/types/permissions'
import type { SafeSettings } from '@safe-global/safe-apps-sdk'
import AppCommunicator from '@/services/safe-apps/AppCommunicator'
import { Errors, logError } from '@/services/exceptions'
Expand Down
2 changes: 1 addition & 1 deletion src/components/safe-apps/PermissionsPrompt.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactElement } from 'react'
import type { PermissionRequest } from '@safe-global/safe-apps-sdk/dist/types/types/permissions'
import type { PermissionRequest } from 'node_modules/@safe-global/safe-apps-sdk/dist/types/types/permissions'
import { Button, Dialog, DialogActions, DialogContent, Divider, Typography } from '@mui/material'

import { ModalDialogTitle } from '@/components/common/ModalDialog'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { faker } from '@faker-js/faker'
import { id, zeroPadValue } from 'ethers'
import { JsonRpcProvider } from 'ethers'
import cloneDeep from 'lodash/cloneDeep'
import type { Delay, TransactionAddedEvent } from '@gnosis.pm/zodiac/dist/cjs/types/Delay'
import type { Delay, TransactionAddedEvent } from 'node_modules/@gnosis.pm/zodiac/dist/cjs/types/Delay'
import type { TransactionReceipt } from 'ethers'

import {
Expand Down
2 changes: 1 addition & 1 deletion src/features/recovery/services/recovery-sender.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getModuleInstance, KnownContracts } from '@gnosis.pm/zodiac'
import type { SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import type { SafeTransaction } from '@safe-global/safe-core-sdk-types'
import type { TransactionAddedEvent } from '@gnosis.pm/zodiac/dist/cjs/types/Delay'
import type { TransactionAddedEvent } from 'node_modules/@gnosis.pm/zodiac/dist/cjs/types/Delay'
import type { Eip1193Provider, TransactionResponse } from 'ethers'

import { didReprice, didRevert } from '@/utils/ethers-utils'
Expand Down
2 changes: 1 addition & 1 deletion src/features/recovery/services/recovery-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import memoize from 'lodash/memoize'
import { getMultiSendCallOnlyDeployment } from '@safe-global/safe-deployments'
import type { SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import type { Delay } from '@gnosis.pm/zodiac'
import type { TransactionAddedEvent } from '@gnosis.pm/zodiac/dist/cjs/types/Delay'
import type { TransactionAddedEvent } from 'node_modules/@gnosis.pm/zodiac/dist/cjs/types/Delay'
import { toBeHex, type JsonRpcProvider, type TransactionReceipt } from 'ethers'
import { trimTrailingSlash } from '@/utils/url'
import { sameAddress } from '@/utils/addresses'
Expand Down
2 changes: 1 addition & 1 deletion src/features/swap/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DataDecoded, Order as SwapOrder } from '@safe-global/safe-gateway-typescript-sdk'
import { formatUnits } from 'ethers'
import type { AnyAppDataDocVersion, latest, LatestAppDataDocVersion } from '@cowprotocol/app-data'
import type { AnyAppDataDocVersion, latest, LatestAppDataDocVersion } from 'node_modules/@cowprotocol/app-data'

import { TradeType, UiOrderType } from '@/features/swap/types'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import useShowOutreachPopup from '../useShowOutreachPopup'
import * as useIsSafeOwner from '@/hooks/useIsSafeOwner'
import * as store from '@/store'
import { HOUR_IN_MS } from '../../constants'
import { faker } from '@faker-js/faker/.'
import { faker } from '@faker-js/faker'

jest.mock('@/hooks/useIsSafeOwner')
jest.mock('@/store')
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/safe-apps/permissions/useSafePermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
Permission,
PermissionCaveat,
PermissionRequest,
} from '@safe-global/safe-apps-sdk/dist/types/types/permissions'
} from 'node_modules/@safe-global/safe-apps-sdk/dist/types/types/permissions'

import { PermissionStatus } from '@/components/safe-apps/types'
import useLocalStorage from '@/services/local-storage/useLocalStorage'
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/wallets/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export const enum WALLET_KEYS {
WALLETCONNECT_V2 = 'WALLETCONNECT_V2',
COINBASE = 'COINBASE',
LEDGER = 'LEDGER',
// Placeholder to appease CGW_NAMES type - module name is also named Ledger
LEDGER_V2 = 'LEDGER_V2',
TREZOR = 'TREZOR',
KEYSTONE = 'KEYSTONE',
PK = 'PK',
Expand All @@ -14,6 +16,7 @@ export const CGW_NAMES: { [_key in WALLET_KEYS]: string | undefined } = {
[WALLET_KEYS.WALLETCONNECT_V2]: 'walletConnect_v2',
[WALLET_KEYS.COINBASE]: 'coinbase',
[WALLET_KEYS.LEDGER]: 'ledger',
[WALLET_KEYS.LEDGER_V2]: 'ledger_v2',
[WALLET_KEYS.TREZOR]: 'trezor',
[WALLET_KEYS.KEYSTONE]: 'keystone',
[WALLET_KEYS.PK]: 'pk',
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/wallets/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import coinbaseModule from '@web3-onboard/coinbase'
import injectedWalletModule from '@web3-onboard/injected-wallets'
import keystoneModule from '@web3-onboard/keystone/dist/index'
import ledgerModule from '@web3-onboard/ledger/dist/index'
import { ledgerModuleV2 } from '@/services/onboard/ledger-module'
import trezorModule from '@web3-onboard/trezor'
import walletConnect from '@web3-onboard/walletconnect'
import pkModule from '@/services/private-key-module'
Expand Down Expand Up @@ -42,7 +43,8 @@ const WALLET_MODULES: Partial<{ [_key in WALLET_KEYS]: (chain: ChainInfo) => Wal
[WALLET_KEYS.INJECTED]: () => injectedWalletModule() as WalletInit,
[WALLET_KEYS.WALLETCONNECT_V2]: (chain) => walletConnectV2(chain) as WalletInit,
[WALLET_KEYS.COINBASE]: () => coinbaseModule({ darkMode: prefersDarkMode() }) as WalletInit,
[WALLET_KEYS.LEDGER]: () => ledgerModule() as WalletInit,
[WALLET_KEYS.LEDGER]: () => ledgerModule(),
[WALLET_KEYS.LEDGER_V2]: () => ledgerModuleV2(),
[WALLET_KEYS.TREZOR]: () => trezorModule({ appUrl: TREZOR_APP_URL, email: TREZOR_EMAIL }) as WalletInit,
[WALLET_KEYS.KEYSTONE]: () => keystoneModule() as WalletInit,
[WALLET_KEYS.PK]: (chain) => pkModule(chain.chainId, chain.rpcUri) as WalletInit,
Expand Down
Loading

0 comments on commit 1a3188b

Please sign in to comment.