|
|
|
@ -7,6 +7,7 @@ import ( |
|
|
|
|
"errors" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"math/big" |
|
|
|
|
"math/rand" |
|
|
|
|
"net" |
|
|
|
|
"net/url" |
|
|
|
@ -14,6 +15,7 @@ import ( |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
|
"github.com/ethereum/go-ethereum/crypto/secp256k1" |
|
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
|
) |
|
|
|
@ -187,6 +189,19 @@ func PubkeyID(pub *ecdsa.PublicKey) NodeID { |
|
|
|
|
return id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Pubkey returns the public key represented by the node ID.
|
|
|
|
|
// It returns an error if the ID is not a point on the curve.
|
|
|
|
|
func (id NodeID) Pubkey() (*ecdsa.PublicKey, error) { |
|
|
|
|
p := &ecdsa.PublicKey{Curve: crypto.S256(), X: new(big.Int), Y: new(big.Int)} |
|
|
|
|
half := len(id) / 2 |
|
|
|
|
p.X.SetBytes(id[:half]) |
|
|
|
|
p.Y.SetBytes(id[half:]) |
|
|
|
|
if !p.Curve.IsOnCurve(p.X, p.Y) { |
|
|
|
|
return nil, errors.New("not a point on the S256 curve") |
|
|
|
|
} |
|
|
|
|
return p, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// recoverNodeID computes the public key used to sign the
|
|
|
|
|
// given hash from the signature.
|
|
|
|
|
func recoverNodeID(hash, sig []byte) (id NodeID, err error) { |
|
|
|
|