psk
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package infrastructure
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"oc-peer/conf"
|
||||
"os"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core/crypto"
|
||||
"github.com/libp2p/go-libp2p/core/pnet"
|
||||
)
|
||||
|
||||
func sign(priv crypto.PrivKey, data []byte) ([]byte, error) {
|
||||
@@ -47,3 +49,18 @@ func VerifyPubWithPriv() bool {
|
||||
}
|
||||
return priv.GetPublic().Equals(pub)
|
||||
}
|
||||
|
||||
func LoadPSKFromFile() (pnet.PSK, error) {
|
||||
path := conf.GetConfig().PSKPath
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Try to unmarshal as libp2p private key (supports ed25519, rsa, etc.)
|
||||
psk, err := pnet.DecodeV1PSK(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return psk, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user