accounts, core, internal, node: Add support for smartcard wallets
This commit is contained in:
committed by
Guillaume Ballet
parent
3996bc1ad9
commit
f7027dd68c
@ -28,6 +28,7 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/accounts/scwallet"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
@ -44,6 +45,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
"github.com/tyler-smith/go-bip39"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -471,6 +473,46 @@ func (s *PrivateAccountAPI) SignAndSendTransaction(ctx context.Context, args Sen
|
||||
return s.SendTransaction(ctx, args, passwd)
|
||||
}
|
||||
|
||||
func (s *PrivateAccountAPI) InitializeWallet(ctx context.Context, url string) (string, error) {
|
||||
wallet, err := s.am.Wallet(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
entropy, err := bip39.NewEntropy(256)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
mnemonic, err := bip39.NewMnemonic(entropy)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
seed := bip39.NewSeed(mnemonic, "")
|
||||
|
||||
switch wallet := wallet.(type) {
|
||||
case *scwallet.Wallet:
|
||||
return mnemonic, wallet.Initialize(seed)
|
||||
default:
|
||||
return "", fmt.Errorf("Specified wallet does not support initialization")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PrivateAccountAPI) Unpair(ctx context.Context, url string, pin string) error {
|
||||
wallet, err := s.am.Wallet(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch wallet := wallet.(type) {
|
||||
case *scwallet.Wallet:
|
||||
return wallet.Unpair([]byte(pin))
|
||||
default:
|
||||
return fmt.Errorf("Specified wallet does not support pairing")
|
||||
}
|
||||
}
|
||||
|
||||
// PublicBlockChainAPI provides an API to access the Ethereum blockchain.
|
||||
// It offers only methods that operate on public data that is freely available to anyone.
|
||||
type PublicBlockChainAPI struct {
|
||||
|
@ -613,6 +613,16 @@ web3._extend({
|
||||
params: 2,
|
||||
inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'unpair',
|
||||
call: 'personal_unpair',
|
||||
params: 2
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'initializeWallet',
|
||||
call: 'personal_initializeWallet',
|
||||
params: 1
|
||||
})
|
||||
],
|
||||
properties: [
|
||||
new web3._extend.Property({
|
||||
|
Reference in New Issue
Block a user