status-go/protocol/communities/request_to_join.go

77 lines
2.2 KiB
Go
Raw Normal View History

2021-01-11 10:32:51 +00:00
package communities
import (
"fmt"
"strconv"
"time"
2021-01-11 10:32:51 +00:00
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/protobuf"
2021-01-11 10:32:51 +00:00
)
type RequestToJoinState uint
2021-01-11 10:32:51 +00:00
const (
RequestToJoinStatePending RequestToJoinState = iota + 1
2021-01-11 10:32:51 +00:00
RequestToJoinStateDeclined
RequestToJoinStateAccepted
RequestToJoinStateCanceled
2021-01-11 10:32:51 +00:00
)
type RequestToJoin struct {
feat: add verified wallet accounts to community requests This commit extends the `CommunityRequestToJoin` with `RevealedAddresses` which represent wallet addresses and signatures provided by the sender, to proof a community owner ownership of those wallet addresses. **Note: This only works with keystore files maanged by status-go** At high level, the follwing happens: 1. User instructs Status to send a request to join to a community. By adding a password hash to the instruction, Status will try to unlock the users keystore and verify each wallet account. 2. For every verified wallet account, a signature is created for the following payload, using each wallet's private key ``` keccak256(chatkey + communityID + requestToJoinID) ``` A map of walletAddress->signature is then attached to the community request to join, which will be sent to the community owner 3. The owner node receives the request, and if the community requires users to hold tokens to become a member, it will check and verify whether the given wallet addresses are indeed owned by the sender. If any signature provided by the request cannot be recovered, the request is immediately declined by the owner. 4. The verified addresses are then added to the owner node's database such that, once the request should be accepted, the addresses can be used to check on chain whether they own the necessary funds to fulfill the community's permissions The checking of required funds is **not** part of this commit. It will be added in a follow-up commit.
2023-03-17 09:19:40 +00:00
ID types.HexBytes `json:"id"`
PublicKey string `json:"publicKey"`
Clock uint64 `json:"clock"`
ENSName string `json:"ensName,omitempty"`
ChatID string `json:"chatId"`
CommunityID types.HexBytes `json:"communityId"`
State RequestToJoinState `json:"state"`
Our bool `json:"our"`
RevealedAddresses map[string][]byte `json:"revealedAddresses,omitempty"`
Deleted bool `json:"deleted"`
2021-01-11 10:32:51 +00:00
}
func (r *RequestToJoin) CalculateID() {
r.ID = CalculateRequestID(r.PublicKey, r.CommunityID)
2021-01-11 10:32:51 +00:00
}
func (r *RequestToJoin) ToSyncProtobuf() *protobuf.SyncCommunityRequestsToJoin {
return &protobuf.SyncCommunityRequestsToJoin{
feat: add verified wallet accounts to community requests This commit extends the `CommunityRequestToJoin` with `RevealedAddresses` which represent wallet addresses and signatures provided by the sender, to proof a community owner ownership of those wallet addresses. **Note: This only works with keystore files maanged by status-go** At high level, the follwing happens: 1. User instructs Status to send a request to join to a community. By adding a password hash to the instruction, Status will try to unlock the users keystore and verify each wallet account. 2. For every verified wallet account, a signature is created for the following payload, using each wallet's private key ``` keccak256(chatkey + communityID + requestToJoinID) ``` A map of walletAddress->signature is then attached to the community request to join, which will be sent to the community owner 3. The owner node receives the request, and if the community requires users to hold tokens to become a member, it will check and verify whether the given wallet addresses are indeed owned by the sender. If any signature provided by the request cannot be recovered, the request is immediately declined by the owner. 4. The verified addresses are then added to the owner node's database such that, once the request should be accepted, the addresses can be used to check on chain whether they own the necessary funds to fulfill the community's permissions The checking of required funds is **not** part of this commit. It will be added in a follow-up commit.
2023-03-17 09:19:40 +00:00
Id: r.ID,
PublicKey: r.PublicKey,
Clock: r.Clock,
EnsName: r.ENSName,
ChatId: r.ChatID,
CommunityId: r.CommunityID,
State: uint64(r.State),
RevealedAddresses: r.RevealedAddresses,
}
}
func (r *RequestToJoin) InitFromSyncProtobuf(proto *protobuf.SyncCommunityRequestsToJoin) {
r.ID = proto.Id
r.PublicKey = proto.PublicKey
r.Clock = proto.Clock
r.ENSName = proto.EnsName
r.ChatID = proto.ChatId
r.CommunityID = proto.CommunityId
r.State = RequestToJoinState(proto.State)
feat: add verified wallet accounts to community requests This commit extends the `CommunityRequestToJoin` with `RevealedAddresses` which represent wallet addresses and signatures provided by the sender, to proof a community owner ownership of those wallet addresses. **Note: This only works with keystore files maanged by status-go** At high level, the follwing happens: 1. User instructs Status to send a request to join to a community. By adding a password hash to the instruction, Status will try to unlock the users keystore and verify each wallet account. 2. For every verified wallet account, a signature is created for the following payload, using each wallet's private key ``` keccak256(chatkey + communityID + requestToJoinID) ``` A map of walletAddress->signature is then attached to the community request to join, which will be sent to the community owner 3. The owner node receives the request, and if the community requires users to hold tokens to become a member, it will check and verify whether the given wallet addresses are indeed owned by the sender. If any signature provided by the request cannot be recovered, the request is immediately declined by the owner. 4. The verified addresses are then added to the owner node's database such that, once the request should be accepted, the addresses can be used to check on chain whether they own the necessary funds to fulfill the community's permissions The checking of required funds is **not** part of this commit. It will be added in a follow-up commit.
2023-03-17 09:19:40 +00:00
r.RevealedAddresses = proto.RevealedAddresses
}
func (r *RequestToJoin) Empty() bool {
return len(r.ID)+len(r.PublicKey)+int(r.Clock)+len(r.ENSName)+len(r.ChatID)+len(r.CommunityID)+int(r.State) == 0
}
func AddTimeoutToRequestToJoinClock(clock uint64) (uint64, error) {
requestToJoinClock, err := strconv.ParseInt(fmt.Sprint(clock), 10, 64)
if err != nil {
return 0, err
}
// Adding 7 days to the request clock
requestTimeOutClock := uint64(time.Unix(requestToJoinClock, 0).AddDate(0, 0, 7).Unix())
return requestTimeOutClock, nil
}