2023-07-10 14:11:37 +00:00
|
|
|
package requests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2023-10-20 06:21:41 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2023-07-10 14:11:37 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ErrInvalidCommunityID = errors.New("invalid community id")
|
|
|
|
var ErrMissingPassword = errors.New("password is necessary when sending a list of addresses")
|
|
|
|
var ErrMissingSharedAddresses = errors.New("list of shared addresses is needed")
|
2023-07-14 17:33:47 +00:00
|
|
|
var ErrMissingAirdropAddress = errors.New("airdropAddress is needed")
|
2023-10-20 06:21:41 +00:00
|
|
|
var ErrNoAirdropAddressAmongAddressesToReveal = errors.New("airdropAddress must be in the set of addresses to reveal")
|
|
|
|
var ErrInvalidSignature = errors.New("invalid signature")
|
2023-07-10 14:11:37 +00:00
|
|
|
|
|
|
|
type EditSharedAddresses struct {
|
2023-10-20 06:21:41 +00:00
|
|
|
CommunityID types.HexBytes `json:"communityId"`
|
|
|
|
AddressesToReveal []string `json:"addressesToReveal"`
|
|
|
|
Signatures []types.HexBytes `json:"signatures"` // the order of signatures should match the order of addresses
|
|
|
|
AirdropAddress string `json:"airdropAddress"`
|
2023-07-10 14:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *EditSharedAddresses) Validate() error {
|
|
|
|
if len(j.CommunityID) == 0 {
|
|
|
|
return ErrInvalidCommunityID
|
|
|
|
}
|
2023-10-20 06:21:41 +00:00
|
|
|
|
2023-07-10 14:11:37 +00:00
|
|
|
if len(j.AddressesToReveal) == 0 {
|
|
|
|
return ErrMissingSharedAddresses
|
|
|
|
}
|
2023-10-20 06:21:41 +00:00
|
|
|
|
2023-07-14 17:33:47 +00:00
|
|
|
if j.AirdropAddress == "" {
|
|
|
|
return ErrMissingAirdropAddress
|
|
|
|
}
|
2023-07-10 14:11:37 +00:00
|
|
|
|
2023-10-20 06:21:41 +00:00
|
|
|
found := false
|
|
|
|
for _, address := range j.AddressesToReveal {
|
|
|
|
if address == j.AirdropAddress {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
return ErrNoAirdropAddressAmongAddressesToReveal
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, signature := range j.Signatures {
|
|
|
|
if len(signature) > 0 && len(signature) != crypto.SignatureLength {
|
|
|
|
return ErrInvalidSignature
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 14:11:37 +00:00
|
|
|
return nil
|
|
|
|
}
|