status-go/protocol/requests/send_contact_request.go

41 lines
863 B
Go
Raw Normal View History

package requests
import (
"errors"
2022-10-14 08:50:36 +00:00
"github.com/status-im/status-go/api/multiformat"
)
var ErrSendContactRequestInvalidID = errors.New("send-contact-request: invalid id")
var ErrSendContactRequestInvalidMessage = errors.New("send-contact-request: invalid message")
2022-10-14 08:50:36 +00:00
const legacyKeyLength = 132
type SendContactRequest struct {
2022-10-14 08:50:36 +00:00
ID string `json:"id"`
Message string `json:"message"`
}
func (a *SendContactRequest) Validate() error {
if len(a.ID) == 0 {
return ErrSendContactRequestInvalidID
}
if len(a.Message) == 0 {
return ErrSendContactRequestInvalidMessage
}
return nil
}
2022-10-14 08:50:36 +00:00
func ConvertCompressedToLegacyKey(k string) (string, error) {
if len(k) == legacyKeyLength {
return k, nil
}
return multiformat.DeserializeCompressedKey(k)
}
func (a *SendContactRequest) HexID() (string, error) {
return ConvertCompressedToLegacyKey(a.ID)
}