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.
|
||||
const KeyStoreScheme = "keystore"
|
||||
|
||||
const keystoreDBTableName = "keystore"
|
||||
|
||||
// KeyStore is the interface which abstracts all needed operations required
|
||||
type KeyStore interface {
|
||||
// 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
|
||||
func NewKeyStoreDB(path, table string, scryptN, scryptP int) (KeyStore, error) {
|
||||
kvstore, err := dbutil.NewKVStore(path, table)
|
||||
func NewKeyStoreDB(path string, scryptN, scryptP int) (KeyStore, error) {
|
||||
kvstore, err := dbutil.NewKVStore(path, keystoreDBTableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -500,9 +500,17 @@ func signer(c *cli.Context) error {
|
|||
nousb = c.GlobalBool(utils.NoUSBFlag.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,
|
||||
"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)
|
||||
|
||||
// Establish the bidirectional communication, by creating a new UI backend and registering
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
|
|
@ -125,7 +126,8 @@ type Metadata struct {
|
|||
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 (
|
||||
backends []accounts.Backend
|
||||
n, p = keystore.StandardScryptN, keystore.StandardScryptP
|
||||
|
|
@ -133,9 +135,28 @@ func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath str
|
|||
if lightKDF {
|
||||
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
|
||||
if len(ksLocation) > 0 {
|
||||
backends = append(backends, keystore.NewKeyStore(ksLocation, n, p))
|
||||
if fsKeystore {
|
||||
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 {
|
||||
// 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
|
||||
if len(scpath) > 0 {
|
||||
if len(scpath) > 0 && fsKeystore {
|
||||
// Sanity check that the smartcard path is valid
|
||||
fi, err := os.Stat(scpath)
|
||||
if err != nil {
|
||||
|
|
@ -181,7 +202,7 @@ func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath str
|
|||
}
|
||||
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -125,7 +125,10 @@ func setup(ksLoc string, t *testing.T) (*core.SignerAPI, *headlessUi) {
|
|||
t.Fatal(err.Error())
|
||||
}
|
||||
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())
|
||||
return api, ui
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue