diff --git a/accounts/scwallet/wallet.go b/accounts/scwallet/wallet.go index 37e2682136..bc7a1c553c 100644 --- a/accounts/scwallet/wallet.go +++ b/accounts/scwallet/wallet.go @@ -37,7 +37,6 @@ import ( "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/crypto" - "github.com/XinFinOrg/XDPoSChain/crypto/secp256k1" "github.com/XinFinOrg/XDPoSChain/log" pcsc "github.com/gballet/go-libpcsclite" "github.com/status-im/keycard-go/derivationpath" @@ -1050,33 +1049,25 @@ func (s *Session) sign(path accounts.DerivationPath, hash []byte) ([]byte, error // determinePublicKey uses a signature and the X component of a public key to // recover the entire public key. func determinePublicKey(sig, pubkeyX []byte) ([]byte, error) { - for v := 0; v < 2; v++ { - sig[64] = byte(v) - pubkey, err := crypto.Ecrecover(DerivationSignatureHash[:], sig) - if err == nil { - if bytes.Equal(pubkey, pubkeyX) { - return pubkey, nil - } - } else if v == 1 || err != secp256k1.ErrRecoverFailed { - return nil, err - } - } - return nil, ErrPubkeyMismatch + return makeRecoverableSignature(DerivationSignatureHash[:], sig, pubkeyX) } // makeRecoverableSignature uses a signature and an expected public key to // recover the v value and produce a recoverable signature. func makeRecoverableSignature(hash, sig, expectedPubkey []byte) ([]byte, error) { + var libraryError error for v := 0; v < 2; v++ { sig[64] = byte(v) - pubkey, err := crypto.Ecrecover(hash, sig) - if err == nil { + if pubkey, err := crypto.Ecrecover(hash, sig); err == nil { if bytes.Equal(pubkey, expectedPubkey) { return sig, nil } - } else if v == 1 || err != secp256k1.ErrRecoverFailed { - return nil, err + } else { + libraryError = err } } + if libraryError != nil { + return nil, libraryError + } return nil, ErrPubkeyMismatch } diff --git a/p2p/discover/node.go b/p2p/discover/node.go index 48fc2edd1b..a748e6b151 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -33,7 +33,6 @@ import ( "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/crypto" - "github.com/XinFinOrg/XDPoSChain/crypto/secp256k1" ) const NodeIDBits = 512 @@ -125,8 +124,8 @@ var incompleteNodeURL = regexp.MustCompile("(?i)^(?:enode://)?([0-9a-f]+)$") // // For incomplete nodes, the designator must look like one of these // -// enode:// -// +// enode:// +// // // For complete nodes, the node ID is encoded in the username portion // of the URL, separated from the host by an @ sign. The hostname can @@ -139,7 +138,7 @@ var incompleteNodeURL = regexp.MustCompile("(?i)^(?:enode://)?([0-9a-f]+)$") // a node with IP address 10.3.58.6, TCP listening port 30303 // and UDP discovery port 30301. // -// enode://@10.3.58.6:30303?discport=30301 +// enode://@10.3.58.6:30303?discport=30301 func ParseNode(rawurl string) (*Node, error) { if m := incompleteNodeURL.FindStringSubmatch(rawurl); m != nil { id, err := HexID(m[1]) @@ -323,7 +322,7 @@ func (id NodeID) Pubkey() (*ecdsa.PublicKey, error) { p.X.SetBytes(id[:half]) p.Y.SetBytes(id[half:]) if !p.Curve.IsOnCurve(p.X, p.Y) { - return nil, errors.New("id is invalid secp256k1 curve point") + return nil, errors.New("invalid secp256k1 curve point") } return p, nil } @@ -331,7 +330,7 @@ func (id NodeID) Pubkey() (*ecdsa.PublicKey, error) { // recoverNodeID computes the public key used to sign the // given hash from the signature. func recoverNodeID(hash, sig []byte) (id NodeID, err error) { - pubkey, err := secp256k1.RecoverPubkey(hash, sig) + pubkey, err := crypto.Ecrecover(hash, sig) if err != nil { return id, err } diff --git a/p2p/rlpx.go b/p2p/rlpx.go index 640e7ce3f2..ad422d5ebd 100644 --- a/p2p/rlpx.go +++ b/p2p/rlpx.go @@ -36,7 +36,6 @@ import ( "github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto/ecies" - "github.com/XinFinOrg/XDPoSChain/crypto/secp256k1" "github.com/XinFinOrg/XDPoSChain/p2p/discover" "github.com/XinFinOrg/XDPoSChain/rlp" "github.com/golang/snappy" @@ -408,7 +407,7 @@ func (h *encHandshake) handleAuthMsg(msg *authMsgV4, prv *ecdsa.PrivateKey) erro return err } signedMsg := xor(token, h.initNonce) - remoteRandomPub, err := secp256k1.RecoverPubkey(signedMsg, msg.Signature[:]) + remoteRandomPub, err := crypto.Ecrecover(signedMsg, msg.Signature[:]) if err != nil { return err }