diff options
author | Guillaume Ballet <gballet@gmail.com> | 2019-04-09 17:53:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-09 17:53:58 +0800 |
commit | 1fc3e44ffecee0afde4620805de718320e676130 (patch) | |
tree | bb9795b6f89f8eb956042edd025c9ddc989daf60 /internal/ethapi | |
parent | 5fc5971438cd7c22996058c6c86eac7c625449fd (diff) | |
parent | 7c28ecbcc3366d73889bd7aedeaeb0c0c544e34b (diff) | |
download | go-tangerine-1fc3e44ffecee0afde4620805de718320e676130.tar go-tangerine-1fc3e44ffecee0afde4620805de718320e676130.tar.gz go-tangerine-1fc3e44ffecee0afde4620805de718320e676130.tar.bz2 go-tangerine-1fc3e44ffecee0afde4620805de718320e676130.tar.lz go-tangerine-1fc3e44ffecee0afde4620805de718320e676130.tar.xz go-tangerine-1fc3e44ffecee0afde4620805de718320e676130.tar.zst go-tangerine-1fc3e44ffecee0afde4620805de718320e676130.zip |
accounts:smartcard wallet without the dependency on libpcsclite (#19273)
* accounts, core, internal, node: Add support for smartcard wallets
* accounts, internal: Changes in response to review
* vendor: pull in missing go-echd library
* accounts/scwallet, console: user friendly card opening
* accounts/scwallet: ordered wallets, tighter events, derivation logs
* accounts, console: frendly card errors, support pin unblock
* accounts/scwallet: fix crypto API change
* accounts/scwallet: rebase and update
* Fix some linter issues
* Remove the direct dependency on libpcsclite
Instead, use a go library that communicates with pcscd over a socket.
Also update the changes introduced by @gravityblast since this PR's
inception
* Temporary fix to the ADBU status call
* fix wallet status update
This is a temporary fix, better checks need to
be performed once the whole process has been
validated.
* Fix key derivation
* Add some documentation
* Update a comment to reflect the workings of the updated system
* Vendor keycard-go/derivationpath
* Formatting fixes
* Add instructions on how to install the card
* Achieve full transaction signature+sending
* PK derivation has to be supported by the card
* Fix linter issues
* Upgrade to keycard app v2.1.1
* Set gballet as codeowner of the smartcard wallet dir
* fix unnecessary condition linter warning
* refuse to overwrite the master key of a previously initialized card
* refresh the account list when initializing the card
* Update the card preparation instructions based on review feedback
* 'sanitize' JSON input
Co-Authored-By: gballet <gballet@gmail.com>
* Apply suggestions from code review
Co-Authored-By: gballet <gballet@gmail.com>
* fix a serialization error
* more review feedback
* More review feedback
* Can now specify the number of empty accounts to derive
* Fix rebase error: include norm package
* Update bip-39 ref and remove ebfe/scard from vendor
* Add missing dependency
Diffstat (limited to 'internal/ethapi')
-rw-r--r-- | internal/ethapi/api.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index ccd918be2..473026606 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -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,48 @@ func (s *PrivateAccountAPI) SignAndSendTransaction(ctx context.Context, args Sen return s.SendTransaction(ctx, args, passwd) } +// InitializeWallet initializes a new wallet at the provided URL, by generating and returning a new private key. +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") + } +} + +// Unpair deletes a pairing between wallet and geth. +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 { |