MCPcopy Create free account
hub / github.com/daodst/chat / sanityCheckAuthChain

Function sanityCheckAuthChain

federationapi/internal/perform.go:650–676  ·  view source on GitHub ↗
(authChain []*gomatrixserverlib.Event)

Source from the content-addressed store, hash-verified

648}
649
650func sanityCheckAuthChain(authChain []*gomatrixserverlib.Event) error {
651 // sanity check we have a create event and it has a known room version
652 for _, ev := range authChain {
653 if ev.Type() == gomatrixserverlib.MRoomCreate && ev.StateKeyEquals("") {
654 // make sure the room version is known
655 content := ev.Content()
656 verBody := struct {
657 Version string `json:"room_version"`
658 }{}
659 err := json.Unmarshal(content, &verBody)
660 if err != nil {
661 return err
662 }
663 if verBody.Version == "" {
664 // https://matrix.org/docs/spec/client_server/r0.6.0#m-room-create
665 // The version of the room. Defaults to "1" if the key does not exist.
666 verBody.Version = "1"
667 }
668 knownVersions := gomatrixserverlib.RoomVersions()
669 if _, ok := knownVersions[gomatrixserverlib.RoomVersion(verBody.Version)]; !ok {
670 return fmt.Errorf("auth chain m.room.create event has an unknown room version: %s", verBody.Version)
671 }
672 return nil
673 }
674 }
675 return fmt.Errorf("auth chain response is missing m.room.create event")
676}
677
678func setDefaultRoomVersionFromJoinEvent(joinEvent gomatrixserverlib.EventBuilder) gomatrixserverlib.RoomVersion {
679 // if auth events are not event references we know it must be v3+

Callers 2

Calls 1

RoomVersionMethod · 0.80

Tested by

no test coverage detected