diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-06 00:21:32 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-06 00:21:32 +0800 |
commit | ba0c41436c8a067937aa0845963f9ec3b81e7aed (patch) | |
tree | 7bd9bbc9422353ab341f01581abeb346b5a6cacf /p2p/discover/node.go | |
parent | fabaf4f1f01db773f6c0c2e9a9499736b1a40848 (diff) | |
parent | 215c763d53fc8e06e8c9807875eacaccf3ef45fa (diff) | |
download | go-tangerine-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar go-tangerine-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.gz go-tangerine-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.bz2 go-tangerine-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.lz go-tangerine-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.xz go-tangerine-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.zst go-tangerine-ba0c41436c8a067937aa0845963f9ec3b81e7aed.zip |
Merge branch 'p2p-handshake-2' of https://github.com/fjl/go-ethereum into fjl-p2p-handshake-2
Diffstat (limited to 'p2p/discover/node.go')
-rw-r--r-- | p2p/discover/node.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/p2p/discover/node.go b/p2p/discover/node.go index c6d2e9766..de2588258 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -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) { |