2022-01-18 16:31:34 +00:00
|
|
|
package requests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2022-10-14 08:50:36 +00:00
|
|
|
"github.com/status-im/status-go/api/multiformat"
|
2022-01-18 16:31:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-01-18 16:31:34 +00:00
|
|
|
type SendContactRequest struct {
|
2022-10-14 08:50:36 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
Message string `json:"message"`
|
2022-01-18 16:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|