2021-01-11 10:32:51 +00:00
package requests
import (
"errors"
2023-10-20 06:21:41 +00:00
"github.com/status-im/status-go/eth-node/crypto"
2021-01-11 10:32:51 +00:00
"github.com/status-im/status-go/eth-node/types"
)
var ErrRequestToJoinCommunityInvalidCommunityID = errors . New ( "request-to-join-community: invalid community id" )
2023-10-20 06:21:41 +00:00
var ErrRequestToJoinCommunityNoAddressesToReveal = errors . New ( "request-to-join-community: no addresses to reveal" )
2023-06-22 18:59:07 +00:00
var ErrRequestToJoinCommunityMissingPassword = errors . New ( "request-to-join-community: password is necessary when sending a list of addresses" )
2023-07-14 17:33:47 +00:00
var ErrRequestToJoinNoAirdropAddress = errors . New ( "request-to-join-community: airdropAddress is necessary when sending a list of addresses" )
2023-10-20 06:21:41 +00:00
var ErrRequestToJoinNoAirdropAddressAmongAddressesToReveal = errors . New ( "request-to-join-community: airdropAddress must be in the set of addresses to reveal" )
var ErrRequestToJoinCommunityInvalidSignature = errors . New ( "request-to-join-community: invalid signature" )
2021-01-11 10:32:51 +00:00
type RequestToJoinCommunity struct {
2024-07-12 09:24:16 +00:00
CommunityID types . HexBytes ` json:"communityId" `
ENSName string ` json:"ensName" `
AddressesToReveal [ ] string ` json:"addressesToReveal" `
Signatures [ ] types . HexBytes ` json:"signatures" ` // the order of signatures should match the order of addresses
AirdropAddress string ` json:"airdropAddress" `
ShareFutureAddresses bool ` json:"shareFutureAddresses" `
2021-01-11 10:32:51 +00:00
}
2024-08-07 15:57:02 +00:00
func ( j * RequestToJoinCommunity ) Validate ( ) error {
2021-01-11 10:32:51 +00:00
if len ( j . CommunityID ) == 0 {
return ErrRequestToJoinCommunityInvalidCommunityID
}
2023-10-20 06:21:41 +00:00
if len ( j . AddressesToReveal ) == 0 {
return ErrRequestToJoinCommunityNoAddressesToReveal
2023-06-22 18:59:07 +00:00
}
2023-10-20 06:21:41 +00:00
if j . AirdropAddress == "" {
2023-07-14 17:33:47 +00:00
return ErrRequestToJoinNoAirdropAddress
}
2021-01-11 10:32:51 +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 ErrRequestToJoinNoAirdropAddressAmongAddressesToReveal
}
for _ , signature := range j . Signatures {
2024-08-07 15:57:02 +00:00
if len ( signature ) != crypto . SignatureLength {
2023-10-20 06:21:41 +00:00
return ErrRequestToJoinCommunityInvalidSignature
}
}
2021-01-11 10:32:51 +00:00
return nil
}