dendrite/zion/user_identifier.go
Tak Wai Wong 04a78694d1
Authorization framework for gating dendrite endpoints (#39)
* import new versions of the zion contracts

* bootstrap zion authz

* define interface for space manager contract

* instantiate spacemanager interface

* load goerli and localhost

* embed json

* remove zion interface. Use contracts directly

* split user identifiter into address and chain id

* isAllowed in routing.go

* remove permission.go

Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
2022-10-24 21:24:35 -07:00

39 lines
929 B
Go

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