mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
signer,accounts,cmd add logic for supporting database backed clef
This commit is contained in:
parent
a674c0b8ed
commit
cf930b9aaa
4 changed files with 42 additions and 8 deletions
|
|
@ -23,6 +23,8 @@ var (
|
||||||
// KeyStoreScheme is the protocol scheme prefixing account and wallet URLs.
|
// KeyStoreScheme is the protocol scheme prefixing account and wallet URLs.
|
||||||
const KeyStoreScheme = "keystore"
|
const KeyStoreScheme = "keystore"
|
||||||
|
|
||||||
|
const keystoreDBTableName = "keystore"
|
||||||
|
|
||||||
// KeyStore is the interface which abstracts all needed operations required
|
// KeyStore is the interface which abstracts all needed operations required
|
||||||
type KeyStore interface {
|
type KeyStore interface {
|
||||||
// Wallets implements accounts.Backend, returning all single-key wallets from the KeyStore.
|
// Wallets implements accounts.Backend, returning all single-key wallets from the KeyStore.
|
||||||
|
|
@ -120,8 +122,8 @@ func NewPlaintextKeyStore(keydir string) KeyStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKeyStoreDB creates a keystore for the given database
|
// NewKeyStoreDB creates a keystore for the given database
|
||||||
func NewKeyStoreDB(path, table string, scryptN, scryptP int) (KeyStore, error) {
|
func NewKeyStoreDB(path string, scryptN, scryptP int) (KeyStore, error) {
|
||||||
kvstore, err := dbutil.NewKVStore(path, table)
|
kvstore, err := dbutil.NewKVStore(path, keystoreDBTableName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -500,9 +500,17 @@ func signer(c *cli.Context) error {
|
||||||
nousb = c.GlobalBool(utils.NoUSBFlag.Name)
|
nousb = c.GlobalBool(utils.NoUSBFlag.Name)
|
||||||
scpath = c.GlobalString(utils.SmartCardDaemonPathFlag.Name)
|
scpath = c.GlobalString(utils.SmartCardDaemonPathFlag.Name)
|
||||||
)
|
)
|
||||||
|
ksDB := c.GlobalString(keystoreDBFlag.Name)
|
||||||
|
if ksDB != "" {
|
||||||
|
// if keystoreDBFlag is set, ignore keystoreFlag
|
||||||
|
ksLoc = ksDB
|
||||||
|
}
|
||||||
log.Info("Starting signer", "chainid", chainId, "keystore", ksLoc,
|
log.Info("Starting signer", "chainid", chainId, "keystore", ksLoc,
|
||||||
"light-kdf", lightKdf, "advanced", advanced)
|
"light-kdf", lightKdf, "advanced", advanced)
|
||||||
am := core.StartClefAccountManager(ksLoc, nousb, lightKdf, scpath)
|
am, err := core.StartClefAccountManager(ksLoc, nousb, lightKdf, scpath)
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatalf(err.Error())
|
||||||
|
}
|
||||||
apiImpl := core.NewSignerAPI(am, chainId, nousb, ui, db, advanced, pwStorage)
|
apiImpl := core.NewSignerAPI(am, chainId, nousb, ui, db, advanced, pwStorage)
|
||||||
|
|
||||||
// Establish the bidirectional communication, by creating a new UI backend and registering
|
// Establish the bidirectional communication, by creating a new UI backend and registering
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
|
|
@ -125,7 +126,8 @@ type Metadata struct {
|
||||||
Origin string `json:"Origin"`
|
Origin string `json:"Origin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath string) *accounts.Manager {
|
// StartClefAccountManager initializes and start clef Account Manager
|
||||||
|
func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath string) (*accounts.Manager, error) {
|
||||||
var (
|
var (
|
||||||
backends []accounts.Backend
|
backends []accounts.Backend
|
||||||
n, p = keystore.StandardScryptN, keystore.StandardScryptP
|
n, p = keystore.StandardScryptN, keystore.StandardScryptP
|
||||||
|
|
@ -133,9 +135,28 @@ func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath str
|
||||||
if lightKDF {
|
if lightKDF {
|
||||||
n, p = keystore.LightScryptN, keystore.LightScryptP
|
n, p = keystore.LightScryptN, keystore.LightScryptP
|
||||||
}
|
}
|
||||||
|
// check keystore type
|
||||||
|
var fsKeystore bool
|
||||||
|
if len(ksLocation) > 0 {
|
||||||
|
ext := filepath.Ext(ksLocation)
|
||||||
|
if ext == ".yaml" {
|
||||||
|
fsKeystore = false
|
||||||
|
} else {
|
||||||
|
fsKeystore = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// support password based accounts
|
// support password based accounts
|
||||||
if len(ksLocation) > 0 {
|
if len(ksLocation) > 0 {
|
||||||
|
if fsKeystore {
|
||||||
backends = append(backends, keystore.NewKeyStore(ksLocation, n, p))
|
backends = append(backends, keystore.NewKeyStore(ksLocation, n, p))
|
||||||
|
} else {
|
||||||
|
ks, err := keystore.NewKeyStoreDB(ksLocation, n, p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
backends = append(backends, ks)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !nousb {
|
if !nousb {
|
||||||
// Start a USB hub for Ledger hardware wallets
|
// Start a USB hub for Ledger hardware wallets
|
||||||
|
|
@ -162,7 +183,7 @@ func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start a smart card hub
|
// Start a smart card hub
|
||||||
if len(scpath) > 0 {
|
if len(scpath) > 0 && fsKeystore {
|
||||||
// Sanity check that the smartcard path is valid
|
// Sanity check that the smartcard path is valid
|
||||||
fi, err := os.Stat(scpath)
|
fi, err := os.Stat(scpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -181,7 +202,7 @@ func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clef doesn't allow insecure http account unlock.
|
// Clef doesn't allow insecure http account unlock.
|
||||||
return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: false}, backends...)
|
return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: false}, backends...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MetadataFromContext extracts Metadata from a given context.Context
|
// MetadataFromContext extracts Metadata from a given context.Context
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,10 @@ func setup(ksLoc string, t *testing.T) (*core.SignerAPI, *headlessUi) {
|
||||||
t.Fatal(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
ui := &headlessUi{make(chan string, 20), make(chan string, 20)}
|
ui := &headlessUi{make(chan string, 20), make(chan string, 20)}
|
||||||
am := core.StartClefAccountManager(ksLoc, true, true, "")
|
am, err := core.StartClefAccountManager(ksLoc, true, true, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
api := core.NewSignerAPI(am, 1337, true, ui, db, true, storage.NewNoStorage())
|
api := core.NewSignerAPI(am, 1337, true, ui, db, true, storage.NewNoStorage())
|
||||||
return api, ui
|
return api, ui
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue