Skip to content

Commit 69ed1c6

Browse files
committed
Merge branch 'master' into portal1
2 parents 1a959fb + c41105c commit 69ed1c6

136 files changed

Lines changed: 5005 additions & 5910 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

accounts/accounts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TextHash(data []byte) []byte {
195195
//
196196
// This gives context to the signed message and prevents signing of transactions.
197197
func TextAndHash(data []byte) ([]byte, string) {
198-
msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), string(data))
198+
msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data)
199199
hasher := sha3.NewLegacyKeccak256()
200200
hasher.Write([]byte(msg))
201201
return hasher.Sum(nil), msg

accounts/keystore/account_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func waitForAccounts(wantAccounts []accounts.Account, ks *KeyStore) error {
8686
func TestWatchNewFile(t *testing.T) {
8787
t.Parallel()
8888

89-
dir, ks := tmpKeyStore(t, false)
89+
dir, ks := tmpKeyStore(t)
9090

9191
// Ensure the watcher is started before adding any files.
9292
ks.Accounts()

accounts/keystore/keystore.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,6 @@ func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore {
8787
return ks
8888
}
8989

90-
// NewPlaintextKeyStore creates a keystore for the given directory.
91-
// Deprecated: Use NewKeyStore.
92-
func NewPlaintextKeyStore(keydir string) *KeyStore {
93-
keydir, _ = filepath.Abs(keydir)
94-
ks := &KeyStore{storage: &keyStorePlain{keydir}}
95-
ks.init(keydir)
96-
return ks
97-
}
98-
9990
func (ks *KeyStore) init(keydir string) {
10091
// Lock the mutex since the account cache might call back with events
10192
ks.mu.Lock()

accounts/keystore/keystore_test.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var testSigData = make([]byte, 32)
3737

3838
func TestKeyStore(t *testing.T) {
3939
t.Parallel()
40-
dir, ks := tmpKeyStore(t, true)
40+
dir, ks := tmpKeyStore(t)
4141

4242
a, err := ks.NewAccount("foo")
4343
if err != nil {
@@ -72,7 +72,7 @@ func TestKeyStore(t *testing.T) {
7272

7373
func TestSign(t *testing.T) {
7474
t.Parallel()
75-
_, ks := tmpKeyStore(t, true)
75+
_, ks := tmpKeyStore(t)
7676

7777
pass := "" // not used but required by API
7878
a1, err := ks.NewAccount(pass)
@@ -89,7 +89,7 @@ func TestSign(t *testing.T) {
8989

9090
func TestSignWithPassphrase(t *testing.T) {
9191
t.Parallel()
92-
_, ks := tmpKeyStore(t, true)
92+
_, ks := tmpKeyStore(t)
9393

9494
pass := "passwd"
9595
acc, err := ks.NewAccount(pass)
@@ -117,7 +117,7 @@ func TestSignWithPassphrase(t *testing.T) {
117117

118118
func TestTimedUnlock(t *testing.T) {
119119
t.Parallel()
120-
_, ks := tmpKeyStore(t, true)
120+
_, ks := tmpKeyStore(t)
121121

122122
pass := "foo"
123123
a1, err := ks.NewAccount(pass)
@@ -152,7 +152,7 @@ func TestTimedUnlock(t *testing.T) {
152152

153153
func TestOverrideUnlock(t *testing.T) {
154154
t.Parallel()
155-
_, ks := tmpKeyStore(t, false)
155+
_, ks := tmpKeyStore(t)
156156

157157
pass := "foo"
158158
a1, err := ks.NewAccount(pass)
@@ -193,7 +193,7 @@ func TestOverrideUnlock(t *testing.T) {
193193
// This test should fail under -race if signing races the expiration goroutine.
194194
func TestSignRace(t *testing.T) {
195195
t.Parallel()
196-
_, ks := tmpKeyStore(t, false)
196+
_, ks := tmpKeyStore(t)
197197

198198
// Create a test account.
199199
a1, err := ks.NewAccount("")
@@ -238,7 +238,7 @@ func waitForKsUpdating(t *testing.T, ks *KeyStore, wantStatus bool, maxTime time
238238
func TestWalletNotifierLifecycle(t *testing.T) {
239239
t.Parallel()
240240
// Create a temporary keystore to test with
241-
_, ks := tmpKeyStore(t, false)
241+
_, ks := tmpKeyStore(t)
242242

243243
// Ensure that the notification updater is not running yet
244244
time.Sleep(250 * time.Millisecond)
@@ -284,7 +284,7 @@ type walletEvent struct {
284284
// or deleted from the keystore.
285285
func TestWalletNotifications(t *testing.T) {
286286
t.Parallel()
287-
_, ks := tmpKeyStore(t, false)
287+
_, ks := tmpKeyStore(t)
288288

289289
// Subscribe to the wallet feed and collect events.
290290
var (
@@ -346,7 +346,7 @@ func TestWalletNotifications(t *testing.T) {
346346
// TestImportExport tests the import functionality of a keystore.
347347
func TestImportECDSA(t *testing.T) {
348348
t.Parallel()
349-
_, ks := tmpKeyStore(t, true)
349+
_, ks := tmpKeyStore(t)
350350
key, err := crypto.GenerateKey()
351351
if err != nil {
352352
t.Fatalf("failed to generate key: %v", key)
@@ -365,7 +365,7 @@ func TestImportECDSA(t *testing.T) {
365365
// TestImportECDSA tests the import and export functionality of a keystore.
366366
func TestImportExport(t *testing.T) {
367367
t.Parallel()
368-
_, ks := tmpKeyStore(t, true)
368+
_, ks := tmpKeyStore(t)
369369
acc, err := ks.NewAccount("old")
370370
if err != nil {
371371
t.Fatalf("failed to create account: %v", acc)
@@ -374,7 +374,7 @@ func TestImportExport(t *testing.T) {
374374
if err != nil {
375375
t.Fatalf("failed to export account: %v", acc)
376376
}
377-
_, ks2 := tmpKeyStore(t, true)
377+
_, ks2 := tmpKeyStore(t)
378378
if _, err = ks2.Import(json, "old", "old"); err == nil {
379379
t.Errorf("importing with invalid password succeeded")
380380
}
@@ -394,7 +394,7 @@ func TestImportExport(t *testing.T) {
394394
// This test should fail under -race if importing races.
395395
func TestImportRace(t *testing.T) {
396396
t.Parallel()
397-
_, ks := tmpKeyStore(t, true)
397+
_, ks := tmpKeyStore(t)
398398
acc, err := ks.NewAccount("old")
399399
if err != nil {
400400
t.Fatalf("failed to create account: %v", acc)
@@ -403,7 +403,7 @@ func TestImportRace(t *testing.T) {
403403
if err != nil {
404404
t.Fatalf("failed to export account: %v", acc)
405405
}
406-
_, ks2 := tmpKeyStore(t, true)
406+
_, ks2 := tmpKeyStore(t)
407407
var atom atomic.Uint32
408408
var wg sync.WaitGroup
409409
wg.Add(2)
@@ -457,11 +457,7 @@ func checkEvents(t *testing.T, want []walletEvent, have []walletEvent) {
457457
}
458458
}
459459

460-
func tmpKeyStore(t *testing.T, encrypted bool) (string, *KeyStore) {
460+
func tmpKeyStore(t *testing.T) (string, *KeyStore) {
461461
d := t.TempDir()
462-
newKs := NewPlaintextKeyStore
463-
if encrypted {
464-
newKs = func(kd string) *KeyStore { return NewKeyStore(kd, veryLightScryptN, veryLightScryptP) }
465-
}
466-
return d, newKs(d)
462+
return d, NewKeyStore(d, veryLightScryptN, veryLightScryptP)
467463
}

accounts/usbwallet/hub.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/ethereum/go-ethereum/accounts"
2727
"github.com/ethereum/go-ethereum/event"
2828
"github.com/ethereum/go-ethereum/log"
29-
"github.com/karalabe/usb"
29+
"github.com/karalabe/hid"
3030
)
3131

3232
// LedgerScheme is the protocol scheme prefixing account and wallet URLs.
@@ -109,7 +109,7 @@ func NewTrezorHubWithWebUSB() (*Hub, error) {
109109

110110
// newHub creates a new hardware wallet manager for generic USB devices.
111111
func newHub(scheme string, vendorID uint16, productIDs []uint16, usageID uint16, endpointID int, makeDriver func(log.Logger) driver) (*Hub, error) {
112-
if !usb.Supported() {
112+
if !hid.Supported() {
113113
return nil, errors.New("unsupported platform")
114114
}
115115
hub := &Hub{
@@ -155,7 +155,7 @@ func (hub *Hub) refreshWallets() {
155155
return
156156
}
157157
// Retrieve the current list of USB wallet devices
158-
var devices []usb.DeviceInfo
158+
var devices []hid.DeviceInfo
159159

160160
if runtime.GOOS == "linux" {
161161
// hidapi on Linux opens the device during enumeration to retrieve some infos,
@@ -170,7 +170,7 @@ func (hub *Hub) refreshWallets() {
170170
return
171171
}
172172
}
173-
infos, err := usb.Enumerate(hub.vendorID, 0)
173+
infos, err := hid.Enumerate(hub.vendorID, 0)
174174
if err != nil {
175175
failcount := hub.enumFails.Add(1)
176176
if runtime.GOOS == "linux" {

accounts/usbwallet/wallet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/core/types"
3232
"github.com/ethereum/go-ethereum/crypto"
3333
"github.com/ethereum/go-ethereum/log"
34-
"github.com/karalabe/usb"
34+
"github.com/karalabe/hid"
3535
)
3636

3737
// Maximum time between wallet health checks to detect USB unplugs.
@@ -79,8 +79,8 @@ type wallet struct {
7979
driver driver // Hardware implementation of the low level device operations
8080
url *accounts.URL // Textual URL uniquely identifying this wallet
8181

82-
info usb.DeviceInfo // Known USB device infos about the wallet
83-
device usb.Device // USB device advertising itself as a hardware wallet
82+
info hid.DeviceInfo // Known USB device infos about the wallet
83+
device hid.Device // USB device advertising itself as a hardware wallet
8484

8585
accounts []accounts.Account // List of derive accounts pinned on the hardware wallet
8686
paths map[common.Address]accounts.DerivationPath // Known derivation paths for signing operations

0 commit comments

Comments
 (0)