Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
ac2a0e61
Unverified
Commit
ac2a0e61
authored
Jan 23, 2017
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/usbwallet: initial support for Ledger wallets
parent
52bd4e29
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
762 additions
and
2 deletions
+762
-2
ledger.go
accounts/usbwallet/ledger.go
+648
-0
ledger_test.go
accounts/usbwallet/ledger_test.go
+75
-0
usb.go
accounts/usbwallet/usb.go
+27
-0
config.go
node/config.go
+12
-2
No files found.
accounts/usbwallet/ledger.go
0 → 100644
View file @
ac2a0e61
This diff is collapsed.
Click to expand it.
accounts/usbwallet/ledger_test.go
0 → 100644
View file @
ac2a0e61
// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
usbwallet
/*
func TestLedgerHub(t *testing.T) {
glog.SetV(6)
glog.SetToStderr(true)
// Create a USB hub watching for Ledger devices
hub, err := NewLedgerHub()
if err != nil {
t.Fatalf("Failed to create Ledger hub: %v", err)
}
defer hub.Close()
// Wait for events :P
time.Sleep(time.Minute)
}
*/
/*
func TestLedger(t *testing.T) {
// Create a USB context to access devices through
ctx, err := usb.NewContext()
defer ctx.Close()
ctx.Debug(6)
// List all of the Ledger wallets
wallets, err := findLedgerWallets(ctx)
if err != nil {
t.Fatalf("Failed to list Ledger wallets: %v", err)
}
// Retrieve the address from every one of them
for _, wallet := range wallets {
// Retrieve the version of the wallet app
ver, err := wallet.Version()
if err != nil {
t.Fatalf("Failed to retrieve wallet version: %v", err)
}
fmt.Printf("Ledger version: %s\n", ver)
// Retrieve the address of the wallet
addr, err := wallet.Address()
if err != nil {
t.Fatalf("Failed to retrieve wallet address: %v", err)
}
fmt.Printf("Ledger address: %x\n", addr)
// Try to sign a transaction with the wallet
unsigned := types.NewTransaction(1, common.HexToAddress("0xbabababababababababababababababababababa"), common.Ether, big.NewInt(20000), common.Shannon, nil)
signed, err := wallet.Sign(unsigned)
if err != nil {
t.Fatalf("Failed to sign transactions: %v", err)
}
signer, err := types.Sender(types.NewEIP155Signer(big.NewInt(1)), signed)
if err != nil {
t.Fatalf("Failed to recover signer: %v", err)
}
fmt.Printf("Ledger signature by: %x\n", signer)
}
}*/
accounts/usbwallet/usb.go
0 → 100644
View file @
ac2a0e61
// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package usbwallet implements support for USB hardware wallets.
package
usbwallet
import
"github.com/karalabe/gousb/usb"
// deviceID is a combined vendor/product identifier to uniquely identify a USB
// hardware device.
type
deviceID
struct
{
Vendor
usb
.
ID
// The Vendor identifer
Product
usb
.
ID
// The Product identifier
}
node/config.go
View file @
ac2a0e61
...
...
@@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/accounts/usbwallet"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
...
...
@@ -432,6 +433,15 @@ func makeAccountManager(conf *Config) (am *accounts.Manager, ephemeralKeystore s
if
err
:=
os
.
MkdirAll
(
keydir
,
0700
);
err
!=
nil
{
return
nil
,
""
,
err
}
ks
:=
keystore
.
NewKeyStore
(
keydir
,
scryptN
,
scryptP
)
return
accounts
.
NewManager
(
ks
),
ephemeralKeystore
,
nil
// Assemble the account manager and supported backends
backends
:=
[]
accounts
.
Backend
{
keystore
.
NewKeyStore
(
keydir
,
scryptN
,
scryptP
),
}
if
ledgerhub
,
err
:=
usbwallet
.
NewLedgerHub
();
err
!=
nil
{
glog
.
V
(
logger
.
Warn
)
.
Infof
(
"Failed to start Ledger hub, disabling: %v"
,
err
)
}
else
{
backends
=
append
(
backends
,
ledgerhub
)
}
return
accounts
.
NewManager
(
backends
...
),
ephemeralKeystore
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment