This commit is contained in:
mr
2026-01-27 15:49:57 +01:00
parent 5a94504abb
commit f7f9d722bd
4 changed files with 27 additions and 4 deletions

View File

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