Skip to content

Commit 1393a46

Browse files
mmsqealjo242
andauthored
fix: allow ledger flag work with coin type 60 (#690)
* fix: allow ledger flag work with coin type 60 aligned ledger firmware with go-ethereum * lint * allow to generate both * cleanup * fix test * fix build * fix resolve --------- Co-authored-by: Alex | Cosmos Labs <[email protected]>
1 parent e15a37d commit 1393a46

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### BUG FIXES
1414

1515
- [\#748](https://github.com/cosmos/evm/pull/748) Fix DynamicFeeChecker in Cosmos ante handler to respect NoBaseFee feemarkets' parameter.
16+
- [\#690](https://github.com/cosmos/evm/pull/690) Fix Ledger hardware wallet support for coin type 60.
1617
- [\#766](https://github.com/cosmos/evm/pull/766) Align gas estimation logic with go-ethereum v1.16.3
1718
- [\#769](https://github.com/cosmos/evm/pull/769) Fix erc20 ibc middleware to not to validate sender address format.
1819
- [\#756](https://github.com/cosmos/evm/pull/756) Fix error message typo in NewMsgCancelProposal.

client/keys/add.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"bytes"
66
"encoding/json"
77
"errors"
8+
"flag"
89
"fmt"
910
"io"
1011
"os"
@@ -13,7 +14,9 @@ import (
1314
"github.com/spf13/cobra"
1415

1516
cryptohd "github.com/cosmos/evm/crypto/hd"
17+
evmkeyring "github.com/cosmos/evm/crypto/keyring"
1618
bip39 "github.com/cosmos/go-bip39"
19+
ledger "github.com/cosmos/ledger-cosmos-go"
1720

1821
"github.com/cosmos/cosmos-sdk/client"
1922
"github.com/cosmos/cosmos-sdk/client/flags"
@@ -22,6 +25,8 @@ import (
2225
"github.com/cosmos/cosmos-sdk/crypto/hd"
2326
"github.com/cosmos/cosmos-sdk/crypto/keyring"
2427
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
28+
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
29+
cosmosLedger "github.com/cosmos/cosmos-sdk/crypto/ledger"
2530
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
2631
sdk "github.com/cosmos/cosmos-sdk/types"
2732
)
@@ -172,7 +177,37 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
172177
// If we're using ledger, only thing we need is the path and the bech32 prefix.
173178
if useLedger {
174179
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
175-
180+
needHardware := flag.Lookup("test.v") == nil && os.Getenv("GO_TEST") != "1"
181+
if needHardware {
182+
switch coinType {
183+
case 60:
184+
cosmosLedger.SetDiscoverLedger(func() (cosmosLedger.SECP256K1, error) {
185+
return evmkeyring.LedgerDerivation()
186+
})
187+
cosmosLedger.SetCreatePubkey(func(key []byte) cryptotypes.PubKey {
188+
return evmkeyring.CreatePubkey(key)
189+
})
190+
cosmosLedger.SetAppName(evmkeyring.AppName)
191+
cosmosLedger.SetDERConversion(false)
192+
case 118:
193+
cosmosLedger.SetDiscoverLedger(func() (cosmosLedger.SECP256K1, error) {
194+
device, err := ledger.FindLedgerCosmosUserApp()
195+
if err != nil {
196+
return nil, err
197+
}
198+
return device, nil
199+
})
200+
cosmosLedger.SetCreatePubkey(func(key []byte) cryptotypes.PubKey {
201+
return &secp256k1.PubKey{Key: key}
202+
})
203+
cosmosLedger.SetAppName(cosmosLedger.AppName)
204+
cosmosLedger.SetDERConversion(true)
205+
default:
206+
return fmt.Errorf(
207+
"unsupported coin type %d for Ledger. Supported coin types: 60 (Ethereum app), 118 (Cosmos app)", coinType,
208+
)
209+
}
210+
}
176211
// use the provided algo to save the ledger key
177212
k, err := kb.SaveLedgerKey(name, algo, bech32PrefixAccAddr, coinType, account, index)
178213
if err != nil {

evmd/cmd/evmd/cmd/root.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package cmd
22

33
import (
44
"errors"
5-
"github.com/cosmos/evm/utils"
6-
"github.com/cosmos/evm/x/vm/types"
75
"io"
86
"os"
97

8+
"github.com/cosmos/evm/utils"
9+
"github.com/cosmos/evm/x/vm/types"
10+
1011
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
1112
"github.com/spf13/cast"
1213
"github.com/spf13/cobra"
@@ -18,7 +19,7 @@ import (
1819
dbm "github.com/cosmos/cosmos-db"
1920
cosmosevmcmd "github.com/cosmos/evm/client"
2021
evmdebug "github.com/cosmos/evm/client/debug"
21-
cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring"
22+
"github.com/cosmos/evm/crypto/hd"
2223
"github.com/cosmos/evm/evmd"
2324
"github.com/cosmos/evm/evmd/config"
2425
cosmosevmserver "github.com/cosmos/evm/server"
@@ -81,7 +82,7 @@ func NewRootCmd() *cobra.Command {
8182
WithHomeDir(config.MustGetDefaultNodeHome()).
8283
WithViper(""). // In simapp, we don't use any prefix for env variables.
8384
// Cosmos EVM specific setup
84-
WithKeyringOptions(cosmosevmkeyring.Option()).
85+
WithKeyringOptions(hd.EthSecp256k1Option()).
8586
WithLedgerHasProtobuf(true)
8687

8788
rootCmd := &cobra.Command{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/cosmos/go-bip39 v1.0.0
2323
github.com/cosmos/gogoproto v1.7.0
2424
github.com/cosmos/ibc-go/v10 v10.0.0-beta.0.0.20251027215440-22f0033d0aee
25+
github.com/cosmos/ledger-cosmos-go v0.16.0
2526
github.com/creachadair/tomledit v0.0.28
2627
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
2728
github.com/ethereum/go-ethereum v1.16.5
@@ -123,7 +124,6 @@ require (
123124
github.com/cosmos/gogogateway v1.2.0 // indirect
124125
github.com/cosmos/iavl v1.2.6 // indirect
125126
github.com/cosmos/ics23/go v0.11.0 // indirect
126-
github.com/cosmos/ledger-cosmos-go v0.16.0 // indirect
127127
github.com/crate-crypto/go-eth-kzg v1.3.0 // indirect
128128
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
129129
github.com/creachadair/atomicfile v0.3.7 // indirect

wallets/usbwallet/hub.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,22 @@ type Hub struct {
5555
func NewLedgerHub() (*Hub, error) {
5656
return newHub(LedgerScheme, 0x2c97, []uint16{
5757
// Device definitions taken from
58-
// https://github.com/LedgerHQ/ledger-live/blob/38012bc8899e0f07149ea9cfe7e64b2c146bc92b/libs/ledgerjs/packages/devices/src/index.ts
58+
// https://github.com/LedgerHQ/ledger-live/blob/595cb73b7e6622dbbcfc11867082ddc886f1bf01/libs/ledgerjs/packages/devices/src/index.ts
5959

6060
// Original product IDs
6161
0x0000, /* Ledger Blue */
6262
0x0001, /* Ledger Nano S */
6363
0x0004, /* Ledger Nano X */
6464
0x0005, /* Ledger Nano S Plus */
6565
0x0006, /* Ledger Nano FTS */
66-
67-
0x0015, /* HID + U2F + WebUSB Ledger Blue */
68-
0x1015, /* HID + U2F + WebUSB Ledger Nano S */
69-
0x4015, /* HID + U2F + WebUSB Ledger Nano X */
70-
0x5015, /* HID + U2F + WebUSB Ledger Nano S Plus */
71-
0x6015, /* HID + U2F + WebUSB Ledger Nano FTS */
72-
73-
0x0011, /* HID + WebUSB Ledger Blue */
74-
0x1011, /* HID + WebUSB Ledger Nano S */
75-
0x4011, /* HID + WebUSB Ledger Nano X */
76-
0x5011, /* HID + WebUSB Ledger Nano S Plus */
77-
0x6011, /* HID + WebUSB Ledger Nano FTS */
66+
0x0007, /* Ledger Flex */
67+
68+
0x0000, /* WebUSB Ledger Blue */
69+
0x1000, /* WebUSB Ledger Nano S */
70+
0x4000, /* WebUSB Ledger Nano X */
71+
0x5000, /* WebUSB Ledger Nano S Plus */
72+
0x6000, /* WebUSB Ledger Nano FTS */
73+
0x7000, /* WebUSB Ledger Flex */
7874
}, 0xffa0, 0, newLedgerDriver)
7975
}
8076

0 commit comments

Comments
 (0)