github.com/status-im/status-go@v1.1.0/protocol/requests/send_contact_request.go (about) 1 package requests 2 3 import ( 4 "errors" 5 6 "github.com/status-im/status-go/api/multiformat" 7 ) 8 9 var ErrSendContactRequestInvalidID = errors.New("send-contact-request: invalid id") 10 var ErrSendContactRequestInvalidMessage = errors.New("send-contact-request: invalid message") 11 12 const legacyKeyLength = 132 13 14 type SendContactRequest struct { 15 ID string `json:"id"` 16 Message string `json:"message"` 17 } 18 19 func (a *SendContactRequest) Validate() error { 20 if len(a.ID) == 0 { 21 return ErrSendContactRequestInvalidID 22 } 23 24 if len(a.Message) == 0 { 25 return ErrSendContactRequestInvalidMessage 26 } 27 28 return nil 29 } 30 31 func ConvertCompressedToLegacyKey(k string) (string, error) { 32 if len(k) == legacyKeyLength { 33 return k, nil 34 } 35 return multiformat.DeserializeCompressedKey(k) 36 } 37 38 func (a *SendContactRequest) HexID() (string, error) { 39 return ConvertCompressedToLegacyKey(a.ID) 40 }