aboutsummaryrefslogtreecommitdiffstats
path: root/internal/ethapi/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/ethapi/api.go')
-rw-r--r--internal/ethapi/api.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index e5a8124b1..7938b264a 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,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 {