async-matrix 3.0.0-x86_64-linux → 3.0.1-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/async/matrix/app_service_client.rb +213 -0
- data/lib/async/matrix/client/encryption.rb +413 -0
- data/lib/async/matrix/client/rooms.rb +478 -0
- data/lib/async/matrix/client/sync.rb +508 -0
- data/lib/async/matrix/client.rb +77 -5
- data/lib/async/matrix/device_store.rb +1621 -0
- data/lib/async/matrix/e2ee/pickle_key.rb +182 -0
- data/lib/async/matrix/error.rb +9 -9
- data/lib/async/matrix/version.rb +3 -3
- data/lib/async/matrix.rb +16 -0
- data/lib/protocol/matrix/canonical_json.rb +200 -0
- data/lib/{async → protocol}/matrix/content.rb +9 -9
- data/lib/protocol/matrix/encrypted_message.rb +1018 -0
- data/lib/protocol/matrix/error.rb +49 -0
- data/lib/{async → protocol}/matrix/event.rb +28 -17
- data/lib/protocol/matrix/key_backup.rb +347 -0
- data/lib/protocol/matrix/keys.rb +381 -0
- data/lib/protocol/matrix/message_batch.rb +482 -0
- data/lib/{async → protocol}/matrix/schema/registry.rb +17 -17
- data/lib/{async → protocol}/matrix/schema/validation_error.rb +14 -12
- data/lib/{async → protocol}/matrix/schema.rb +17 -17
- data/lib/protocol/matrix/secret_storage.rb +535 -0
- data/lib/protocol/matrix/signing.rb +278 -0
- data/lib/protocol/matrix.rb +25 -0
- metadata +22 -7
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
require_relative "../error"
|
|
7
7
|
|
|
8
|
-
module
|
|
8
|
+
module Protocol
|
|
9
9
|
module Matrix
|
|
10
10
|
module Schema
|
|
11
11
|
# Raised by Event#valid! when data fails schema validation.
|
|
@@ -17,7 +17,9 @@ module Async
|
|
|
17
17
|
# - content.membership = "invalid" -- must be one of: ["invite", "join", "knock", "leave", "ban"]
|
|
18
18
|
# - sender is required but missing
|
|
19
19
|
#
|
|
20
|
-
|
|
20
|
+
# Carries an errcode, which the base supports: M_BAD_JSON is what a
|
|
21
|
+
# homeserver answers for a payload that fails its schema.
|
|
22
|
+
class ValidationError < Protocol::Matrix::Error
|
|
21
23
|
attr_reader :errors, :event_type, :event_id
|
|
22
24
|
|
|
23
25
|
# @param errors [Array<Hash>] raw JSONSchemer error hashes
|
|
@@ -123,7 +125,7 @@ module Async
|
|
|
123
125
|
end
|
|
124
126
|
|
|
125
127
|
__END__
|
|
126
|
-
describe "
|
|
128
|
+
describe "Protocol::Matrix::Schema::ValidationError" do
|
|
127
129
|
def error_hash(overrides = {})
|
|
128
130
|
{
|
|
129
131
|
"data" => nil,
|
|
@@ -137,7 +139,7 @@ __END__
|
|
|
137
139
|
end
|
|
138
140
|
|
|
139
141
|
it "includes event type in header" do
|
|
140
|
-
err =
|
|
142
|
+
err = Protocol::Matrix::Schema::ValidationError.new(
|
|
141
143
|
[error_hash],
|
|
142
144
|
event_type: "m.room.message"
|
|
143
145
|
)
|
|
@@ -145,7 +147,7 @@ __END__
|
|
|
145
147
|
end
|
|
146
148
|
|
|
147
149
|
it "includes event ID in header" do
|
|
148
|
-
err =
|
|
150
|
+
err = Protocol::Matrix::Schema::ValidationError.new(
|
|
149
151
|
[error_hash],
|
|
150
152
|
event_type: "m.room.member",
|
|
151
153
|
event_id: "$abc123"
|
|
@@ -154,7 +156,7 @@ __END__
|
|
|
154
156
|
end
|
|
155
157
|
|
|
156
158
|
it "formats type mismatch errors" do
|
|
157
|
-
err =
|
|
159
|
+
err = Protocol::Matrix::Schema::ValidationError.new([
|
|
158
160
|
error_hash(
|
|
159
161
|
"data_pointer" => "/content/body",
|
|
160
162
|
"type" => "string",
|
|
@@ -165,7 +167,7 @@ __END__
|
|
|
165
167
|
end
|
|
166
168
|
|
|
167
169
|
it "formats required errors with missing keys" do
|
|
168
|
-
err =
|
|
170
|
+
err = Protocol::Matrix::Schema::ValidationError.new([
|
|
169
171
|
error_hash(
|
|
170
172
|
"data_pointer" => "/content",
|
|
171
173
|
"type" => "required",
|
|
@@ -177,7 +179,7 @@ __END__
|
|
|
177
179
|
end
|
|
178
180
|
|
|
179
181
|
it "formats enum errors" do
|
|
180
|
-
err =
|
|
182
|
+
err = Protocol::Matrix::Schema::ValidationError.new([
|
|
181
183
|
error_hash(
|
|
182
184
|
"data_pointer" => "/content/membership",
|
|
183
185
|
"type" => "enum",
|
|
@@ -190,7 +192,7 @@ __END__
|
|
|
190
192
|
end
|
|
191
193
|
|
|
192
194
|
it "formats pattern errors" do
|
|
193
|
-
err =
|
|
195
|
+
err = Protocol::Matrix::Schema::ValidationError.new([
|
|
194
196
|
error_hash(
|
|
195
197
|
"data_pointer" => "/state_key",
|
|
196
198
|
"type" => "pattern",
|
|
@@ -202,7 +204,7 @@ __END__
|
|
|
202
204
|
end
|
|
203
205
|
|
|
204
206
|
it "formats format errors" do
|
|
205
|
-
err =
|
|
207
|
+
err = Protocol::Matrix::Schema::ValidationError.new([
|
|
206
208
|
error_hash(
|
|
207
209
|
"data_pointer" => "/content/avatar_url",
|
|
208
210
|
"type" => "format",
|
|
@@ -214,7 +216,7 @@ __END__
|
|
|
214
216
|
end
|
|
215
217
|
|
|
216
218
|
it "truncates long values" do
|
|
217
|
-
err =
|
|
219
|
+
err = Protocol::Matrix::Schema::ValidationError.new([
|
|
218
220
|
error_hash(
|
|
219
221
|
"data_pointer" => "/content/body",
|
|
220
222
|
"type" => "integer",
|
|
@@ -226,7 +228,7 @@ __END__
|
|
|
226
228
|
|
|
227
229
|
it "exposes the raw errors array" do
|
|
228
230
|
raw = [error_hash]
|
|
229
|
-
err =
|
|
231
|
+
err = Protocol::Matrix::Schema::ValidationError.new(raw)
|
|
230
232
|
err.errors.should.equal raw
|
|
231
233
|
end
|
|
232
234
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Released under the Apache License, Version 2.0.
|
|
4
4
|
# Copyright, 2026, by General Intelligence Systems.
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module Protocol
|
|
7
7
|
module Matrix
|
|
8
8
|
# Schema-driven validation for Matrix events using the official matrix-org/matrix-spec
|
|
9
9
|
# YAML schemas and the json_schemer gem.
|
|
@@ -13,14 +13,14 @@ module Async
|
|
|
13
13
|
# spec -- just re-run `bin/fetch-matrix-schemas` to pull the latest.
|
|
14
14
|
#
|
|
15
15
|
# # Look up a schema by event type
|
|
16
|
-
#
|
|
16
|
+
# Protocol::Matrix::Schema["m.room.message"] # => JSONSchemer::Schema
|
|
17
17
|
#
|
|
18
18
|
# # Validate an event hash
|
|
19
|
-
#
|
|
20
|
-
#
|
|
19
|
+
# Protocol::Matrix::Schema.valid?(event_hash) # => true/false
|
|
20
|
+
# Protocol::Matrix::Schema.validate(event_hash) # => [errors]
|
|
21
21
|
#
|
|
22
22
|
# # List all known event types
|
|
23
|
-
#
|
|
23
|
+
# Protocol::Matrix::Schema.event_types # => ["m.accepted_terms", "m.call.answer", ...]
|
|
24
24
|
#
|
|
25
25
|
module Schema
|
|
26
26
|
class << self
|
|
@@ -89,15 +89,15 @@ module Async
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
__END__
|
|
92
|
-
describe "
|
|
92
|
+
describe "Protocol::Matrix::Schema" do
|
|
93
93
|
it "looks up schemas by event type" do
|
|
94
|
-
schema =
|
|
94
|
+
schema = Protocol::Matrix::Schema["m.room.message"]
|
|
95
95
|
schema.should.not.be.nil
|
|
96
96
|
schema.should.be.kind_of JSONSchemer::Schema
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
it "returns nil for unknown event types" do
|
|
100
|
-
|
|
100
|
+
Protocol::Matrix::Schema["m.fake.event"].should.be.nil
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
it "validates event hashes" do
|
|
@@ -109,7 +109,7 @@ __END__
|
|
|
109
109
|
"origin_server_ts" => 1234567890,
|
|
110
110
|
"room_id" => "!room:example.org"
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
Protocol::Matrix::Schema.valid?(valid_event).should == true
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
it "returns errors for invalid events" do
|
|
@@ -121,39 +121,39 @@ __END__
|
|
|
121
121
|
"origin_server_ts" => 1234567890,
|
|
122
122
|
"room_id" => "!room:example.org"
|
|
123
123
|
}
|
|
124
|
-
errors =
|
|
124
|
+
errors = Protocol::Matrix::Schema.validate(invalid_event)
|
|
125
125
|
errors.should.not.be.empty
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
it "lists event types" do
|
|
129
|
-
types =
|
|
129
|
+
types = Protocol::Matrix::Schema.event_types
|
|
130
130
|
types.should.be.kind_of Array
|
|
131
131
|
types.should.include "m.room.message"
|
|
132
132
|
types.should.include "m.room.member"
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
it "lists variant types" do
|
|
136
|
-
variants =
|
|
136
|
+
variants = Protocol::Matrix::Schema.variant_types
|
|
137
137
|
variants.should.not.be.empty
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
it "looks up variant schemas" do
|
|
141
|
-
schema =
|
|
141
|
+
schema = Protocol::Matrix::Schema.variant("m.room.message", "m.text")
|
|
142
142
|
schema.should.not.be.nil
|
|
143
143
|
end
|
|
144
144
|
|
|
145
145
|
it "returns content properties" do
|
|
146
|
-
props =
|
|
146
|
+
props = Protocol::Matrix::Schema.content_properties("m.room.message")
|
|
147
147
|
props.should.include "msgtype"
|
|
148
148
|
props.should.include "body"
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
it "reports total schema count" do
|
|
152
|
-
|
|
152
|
+
Protocol::Matrix::Schema.size.should.be > 50
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
it "parses a raw hash into a schema-aware Event" do
|
|
156
|
-
event =
|
|
156
|
+
event = Protocol::Matrix::Schema.parse({
|
|
157
157
|
"type" => "m.room.message",
|
|
158
158
|
"content" => {"msgtype" => "m.text", "body" => "hello"},
|
|
159
159
|
"event_id" => "$abc123",
|
|
@@ -161,7 +161,7 @@ __END__
|
|
|
161
161
|
"origin_server_ts" => 1234567890,
|
|
162
162
|
"room_id" => "!room:example.org"
|
|
163
163
|
})
|
|
164
|
-
event.should.be.kind_of
|
|
164
|
+
event.should.be.kind_of Protocol::Matrix::Event
|
|
165
165
|
event.type.should == "m.room.message"
|
|
166
166
|
event.content.body.should == "hello"
|
|
167
167
|
event.valid?.should == true
|