Skip to content

Commit 68bac57

Browse files
authored
Merge pull request #12 from KiiChain/fix/ledger
Fix ledger chain ID and linux nano
2 parents fc08882 + d308247 commit 68bac57

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

ethereum/eip712/encoding.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package eip712
33
import (
44
"errors"
55
"fmt"
6+
"strconv"
67

78
apitypes "github.com/ethereum/go-ethereum/signer/core/apitypes"
89

@@ -101,8 +102,17 @@ func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
101102
return apitypes.TypedData{}, err
102103
}
103104

105+
// Extract the chain ID from the sign doc itself for EIP-712 domain
106+
// This ensures we use the same chain ID that was used during signing
107+
chainID := eip155ChainID
108+
if aminoDoc.ChainID != "" {
109+
if parsedChainID, err := parseChainID(aminoDoc.ChainID); err == nil {
110+
chainID = parsedChainID
111+
}
112+
}
113+
104114
typedData, err := WrapTxToTypedData(
105-
eip155ChainID,
115+
chainID,
106116
signDocBytes,
107117
)
108118
if err != nil {
@@ -176,8 +186,17 @@ func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
176186
body.Memo,
177187
)
178188

189+
// Extract the chain ID from the sign doc itself for EIP-712 domain
190+
// This ensures we use the same chain ID that was used during signing
191+
chainID := eip155ChainID
192+
if signDoc.ChainId != "" {
193+
if parsedChainID, err := parseChainID(signDoc.ChainId); err == nil {
194+
chainID = parsedChainID
195+
}
196+
}
197+
179198
typedData, err := WrapTxToTypedData(
180-
eip155ChainID,
199+
chainID,
181200
signBytes,
182201
)
183202
if err != nil {
@@ -227,3 +246,9 @@ func validatePayloadMessages(msgs []sdk.Msg) error {
227246

228247
return nil
229248
}
249+
250+
// parseChainID attempts to parse the chain ID string as a uint64.
251+
// The chain ID in the sign doc should be the EIP-155 chain ID.
252+
func parseChainID(chainIDStr string) (uint64, error) {
253+
return strconv.ParseUint(chainIDStr, 10, 64)
254+
}

wallets/usbwallet/hub.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ func (hub *Hub) refreshWallets() {
152152
for _, info := range infos {
153153
for _, id := range hub.productIDs {
154154
// Windows and macOS use UsageID matching, Linux uses Interface matching
155-
if info.ProductID == id && (info.UsagePage == hub.usageID || info.Interface == hub.endpointID) {
155+
// Ledger product IDs use MMII format where MM is device model and II is interface flags.
156+
// Match either exact legacy IDs (0x0001, 0x0004, etc.) or device model prefix for
157+
// WebUSB/app-specific IDs (e.g., 0x4011 matches 0x4000 prefix for Nano X with Ethereum app).
158+
modelMatch := id >= 0x1000 && (info.ProductID>>8 == id>>8)
159+
if (info.ProductID == id || modelMatch) && (info.UsagePage == hub.usageID || info.Interface == hub.endpointID) {
156160
devices = append(devices, info)
157161
break
158162
}

0 commit comments

Comments
 (0)