matrix-nodejs-homeserver 0.0.0-stage → 0.3.1
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.
- package/LICENSE +75 -0
- package/README.md +479 -2
- package/dist/adapters/auth.d.ts +50 -0
- package/dist/adapters/auth.js +18 -0
- package/dist/adapters/cluster.d.ts +55 -0
- package/dist/adapters/cluster.js +249 -0
- package/dist/adapters/media.d.ts +50 -0
- package/dist/adapters/media.js +63 -0
- package/dist/adapters/s3.d.ts +33 -0
- package/dist/adapters/s3.js +95 -0
- package/dist/api/account.js +594 -0
- package/dist/api/admin.js +267 -0
- package/dist/api/appservice.js +45 -0
- package/dist/api/backup.js +280 -0
- package/dist/api/federation.js +826 -0
- package/dist/api/filters.js +88 -0
- package/dist/api/index.js +47 -0
- package/dist/api/legacy.js +183 -0
- package/dist/api/media.js +271 -0
- package/dist/api/misc.js +95 -0
- package/dist/api/preview.js +201 -0
- package/dist/api/profile.js +176 -0
- package/dist/api/push.js +202 -0
- package/dist/api/relationships.js +270 -0
- package/dist/api/rooms.js +1487 -0
- package/dist/api/rtc.d.ts +23 -0
- package/dist/api/rtc.js +66 -0
- package/dist/api/search.js +161 -0
- package/dist/api/slidingsync.js +474 -0
- package/dist/api/spaces.js +177 -0
- package/dist/api/sync.js +609 -0
- package/dist/api/threadsubs.js +140 -0
- package/dist/api/threepid.js +155 -0
- package/dist/api/uia.js +127 -0
- package/dist/api/user.js +329 -0
- package/dist/core/admin.d.ts +84 -0
- package/dist/core/admin.js +308 -0
- package/dist/core/adminroom.d.ts +49 -0
- package/dist/core/adminroom.js +483 -0
- package/dist/core/appservices.d.ts +74 -0
- package/dist/core/appservices.js +369 -0
- package/dist/core/audit.d.ts +50 -0
- package/dist/core/audit.js +86 -0
- package/dist/core/auth.d.ts +48 -0
- package/dist/core/auth.js +237 -0
- package/dist/core/authrules.d.ts +4 -0
- package/dist/core/authrules.js +348 -0
- package/dist/core/cluster.d.ts +66 -0
- package/dist/core/cluster.js +191 -0
- package/dist/core/crypto.d.ts +10 -0
- package/dist/core/crypto.js +100 -0
- package/dist/core/delayed.d.ts +39 -0
- package/dist/core/delayed.js +160 -0
- package/dist/core/errors.d.ts +9 -0
- package/dist/core/errors.js +45 -0
- package/dist/core/events.d.ts +32 -0
- package/dist/core/events.js +186 -0
- package/dist/core/glob.js +66 -0
- package/dist/core/identity.d.ts +24 -0
- package/dist/core/identity.js +96 -0
- package/dist/core/ids.js +36 -0
- package/dist/core/invitefilter.js +36 -0
- package/dist/core/json.js +16 -0
- package/dist/core/keys.d.ts +36 -0
- package/dist/core/keys.js +450 -0
- package/dist/core/m.d.ts +209 -0
- package/dist/core/m.js +182 -0
- package/dist/core/notifier.d.ts +17 -0
- package/dist/core/notifier.js +54 -0
- package/dist/core/oauth.d.ts +38 -0
- package/dist/core/oauth.js +108 -0
- package/dist/core/partialstate.d.ts +32 -0
- package/dist/core/partialstate.js +198 -0
- package/dist/core/phone.js +268 -0
- package/dist/core/policy.d.ts +29 -0
- package/dist/core/policy.js +97 -0
- package/dist/core/profile.js +39 -0
- package/dist/core/push.d.ts +46 -0
- package/dist/core/push.js +307 -0
- package/dist/core/pushrules.js +229 -0
- package/dist/core/ratelimit.d.ts +23 -0
- package/dist/core/ratelimit.js +77 -0
- package/dist/core/rooms.d.ts +215 -0
- package/dist/core/rooms.js +1731 -0
- package/dist/core/settings.d.ts +11 -0
- package/dist/core/settings.js +29 -0
- package/dist/core/sso.d.ts +46 -0
- package/dist/core/sso.js +165 -0
- package/dist/core/stateres.d.ts +4 -0
- package/dist/core/stateres.js +209 -0
- package/dist/core/threepid.d.ts +80 -0
- package/dist/core/threepid.js +275 -0
- package/dist/core/typing.d.ts +16 -0
- package/dist/core/typing.js +60 -0
- package/dist/federation/client.d.ts +51 -0
- package/dist/federation/client.js +279 -0
- package/dist/federation/index.d.ts +153 -0
- package/dist/federation/index.js +1059 -0
- package/dist/federation/keyring.d.ts +26 -0
- package/dist/federation/keyring.js +122 -0
- package/dist/federation/sender.d.ts +26 -0
- package/dist/federation/sender.js +164 -0
- package/dist/homeserver.d.ts +224 -0
- package/dist/homeserver.js +302 -0
- package/dist/http/adapters.d.ts +40 -0
- package/dist/http/adapters.js +130 -0
- package/dist/http/handler.d.ts +8 -0
- package/dist/http/handler.js +181 -0
- package/dist/http/input.js +24 -0
- package/dist/http/procedure.js +25 -0
- package/dist/http/router.d.ts +43 -0
- package/dist/http/router.js +56 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +15 -0
- package/dist/storage/memory.d.ts +5 -0
- package/dist/storage/memory.js +122 -0
- package/dist/storage/schema.d.ts +4 -0
- package/dist/storage/schema.js +664 -0
- package/dist/storage/sql.d.ts +72 -0
- package/dist/storage/sql.js +274 -0
- package/dist/storage/types.d.ts +55 -0
- package/dist/vendor/zod/LICENSE +21 -0
- package/dist/vendor/zod/v4/classic/errors.js +54 -0
- package/dist/vendor/zod/v4/classic/parse.js +17 -0
- package/dist/vendor/zod/v4/classic/schemas.js +865 -0
- package/dist/vendor/zod/v4/core/api.js +512 -0
- package/dist/vendor/zod/v4/core/checks.js +300 -0
- package/dist/vendor/zod/v4/core/core.js +109 -0
- package/dist/vendor/zod/v4/core/doc.js +35 -0
- package/dist/vendor/zod/v4/core/errors.js +118 -0
- package/dist/vendor/zod/v4/core/json-schema-processors.js +428 -0
- package/dist/vendor/zod/v4/core/memoizer.js +255 -0
- package/dist/vendor/zod/v4/core/parse.js +206 -0
- package/dist/vendor/zod/v4/core/regexes.js +73 -0
- package/dist/vendor/zod/v4/core/registries.js +48 -0
- package/dist/vendor/zod/v4/core/schemas.js +1378 -0
- package/dist/vendor/zod/v4/core/to-json-schema.js +448 -0
- package/dist/vendor/zod/v4/core/util.js +537 -0
- package/dist/vendor/zod/v4/core/versions.js +8 -0
- package/dist/vendor/zod/v4/locales/en.js +110 -0
- package/package.json +65 -4
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
//#region src/core/phone.ts
|
|
2
|
+
/** Country calling codes by ISO 3166-1 alpha-2 code. */
|
|
3
|
+
const CALLING_CODES = {
|
|
4
|
+
AD: "376",
|
|
5
|
+
AE: "971",
|
|
6
|
+
AF: "93",
|
|
7
|
+
AG: "1",
|
|
8
|
+
AI: "1",
|
|
9
|
+
AL: "355",
|
|
10
|
+
AM: "374",
|
|
11
|
+
AO: "244",
|
|
12
|
+
AR: "54",
|
|
13
|
+
AS: "1",
|
|
14
|
+
AT: "43",
|
|
15
|
+
AU: "61",
|
|
16
|
+
AW: "297",
|
|
17
|
+
AX: "358",
|
|
18
|
+
AZ: "994",
|
|
19
|
+
BA: "387",
|
|
20
|
+
BB: "1",
|
|
21
|
+
BD: "880",
|
|
22
|
+
BE: "32",
|
|
23
|
+
BF: "226",
|
|
24
|
+
BG: "359",
|
|
25
|
+
BH: "973",
|
|
26
|
+
BI: "257",
|
|
27
|
+
BJ: "229",
|
|
28
|
+
BL: "590",
|
|
29
|
+
BM: "1",
|
|
30
|
+
BN: "673",
|
|
31
|
+
BO: "591",
|
|
32
|
+
BQ: "599",
|
|
33
|
+
BR: "55",
|
|
34
|
+
BS: "1",
|
|
35
|
+
BT: "975",
|
|
36
|
+
BW: "267",
|
|
37
|
+
BY: "375",
|
|
38
|
+
BZ: "501",
|
|
39
|
+
CA: "1",
|
|
40
|
+
CC: "61",
|
|
41
|
+
CD: "243",
|
|
42
|
+
CF: "236",
|
|
43
|
+
CG: "242",
|
|
44
|
+
CH: "41",
|
|
45
|
+
CI: "225",
|
|
46
|
+
CK: "682",
|
|
47
|
+
CL: "56",
|
|
48
|
+
CM: "237",
|
|
49
|
+
CN: "86",
|
|
50
|
+
CO: "57",
|
|
51
|
+
CR: "506",
|
|
52
|
+
CU: "53",
|
|
53
|
+
CV: "238",
|
|
54
|
+
CW: "599",
|
|
55
|
+
CX: "61",
|
|
56
|
+
CY: "357",
|
|
57
|
+
CZ: "420",
|
|
58
|
+
DE: "49",
|
|
59
|
+
DJ: "253",
|
|
60
|
+
DK: "45",
|
|
61
|
+
DM: "1",
|
|
62
|
+
DO: "1",
|
|
63
|
+
DZ: "213",
|
|
64
|
+
EC: "593",
|
|
65
|
+
EE: "372",
|
|
66
|
+
EG: "20",
|
|
67
|
+
EH: "212",
|
|
68
|
+
ER: "291",
|
|
69
|
+
ES: "34",
|
|
70
|
+
ET: "251",
|
|
71
|
+
FI: "358",
|
|
72
|
+
FJ: "679",
|
|
73
|
+
FK: "500",
|
|
74
|
+
FM: "691",
|
|
75
|
+
FO: "298",
|
|
76
|
+
FR: "33",
|
|
77
|
+
GA: "241",
|
|
78
|
+
GB: "44",
|
|
79
|
+
GD: "1",
|
|
80
|
+
GE: "995",
|
|
81
|
+
GF: "594",
|
|
82
|
+
GG: "44",
|
|
83
|
+
GH: "233",
|
|
84
|
+
GI: "350",
|
|
85
|
+
GL: "299",
|
|
86
|
+
GM: "220",
|
|
87
|
+
GN: "224",
|
|
88
|
+
GP: "590",
|
|
89
|
+
GQ: "240",
|
|
90
|
+
GR: "30",
|
|
91
|
+
GT: "502",
|
|
92
|
+
GU: "1",
|
|
93
|
+
GW: "245",
|
|
94
|
+
GY: "592",
|
|
95
|
+
HK: "852",
|
|
96
|
+
HN: "504",
|
|
97
|
+
HR: "385",
|
|
98
|
+
HT: "509",
|
|
99
|
+
HU: "36",
|
|
100
|
+
ID: "62",
|
|
101
|
+
IE: "353",
|
|
102
|
+
IL: "972",
|
|
103
|
+
IM: "44",
|
|
104
|
+
IN: "91",
|
|
105
|
+
IO: "246",
|
|
106
|
+
IQ: "964",
|
|
107
|
+
IR: "98",
|
|
108
|
+
IS: "354",
|
|
109
|
+
IT: "39",
|
|
110
|
+
JE: "44",
|
|
111
|
+
JM: "1",
|
|
112
|
+
JO: "962",
|
|
113
|
+
JP: "81",
|
|
114
|
+
KE: "254",
|
|
115
|
+
KG: "996",
|
|
116
|
+
KH: "855",
|
|
117
|
+
KI: "686",
|
|
118
|
+
KM: "269",
|
|
119
|
+
KN: "1",
|
|
120
|
+
KP: "850",
|
|
121
|
+
KR: "82",
|
|
122
|
+
KW: "965",
|
|
123
|
+
KY: "1",
|
|
124
|
+
KZ: "7",
|
|
125
|
+
LA: "856",
|
|
126
|
+
LB: "961",
|
|
127
|
+
LC: "1",
|
|
128
|
+
LI: "423",
|
|
129
|
+
LK: "94",
|
|
130
|
+
LR: "231",
|
|
131
|
+
LS: "266",
|
|
132
|
+
LT: "370",
|
|
133
|
+
LU: "352",
|
|
134
|
+
LV: "371",
|
|
135
|
+
LY: "218",
|
|
136
|
+
MA: "212",
|
|
137
|
+
MC: "377",
|
|
138
|
+
MD: "373",
|
|
139
|
+
ME: "382",
|
|
140
|
+
MF: "590",
|
|
141
|
+
MG: "261",
|
|
142
|
+
MH: "692",
|
|
143
|
+
MK: "389",
|
|
144
|
+
ML: "223",
|
|
145
|
+
MM: "95",
|
|
146
|
+
MN: "976",
|
|
147
|
+
MO: "853",
|
|
148
|
+
MP: "1",
|
|
149
|
+
MQ: "596",
|
|
150
|
+
MR: "222",
|
|
151
|
+
MS: "1",
|
|
152
|
+
MT: "356",
|
|
153
|
+
MU: "230",
|
|
154
|
+
MV: "960",
|
|
155
|
+
MW: "265",
|
|
156
|
+
MX: "52",
|
|
157
|
+
MY: "60",
|
|
158
|
+
MZ: "258",
|
|
159
|
+
NA: "264",
|
|
160
|
+
NC: "687",
|
|
161
|
+
NE: "227",
|
|
162
|
+
NF: "672",
|
|
163
|
+
NG: "234",
|
|
164
|
+
NI: "505",
|
|
165
|
+
NL: "31",
|
|
166
|
+
NO: "47",
|
|
167
|
+
NP: "977",
|
|
168
|
+
NR: "674",
|
|
169
|
+
NU: "683",
|
|
170
|
+
NZ: "64",
|
|
171
|
+
OM: "968",
|
|
172
|
+
PA: "507",
|
|
173
|
+
PE: "51",
|
|
174
|
+
PF: "689",
|
|
175
|
+
PG: "675",
|
|
176
|
+
PH: "63",
|
|
177
|
+
PK: "92",
|
|
178
|
+
PL: "48",
|
|
179
|
+
PM: "508",
|
|
180
|
+
PR: "1",
|
|
181
|
+
PS: "970",
|
|
182
|
+
PT: "351",
|
|
183
|
+
PW: "680",
|
|
184
|
+
PY: "595",
|
|
185
|
+
QA: "974",
|
|
186
|
+
RE: "262",
|
|
187
|
+
RO: "40",
|
|
188
|
+
RS: "381",
|
|
189
|
+
RU: "7",
|
|
190
|
+
RW: "250",
|
|
191
|
+
SA: "966",
|
|
192
|
+
SB: "677",
|
|
193
|
+
SC: "248",
|
|
194
|
+
SD: "249",
|
|
195
|
+
SE: "46",
|
|
196
|
+
SG: "65",
|
|
197
|
+
SH: "290",
|
|
198
|
+
SI: "386",
|
|
199
|
+
SJ: "47",
|
|
200
|
+
SK: "421",
|
|
201
|
+
SL: "232",
|
|
202
|
+
SM: "378",
|
|
203
|
+
SN: "221",
|
|
204
|
+
SO: "252",
|
|
205
|
+
SR: "597",
|
|
206
|
+
SS: "211",
|
|
207
|
+
ST: "239",
|
|
208
|
+
SV: "503",
|
|
209
|
+
SX: "1",
|
|
210
|
+
SY: "963",
|
|
211
|
+
SZ: "268",
|
|
212
|
+
TC: "1",
|
|
213
|
+
TD: "235",
|
|
214
|
+
TG: "228",
|
|
215
|
+
TH: "66",
|
|
216
|
+
TJ: "992",
|
|
217
|
+
TK: "690",
|
|
218
|
+
TL: "670",
|
|
219
|
+
TM: "993",
|
|
220
|
+
TN: "216",
|
|
221
|
+
TO: "676",
|
|
222
|
+
TR: "90",
|
|
223
|
+
TT: "1",
|
|
224
|
+
TV: "688",
|
|
225
|
+
TW: "886",
|
|
226
|
+
TZ: "255",
|
|
227
|
+
UA: "380",
|
|
228
|
+
UG: "256",
|
|
229
|
+
US: "1",
|
|
230
|
+
UY: "598",
|
|
231
|
+
UZ: "998",
|
|
232
|
+
VA: "39",
|
|
233
|
+
VC: "1",
|
|
234
|
+
VE: "58",
|
|
235
|
+
VG: "1",
|
|
236
|
+
VI: "1",
|
|
237
|
+
VN: "84",
|
|
238
|
+
VU: "678",
|
|
239
|
+
WF: "681",
|
|
240
|
+
WS: "685",
|
|
241
|
+
XK: "383",
|
|
242
|
+
YE: "967",
|
|
243
|
+
YT: "262",
|
|
244
|
+
ZA: "27",
|
|
245
|
+
ZM: "260",
|
|
246
|
+
ZW: "263"
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* The MSISDN for a phone number entered in a country (`country` is an ISO 3166-1 alpha-2 code).
|
|
250
|
+
* Numbers given in international form ("+48 ...", "0048 ...") keep their own country code.
|
|
251
|
+
* Returns null for numbers that cannot be valid.
|
|
252
|
+
*/
|
|
253
|
+
function toMsisdn(country, phoneNumber) {
|
|
254
|
+
let digits = phoneNumber.trim().replace(/[\s().\-/]/g, "");
|
|
255
|
+
if (!/^\+?\d+$/.test(digits)) return null;
|
|
256
|
+
let msisdn;
|
|
257
|
+
if (digits.startsWith("+")) msisdn = digits.slice(1);
|
|
258
|
+
else if (digits.startsWith("00")) msisdn = digits.slice(2);
|
|
259
|
+
else {
|
|
260
|
+
const code = CALLING_CODES[country.toUpperCase()];
|
|
261
|
+
if (!code) return null;
|
|
262
|
+
if (digits.startsWith("0") && code !== "39") digits = digits.replace(/^0+/, "");
|
|
263
|
+
msisdn = code + digits;
|
|
264
|
+
}
|
|
265
|
+
return msisdn.length >= 7 && msisdn.length <= 15 ? msisdn : null;
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export { toMsisdn };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PDU } from "./events.js";
|
|
2
|
+
import { Homeserver } from "../homeserver.js";
|
|
3
|
+
import { KeyObject } from "node:crypto";
|
|
4
|
+
//#region src/core/policy.d.ts
|
|
5
|
+
interface RoomPolicy {
|
|
6
|
+
via: string;
|
|
7
|
+
key: KeyObject;
|
|
8
|
+
}
|
|
9
|
+
export declare class PolicyServers {
|
|
10
|
+
private readonly hs;
|
|
11
|
+
constructor(hs: Homeserver);
|
|
12
|
+
/** The room's policy server, if the room uses one (valid `m.room.policy` and a joined user on `via`). */
|
|
13
|
+
policyOf(roomId: string): Promise<RoomPolicy | null>;
|
|
14
|
+
/** The policy state event itself is never sent to the policy server. */
|
|
15
|
+
private exempt;
|
|
16
|
+
private validSignature;
|
|
17
|
+
/** Ask the policy server to sign `pdu`; adds the signature to it. Throws the server's error. */
|
|
18
|
+
private requestSignature;
|
|
19
|
+
/**
|
|
20
|
+
* Before a local event is sent: get the policy server's signature, or refuse the event with the
|
|
21
|
+
* policy server's error. If the policy server cannot be reached the event is sent unsigned (other
|
|
22
|
+
* servers may then soft-fail it), so an unavailable policy server does not lock up the room.
|
|
23
|
+
*/
|
|
24
|
+
signLocal(roomId: string, version: string, pdu: PDU): Promise<void>;
|
|
25
|
+
/** Whether a remote event is recommended for inclusion (otherwise it is soft-failed). */
|
|
26
|
+
recommended(roomId: string, version: string, pdu: PDU): Promise<boolean>;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { publicKeyFromBase64, verifyJsonSignature } from "./crypto.js";
|
|
2
|
+
import { M } from "./m.js";
|
|
3
|
+
import { redact } from "./events.js";
|
|
4
|
+
import { MatrixError } from "./errors.js";
|
|
5
|
+
import { getState } from "./authrules.js";
|
|
6
|
+
import { domainOf } from "../federation/index.js";
|
|
7
|
+
//#region src/core/policy.ts
|
|
8
|
+
const KEY_ID = "ed25519:policy_server";
|
|
9
|
+
var PolicyServers = class {
|
|
10
|
+
hs;
|
|
11
|
+
constructor(hs) {
|
|
12
|
+
this.hs = hs;
|
|
13
|
+
}
|
|
14
|
+
/** The room's policy server, if the room uses one (valid `m.room.policy` and a joined user on `via`). */
|
|
15
|
+
async policyOf(roomId) {
|
|
16
|
+
const state = await this.hs.rooms.currentState(roomId);
|
|
17
|
+
const content = getState(state, M.ROOM.POLICY, "")?.content;
|
|
18
|
+
const via = content?.via;
|
|
19
|
+
const ed25519 = content?.public_keys?.ed25519;
|
|
20
|
+
if (typeof via !== "string" || typeof ed25519 !== "string") return null;
|
|
21
|
+
let key;
|
|
22
|
+
try {
|
|
23
|
+
key = publicKeyFromBase64(ed25519);
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
for (const ev of state.values()) if (ev.type === M.ROOM.MEMBER && ev.content?.membership === "join" && typeof ev.state_key === "string" && domainOf(ev.state_key) === via) return {
|
|
28
|
+
via,
|
|
29
|
+
key
|
|
30
|
+
};
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/** The policy state event itself is never sent to the policy server. */
|
|
34
|
+
exempt(pdu) {
|
|
35
|
+
return pdu.type === M.ROOM.POLICY && pdu.state_key === "";
|
|
36
|
+
}
|
|
37
|
+
validSignature(pdu, version, policy) {
|
|
38
|
+
const wire = this.hs.federation.toFederationPdu(pdu, version);
|
|
39
|
+
return verifyJsonSignature(redact(wire, version), policy.via, KEY_ID, policy.key);
|
|
40
|
+
}
|
|
41
|
+
/** Ask the policy server to sign `pdu`; adds the signature to it. Throws the server's error. */
|
|
42
|
+
async requestSignature(pdu, version, policy) {
|
|
43
|
+
const sig = (await this.hs.federation.client.request(policy.via, "POST", "/_matrix/policy/v1/sign", {
|
|
44
|
+
body: this.hs.federation.toFederationPdu(pdu, version),
|
|
45
|
+
timeoutMs: 1e4
|
|
46
|
+
}))?.[policy.via]?.[KEY_ID];
|
|
47
|
+
if (typeof sig !== "string") throw new MatrixError(403, "M_FORBIDDEN", "The policy server did not sign the event");
|
|
48
|
+
pdu.signatures = {
|
|
49
|
+
...pdu.signatures,
|
|
50
|
+
[policy.via]: {
|
|
51
|
+
...pdu.signatures?.[policy.via],
|
|
52
|
+
[KEY_ID]: sig
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Before a local event is sent: get the policy server's signature, or refuse the event with the
|
|
58
|
+
* policy server's error. If the policy server cannot be reached the event is sent unsigned (other
|
|
59
|
+
* servers may then soft-fail it), so an unavailable policy server does not lock up the room.
|
|
60
|
+
*/
|
|
61
|
+
async signLocal(roomId, version, pdu) {
|
|
62
|
+
if (this.exempt(pdu) || !this.hs.federation.enabled) return;
|
|
63
|
+
const policy = await this.policyOf(roomId);
|
|
64
|
+
if (!policy) return;
|
|
65
|
+
if (policy.via === this.hs.serverName) {
|
|
66
|
+
this.hs.logger.warn("Room", roomId, "names this server as its policy server, which it does not implement");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
await this.requestSignature(pdu, version, policy);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (err instanceof MatrixError && err.status < 500) throw err;
|
|
73
|
+
this.hs.logger.warn("Policy server", policy.via, "unreachable; sending", pdu.event_id, "without its signature", err);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!this.validSignature(pdu, version, policy)) throw new MatrixError(403, "M_FORBIDDEN", "The policy server's signature is invalid");
|
|
77
|
+
}
|
|
78
|
+
/** Whether a remote event is recommended for inclusion (otherwise it is soft-failed). */
|
|
79
|
+
async recommended(roomId, version, pdu) {
|
|
80
|
+
if (this.exempt(pdu)) return true;
|
|
81
|
+
const policy = await this.policyOf(roomId);
|
|
82
|
+
if (!policy) return true;
|
|
83
|
+
if (this.validSignature(pdu, version, policy)) return true;
|
|
84
|
+
if (policy.via === this.hs.serverName) return false;
|
|
85
|
+
const copy = structuredClone(pdu);
|
|
86
|
+
try {
|
|
87
|
+
await this.requestSignature(copy, version, policy);
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (!this.validSignature(copy, version, policy)) return false;
|
|
92
|
+
pdu.signatures = copy.signatures;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
97
|
+
export { PolicyServers };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { canonicalJson } from "./json.js";
|
|
2
|
+
//#region src/core/profile.ts
|
|
3
|
+
const BUILTIN_FIELDS = /* @__PURE__ */ new Set(["displayname", "avatar_url"]);
|
|
4
|
+
const MAX_PROFILE_BYTES = 65536;
|
|
5
|
+
async function fullProfile(hs, userId) {
|
|
6
|
+
const user = await hs.db.findOne("users", [{
|
|
7
|
+
field: "user_id",
|
|
8
|
+
value: userId
|
|
9
|
+
}]);
|
|
10
|
+
if (!user || user.deactivated) return null;
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const row of await hs.db.findMany("profile_fields", { where: [{
|
|
13
|
+
field: "user_id",
|
|
14
|
+
value: userId
|
|
15
|
+
}] })) if (row.value !== null && row.value !== void 0 && !BUILTIN_FIELDS.has(row.field)) out[row.field] = row.value;
|
|
16
|
+
if (user.displayname) out.displayname = user.displayname;
|
|
17
|
+
if (user.avatar_url) out.avatar_url = user.avatar_url;
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
function profileSize(profile) {
|
|
21
|
+
return Buffer.byteLength(canonicalJson(profile));
|
|
22
|
+
}
|
|
23
|
+
/** Set (or with `null`, clear) one profile field and notify users sharing a room. */
|
|
24
|
+
async function setProfileField(hs, userId, field, value) {
|
|
25
|
+
if (BUILTIN_FIELDS.has(field)) await hs.db.update("users", [{
|
|
26
|
+
field: "user_id",
|
|
27
|
+
value: userId
|
|
28
|
+
}], { [field]: value || null });
|
|
29
|
+
await hs.streams.write((stream) => hs.db.upsert("profile_fields", {
|
|
30
|
+
user_id: userId,
|
|
31
|
+
field,
|
|
32
|
+
value: value ?? null,
|
|
33
|
+
stream
|
|
34
|
+
}));
|
|
35
|
+
if (BUILTIN_FIELDS.has(field)) await hs.rooms.propagateProfile(userId);
|
|
36
|
+
hs.notifier.notify([...await hs.rooms.usersSharingRooms(userId)]);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { BUILTIN_FIELDS, MAX_PROFILE_BYTES, fullProfile, profileSize, setProfileField };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ClientEvent } from "./events.js";
|
|
2
|
+
import { StateMap } from "./authrules.js";
|
|
3
|
+
import { StoredEvent } from "./rooms.js";
|
|
4
|
+
import { Homeserver } from "../homeserver.js";
|
|
5
|
+
//#region src/core/push.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Push rule evaluation and push gateway delivery. Every new event is evaluated for
|
|
8
|
+
* every local member; matches are stored for unread counts and `/notifications`.
|
|
9
|
+
*/
|
|
10
|
+
export declare class PushService {
|
|
11
|
+
private hs;
|
|
12
|
+
constructor(hs: Homeserver);
|
|
13
|
+
onEvent(ev: StoredEvent, state: StateMap, version: string): Promise<void>;
|
|
14
|
+
/** Unread notification counts since the user's read receipts. */
|
|
15
|
+
/** Stream positions up to which the user has read the room (unthreaded) and each thread. */
|
|
16
|
+
private readPositions;
|
|
17
|
+
isRead(row: Record<string, any>, read: {
|
|
18
|
+
unthreaded: number;
|
|
19
|
+
threads: Map<string, number>;
|
|
20
|
+
}): boolean;
|
|
21
|
+
unreadCounts(userId: string, roomId: string): Promise<{
|
|
22
|
+
room: {
|
|
23
|
+
notification_count: number;
|
|
24
|
+
highlight_count: number;
|
|
25
|
+
};
|
|
26
|
+
threads: Record<string, {
|
|
27
|
+
notification_count: number;
|
|
28
|
+
highlight_count: number;
|
|
29
|
+
}>;
|
|
30
|
+
}>;
|
|
31
|
+
private deliver;
|
|
32
|
+
/** Rows for `GET /notifications`. */
|
|
33
|
+
list(userId: string, opts: {
|
|
34
|
+
from: number | null;
|
|
35
|
+
limit: number;
|
|
36
|
+
onlyHighlight: boolean;
|
|
37
|
+
}): Promise<{
|
|
38
|
+
actions: any;
|
|
39
|
+
event: ClientEvent;
|
|
40
|
+
room_id: any;
|
|
41
|
+
ts: any;
|
|
42
|
+
read: boolean;
|
|
43
|
+
stream: any;
|
|
44
|
+
}[]>;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|