mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 22:46:40 +01:00
30 lines
556 B
Go
30 lines
556 B
Go
|
package lnwire
|
||
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
|
"encoding/hex"
|
||
|
|
||
|
"github.com/btcsuite/btcd/btcec/v2"
|
||
|
)
|
||
|
|
||
|
// pubkeyFromHex parses a Bitcoin public key from a hex encoded string.
|
||
|
func pubkeyFromHex(keyHex string) (*btcec.PublicKey, error) {
|
||
|
bytes, err := hex.DecodeString(keyHex)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return btcec.ParsePubKey(bytes)
|
||
|
}
|
||
|
|
||
|
// generateRandomBytes returns a slice of n random bytes.
|
||
|
func generateRandomBytes(n int) ([]byte, error) {
|
||
|
b := make([]byte, n)
|
||
|
_, err := rand.Read(b)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return b, nil
|
||
|
}
|