Skip to content

Commit

Permalink
Implement use of new key package
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Aug 16, 2023
1 parent 3747484 commit 56c6adc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
6 changes: 5 additions & 1 deletion chatroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func (cr *ChatRoom) join() error {
func (cr *ChatRoom) Publish(content string) error {

m := message.New(cr.self.Pretty(), cr.topic.String(), []byte(content))
m.Sign(key.ExtractSecretKey(secret))
k, err := key.NewFromEncodedPrivKey(secret)
if err != nil {
return fmt.Errorf("failed to create key: %v", err)
}
m.Sign(k.PrivKey)
msgBytes, err := json.Marshal(m)
if err != nil {
return fmt.Errorf("failed to marshal message: %v", err)
Expand Down
7 changes: 5 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ func initConfig(wg *sync.WaitGroup) {

// If just to generate a secret key, do it and exit
if *genenv {
k := key.GenerateSecretKey()
fmt.Println("export GO_MYSPACE_CLIENT_IDENTITY=" + k)
k, err := key.New()
if err != nil {
log.Fatalf("Failed to generate new key: %v", err)
}
fmt.Println("export GO_MYSPACE_CLIENT_IDENTITY=" + k.EncodedPrivKey)
os.Exit(0)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bahner/go-myspace-client
go 1.20

require (
github.com/bahner/go-myspace v0.0.0-20230815231400-6a8f39c9aac7
github.com/bahner/go-myspace v0.0.0-20230816220323-33c73a3a65cd
github.com/gdamore/tcell/v2 v2.6.0
github.com/ipfs/boxo v0.11.0
github.com/libp2p/go-libp2p v0.29.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/bahner/go-myspace v0.0.0-20230815231400-6a8f39c9aac7 h1:po6WTXiwfOYlAbjJX1gSGgcDm03keaYz3+SYEKLlz8g=
github.com/bahner/go-myspace v0.0.0-20230815231400-6a8f39c9aac7/go.mod h1:/hfwU36ydjaW7KxPSRm1MH3hxU5NAkTX5V0mKQ7o4ZU=
github.com/bahner/go-myspace v0.0.0-20230816220323-33c73a3a65cd h1:q+XkaVVkd8O65DniFHLjXNG4NepKFO/tva2lJ2cq4NY=
github.com/bahner/go-myspace v0.0.0-20230816220323-33c73a3a65cd/go.mod h1:cVQWzqaFSQSBaJzR32YFLBEX6esTPIl7m2+LTAvZi/0=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func main() {
initConfig(wg)
wg.Wait()

identity := key.CreateIdentity(secret)
identity, err := key.DecodePrivKey(secret)
if err != nil {
panic(err)
}

h := host.New()
h.AddOption(libp2p.Identity(identity))
Expand Down
2 changes: 1 addition & 1 deletion pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/bahner/go-myspace/p2p/pubsub"
)

func initPubSubService(ctx context.Context, wg *sync.WaitGroup, h *host.P2pHost) {
func initPubSubService(ctx context.Context, wg *sync.WaitGroup, h *host.Host) {

defer wg.Done()

Expand Down

0 comments on commit 56c6adc

Please sign in to comment.