diff --git a/LibMatrix.Federation/FederationTypes/FederationBackfillResponse.cs b/LibMatrix.Federation/FederationTypes/FederationBackfillResponse.cs
new file mode 100644
index 0000000..0fe72bd
--- /dev/null
+++ b/LibMatrix.Federation/FederationTypes/FederationBackfillResponse.cs
@@ -0,0 +1,14 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Federation.FederationTypes;
+
+public class FederationBackfillResponse {
+ [JsonPropertyName("origin")]
+ public required string Origin { get; set; }
+
+ [JsonPropertyName("origin_server_ts")]
+ public required long OriginServerTs { get; set; }
+
+ [JsonPropertyName("pdus")]
+ public required List<SignedFederationEvent> Pdus { get; set; }
+}
\ No newline at end of file
diff --git a/LibMatrix.Federation/FederationTypes/FederationEvent.cs b/LibMatrix.Federation/FederationTypes/FederationEvent.cs
new file mode 100644
index 0000000..05bdcc9
--- /dev/null
+++ b/LibMatrix.Federation/FederationTypes/FederationEvent.cs
@@ -0,0 +1,30 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Federation.FederationTypes;
+
+public class FederationEvent : MatrixEventResponse {
+ [JsonPropertyName("auth_events")]
+ public required List<string> AuthEvents { get; set; } = [];
+
+ [JsonPropertyName("prev_events")]
+ public required List<string> PrevEvents { get; set; } = [];
+
+ [JsonPropertyName("depth")]
+ public required int Depth { get; set; }
+}
+
+public class SignedFederationEvent : FederationEvent {
+ [JsonPropertyName("signatures")]
+ public required Dictionary<string, Dictionary<string, string>> Signatures { get; set; } = new();
+
+ [JsonPropertyName("hashes")]
+ public required Dictionary<string, string> Hashes { get; set; } = new();
+}
+
+public class FederationEphemeralEvent {
+ [JsonPropertyName("edu_type")]
+ public required string Type { get; set; }
+
+ [JsonPropertyName("content")]
+ public required Dictionary<string, object> Content { get; set; } = new();
+}
\ No newline at end of file
diff --git a/LibMatrix.Federation/FederationTypes/FederationGetMissingEventsRequest.cs b/LibMatrix.Federation/FederationTypes/FederationGetMissingEventsRequest.cs
new file mode 100644
index 0000000..f43dd49
--- /dev/null
+++ b/LibMatrix.Federation/FederationTypes/FederationGetMissingEventsRequest.cs
@@ -0,0 +1,34 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Federation.FederationTypes;
+
+public class FederationGetMissingEventsRequest {
+ /// <summary>
+ /// Latest event IDs we already have (aka earliest to return)
+ /// </summary>
+ [JsonPropertyName("earliest_events")]
+ public required List<string> EarliestEvents { get; set; }
+
+ /// <summary>
+ /// Events we want to get events before
+ /// </summary>
+ [JsonPropertyName("latest_events")]
+ public required List<string> LatestEvents { get; set; }
+
+ /// <summary>
+ /// 10 by default
+ /// </summary>
+ [JsonPropertyName("limit")]
+ public int Limit { get; set; }
+
+ /// <summary>
+ /// 0 by default
+ /// </summary>
+ [JsonPropertyName("min_depth")]
+ public long MinDepth { get; set; }
+}
+
+public class FederationGetMissingEventsResponse {
+ [JsonPropertyName("events")]
+ public required List<SignedFederationEvent> Events { get; set; }
+}
\ No newline at end of file
diff --git a/LibMatrix.Federation/FederationTypes/FederationTransaction.cs b/LibMatrix.Federation/FederationTypes/FederationTransaction.cs
new file mode 100644
index 0000000..0581a08
--- /dev/null
+++ b/LibMatrix.Federation/FederationTypes/FederationTransaction.cs
@@ -0,0 +1,26 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Federation.FederationTypes;
+
+/// <summary>
+/// This only covers v12 rooms for now?
+/// </summary>
+public class FederationTransaction {
+ /// <summary>
+ /// Up to 100 EDUs per transaction
+ /// </summary>
+ [JsonPropertyName("edus")]
+ public List<FederationEvent>? EphemeralEvents { get; set; }
+
+ [JsonPropertyName("origin")]
+ public required string Origin { get; set; }
+
+ [JsonPropertyName("origin_server_ts")]
+ public required long OriginServerTs { get; set; }
+
+ /// <summary>
+ /// Up to 50 PDUs per transaction
+ /// </summary>
+ [JsonPropertyName("pdus")]
+ public List<SignedFederationEvent>? PersistentEvents { get; set; }
+}
\ No newline at end of file
diff --git a/LibMatrix.Federation/FederationTypes/RoomInvite.cs b/LibMatrix.Federation/FederationTypes/RoomInvite.cs
new file mode 100644
index 0000000..dc550f3
--- /dev/null
+++ b/LibMatrix.Federation/FederationTypes/RoomInvite.cs
@@ -0,0 +1,14 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Federation.FederationTypes;
+
+public class RoomInvite {
+ [JsonPropertyName("event")]
+ public required SignedFederationEvent Event { get; set; }
+
+ [JsonPropertyName("invite_room_state")]
+ public required List<MatrixEventResponse> InviteRoomState { get; set; } = [];
+
+ [JsonPropertyName("room_version")]
+ public required string RoomVersion { get; set; }
+}
\ No newline at end of file
diff --git a/LibMatrix.Federation/XMatrixAuthorizationScheme.cs b/LibMatrix.Federation/XMatrixAuthorizationScheme.cs
index 392cd93..c6be906 100644
--- a/LibMatrix.Federation/XMatrixAuthorizationScheme.cs
+++ b/LibMatrix.Federation/XMatrixAuthorizationScheme.cs
@@ -3,6 +3,7 @@ using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using ArcaneLibs.Extensions;
using LibMatrix.Abstractions;
+using LibMatrix.Extensions;
using LibMatrix.Responses.Federation;
using Microsoft.Extensions.Primitives;
@@ -37,17 +38,27 @@ public class XMatrixAuthorizationScheme {
ErrorCode = MatrixException.ErrorCodes.M_UNAUTHORIZED
};
- var headerValues = new StringValues(header.Parameter);
- foreach (var value in headerValues) {
- Console.WriteLine(headerValues.ToJson());
+ var headerValues = new Dictionary<string, string>();
+ var parts = header.Parameter.Split(',');
+ foreach (var part in parts) {
+ var kv = part.Split('=', 2);
+ if (kv.Length != 2)
+ continue;
+ var key = kv[0].Trim();
+ var value = kv[1].Trim().Trim('"');
+ headerValues[key] = value;
}
- return new() {
- Destination = "",
- Key = "",
- Origin = "",
- Signature = ""
+ Console.WriteLine("X-Matrix parts: " + headerValues.ToJson(unsafeContent: true));
+
+ var xma = new XMatrixAuthorizationHeader() {
+ Destination = headerValues["destination"],
+ Key = headerValues["key"],
+ Origin = headerValues["origin"],
+ Signature = headerValues["sig"]
};
+ Console.WriteLine("Parsed X-Matrix Auth Header: " + xma.ToJson());
+ return xma;
}
public static XMatrixAuthorizationHeader FromSignedObject(SignedObject<XMatrixRequestSignature> signedObj, VersionedHomeserverPrivateKey currentKey) =>
@@ -74,7 +85,7 @@ public class XMatrixAuthorizationScheme {
[JsonPropertyName("destination")]
public required string DestinationServerName { get; set; }
- [JsonPropertyName("content"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
+ [JsonPropertyName("content"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public JsonObject? Content { get; set; }
}
}
\ No newline at end of file
|