mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-17 11:03:11 -06:00
Pulls in upstream latest changes from [dendrite-fork ](https://github.com/HereNotThere/dendrite)to subtree at servers/dendrite here. Co-authored-by: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com> Co-authored-by: Tak Wai Wong <tak@hntlabs.com> Co-authored-by: John Terzis <john@hntlabs.com>
46 lines
1.1 KiB
Go
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,
|
|
}
|
|
}
|