Skip to content

Commit b89cdaf

Browse files
wallet: remove ledger support in favor of golang SDK implementation of ledger keychain (#4413)
Co-authored-by: Stephen Buttolph <[email protected]>
1 parent 982f6e6 commit b89cdaf

File tree

11 files changed

+25
-1009
lines changed

11 files changed

+25
-1009
lines changed

go.mod

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ require (
2222
github.com/StephenButtolph/canoto v0.17.2
2323
github.com/antithesishq/antithesis-sdk-go v0.3.8
2424
github.com/ava-labs/coreth v0.15.5-0.20251022172030-6c57d8ace537
25-
github.com/ava-labs/ledger-avalanche-go v1.1.0
2625
github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2
2726
github.com/ava-labs/subnet-evm v0.8.0-fuji-rc.0.0.20251028200304-b91527f73c61
2827
github.com/btcsuite/btcd/btcutil v1.1.3
@@ -59,7 +58,6 @@ require (
5958
github.com/supranational/blst v0.3.14
6059
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a
6160
github.com/thepudds/fzgen v0.4.3
62-
github.com/tyler-smith/go-bip32 v1.0.0
6361
go.opentelemetry.io/otel v1.37.0
6462
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0
6563
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.37.0
@@ -90,8 +88,6 @@ require (
9088
)
9189

9290
require (
93-
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
94-
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
9591
github.com/Microsoft/go-winio v0.6.1 // indirect
9692
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
9793
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.13 // indirect
@@ -186,9 +182,6 @@ require (
186182
github.com/urfave/cli/v2 v2.25.7 // indirect
187183
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
188184
github.com/yusufpapurcu/wmi v1.2.4 // indirect
189-
github.com/zondax/golem v0.27.0 // indirect
190-
github.com/zondax/hid v0.9.2 // indirect
191-
github.com/zondax/ledger-go v1.0.1 // indirect
192185
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
193186
go.opentelemetry.io/otel/metric v1.37.0 // indirect
194187
go.opentelemetry.io/proto/otlp v1.7.0 // indirect

go.sum

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3
5050
github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo=
5151
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
5252
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
53-
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
54-
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
55-
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
56-
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
5753
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
5854
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
5955
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
@@ -79,8 +75,6 @@ github.com/ava-labs/coreth v0.15.5-0.20251022172030-6c57d8ace537 h1:M173eUWGlvAb
7975
github.com/ava-labs/coreth v0.15.5-0.20251022172030-6c57d8ace537/go.mod h1:4+gR+5AJjqsw1Pw3O3tpwJG6DRmFBzGGZtFv8iRML2k=
8076
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.13 h1:obPwnVCkF5+B2f8WbTepHj0ZgiW21vKUgFCtATuAYNY=
8177
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.13/go.mod h1:gsGr1ICjokI9CyPaaRHMqDoDCaT1VguC/IyOTx6rJ14=
82-
github.com/ava-labs/ledger-avalanche-go v1.1.0 h1:OkscKtb/gX20HBt8RyAtwXLrQnCEls5SzWGieE7NoNM=
83-
github.com/ava-labs/ledger-avalanche-go v1.1.0/go.mod h1:mAlG9ptnPjvNoLGLHXnM3slGY8ewvBJtJNVTEjG8KvI=
8478
github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 h1:hQ15IJxY7WOKqeJqCXawsiXh0NZTzmoQOemkWHz7rr4=
8579
github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2/go.mod h1:DqSotSn4Dx/UJV+d3svfW8raR+cH7+Ohl9BpsQ5HlGU=
8680
github.com/ava-labs/simplex v0.0.0-20250919142550-9cdfff10fd19 h1:S6oFasZsplNmw8B2S8cMJQMa62nT5ZKGzZRdCpd+5qQ=
@@ -136,8 +130,6 @@ github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86c
136130
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
137131
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
138132
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
139-
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
140-
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
141133
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
142134
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
143135
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
@@ -675,7 +667,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
675667
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
676668
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
677669
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
678-
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
679670
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
680671
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
681672
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -702,8 +693,6 @@ github.com/tklauser/go-sysconf v0.3.15 h1:VE89k0criAymJ/Os65CSn1IXaol+1wrsFHEB8O
702693
github.com/tklauser/go-sysconf v0.3.15/go.mod h1:Dmjwr6tYFIseJw7a3dRLJfsHAMXZ3nEnL/aZY+0IuI4=
703694
github.com/tklauser/numcpus v0.10.0 h1:18njr6LDBk1zuna922MgdjQuJFjrdppsZG60sHGfjso=
704695
github.com/tklauser/numcpus v0.10.0/go.mod h1:BiTKazU708GQTYF4mB+cmlpT2Is1gLk7XVuEeem8LsQ=
705-
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
706-
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
707696
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
708697
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
709698
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
@@ -736,12 +725,6 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
736725
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
737726
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
738727
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
739-
github.com/zondax/golem v0.27.0 h1:IbBjGIXF3SoGOZHsILJvIM/F/ylwJzMcHAcggiqniPw=
740-
github.com/zondax/golem v0.27.0/go.mod h1:AmorCgJPt00L8xN1VrMBe13PSifoZksnQ1Ge906bu4A=
741-
github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U=
742-
github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
743-
github.com/zondax/ledger-go v1.0.1 h1:Ks/2tz/dOF+dbRynfZ0dEhcdL1lqw43Sa0zMXHpQ3aQ=
744-
github.com/zondax/ledger-go v1.0.1/go.mod h1:j7IgMY39f30apthJYMd1YsHZRqdyu4KbVmUp0nU78X0=
745728
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
746729
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
747730
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
@@ -783,7 +766,6 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
783766
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
784767
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
785768
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
786-
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
787769
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
788770
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
789771
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -1254,8 +1236,6 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A
12541236
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
12551237
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
12561238
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
1257-
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
1258-
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
12591239
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
12601240
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
12611241
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

utils/crypto/keychain/keychain.go

Lines changed: 1 addition & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,13 @@
44
package keychain
55

66
import (
7-
"errors"
8-
"fmt"
9-
107
"github.com/ava-labs/avalanchego/ids"
118
"github.com/ava-labs/avalanchego/utils/set"
129
)
1310

14-
var (
15-
_ Keychain = (*ledgerKeychain)(nil)
16-
_ Signer = (*ledgerSigner)(nil)
17-
18-
ErrInvalidIndicesLength = errors.New("number of indices should be greater than 0")
19-
ErrInvalidNumAddrsToDerive = errors.New("number of addresses to derive should be greater than 0")
20-
ErrInvalidNumAddrsDerived = errors.New("incorrect number of ledger derived addresses")
21-
ErrInvalidNumSignatures = errors.New("incorrect number of signatures")
22-
)
23-
2411
// Signer implements functions for a keychain to return its main address and
25-
// to sign a hash
12+
// to sign a transaction
2613
type Signer interface {
27-
SignHash([]byte) ([]byte, error)
2814
Sign([]byte) ([]byte, error)
2915
Address() ids.ShortID
3016
}
@@ -38,128 +24,3 @@ type Keychain interface {
3824
// signer
3925
Addresses() set.Set[ids.ShortID]
4026
}
41-
42-
// ledgerKeychain is an abstraction of the underlying ledger hardware device,
43-
// to be able to get a signer from a finite set of derived signers
44-
type ledgerKeychain struct {
45-
ledger Ledger
46-
addrs set.Set[ids.ShortID]
47-
addrToIdx map[ids.ShortID]uint32
48-
}
49-
50-
// ledgerSigner is an abstraction of the underlying ledger hardware device,
51-
// to be able sign for a specific address
52-
type ledgerSigner struct {
53-
ledger Ledger
54-
idx uint32
55-
addr ids.ShortID
56-
}
57-
58-
// NewLedgerKeychain creates a new Ledger with [numToDerive] addresses.
59-
func NewLedgerKeychain(l Ledger, numToDerive int) (Keychain, error) {
60-
if numToDerive < 1 {
61-
return nil, ErrInvalidNumAddrsToDerive
62-
}
63-
64-
indices := make([]uint32, numToDerive)
65-
for i := range indices {
66-
indices[i] = uint32(i)
67-
}
68-
69-
return NewLedgerKeychainFromIndices(l, indices)
70-
}
71-
72-
// NewLedgerKeychainFromIndices creates a new Ledger with addresses taken from the given [indices].
73-
func NewLedgerKeychainFromIndices(l Ledger, indices []uint32) (Keychain, error) {
74-
if len(indices) == 0 {
75-
return nil, ErrInvalidIndicesLength
76-
}
77-
78-
addrs, err := l.Addresses(indices)
79-
if err != nil {
80-
return nil, err
81-
}
82-
83-
if len(addrs) != len(indices) {
84-
return nil, fmt.Errorf(
85-
"%w. expected %d, got %d",
86-
ErrInvalidNumAddrsDerived,
87-
len(indices),
88-
len(addrs),
89-
)
90-
}
91-
92-
addrsSet := set.Of(addrs...)
93-
94-
addrToIdx := map[ids.ShortID]uint32{}
95-
for i := range indices {
96-
addrToIdx[addrs[i]] = indices[i]
97-
}
98-
99-
return &ledgerKeychain{
100-
ledger: l,
101-
addrs: addrsSet,
102-
addrToIdx: addrToIdx,
103-
}, nil
104-
}
105-
106-
func (l *ledgerKeychain) Addresses() set.Set[ids.ShortID] {
107-
return l.addrs
108-
}
109-
110-
func (l *ledgerKeychain) Get(addr ids.ShortID) (Signer, bool) {
111-
idx, ok := l.addrToIdx[addr]
112-
if !ok {
113-
return nil, false
114-
}
115-
116-
return &ledgerSigner{
117-
ledger: l.ledger,
118-
idx: idx,
119-
addr: addr,
120-
}, true
121-
}
122-
123-
// expects to receive a hash of the unsigned tx bytes
124-
func (l *ledgerSigner) SignHash(b []byte) ([]byte, error) {
125-
// Sign using the address with index l.idx on the ledger device. The number
126-
// of returned signatures should be the same length as the provided indices.
127-
sigs, err := l.ledger.SignHash(b, []uint32{l.idx})
128-
if err != nil {
129-
return nil, err
130-
}
131-
132-
if sigsLen := len(sigs); sigsLen != 1 {
133-
return nil, fmt.Errorf(
134-
"%w. expected 1, got %d",
135-
ErrInvalidNumSignatures,
136-
sigsLen,
137-
)
138-
}
139-
140-
return sigs[0], nil
141-
}
142-
143-
// expects to receive the unsigned tx bytes
144-
func (l *ledgerSigner) Sign(b []byte) ([]byte, error) {
145-
// Sign using the address with index l.idx on the ledger device. The number
146-
// of returned signatures should be the same length as the provided indices.
147-
sigs, err := l.ledger.Sign(b, []uint32{l.idx})
148-
if err != nil {
149-
return nil, err
150-
}
151-
152-
if sigsLen := len(sigs); sigsLen != 1 {
153-
return nil, fmt.Errorf(
154-
"%w. expected 1, got %d",
155-
ErrInvalidNumSignatures,
156-
sigsLen,
157-
)
158-
}
159-
160-
return sigs[0], nil
161-
}
162-
163-
func (l *ledgerSigner) Address() ids.ShortID {
164-
return l.addr
165-
}

0 commit comments

Comments
 (0)