dendrite/zion/user_identifier.go
Tak Wai Wong 18db428c23
Figure out space vs channel from roomid (#43)
* pass in roomserver API so that we have access to the db

* interface to get db info for spaceid and channelid

* determine space or channel by querying the room db

* Add authorization check to the JOIN endpoint

* fix lint errors
2022-10-24 21:35:36 -07:00

46 lines
1.1 KiB
Go

package zion
import (
"fmt"
"regexp"
"strconv"
"github.com/ethereum/go-ethereum/common"
)
var regexpMatrixId = regexp.MustCompile(`^@eip155=3a(?P<ChainId>[0-9]+)=3a(?P<Address>0x[0-9a-fA-F]+):(?P<HomeServer>.*)$`)
var chainIdIndex = regexpMatrixId.SubexpIndex("ChainId")
var addressIndex = regexpMatrixId.SubexpIndex("Address")
//var homeServerIndex = regexpMatrixId.SubexpIndex("HomeServer")
type UserIdentifier struct {
AccountAddress common.Address
ChainId int
MatrixUserId string
LocalPart string
}
func CreateUserIdentifier(matrixUserId string) UserIdentifier {
matches := regexpMatrixId.FindStringSubmatch(matrixUserId)
address := ""
chainId := -1
localPart := ""
if chainIdIndex < len(matches) {
chainId, _ = strconv.Atoi(matches[chainIdIndex])
}
if addressIndex < len(matches) {
address = matches[addressIndex]
localPart = fmt.Sprintf("@eip155=3a%d=3a%s", chainId, address)
}
return UserIdentifier{
AccountAddress: common.HexToAddress(address),
ChainId: chainId,
MatrixUserId: matrixUserId,
LocalPart: localPart,
}
}