Skip to content

Conversation

@patrickjeremic
Copy link

@patrickjeremic patrickjeremic commented Feb 4, 2026

Describe your changes and provide context

Currently sei-chain uses a old version of ledger-go (v0.14.1) which does not recognize the newer range of ledger devices.

This PR simply does:

go get github.com/zondax/ledger-go@v1.0.1
make install

Testing performed to validate your change

On the current main branch of sei-chain it's not possible to add more modern ledger devices (in my testing i used a Ledger Nano S Plus on Firmware 1.5.1 running Cosmos App v2.38.9).

Here's what happens when trying to add the key via sei-chain:

$ seid keys add myledger --ledger
Error: failed to generate ledger key: failed to retrieve device: ledger nano S: LedgerHID device (idx 0) not found. Ledger LOCKED OR Other Program/Web Browser may have control of device.
Usage:
  seid keys add <name> [flags]

This makes sense, as only v1.0.0 and newer add the HID ids for the newer ledger devices.

After applying the patch it works:

$ seid keys add myledger --ledger

- name: myledger
  type: ledger
  address: seixxx
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"xxx"}'
  mnemonic: ""

I think the responsible ledger-go change is: Zondax/ledger-go@33eff3c

@patrickjeremic patrickjeremic force-pushed the main branch 2 times, most recently from 7581fc6 to 48860ab Compare February 4, 2026 15:16
@patrickjeremic
Copy link
Author

patrickjeremic commented Feb 9, 2026

I played around with this a bit more today. This PR will only fix the HID device detection and key derivation (due to the ledger-go update). Another issue is signing which requires a newer version of https://github.com/cosmos/ledger-cosmos-go

During my testing the minimum version should be v0.12.4 (which also is a bit old by now). The latest version v1.0.0 requires some additional tiny code changes in the ledger signing flow. Without upgrading ledger-cosmos-go I usually encounter some error code indicating 0x698A Wrong HRP Length (which only happens on newer cosmos ledger app versions).

However, either version of ledger-cosmos-go yields to another error: Error: malformed signature: not 64 bytes.

@patrickjeremic
Copy link
Author

These are the patches i had to apply to use ledger-cosmos-go v1.0.0:

diff --git a/sei-cosmos/crypto/keys/secp256k1/secp256k1_nocgo.go b/sei-cosmos/crypto/keys/secp256k1/secp256k1_nocgo.go
index e4c96a41..01c52409 100644
--- a/sei-cosmos/crypto/keys/secp256k1/secp256k1_nocgo.go
+++ b/sei-cosmos/crypto/keys/secp256k1/secp256k1_nocgo.go
@@ -14,10 +14,7 @@ import (
 func (pk *PrivKey) Sign(msg []byte) ([]byte, error) {
 	priv, _ := secp256k1.PrivKeyFromBytes(pk.Key)
 	hash := cosmoscrypto.Sha256(msg)
-	sig, err := ecdsa.SignCompact(priv, hash, true) // true=compressed pubkey
-	if err != nil {
-		return nil, err
-	}
+	sig := ecdsa.SignCompact(priv, hash, true) // true=compressed pubkey
 	// SignCompact struct: [recovery_id][R][S]
 	// we need to remove the recovery id and return the R||S bytes
 	return sig[1:], nil
diff --git a/sei-cosmos/crypto/ledger/ledger_secp256k1.go b/sei-cosmos/crypto/ledger/ledger_secp256k1.go
index f4769714..05d77dc1 100644
--- a/sei-cosmos/crypto/ledger/ledger_secp256k1.go
+++ b/sei-cosmos/crypto/ledger/ledger_secp256k1.go
@@ -34,7 +34,7 @@ type (
 		// Returns a compressed pubkey and bech32 address (requires user confirmation)
 		GetAddressPubKeySECP256K1([]uint32, string) ([]byte, string, error)
 		// Signs a message (requires user confirmation)
-		SignSECP256K1([]uint32, []byte) ([]byte, error)
+		SignSECP256K1([]uint32, []byte, byte) ([]byte, error)
 	}
 
 	// PrivKeyLedgerSecp256k1 implements PrivKey, calling the ledger nano we
@@ -230,7 +230,7 @@ func sign(device SECP256K1, pkl PrivKeyLedgerSecp256k1, msg []byte) ([]byte, err
 		return nil, err
 	}
 
-	sig, err := device.SignSECP256K1(pkl.Path.DerivationPath(), msg)
+	sig, err := device.SignSECP256K1(pkl.Path.DerivationPath(), msg, 0) // SIGN_MODE_LEGACY_AMINO_JSON
 	if err != nil {
 		return nil, err
 	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants