matrix-nodejs-homeserver 0.0.0-stage → 0.2.0

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.
Files changed (120) hide show
  1. package/LICENSE +75 -0
  2. package/README.md +457 -2
  3. package/dist/adapters/auth.d.ts +50 -0
  4. package/dist/adapters/auth.js +18 -0
  5. package/dist/adapters/cluster.d.ts +55 -0
  6. package/dist/adapters/cluster.js +249 -0
  7. package/dist/adapters/media.d.ts +50 -0
  8. package/dist/adapters/media.js +63 -0
  9. package/dist/adapters/s3.d.ts +33 -0
  10. package/dist/adapters/s3.js +95 -0
  11. package/dist/api/account.js +560 -0
  12. package/dist/api/admin.js +251 -0
  13. package/dist/api/appservice.js +33 -0
  14. package/dist/api/backup.js +269 -0
  15. package/dist/api/federation.js +792 -0
  16. package/dist/api/filters.js +87 -0
  17. package/dist/api/index.js +47 -0
  18. package/dist/api/legacy.js +170 -0
  19. package/dist/api/media.js +255 -0
  20. package/dist/api/misc.js +86 -0
  21. package/dist/api/preview.js +200 -0
  22. package/dist/api/profile.js +165 -0
  23. package/dist/api/push.js +187 -0
  24. package/dist/api/relationships.js +264 -0
  25. package/dist/api/rooms.js +1364 -0
  26. package/dist/api/rtc.d.ts +24 -0
  27. package/dist/api/rtc.js +52 -0
  28. package/dist/api/search.js +155 -0
  29. package/dist/api/slidingsync.js +464 -0
  30. package/dist/api/spaces.js +172 -0
  31. package/dist/api/sync.js +600 -0
  32. package/dist/api/threadsubs.js +129 -0
  33. package/dist/api/threepid.js +122 -0
  34. package/dist/api/uia.js +126 -0
  35. package/dist/api/user.js +286 -0
  36. package/dist/core/admin.d.ts +85 -0
  37. package/dist/core/admin.js +307 -0
  38. package/dist/core/adminroom.d.ts +49 -0
  39. package/dist/core/adminroom.js +482 -0
  40. package/dist/core/appservices.d.ts +73 -0
  41. package/dist/core/appservices.js +368 -0
  42. package/dist/core/audit.d.ts +51 -0
  43. package/dist/core/audit.js +86 -0
  44. package/dist/core/auth.d.ts +48 -0
  45. package/dist/core/auth.js +237 -0
  46. package/dist/core/authrules.d.ts +4 -0
  47. package/dist/core/authrules.js +347 -0
  48. package/dist/core/cluster.d.ts +66 -0
  49. package/dist/core/cluster.js +191 -0
  50. package/dist/core/crypto.d.ts +10 -0
  51. package/dist/core/crypto.js +100 -0
  52. package/dist/core/delayed.d.ts +39 -0
  53. package/dist/core/delayed.js +159 -0
  54. package/dist/core/errors.d.ts +9 -0
  55. package/dist/core/errors.js +45 -0
  56. package/dist/core/events.d.ts +32 -0
  57. package/dist/core/events.js +185 -0
  58. package/dist/core/glob.js +66 -0
  59. package/dist/core/identity.d.ts +24 -0
  60. package/dist/core/identity.js +96 -0
  61. package/dist/core/ids.js +36 -0
  62. package/dist/core/invitefilter.js +35 -0
  63. package/dist/core/json.js +16 -0
  64. package/dist/core/keys.d.ts +36 -0
  65. package/dist/core/keys.js +449 -0
  66. package/dist/core/notifier.d.ts +17 -0
  67. package/dist/core/notifier.js +54 -0
  68. package/dist/core/oauth.d.ts +38 -0
  69. package/dist/core/oauth.js +108 -0
  70. package/dist/core/partialstate.d.ts +32 -0
  71. package/dist/core/partialstate.js +197 -0
  72. package/dist/core/phone.js +268 -0
  73. package/dist/core/policy.d.ts +29 -0
  74. package/dist/core/policy.js +96 -0
  75. package/dist/core/profile.js +39 -0
  76. package/dist/core/push.d.ts +47 -0
  77. package/dist/core/push.js +306 -0
  78. package/dist/core/pushrules.d.ts +1 -0
  79. package/dist/core/pushrules.js +228 -0
  80. package/dist/core/ratelimit.d.ts +23 -0
  81. package/dist/core/ratelimit.js +77 -0
  82. package/dist/core/rooms.d.ts +215 -0
  83. package/dist/core/rooms.js +1729 -0
  84. package/dist/core/settings.d.ts +11 -0
  85. package/dist/core/settings.js +29 -0
  86. package/dist/core/sso.d.ts +46 -0
  87. package/dist/core/sso.js +165 -0
  88. package/dist/core/stateres.d.ts +4 -0
  89. package/dist/core/stateres.js +208 -0
  90. package/dist/core/threepid.d.ts +80 -0
  91. package/dist/core/threepid.js +275 -0
  92. package/dist/core/typing.d.ts +16 -0
  93. package/dist/core/typing.js +60 -0
  94. package/dist/federation/client.d.ts +51 -0
  95. package/dist/federation/client.js +278 -0
  96. package/dist/federation/index.d.ts +153 -0
  97. package/dist/federation/index.js +1058 -0
  98. package/dist/federation/keyring.d.ts +26 -0
  99. package/dist/federation/keyring.js +122 -0
  100. package/dist/federation/sender.d.ts +26 -0
  101. package/dist/federation/sender.js +164 -0
  102. package/dist/homeserver.d.ts +223 -0
  103. package/dist/homeserver.js +301 -0
  104. package/dist/http/adapters.d.ts +40 -0
  105. package/dist/http/adapters.js +130 -0
  106. package/dist/http/handler.d.ts +8 -0
  107. package/dist/http/handler.js +202 -0
  108. package/dist/http/input.js +24 -0
  109. package/dist/http/router.d.ts +60 -0
  110. package/dist/http/router.js +76 -0
  111. package/dist/index.d.ts +25 -0
  112. package/dist/index.js +14 -0
  113. package/dist/storage/memory.d.ts +5 -0
  114. package/dist/storage/memory.js +122 -0
  115. package/dist/storage/schema.d.ts +4 -0
  116. package/dist/storage/schema.js +664 -0
  117. package/dist/storage/sql.d.ts +72 -0
  118. package/dist/storage/sql.js +274 -0
  119. package/dist/storage/types.d.ts +55 -0
  120. package/package.json +67 -4
@@ -0,0 +1,153 @@
1
+ import { PDU } from "../core/events.js";
2
+ import { StateMap } from "../core/authrules.js";
3
+ import { MatrixError } from "../core/errors.js";
4
+ import { FederationClient } from "./client.js";
5
+ import { KeyRing } from "./keyring.js";
6
+ import { TransactionSender } from "./sender.js";
7
+ import { Homeserver } from "../homeserver.js";
8
+ //#region src/federation/index.d.ts
9
+ export interface FederationOptions {
10
+ /** Enable federation. Default: true. */
11
+ enabled?: boolean;
12
+ /** Join remote rooms with partial state first (MSC3902 "faster joins"). Default true. */
13
+ fasterJoins?: boolean;
14
+ /** Verify remote TLS certificates. Default: true. Disable only for development. */
15
+ verifyTls?: boolean;
16
+ /** Only federate with these servers (allow list). */
17
+ allowedServers?: string[];
18
+ /** Never federate with these servers. */
19
+ blockedServers?: string[];
20
+ }
21
+ /** Server-server API: verification, inbound processing and outbound requests. */
22
+ export declare class FederationService {
23
+ private hs;
24
+ readonly enabled: boolean;
25
+ readonly fasterJoins: boolean;
26
+ readonly client: FederationClient;
27
+ readonly keyring: KeyRing;
28
+ readonly sender: TransactionSender;
29
+ private options;
30
+ private seenTxns;
31
+ private deviceStreams;
32
+ constructor(hs: Homeserver, options?: FederationOptions);
33
+ serverAllowed(serverName: string): boolean;
34
+ private requireEnabled;
35
+ /** Convert a stored event into its federation (wire) format. */
36
+ toFederationPdu(pdu: PDU, version: string): Record<string, any>;
37
+ computeEventId(raw: Record<string, any>, version: string): string;
38
+ /**
39
+ * Verify an incoming PDU: event ID, signatures and content hash. Events with a bad
40
+ * content hash are redacted (as the spec requires) rather than rejected.
41
+ */
42
+ verifyPdu(raw: Record<string, any>, version: string, roomId: string): Promise<{
43
+ pdu: PDU;
44
+ joinAuthorisedSignatureValid?: boolean;
45
+ }>;
46
+ /** Servers with joined members in a room (excluding ourselves). */
47
+ serversInRoom(state: StateMap, applyAcl?: boolean): Set<string>;
48
+ /**
49
+ * Servers to send a room's traffic to: joined servers per the state, plus, while the room's
50
+ * state is partial (MSC3902), the servers the resident server said were in the room.
51
+ */
52
+ roomDestinations(roomId: string, state: StateMap, applyAcl?: boolean): Promise<Set<string>>;
53
+ /** Send a newly created local event to every server in the room. */
54
+ onLocalEvent(pdu: PDU, state: StateMap): void;
55
+ /** Send an EDU to every server in the given rooms. */
56
+ sendEduToRooms(roomIds: string[], eduType: string, content: Record<string, any>, durable?: boolean): Promise<void>;
57
+ /** Servers sharing a room with a local user. */
58
+ serversSharingRooms(userId: string): Promise<Set<string>>;
59
+ onTyping(roomId: string, userId: string, typing: boolean): Promise<void>;
60
+ onReceipt(roomId: string, userId: string, receiptType: string, eventId: string, ts: number, threadId: string): Promise<void>;
61
+ onPresence(userId: string, presence: string, statusMsg: string | null): Promise<void>;
62
+ /** Tell servers sharing rooms with a local user that their device list changed. */
63
+ onDeviceListChange(userId: string, deletedDeviceId?: string, to?: Set<string>): Promise<void>;
64
+ onSigningKeyUpdate(userId: string): Promise<void>;
65
+ /** Deliver to-device messages addressed to remote users. */
66
+ sendToDevice(sender: string, type: string, messages: Record<string, Record<string, any>>, messageId: string): Promise<void>;
67
+ receiveTransaction(origin: string, txnId: string, body: Record<string, any>): Promise<Record<string, any>>;
68
+ private processTransaction;
69
+ /**
70
+ * A PDU for a room we are not in can still matter: a local user's invite being
71
+ * rescinded or their knock being accepted/rejected.
72
+ */
73
+ private handleOutOfRoomMembership;
74
+ /** Process one incoming PDU (caller holds the room lock). */
75
+ handlePdu(origin: string, roomId: string, version: string, raw: Record<string, any>, depth?: number): Promise<void>;
76
+ /**
77
+ * State before an event whose predecessors we lack: for each unknown prev event,
78
+ * fetch the state at it (/state_ids) plus the event itself, then resolve all
79
+ * predecessors' states. Throws if a required event cannot be fetched.
80
+ */
81
+ stateFromPrevs(origin: string, roomId: string, version: string, prevIds: string[], opts?: {
82
+ remote?: boolean;
83
+ }): Promise<Record<string, string>>;
84
+ private fetchMissingAuthEvents;
85
+ /** Fill a gap with /get_missing_events. Returns false when the response contained invalid events. */
86
+ private fetchMissingPrevEvents;
87
+ /** Fetch one event from a remote server and store it as an outlier. */
88
+ private fetchEvent;
89
+ private fetchRawEvent;
90
+ /**
91
+ * Fetch the state before an event from a remote server. Uses /state_ids and
92
+ * fetches only unknown events (falling back to /state), storing them as outliers.
93
+ */
94
+ fetchStateBefore(origin: string, roomId: string, version: string, eventId: string): Promise<Record<string, string>>;
95
+ /** Verify and store events that are not (yet) part of the timeline. */
96
+ storeOutliers(roomId: string, version: string, raws: unknown[]): Promise<void>;
97
+ /** Check an outlier against its own auth events. Returns a rejection reason, or null. */
98
+ private checkOutlierAuth;
99
+ /**
100
+ * Whether a remote user's ephemeral activity (typing, receipts) in a room is accepted: they are
101
+ * joined, or the room's state is partial (MSC3902) and their server is one of the room's servers.
102
+ */
103
+ private mayActInRoom;
104
+ handleEdu(origin: string, edu: Record<string, any>): Promise<void>;
105
+ /** Build a full event from a make_join/make_leave/make_knock template and sign it. */
106
+ private finaliseTemplate;
107
+ /** Join a room hosted on other servers. Returns the room ID. */
108
+ joinRemoteRoom(userId: string, roomId: string, servers: string[], content: Record<string, any>): Promise<string>;
109
+ private completeJoin;
110
+ /** Leave (or reject an invite to) a room hosted elsewhere. */
111
+ leaveRemoteRoom(userId: string, roomId: string, servers: string[], reason?: string): Promise<PDU>;
112
+ knockRemoteRoom(userId: string, roomId: string, servers: string[], reason?: string): Promise<{
113
+ pdu: PDU;
114
+ knockState: any[];
115
+ }>;
116
+ /** Ask the invitee's server to sign an invite; returns the countersigned event. */
117
+ sendInvite(pdu: PDU, version: string, inviteRoomState: Record<string, any>[]): Promise<PDU>;
118
+ queryProfile(userId: string, field?: string): Promise<Record<string, any>>;
119
+ queryAlias(alias: string): Promise<{
120
+ room_id: string;
121
+ servers: string[];
122
+ }>;
123
+ queryKeys(deviceKeys: Record<string, string[]>, timeoutMs?: number): Promise<{
124
+ results: Record<string, any>[];
125
+ failures: Record<string, any>;
126
+ }>;
127
+ claimKeys(oneTimeKeys: Record<string, Record<string, string>>, timeoutMs?: number): Promise<{
128
+ results: Record<string, any>;
129
+ failures: Record<string, any>;
130
+ }>;
131
+ queryPublicRooms(server: string, body: Record<string, any>): Promise<Record<string, any>>;
132
+ queryHierarchy(server: string, roomId: string, suggestedOnly: boolean): Promise<Record<string, any>>;
133
+ /**
134
+ * Fetch history preceding the oldest events we have. Returns the number of new
135
+ * events stored. Caller should not hold the room lock.
136
+ */
137
+ backfill(roomId: string, fromEventIds: string[], limit?: number): Promise<number>;
138
+ /** Download remote media (authenticated federation endpoint, falling back to the legacy one). */
139
+ fetchMedia(server: string, mediaId: string): Promise<{
140
+ data: Uint8Array;
141
+ contentType: string | null;
142
+ filename: string | null;
143
+ }>;
144
+ /** Remote members who should receive the invitee's stripped state. */
145
+ strippedStateFor(state: StateMap): Record<string, any>[];
146
+ /** Servers that may be able to help us join `roomId`. */
147
+ candidateServers(roomId: string, extra?: string[]): string[];
148
+ static memberServers(state: StateMap): string[];
149
+ isMembershipVisibleTo(state: StateMap, server: string): boolean;
150
+ stripped(pdu: PDU): Record<string, any>;
151
+ error(status: number, errcode: string, message: string): MatrixError;
152
+ }
153
+ //#endregion