github.com/status-im/status-go@v1.1.0/protocol/requests/edit_shared_addresses.go (about) 1 package requests 2 3 import ( 4 "errors" 5 6 "github.com/status-im/status-go/eth-node/crypto" 7 "github.com/status-im/status-go/eth-node/types" 8 ) 9 10 var ErrInvalidCommunityID = errors.New("invalid community id") 11 var ErrMissingPassword = errors.New("password is necessary when sending a list of addresses") 12 var ErrMissingSharedAddresses = errors.New("list of shared addresses is needed") 13 var ErrMissingAirdropAddress = errors.New("airdropAddress is needed") 14 var ErrNoAirdropAddressAmongAddressesToReveal = errors.New("airdropAddress must be in the set of addresses to reveal") 15 var ErrInvalidSignature = errors.New("invalid signature") 16 17 type EditSharedAddresses struct { 18 CommunityID types.HexBytes `json:"communityId"` 19 AddressesToReveal []string `json:"addressesToReveal"` 20 Signatures []types.HexBytes `json:"signatures"` // the order of signatures should match the order of addresses 21 AirdropAddress string `json:"airdropAddress"` 22 } 23 24 func (j *EditSharedAddresses) Validate() error { 25 if len(j.CommunityID) == 0 { 26 return ErrInvalidCommunityID 27 } 28 29 if len(j.AddressesToReveal) == 0 { 30 return ErrMissingSharedAddresses 31 } 32 33 if j.AirdropAddress == "" { 34 return ErrMissingAirdropAddress 35 } 36 37 found := false 38 for _, address := range j.AddressesToReveal { 39 if address == j.AirdropAddress { 40 found = true 41 break 42 } 43 } 44 45 if !found { 46 return ErrNoAirdropAddressAmongAddressesToReveal 47 } 48 49 for _, signature := range j.Signatures { 50 if len(signature) > 0 && len(signature) != crypto.SignatureLength { 51 return ErrInvalidSignature 52 } 53 } 54 55 return nil 56 }