packages/hyprspace: use multibase-encoded private keys
This commit is contained in:
parent
e78677882d
commit
a65960bcdd
4 changed files with 8 additions and 4 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/hyprspace/hyprspace/config"
|
"github.com/hyprspace/hyprspace/config"
|
||||||
"github.com/libp2p/go-libp2p"
|
"github.com/libp2p/go-libp2p"
|
||||||
"github.com/libp2p/go-libp2p-core/crypto"
|
"github.com/libp2p/go-libp2p-core/crypto"
|
||||||
|
"github.com/multiformats/go-multibase"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ func InitRun(r *cmd.Root, c *cmd.Sub) {
|
||||||
ListenPort: 8001,
|
ListenPort: 8001,
|
||||||
Address: "10.1.1.1/24",
|
Address: "10.1.1.1/24",
|
||||||
ID: host.ID().Pretty(),
|
ID: host.ID().Pretty(),
|
||||||
PrivateKey: string(keyBytes),
|
PrivateKey: multibase.MustNewEncoder(multibase.Base58BTC).Encode(keyBytes),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
"github.com/libp2p/go-libp2p-core/network"
|
"github.com/libp2p/go-libp2p-core/network"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
"github.com/multiformats/go-multibase"
|
||||||
"github.com/nxadm/tail"
|
"github.com/nxadm/tail"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -132,10 +133,11 @@ func UpRun(r *cmd.Root, c *cmd.Sub) {
|
||||||
port, err := verifyPort(cfg.Interface.ListenPort)
|
port, err := verifyPort(cfg.Interface.ListenPort)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
|
_, privateKey, err := multibase.Decode(cfg.Interface.PrivateKey)
|
||||||
// Create P2P Node
|
// Create P2P Node
|
||||||
host, dht, err := p2p.CreateNode(
|
host, dht, err := p2p.CreateNode(
|
||||||
ctx,
|
ctx,
|
||||||
cfg.Interface.PrivateKey,
|
privateKey,
|
||||||
port,
|
port,
|
||||||
streamHandler,
|
streamHandler,
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,6 +13,7 @@ require (
|
||||||
github.com/libp2p/go-libp2p-kad-dht v0.15.0
|
github.com/libp2p/go-libp2p-kad-dht v0.15.0
|
||||||
github.com/libp2p/go-tcp-transport v0.4.0
|
github.com/libp2p/go-tcp-transport v0.4.0
|
||||||
github.com/multiformats/go-multiaddr v0.4.1
|
github.com/multiformats/go-multiaddr v0.4.1
|
||||||
|
github.com/multiformats/go-multibase v0.0.3
|
||||||
github.com/nxadm/tail v1.4.8
|
github.com/nxadm/tail v1.4.8
|
||||||
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
|
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
|
||||||
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e
|
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e
|
||||||
|
|
|
@ -56,9 +56,9 @@ func getExtraBootstrapNodes(addr ma.Multiaddr) (nodesList []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateNode creates an internal Libp2p nodes and returns it and it's DHT Discovery service.
|
// CreateNode creates an internal Libp2p nodes and returns it and it's DHT Discovery service.
|
||||||
func CreateNode(ctx context.Context, inputKey string, port int, handler network.StreamHandler) (node host.Host, dhtOut *dht.IpfsDHT, err error) {
|
func CreateNode(ctx context.Context, inputKey []byte, port int, handler network.StreamHandler) (node host.Host, dhtOut *dht.IpfsDHT, err error) {
|
||||||
// Unmarshal Private Key
|
// Unmarshal Private Key
|
||||||
privateKey, err := crypto.UnmarshalPrivateKey([]byte(inputKey))
|
privateKey, err := crypto.UnmarshalPrivateKey(inputKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue