Skip to content

Commit

Permalink
Remove complexity from message. Leave it to apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed May 9, 2024
1 parent ff1d800 commit bff192f
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 181 deletions.
5 changes: 3 additions & 2 deletions key/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func (k *SigningKey) Sign(data []byte) ([]byte, error) {
return ed25519.Sign(k.PrivKey, data), nil
}

// Generates a signing key for the given identifier, ie. IPNS name
// Generates a signing key for the given identifier, ie. IPNS name.
// The IPNS key itself could be used, but lets stick to a more common DID structure.
func NewSigningKey(d did.DID) (SigningKey, error) {

name, err := nanoid.New()
Expand Down Expand Up @@ -121,7 +122,7 @@ func validateSigningPrivateKey(privKey ed25519.PrivateKey) error {
}

if len(privKey) != ed25519.PrivateKeySize {
return fmt.Errorf("Invalid key length %d, should be %d: %w", len(privKey), ed25519.PrivateKeySize, ErrInvalidKeySize)
return fmt.Errorf("invalid key length %d, should be %d: %w", len(privKey), ed25519.PrivateKeySize, ErrInvalidKeySize)
}
return nil
}
48 changes: 0 additions & 48 deletions msg/chat.go

This file was deleted.

4 changes: 1 addition & 3 deletions msg/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (
var (
ErrBroadcastHasRecipient = fmt.Errorf("broadcast message must not have a recipient")
ErrBroadcastInvalidTopic = fmt.Errorf("broadcast topic must be %s", ma.BROADCAST_TOPIC)
ErrBroadcastInvalidType = fmt.Errorf("broadcast message must not %s", BROADCAST)
ErrEmptyID = fmt.Errorf("id must be non-empty")
ErrInvalidID = fmt.Errorf("invalid message id")
ErrEmptyID = fmt.Errorf("empty message id")
ErrFetchDoc = fmt.Errorf("failed to fetch entity document")
ErrInvalidMessageType = fmt.Errorf("invalid Message type")
ErrInvalidSender = fmt.Errorf("invalid sender")
ErrInvalidRecipient = fmt.Errorf("invalid recipient")
ErrMissingContentType = fmt.Errorf("empty ContentType")
ErrMissingContent = fmt.Errorf("empty ContentType")
Expand Down
7 changes: 4 additions & 3 deletions msg/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"crypto/ed25519"
"fmt"

"github.com/bahner/go-ma"
cbor "github.com/fxamacker/cbor/v2"
pubsub "github.com/libp2p/go-libp2p-pubsub"
nanoid "github.com/matoous/go-nanoid/v2"
)

const (
PREFIX = "/ma/message/"
PREFIX = "/ma/"
MESSAGE = PREFIX + ma.VERSION
DEFAULT_CONTENT_TYPE = "text/plain"
)

Expand Down Expand Up @@ -39,7 +41,6 @@ type Message struct {
func New(
from string,
to string,
msg_type string,
content []byte,
contentType string,
priv_key ed25519.PrivateKey) (*Message, error) {
Expand All @@ -52,7 +53,7 @@ func New(
m := &Message{
// Message meta data
Id: id,
Type: msg_type,
Type: MESSAGE,
// Recipient
From: from,
To: to,
Expand Down
71 changes: 0 additions & 71 deletions msg/reply.go

This file was deleted.

51 changes: 0 additions & 51 deletions msg/request.go

This file was deleted.

4 changes: 1 addition & 3 deletions msg/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ func verifyID(id string) error {
func verifyType(t string) error {

if t == BROADCAST ||
t == CHAT ||
t == REQUEST ||
t == REPLY {
t == MESSAGE {
return nil
}

Expand Down

0 comments on commit bff192f

Please sign in to comment.