Skip to content

Commit

Permalink
upgrade go-ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
outprog committed Jul 21, 2021
1 parent a086106 commit a4db353
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 35 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module github.com/everFinance/goether
go 1.15

require (
github.com/ethereum/go-ethereum v1.10.1
github.com/ethereum/go-ethereum v1.10.5
github.com/everFinance/ethrpc v1.0.3
github.com/miguelmota/go-ethereum-hdwallet v0.0.1
github.com/stretchr/testify v1.7.0
)
26 changes: 3 additions & 23 deletions signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package goether

import (
"crypto/ecdsa"
"encoding/hex"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto/ecies"
hdwallet "github.com/miguelmota/go-ethereum-hdwallet"
"io/ioutil"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto/ecies"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -43,25 +42,6 @@ func NewSignerFromPath(prvPath string) (*Signer, error) {
return NewSigner(strings.TrimSpace(string(b)))
}

func NewSignerFromMnemonic(mnemonic string) (*Signer, error) {
wallet, err := hdwallet.NewFromMnemonic(mnemonic)
if err != nil {
return nil, err
}
path := hdwallet.MustParseDerivationPath("m/44'/60'/0'/0/0") // ethereum private path
account, err := wallet.Derive(path, false)
if err != nil {
return nil, err
}
priv, err := wallet.PrivateKey(account)
if err != nil {
return nil, err
}

prvHex := crypto.FromECDSA(priv)
return NewSigner(hex.EncodeToString(prvHex))
}

func (s Signer) GetPrivateKey() *ecdsa.PrivateKey {
return s.key
}
Expand Down
11 changes: 1 addition & 10 deletions signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,8 @@ func TestSignTypedData(t *testing.T) {
assert.Equal(t, "0xab6c371B6c466BcF14d4003601951e5873dF2AcA", addr.String())
}

func TestNewSignerFromMnemonic(t *testing.T) {
mnemonic := "bean satisfy swarm account lizard window renew hen people cousin rural liquid"
address := "0x022D4F7c757f61ed006Cd06A74cDf4E1510Af9C4"
signer, err := NewSignerFromMnemonic(mnemonic)
assert.NoError(t, err)
assert.Equal(t, address, signer.Address.String())
}

func TestSigner_Decrypt_Encrypt(t *testing.T) {
mnemonic := "bean satisfy swarm account lizard window renew hen people cousin rural liquid"
signer, err := NewSignerFromMnemonic(mnemonic)
signer, err := NewSigner("dde30fa25128addf45656a39c0570fd06fce3e48056457b9f1f9fda603cc4be1")
assert.NoError(t, err)

msg := "aaa bbb ccc ddd"
Expand Down

0 comments on commit a4db353

Please sign in to comment.