accounts/scwallet: add a switch to specify path to sc daemon (#19439)

This commit is contained in:
Daniel Liu 2025-01-14 10:56:09 +08:00
parent fb35c54280
commit 100ea1c8e0
3 changed files with 61 additions and 14 deletions

View file

@ -63,6 +63,7 @@ var (
utils.DataDirFlag,
utils.KeyStoreDirFlag,
//utils.NoUSBFlag,
utils.SmartCardDaemonPathFlag,
//utils.EthashCacheDirFlag,
//utils.EthashCachesInMemoryFlag,
//utils.EthashCachesOnDiskFlag,

View file

@ -63,6 +63,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/p2p/netutil"
"github.com/XinFinOrg/XDPoSChain/params"
"github.com/XinFinOrg/XDPoSChain/rpc"
pcsclite "github.com/gballet/go-libpcsclite"
gopsutil "github.com/shirou/gopsutil/mem"
"github.com/urfave/cli/v2"
)
@ -87,6 +88,12 @@ var (
Usage: "Directory for the keystore (default = inside the datadir)",
Category: flags.AccountCategory,
}
SmartCardDaemonPathFlag = &cli.StringFlag{
Name: "pcscdpath",
Usage: "Path to the smartcard daemon (pcscd) socket file",
Value: pcsclite.PCSCDSockName,
Category: flags.AccountCategory,
}
NetworkIdFlag = &cli.Uint64Flag{
Name: "networkid",
Usage: "Network identifier (integer, 89=XDPoSChain)",
@ -1194,6 +1201,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
setWS(ctx, cfg)
setNodeUserIdent(ctx, cfg)
setPrefix(ctx, cfg)
setSmartCard(ctx, cfg)
switch {
case ctx.IsSet(DataDirFlag.Name):
@ -1227,6 +1235,26 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
}
}
func setSmartCard(ctx *cli.Context, cfg *node.Config) {
// Skip enabling smartcards if no path is set
path := ctx.String(SmartCardDaemonPathFlag.Name)
if path == "" {
return
}
// Sanity check that the smartcard path is valid
fi, err := os.Stat(path)
if err != nil {
log.Info("Smartcard socket not found, disabling", "err", err)
return
}
if fi.Mode()&os.ModeType != os.ModeSocket {
log.Error("Invalid smartcard daemon path", "path", path, "type", fi.Mode().String())
return
}
// Smartcard daemon path exists and is a socket, enable it
cfg.SmartCardDaemonPath = path
}
func setGPO(ctx *cli.Context, cfg *gasprice.Config, light bool) {
// If we are running the light client, apply another group
// settings for gas oracle.

View file

@ -26,6 +26,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/accounts"
"github.com/XinFinOrg/XDPoSChain/accounts/keystore"
"github.com/XinFinOrg/XDPoSChain/accounts/scwallet"
"github.com/XinFinOrg/XDPoSChain/accounts/usbwallet"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/crypto"
@ -88,6 +89,9 @@ type Config struct {
// NoUSB disables hardware wallet monitoring and connectivity.
NoUSB bool `toml:",omitempty"`
// SmartCardDaemonPath is the path to the smartcard daemon's socket.
SmartCardDaemonPath string `toml:",omitempty"`
// IPCPath is the requested location to place the IPC endpoint. If the path is
// a simple file name, it is placed inside the data directory (or on the root
// pipe path on Windows), whereas if it's a resolvable path name (absolute or
@ -425,22 +429,36 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
return nil, "", err
}
// Assemble the account manager and supported backends
backends := []accounts.Backend{
keystore.NewKeyStore(keydir, scryptN, scryptP),
}
if !conf.NoUSB {
// Start a USB hub for Ledger hardware wallets
if ledgerhub, err := usbwallet.NewLedgerHub(); err != nil {
log.Warn(fmt.Sprintf("Failed to start Ledger hub, disabling: %v", err))
} else {
backends = append(backends, ledgerhub)
var backends []accounts.Backend
if len(backends) == 0 {
// For now, we're using EITHER external signer OR local signers.
// If/when we implement some form of lockfile for USB and keystore wallets,
// we can have both, but it's very confusing for the user to see the same
// accounts in both externally and locally, plus very racey.
backends = append(backends, keystore.NewKeyStore(keydir, scryptN, scryptP))
if !conf.NoUSB {
// Start a USB hub for Ledger hardware wallets
if ledgerhub, err := usbwallet.NewLedgerHub(); err != nil {
log.Warn(fmt.Sprintf("Failed to start Ledger hub, disabling: %v", err))
} else {
backends = append(backends, ledgerhub)
}
// Start a USB hub for Trezor hardware wallets
if trezorhub, err := usbwallet.NewTrezorHub(); err != nil {
log.Warn(fmt.Sprintf("Failed to start Trezor hub, disabling: %v", err))
} else {
backends = append(backends, trezorhub)
}
}
// Start a USB hub for Trezor hardware wallets
if trezorhub, err := usbwallet.NewTrezorHub(); err != nil {
log.Warn(fmt.Sprintf("Failed to start Trezor hub, disabling: %v", err))
} else {
backends = append(backends, trezorhub)
if len(conf.SmartCardDaemonPath) > 0 {
// Start a smart card hub
if schub, err := scwallet.NewHub(conf.SmartCardDaemonPath, scwallet.Scheme, keydir); err != nil {
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
} else {
backends = append(backends, schub)
}
}
}
return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}, backends...), ephemeral, nil
}