saltyim is the Go library and reference client and broker implementation for Salty IM it contains a command-line client (cli), a terminal user interface (tui), builtin server/broker and a Mobile / Desktop App PWA (progressive web app) https://salty.im/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
saltyim/types.go

79 lines
2.0 KiB

package saltyim
import (
"encoding/json"
"io"
"io/ioutil"
"go.mills.io/salty"
)
// RegisterRequest is the request used by clients to register to a broker
type RegisterRequest struct {
Hash string
Key string
}
// NewRegisterRequest reads the signed request body from a client, verifies its signature
// and returns the resulting `RegisterRequest` and key used to sign the request on success
// otherwise an empty object and en error on failure.
func NewRegisterRequest(r io.Reader) (req RegisterRequest, signer string, err error) {
body, err := ioutil.ReadAll(r)
if err != nil {
return
}
out, key, err := salty.Verify(body)
if err != nil {
return
}
signer = key.ID().String()
err = json.Unmarshal(out, &req)
return
}
// SendRequest is the request used by clients to send messages via a broker
type SendRequest struct {
Endpoint string
Message string
Capabilities Capabilities
}
// NewSendRequest reads the signed request body from a client, verifies its signature
// and returns the resulting `SendRequest` and key used to sign the request on success
// otherwise an empty object and en error on failure.
func NewSendRequest(r io.Reader) (req SendRequest, signer string, err error) {
body, err := ioutil.ReadAll(r)
if err != nil {
return
}
out, key, err := salty.Verify(body)
if err != nil {
return
}
signer = key.ID().String()
err = json.Unmarshal(out, &req)
return
}
// AvatarRequest is the request used by clients to send messages via a broker
type AvatarRequest struct {
Addr *Addr
Content []byte
}
// NewAvatarRequest reads the signed request body from a client, verifies its signature
// and returns the resulting `AvatarRequest` and key used to sign the request on success
// otherwise an empty object and en error on failure.
func NewAvatarRequest(r io.Reader) (req AvatarRequest, signer string, err error) {
body, err := ioutil.ReadAll(r)
if err != nil {
return
}
out, key, err := salty.Verify(body)
if err != nil {
return
}
signer = key.ID().String()
err = json.Unmarshal(out, &req)
return
}