mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
File transfer: New API /file/read
This commit is contained in:
11
Peer ID.go
11
Peer ID.go
@@ -8,6 +8,7 @@ package core
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
@@ -281,14 +282,12 @@ func DeleteAccount() {
|
||||
saveConfig()
|
||||
}
|
||||
|
||||
// PublicKeyFromPeerID decodes the peer ID (hex encoded) into a public key. Returns nil if invalid.
|
||||
func PublicKeyFromPeerID(peerID string) (publicKey *btcec.PublicKey) {
|
||||
// PublicKeyFromPeerID decodes the peer ID (hex encoded) into a public key.
|
||||
func PublicKeyFromPeerID(peerID string) (publicKey *btcec.PublicKey, err error) {
|
||||
hash, err := hex.DecodeString(peerID)
|
||||
if err != nil || len(hash) != 33 {
|
||||
return nil
|
||||
return nil, errors.New("invalid peer ID length")
|
||||
}
|
||||
|
||||
publicKey, _ = btcec.ParsePubKey(hash, btcec.S256())
|
||||
|
||||
return publicKey
|
||||
return btcec.ParsePubKey(hash, btcec.S256())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user