mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 10:33:11 -06:00
* 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>
39 lines
929 B
Go
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,
|
|
}
|
|
}
|