File transfer: New API /file/read

This commit is contained in:
Kleissner
2021-10-27 14:16:13 +02:00
parent b0f98fdd4f
commit 5d9d1bf838
5 changed files with 274 additions and 6 deletions

View File

@@ -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())
}