matrix-js-sdk 41.0.0 → 41.1.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.
- package/CHANGELOG.md +8 -0
- package/lib/@types/event.d.ts +1 -1
- package/lib/@types/event.d.ts.map +1 -1
- package/lib/@types/event.js +1 -1
- package/lib/@types/event.js.map +1 -1
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +250 -246
- package/lib/client.js.map +1 -1
- package/lib/crypto-api/index.d.ts +13 -2
- package/lib/crypto-api/index.d.ts.map +1 -1
- package/lib/crypto-api/index.js +11 -0
- package/lib/crypto-api/index.js.map +1 -1
- package/lib/logger.d.ts +5 -5
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/matrixrtc/CallMembership.d.ts +49 -145
- package/lib/matrixrtc/CallMembership.d.ts.map +1 -1
- package/lib/matrixrtc/CallMembership.js +157 -265
- package/lib/matrixrtc/CallMembership.js.map +1 -1
- package/lib/matrixrtc/EncryptionManager.d.ts +1 -85
- package/lib/matrixrtc/EncryptionManager.d.ts.map +1 -1
- package/lib/matrixrtc/EncryptionManager.js +0 -317
- package/lib/matrixrtc/EncryptionManager.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts +18 -22
- package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.js +48 -76
- package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.d.ts +2 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.d.ts.map +1 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.js +3 -2
- package/lib/matrixrtc/MatrixRTCSessionManager.js.map +1 -1
- package/lib/matrixrtc/MembershipManager.d.ts +10 -4
- package/lib/matrixrtc/MembershipManager.d.ts.map +1 -1
- package/lib/matrixrtc/MembershipManager.js +10 -4
- package/lib/matrixrtc/MembershipManager.js.map +1 -1
- package/lib/matrixrtc/RTCEncryptionManager.d.ts +6 -7
- package/lib/matrixrtc/RTCEncryptionManager.d.ts.map +1 -1
- package/lib/matrixrtc/RTCEncryptionManager.js +4 -7
- package/lib/matrixrtc/RTCEncryptionManager.js.map +1 -1
- package/lib/matrixrtc/index.d.ts +1 -0
- package/lib/matrixrtc/index.d.ts.map +1 -1
- package/lib/matrixrtc/index.js.map +1 -1
- package/lib/matrixrtc/membershipData/common.d.ts +8 -0
- package/lib/matrixrtc/membershipData/common.d.ts.map +1 -0
- package/lib/matrixrtc/membershipData/common.js +26 -0
- package/lib/matrixrtc/membershipData/common.js.map +1 -0
- package/lib/matrixrtc/membershipData/index.d.ts +4 -0
- package/lib/matrixrtc/membershipData/index.d.ts.map +1 -0
- package/lib/matrixrtc/membershipData/index.js +20 -0
- package/lib/matrixrtc/membershipData/index.js.map +1 -0
- package/lib/matrixrtc/membershipData/rtc.d.ts +33 -0
- package/lib/matrixrtc/membershipData/rtc.d.ts.map +1 -0
- package/lib/matrixrtc/membershipData/rtc.js +137 -0
- package/lib/matrixrtc/membershipData/rtc.js.map +1 -0
- package/lib/matrixrtc/membershipData/session.d.ts +77 -0
- package/lib/matrixrtc/membershipData/session.d.ts.map +1 -0
- package/lib/matrixrtc/membershipData/session.js +62 -0
- package/lib/matrixrtc/membershipData/session.js.map +1 -0
- package/lib/matrixrtc/types.d.ts +23 -0
- package/lib/matrixrtc/types.d.ts.map +1 -1
- package/lib/matrixrtc/types.js +9 -1
- package/lib/matrixrtc/types.js.map +1 -1
- package/lib/matrixrtc/utils.d.ts +11 -1
- package/lib/matrixrtc/utils.d.ts.map +1 -1
- package/lib/matrixrtc/utils.js +24 -1
- package/lib/matrixrtc/utils.js.map +1 -1
- package/lib/rust-crypto/rust-crypto.d.ts.map +1 -1
- package/lib/rust-crypto/rust-crypto.js +2 -2
- package/lib/rust-crypto/rust-crypto.js.map +1 -1
- package/package.json +5 -7
- package/src/@types/event.ts +2 -2
- package/src/client.ts +5 -3
- package/src/crypto-api/index.ts +17 -2
- package/src/logger.ts +5 -5
- package/src/matrixrtc/CallMembership.ts +159 -373
- package/src/matrixrtc/EncryptionManager.ts +1 -417
- package/src/matrixrtc/MatrixRTCSession.ts +82 -122
- package/src/matrixrtc/MatrixRTCSessionManager.ts +5 -3
- package/src/matrixrtc/MembershipManager.ts +14 -17
- package/src/matrixrtc/RTCEncryptionManager.ts +7 -10
- package/src/matrixrtc/index.ts +1 -0
- package/src/matrixrtc/membershipData/common.ts +27 -0
- package/src/matrixrtc/membershipData/index.ts +19 -0
- package/src/matrixrtc/membershipData/rtc.ts +156 -0
- package/src/matrixrtc/membershipData/session.ts +146 -0
- package/src/matrixrtc/types.ts +27 -1
- package/src/matrixrtc/utils.ts +24 -2
- package/src/rust-crypto/rust-crypto.ts +4 -1
- package/lib/matrixrtc/RoomKeyTransport.d.ts +0 -25
- package/lib/matrixrtc/RoomKeyTransport.d.ts.map +0 -1
- package/lib/matrixrtc/RoomKeyTransport.js +0 -152
- package/lib/matrixrtc/RoomKeyTransport.js.map +0 -1
- package/src/matrixrtc/RoomKeyTransport.ts +0 -189
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RTCEncryptionManager.js","names":["getEncryptionKeyMapKey","CallMembership","decodeBase64","encodeBase64","KeyTransportEvents","sleep","OutdatedKeyFilter","RTCEncryptionManager","constructor","ownMembership","getMemberships","transport","statistics","onEncryptionKeysChanged","parentLogger","rtcBackendIdProvider","_defineProperty","Map","undefined","membership","keyBase64Encoded","index","timestamp","_this$logger2","manageMediaKeys","_this$logger","logger","warn","concat","userId","deviceId","debug","keyBin","candidateInboundSession","key","keyIndex","creationTS","outdated","keyBuffer","isOutdated","addKeyToParticipant","counters","roomEventEncryptionKeysReceived","_this$logger3","info","getChild","rtcIdentityProvider","computeRtcIdentityRaw","getOwnRtcBackendIdentity","_this","_asyncToGenerator","ownRtcBackendIdentityCache","useHashedRtcBackendIdentity","_this$logger4","memberId","getEncryptionKeys","participantKeyRings","checkKeysWithoutMatchingRTCMembership","keyInfoTemp","keysWithoutMatchingRTCMembership","forEach","keyInfo","knownRtcMembership","fullMembership","find","member","_this$logger5","push","addKeyToParticipantWithBackendIdentity","rtcBackendIdentity","mapKey","has","set","get","join","joinConfig","_joinConfig$manageMed","_joinConfig$unstableS","_joinConfig$useKeyDel","_joinConfig$keyRotati","_this$logger6","unstableSendStickyEvents","useKeyDelay","keyRotationGracePeriodMs","on","ReceivedKeys","onNewKeyReceived","start","leave","off","stop","clear","ensureKeyDistribution","currentKeyDistributionPromise","_this$logger7","rolloutOutboundKey","then","_this$logger8","needToEnsureKeyAgain","_this$logger9","_this$logger0","onMembershipsUpdate","_this$logger1","oldMemberships","arguments","length","trace","_this2","_this2$outboundSessio","_this2$outboundSessio2","isFirstKey","outboundSession","firstKey","generateRandomKey","Date","now","sharedWith","keyId","toShareWith","filter","sender","map","membershipTs","createdTs","alreadySharedWith","x","some","o","anyLeft","anyJoined","toDistributeTo","outboundKey","hasKeyChanged","newOutboundKey","createNewOutboundSession","keyAge","_this2$logger","_this2$logger2","_this2$logger3","_this2$logger4","sendKey","roomEventEncryptionKeysSent","m","_this2$logger5","_this2$logger6","err","_this2$logger7","error","_this$logger10","nextKeyIndex","Uint8Array","globalThis","crypto","getRandomValues"],"sources":["../../src/matrixrtc/RTCEncryptionManager.ts"],"sourcesContent":["/*\nCopyright 2025 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport {\n type CallMembershipIdentityParts,\n getEncryptionKeyMapKey,\n type IEncryptionManager,\n} from \"./EncryptionManager.ts\";\nimport { type EncryptionConfig, type MembershipConfig } from \"./MatrixRTCSession.ts\";\nimport { CallMembership } from \"./CallMembership.ts\";\nimport { decodeBase64, encodeBase64 } from \"../base64.ts\";\nimport { type IKeyTransport, type KeyTransportEventListener, KeyTransportEvents } from \"./IKeyTransport.ts\";\nimport { type Logger } from \"../logger.ts\";\nimport { sleep } from \"../utils.ts\";\nimport {\n type EncryptionKeyMapKey,\n type InboundEncryptionSession,\n type OutboundEncryptionSession,\n type ParticipantDeviceInfo,\n type Statistics,\n} from \"./types.ts\";\nimport { OutdatedKeyFilter } from \"./utils.ts\";\n\n/**\n * RTCEncryptionManager is used to manage the encryption keys for a call.\n *\n * It is responsible for distributing the keys to the other participants and rotating the keys if needed.\n *\n * This manager when used with to-device transport will share the existing key only to new joiners, and rotate\n * if there is a leaver.\n *\n * XXX In the future we want to distribute a ratcheted key not the current one for new joiners.\n */\nexport class RTCEncryptionManager implements IEncryptionManager {\n // This is a stop-gap solution for now. The preferred way to handle this case would be instead\n // to create a NoOpEncryptionManager that does nothing and use it for the session.\n // This will be done when removing the legacy EncryptionManager.\n private manageMediaKeys = false;\n\n private useHashedRtcBackendIdentity = false;\n private ownRtcBackendIdentityCache: string | undefined;\n\n /**\n * Store the key rings for each participant.\n * The encryption manager stores the keys because the application layer might not be ready yet to handle the keys.\n * The keys are stored and can be retrieved later when the application layer is ready {@link RTCEncryptionManager#getEncryptionKeys}.\n */\n private participantKeyRings = new Map<\n EncryptionKeyMapKey,\n Array<{\n key: Uint8Array<ArrayBuffer>;\n keyIndex: number;\n membership: CallMembershipIdentityParts;\n rtcBackendIdentity: string;\n }>\n >();\n\n // The current per-sender media key for this device\n private outboundSession: OutboundEncryptionSession | null = null;\n\n /**\n * Ensures that there is only one distribute operation at a time for that call.\n */\n private currentKeyDistributionPromise: Promise<void> | null = null;\n\n /**\n * The time to wait before using the outbound session after it has been distributed.\n * This is to ensure that the key is delivered to all participants before it is used.\n * When creating the first key, this is set to 0 so that the key can be used immediately.\n */\n private useKeyDelay = 5000;\n\n /**\n * We want to avoid rolling out a new outbound key when the previous one was created less than `keyRotationGracePeriodMs` milliseconds ago.\n * This is to avoid expensive key rotations when users quickly join the call in a row.\n *\n * This must be higher than `useKeyDelay` to have an effect.\n * If it is lower, the current key will always be older than the grace period.\n * @private\n */\n private keyRotationGracePeriodMs = 10_000;\n\n /**\n * If a new key distribution is being requested while one is going on, we will set this flag to true.\n * This will ensure that a new round is started after the current one.\n * @private\n */\n private needToEnsureKeyAgain = false;\n\n /**\n * There is a possibility that keys arrive in the wrong order.\n * For example, after a quick join/leave/join, there will be 2 keys of index 0 distributed, and\n * if they are received in the wrong order, the stream won't be decryptable.\n * For that reason we keep a small buffer of keys for a limited time to disambiguate.\n * @private\n */\n private keyBuffer = new OutdatedKeyFilter();\n\n private logger: Logger | undefined = undefined;\n\n private rtcIdentityProvider: (userId: string, deviceId: string, memberId: string) => Promise<string>;\n\n /**\n *\n * @param ownMembership - our own membership info\n * @param getMemberships - function to get current memberships\n * @param transport - key transport (room or to-device)\n * @param statistics - statistics collector\n * @param onEncryptionKeysChanged - callback to notify the media layer of new keys\n * @param parentLogger - optional parent logger\n * @param rtcBackendIdProvider - A function to compute the rtc backend identity, exposed for testing purposes\n */\n public constructor(\n private ownMembership: CallMembershipIdentityParts,\n private getMemberships: () => CallMembership[],\n private transport: IKeyTransport,\n private statistics: Statistics,\n // Callback to notify the media layer of new keys\n private onEncryptionKeysChanged: (\n keyBin: Uint8Array<ArrayBuffer>,\n encryptionKeyIndex: number,\n membership: CallMembershipIdentityParts,\n rtcBackendIdentity: string,\n ) => void,\n parentLogger?: Logger,\n rtcBackendIdProvider?: (userId: string, deviceId: string, memberId: string) => Promise<string>,\n ) {\n this.logger = parentLogger?.getChild(`[EncryptionManager]`);\n this.rtcIdentityProvider = rtcBackendIdProvider ?? CallMembership.computeRtcIdentityRaw;\n }\n\n private async getOwnRtcBackendIdentity(): Promise<string> {\n if (this.ownRtcBackendIdentityCache) return this.ownRtcBackendIdentityCache;\n\n if (this.useHashedRtcBackendIdentity) {\n const { userId, deviceId, memberId } = this.ownMembership;\n this.logger?.info(\n // If we see this log multiple times, we need to reconsider the precompute call of getOwnRtcBackendIdentity\n `Computing RTC backend identity for ${userId}:${deviceId}:${memberId} (SHOULD ONLY BE CALLED ONCE)`,\n );\n this.ownRtcBackendIdentityCache = await this.rtcIdentityProvider(userId, deviceId, memberId);\n } else {\n this.ownRtcBackendIdentityCache = `${this.ownMembership.userId}:${this.ownMembership.deviceId}`;\n }\n return this.ownRtcBackendIdentityCache;\n }\n\n public getEncryptionKeys(): ReadonlyMap<\n EncryptionKeyMapKey,\n ReadonlyArray<{\n key: Uint8Array<ArrayBuffer>;\n keyIndex: number;\n membership: CallMembershipIdentityParts;\n rtcBackendIdentity: string;\n }>\n > {\n return new Map(this.participantKeyRings);\n }\n\n private keysWithoutMatchingRTCMembership: Array<{\n key: Uint8Array<ArrayBuffer>;\n keyIndex: number;\n membership: CallMembershipIdentityParts;\n }> = [];\n\n private checkKeysWithoutMatchingRTCMembership(): void {\n const keyInfoTemp = this.keysWithoutMatchingRTCMembership;\n this.keysWithoutMatchingRTCMembership = [];\n keyInfoTemp.forEach((keyInfo) => {\n this.addKeyToParticipant(keyInfo.key, keyInfo.keyIndex, keyInfo.membership);\n });\n }\n\n private addKeyToParticipant(\n key: Uint8Array<ArrayBuffer>,\n keyIndex: number,\n membership: CallMembershipIdentityParts,\n ): void {\n const knownRtcMembership = this.getMemberships();\n const fullMembership = knownRtcMembership.find(\n (member) => member.userId === membership.userId && member.deviceId === membership.deviceId,\n );\n if (!fullMembership) {\n this.logger?.info(\n `No matching RTC membership for key from ${membership.userId}:${membership.deviceId}, delaying key addition`,\n );\n this.keysWithoutMatchingRTCMembership.push({ key, keyIndex, membership });\n return;\n }\n this.addKeyToParticipantWithBackendIdentity(key, keyIndex, membership, fullMembership.rtcBackendIdentity);\n }\n\n private addKeyToParticipantWithBackendIdentity(\n key: Uint8Array<ArrayBuffer>,\n keyIndex: number,\n membership: CallMembershipIdentityParts,\n rtcBackendIdentity: string,\n ): void {\n const mapKey = getEncryptionKeyMapKey(membership);\n if (!this.participantKeyRings.has(mapKey)) {\n this.participantKeyRings.set(mapKey, []);\n }\n this.participantKeyRings.get(mapKey)!.push({ key, keyIndex, membership, rtcBackendIdentity });\n this.onEncryptionKeysChanged(key, keyIndex, membership, rtcBackendIdentity);\n }\n\n public join(joinConfig: (EncryptionConfig & MembershipConfig) | undefined): void {\n this.manageMediaKeys = joinConfig?.manageMediaKeys ?? true; // default to true\n this.useHashedRtcBackendIdentity = joinConfig?.unstableSendStickyEvents ?? false;\n this.useKeyDelay = joinConfig?.useKeyDelay ?? 1000;\n this.keyRotationGracePeriodMs = joinConfig?.keyRotationGracePeriodMs ?? 10_000;\n\n this.transport.on(KeyTransportEvents.ReceivedKeys, this.onNewKeyReceived);\n void this.getOwnRtcBackendIdentity(); // precompute own identity\n\n this.logger?.info(`Joining room`);\n this.transport.start();\n }\n\n public leave(): void {\n this.transport.off(KeyTransportEvents.ReceivedKeys, this.onNewKeyReceived);\n this.transport.stop();\n this.participantKeyRings.clear();\n }\n\n /**\n * Will ensure that a new key is distributed and used to encrypt our media.\n * If there is already a key distribution in progress, it will schedule a new distribution round just after the current one is completed.\n * If this function is called repeatedly while a distribution is in progress,\n * the calls will be coalesced to a single new distribution (that will start just after the current one has completed).\n */\n private ensureKeyDistribution(): void {\n // `manageMediaKeys` is a stop-gap solution for now. The preferred way to handle this case would be instead\n // to create a NoOpEncryptionManager that does nothing and use it for the session.\n // This will be done when removing the legacy EncryptionManager.\n if (!this.manageMediaKeys) return;\n if (this.currentKeyDistributionPromise == null) {\n this.logger?.debug(`No active rollout, start a new one`);\n // start a rollout\n this.currentKeyDistributionPromise = this.rolloutOutboundKey().then(() => {\n this.logger?.debug(`Rollout completed`);\n this.currentKeyDistributionPromise = null;\n if (this.needToEnsureKeyAgain) {\n this.logger?.debug(`New Rollout needed`);\n this.needToEnsureKeyAgain = false;\n // rollout a new one\n this.ensureKeyDistribution();\n }\n });\n } else {\n // There is a rollout in progress, but a key rotation is requested (could be caused by a ownMembership change)\n // Remember that a new rotation is needed after the current one.\n this.logger?.debug(`Rollout in progress, a new rollout will be started after the current one`);\n this.needToEnsureKeyAgain = true;\n }\n }\n\n public onNewKeyReceived: KeyTransportEventListener = (membership, keyBase64Encoded, index, timestamp) => {\n // `manageMediaKeys` is a stop-gap solution for now. The preferred way to handle this case would be instead\n // to create a NoOpEncryptionManager that does nothing and use it for the session.\n // This will be done when removing the legacy EncryptionManager.\n if (!this.manageMediaKeys) {\n this.logger?.warn(\n `Received key over transport ${membership.userId}:${membership.deviceId} at index ${index} but media keys are disabled`,\n );\n return;\n }\n this.logger?.debug(`Received key over transport ${membership.userId}:${membership.deviceId} at index ${index}`);\n\n // We received a new key, notify the video layer of this new key so that it can decrypt the frames properly.\n const keyBin = decodeBase64(keyBase64Encoded);\n const candidateInboundSession: InboundEncryptionSession = {\n key: keyBin,\n membership,\n keyIndex: index,\n creationTS: timestamp,\n };\n\n const outdated = this.keyBuffer.isOutdated(membership, candidateInboundSession);\n if (!outdated) {\n this.addKeyToParticipant(\n candidateInboundSession.key,\n candidateInboundSession.keyIndex,\n candidateInboundSession.membership,\n );\n this.statistics.counters.roomEventEncryptionKeysReceived += 1;\n } else {\n this.logger?.info(\n `Received an out of order key for ${membership.userId}:${membership.deviceId}, dropping it`,\n );\n }\n };\n\n /**\n * Called when the ownMembership of the call changes.\n * This encryption manager is very basic, it will rotate the key everytime this is called.\n * @param oldMemberships - This parameter is not used here, but it is kept for compatibility with the interface.\n */\n public onMembershipsUpdate(oldMemberships: CallMembership[] = []): void {\n this.logger?.trace(`onMembershipsUpdate`);\n\n // Ensure the key is distributed. This will be no-op if the key is already being distributed to everyone.\n // If there is an ongoing distribution, it will be completed before a new one is started.\n this.ensureKeyDistribution();\n // ensure key emission to the rtc backend\n this.checkKeysWithoutMatchingRTCMembership();\n }\n\n private async rolloutOutboundKey(): Promise<void> {\n const isFirstKey = this.outboundSession == null;\n if (isFirstKey) {\n // create the first key\n const firstKey = {\n key: this.generateRandomKey(),\n creationTS: Date.now(),\n sharedWith: [],\n keyId: 0,\n };\n this.outboundSession = firstKey;\n this.addKeyToParticipantWithBackendIdentity(\n firstKey.key,\n firstKey.keyId,\n this.ownMembership,\n await this.getOwnRtcBackendIdentity(),\n );\n }\n // get current memberships\n const toShareWith: ParticipantDeviceInfo[] = this.getMemberships()\n .filter((membership) => {\n return membership.sender != undefined;\n })\n .map((membership) => {\n return {\n userId: membership.sender!,\n deviceId: membership.deviceId,\n membershipTs: membership.createdTs(),\n };\n });\n\n let alreadySharedWith = this.outboundSession?.sharedWith ?? [];\n\n // Some users might have rotate their ownMembership event (formally called fingerprint) meaning they might have\n // clear their key. Reset the `alreadySharedWith` flag for them.\n alreadySharedWith = alreadySharedWith.filter(\n (x) =>\n // If there was a member with same userId and deviceId but different membershipTs, we need to clear it\n !toShareWith.some(\n (o) => x.userId == o.userId && x.deviceId == o.deviceId && x.membershipTs != o.membershipTs,\n ),\n );\n\n const anyLeft = alreadySharedWith.filter(\n (x) =>\n !toShareWith.some(\n (o) => x.userId == o.userId && x.deviceId == o.deviceId && x.membershipTs == o.membershipTs,\n ),\n );\n const anyJoined = toShareWith.filter(\n (x) =>\n !alreadySharedWith.some(\n (o) => x.userId == o.userId && x.deviceId == o.deviceId && x.membershipTs == o.membershipTs,\n ),\n );\n\n let toDistributeTo: ParticipantDeviceInfo[] = [];\n let outboundKey: OutboundEncryptionSession;\n let hasKeyChanged = false;\n if (anyLeft.length > 0) {\n // We need to rotate the key\n const newOutboundKey = this.createNewOutboundSession();\n hasKeyChanged = true;\n toDistributeTo = toShareWith;\n outboundKey = newOutboundKey;\n } else if (anyJoined.length > 0) {\n const now = Date.now();\n const keyAge = now - this.outboundSession!.creationTS;\n // If the current key is recently created (less than `keyRotationGracePeriodMs`), we can keep it and just distribute it to the new joiners.\n if (keyAge < this.keyRotationGracePeriodMs) {\n // keep the same key\n // XXX In the future we want to distribute a ratcheted key, not the current one\n this.logger?.debug(`New joiners detected, but the key is recent enough (age:${keyAge}), keeping it`);\n toDistributeTo = anyJoined;\n outboundKey = this.outboundSession!;\n } else {\n // We need to rotate the key\n this.logger?.debug(`New joiners detected, rotating the key`);\n const newOutboundKey = this.createNewOutboundSession();\n hasKeyChanged = true;\n toDistributeTo = toShareWith;\n outboundKey = newOutboundKey;\n }\n } else {\n // no changes\n return;\n }\n\n try {\n this.logger?.trace(`Sending key...`);\n await this.transport.sendKey(encodeBase64(outboundKey.key), outboundKey.keyId, toDistributeTo);\n this.statistics.counters.roomEventEncryptionKeysSent += 1;\n outboundKey.sharedWith.push(...toDistributeTo);\n this.logger?.trace(\n `key index:${outboundKey.keyId} sent to ${outboundKey.sharedWith.map((m) => `${m.userId}:${m.deviceId}`).join(\",\")}`,\n );\n if (hasKeyChanged) {\n // Delay a bit before using this key\n // It is recommended not to start using a key immediately but instead wait for a short time to make sure it is delivered.\n this.logger?.trace(`Delay Rollout for key:${outboundKey.keyId}...`);\n await sleep(this.useKeyDelay);\n this.logger?.trace(`...Delayed rollout of index:${outboundKey.keyId} `);\n this.addKeyToParticipantWithBackendIdentity(\n outboundKey.key,\n outboundKey.keyId,\n this.ownMembership,\n await this.getOwnRtcBackendIdentity(),\n );\n }\n } catch (err) {\n this.logger?.error(`Failed to rollout key`, err);\n }\n }\n\n private createNewOutboundSession(): OutboundEncryptionSession {\n const newOutboundKey: OutboundEncryptionSession = {\n key: this.generateRandomKey(),\n creationTS: Date.now(),\n sharedWith: [],\n keyId: this.nextKeyIndex(),\n };\n\n this.logger?.info(`creating new outbound key index:${newOutboundKey.keyId}`);\n // Set this new key as the current one\n this.outboundSession = newOutboundKey;\n return newOutboundKey;\n }\n\n private nextKeyIndex(): number {\n if (this.outboundSession) {\n return (this.outboundSession!.keyId + 1) % 256;\n }\n return 0;\n }\n\n private generateRandomKey(): Uint8Array<ArrayBuffer> {\n const key = new Uint8Array(16);\n globalThis.crypto.getRandomValues(key);\n return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wBAAwB,CAAC,CACxC,CAAC;QACL;MACJ,CAAC,CAAC,OAAOiG,GAAG,EAAE;QAAA,IAAAC,cAAA;QACV,CAAAA,cAAA,GAAAvC,MAAI,CAACjF,MAAM,cAAAwH,cAAA,eAAXA,cAAA,CAAaC,KAAK,0BAA0BF,GAAG,CAAC;MACpD;IAAC;EACL;EAEQX,wBAAwBA,CAAA,EAA8B;IAAA,IAAAc,cAAA;IAC1D,IAAMf,cAAyC,GAAG;MAC9CnG,GAAG,EAAE,IAAI,CAAC+E,iBAAiB,CAAC,CAAC;MAC7B7E,UAAU,EAAE8E,IAAI,CAACC,GAAG,CAAC,CAAC;MACtBC,UAAU,EAAE,EAAE;MACdC,KAAK,EAAE,IAAI,CAACgC,YAAY,CAAC;IAC7B,CAAC;IAED,CAAAD,cAAA,OAAI,CAAC1H,MAAM,cAAA0H,cAAA,eAAXA,cAAA,CAAaxG,IAAI,oCAAAhB,MAAA,CAAoCyG,cAAc,CAAChB,KAAK,CAAE,CAAC;IAC5E;IACA,IAAI,CAACN,eAAe,GAAGsB,cAAc;IACrC,OAAOA,cAAc;EACzB;EAEQgB,YAAYA,CAAA,EAAW;IAC3B,IAAI,IAAI,CAACtC,eAAe,EAAE;MACtB,OAAO,CAAC,IAAI,CAACA,eAAe,CAAEM,KAAK,GAAG,CAAC,IAAI,GAAG;IAClD;IACA,OAAO,CAAC;EACZ;EAEQJ,iBAAiBA,CAAA,EAA4B;IACjD,IAAM/E,GAAG,GAAG,IAAIoH,UAAU,CAAC,EAAE,CAAC;IAC9BC,UAAU,CAACC,MAAM,CAACC,eAAe,CAACvH,GAAG,CAAC;IACtC,OAAOA,GAAG;EACd;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"RTCEncryptionManager.js","names":["getEncryptionKeyMapKey","decodeBase64","encodeBase64","KeyTransportEvents","sleep","OutdatedKeyFilter","computeRtcIdentityRaw","RTCEncryptionManager","constructor","ownMembership","getMemberships","transport","onEncryptionKeysChanged","parentLogger","rtcBackendIdProvider","_defineProperty","Map","undefined","membership","keyBase64Encoded","index","timestamp","_this$logger2","manageMediaKeys","_this$logger","logger","warn","concat","userId","deviceId","debug","keyBin","candidateInboundSession","key","keyIndex","creationTS","outdated","keyBuffer","isOutdated","addKeyToParticipant","_this$logger3","info","getChild","rtcIdentityProvider","getOwnRtcBackendIdentity","_this","_asyncToGenerator","ownRtcBackendIdentityCache","useHashedRtcBackendIdentity","_this$logger4","memberId","getEncryptionKeys","participantKeyRings","checkKeysWithoutMatchingRTCMembership","keyInfoTemp","keysWithoutMatchingRTCMembership","forEach","keyInfo","knownRtcMembership","fullMembership","find","member","_this$logger5","push","addKeyToParticipantWithBackendIdentity","rtcBackendIdentity","mapKey","has","set","get","join","joinConfig","_joinConfig$manageMed","_joinConfig$unstableS","_joinConfig$useKeyDel","_joinConfig$keyRotati","_this$logger6","unstableSendStickyEvents","useKeyDelay","keyRotationGracePeriodMs","on","ReceivedKeys","onNewKeyReceived","start","leave","off","stop","clear","ensureKeyDistribution","currentKeyDistributionPromise","_this$logger7","rolloutOutboundKey","then","_this$logger8","needToEnsureKeyAgain","_this$logger9","_this$logger0","onMembershipsUpdate","_this$logger1","oldMemberships","arguments","length","trace","_this2","_this2$outboundSessio","_this2$outboundSessio2","isFirstKey","outboundSession","firstKey","generateRandomKey","Date","now","sharedWith","keyId","toShareWith","filter","sender","map","membershipTs","createdTs","alreadySharedWith","x","some","o","anyLeft","anyJoined","toDistributeTo","outboundKey","hasKeyChanged","newOutboundKey","createNewOutboundSession","keyAge","_this2$logger","_this2$logger2","_this2$logger3","_this2$logger4","sendKey","m","_this2$logger5","_this2$logger6","err","_this2$logger7","error","_this$logger10","nextKeyIndex","Uint8Array","globalThis","crypto","getRandomValues"],"sources":["../../src/matrixrtc/RTCEncryptionManager.ts"],"sourcesContent":["/*\nCopyright 2025-2026 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport {\n type CallMembershipIdentityParts,\n getEncryptionKeyMapKey,\n type IEncryptionManager,\n} from \"./EncryptionManager.ts\";\nimport { type EncryptionConfig, type MembershipConfig } from \"./MatrixRTCSession.ts\";\nimport type { CallMembership } from \"./CallMembership.ts\";\nimport { decodeBase64, encodeBase64 } from \"../base64.ts\";\nimport { type IKeyTransport, type KeyTransportEventListener, KeyTransportEvents } from \"./IKeyTransport.ts\";\nimport { type Logger } from \"../logger.ts\";\nimport { sleep } from \"../utils.ts\";\nimport {\n type EncryptionKeyMapKey,\n type InboundEncryptionSession,\n type OutboundEncryptionSession,\n type ParticipantDeviceInfo,\n} from \"./types.ts\";\nimport { OutdatedKeyFilter } from \"./utils.ts\";\nimport { computeRtcIdentityRaw } from \"./membershipData/rtc.ts\";\n\n/**\n * RTCEncryptionManager is used to manage the encryption keys for a call.\n *\n * It is responsible for distributing the keys to the other participants and rotating the keys if needed.\n *\n * This manager when used with to-device transport will share the existing key only to new joiners, and rotate\n * if there is a leaver.\n *\n * XXX In the future we want to distribute a ratcheted key not the current one for new joiners.\n */\nexport class RTCEncryptionManager implements IEncryptionManager {\n // This is a stop-gap solution for now. The preferred way to handle this case would be instead\n // to create a NoOpEncryptionManager that does nothing and use it for the session.\n // This will be done when removing the legacy EncryptionManager.\n private manageMediaKeys = false;\n\n private useHashedRtcBackendIdentity = false;\n private ownRtcBackendIdentityCache: string | undefined;\n\n /**\n * Store the key rings for each participant.\n * The encryption manager stores the keys because the application layer might not be ready yet to handle the keys.\n * The keys are stored and can be retrieved later when the application layer is ready {@link RTCEncryptionManager#getEncryptionKeys}.\n */\n private readonly participantKeyRings = new Map<\n EncryptionKeyMapKey,\n Array<{\n key: Uint8Array<ArrayBuffer>;\n keyIndex: number;\n membership: CallMembershipIdentityParts;\n rtcBackendIdentity: string;\n }>\n >();\n\n // The current per-sender media key for this device\n private outboundSession: OutboundEncryptionSession | null = null;\n\n /**\n * Ensures that there is only one distribute operation at a time for that call.\n */\n private currentKeyDistributionPromise: Promise<void> | null = null;\n\n /**\n * The time to wait before using the outbound session after it has been distributed.\n * This is to ensure that the key is delivered to all participants before it is used.\n * When creating the first key, this is set to 0 so that the key can be used immediately.\n */\n private useKeyDelay = 5000;\n\n /**\n * We want to avoid rolling out a new outbound key when the previous one was created less than `keyRotationGracePeriodMs` milliseconds ago.\n * This is to avoid expensive key rotations when users quickly join the call in a row.\n *\n * This must be higher than `useKeyDelay` to have an effect.\n * If it is lower, the current key will always be older than the grace period.\n * @private\n */\n private keyRotationGracePeriodMs = 10_000;\n\n /**\n * If a new key distribution is being requested while one is going on, we will set this flag to true.\n * This will ensure that a new round is started after the current one.\n * @private\n */\n private needToEnsureKeyAgain = false;\n\n /**\n * There is a possibility that keys arrive in the wrong order.\n * For example, after a quick join/leave/join, there will be 2 keys of index 0 distributed, and\n * if they are received in the wrong order, the stream won't be decryptable.\n * For that reason we keep a small buffer of keys for a limited time to disambiguate.\n * @private\n */\n private keyBuffer = new OutdatedKeyFilter();\n\n private logger: Logger | undefined = undefined;\n\n private readonly rtcIdentityProvider: (userId: string, deviceId: string, memberId: string) => Promise<string>;\n\n /**\n *\n * @param ownMembership - our own membership info\n * @param getMemberships - function to get current memberships\n * @param transport - key transport (room or to-device)\n * @param statistics - statistics collector\n * @param onEncryptionKeysChanged - callback to notify the media layer of new keys\n * @param parentLogger - optional parent logger\n * @param rtcBackendIdProvider - A function to compute the rtc backend identity, exposed for testing purposes\n */\n public constructor(\n private readonly ownMembership: CallMembershipIdentityParts,\n private getMemberships: () => CallMembership[],\n private transport: IKeyTransport,\n // Callback to notify the media layer of new keys\n private onEncryptionKeysChanged: (\n keyBin: Uint8Array<ArrayBuffer>,\n encryptionKeyIndex: number,\n membership: CallMembershipIdentityParts,\n rtcBackendIdentity: string,\n ) => void,\n parentLogger?: Logger,\n rtcBackendIdProvider?: (userId: string, deviceId: string, memberId: string) => Promise<string>,\n ) {\n this.logger = parentLogger?.getChild(`[EncryptionManager]`);\n this.rtcIdentityProvider = rtcBackendIdProvider ?? computeRtcIdentityRaw;\n }\n\n private async getOwnRtcBackendIdentity(): Promise<string> {\n if (this.ownRtcBackendIdentityCache) return this.ownRtcBackendIdentityCache;\n\n if (this.useHashedRtcBackendIdentity) {\n const { userId, deviceId, memberId } = this.ownMembership;\n this.logger?.info(\n // If we see this log multiple times, we need to reconsider the precompute call of getOwnRtcBackendIdentity\n `Computing RTC backend identity for ${userId}:${deviceId}:${memberId} (SHOULD ONLY BE CALLED ONCE)`,\n );\n this.ownRtcBackendIdentityCache = await this.rtcIdentityProvider(userId, deviceId, memberId);\n } else {\n this.ownRtcBackendIdentityCache = `${this.ownMembership.userId}:${this.ownMembership.deviceId}`;\n }\n return this.ownRtcBackendIdentityCache;\n }\n\n public getEncryptionKeys(): ReadonlyMap<\n EncryptionKeyMapKey,\n ReadonlyArray<{\n key: Uint8Array<ArrayBuffer>;\n keyIndex: number;\n membership: CallMembershipIdentityParts;\n rtcBackendIdentity: string;\n }>\n > {\n return new Map(this.participantKeyRings);\n }\n\n private keysWithoutMatchingRTCMembership: Array<{\n key: Uint8Array<ArrayBuffer>;\n keyIndex: number;\n membership: CallMembershipIdentityParts;\n }> = [];\n\n private checkKeysWithoutMatchingRTCMembership(): void {\n const keyInfoTemp = this.keysWithoutMatchingRTCMembership;\n this.keysWithoutMatchingRTCMembership = [];\n keyInfoTemp.forEach((keyInfo) => {\n this.addKeyToParticipant(keyInfo.key, keyInfo.keyIndex, keyInfo.membership);\n });\n }\n\n private addKeyToParticipant(\n key: Uint8Array<ArrayBuffer>,\n keyIndex: number,\n membership: CallMembershipIdentityParts,\n ): void {\n const knownRtcMembership = this.getMemberships();\n const fullMembership = knownRtcMembership.find(\n (member) => member.userId === membership.userId && member.deviceId === membership.deviceId,\n );\n if (!fullMembership) {\n this.logger?.info(\n `No matching RTC membership for key from ${membership.userId}:${membership.deviceId}, delaying key addition`,\n );\n this.keysWithoutMatchingRTCMembership.push({ key, keyIndex, membership });\n return;\n }\n this.addKeyToParticipantWithBackendIdentity(key, keyIndex, membership, fullMembership.rtcBackendIdentity);\n }\n\n private addKeyToParticipantWithBackendIdentity(\n key: Uint8Array<ArrayBuffer>,\n keyIndex: number,\n membership: CallMembershipIdentityParts,\n rtcBackendIdentity: string,\n ): void {\n const mapKey = getEncryptionKeyMapKey(membership);\n if (!this.participantKeyRings.has(mapKey)) {\n this.participantKeyRings.set(mapKey, []);\n }\n this.participantKeyRings.get(mapKey)!.push({ key, keyIndex, membership, rtcBackendIdentity });\n this.onEncryptionKeysChanged(key, keyIndex, membership, rtcBackendIdentity);\n }\n\n public join(joinConfig: (EncryptionConfig & MembershipConfig) | undefined): void {\n this.manageMediaKeys = joinConfig?.manageMediaKeys ?? true; // default to true\n this.useHashedRtcBackendIdentity = joinConfig?.unstableSendStickyEvents ?? false;\n this.useKeyDelay = joinConfig?.useKeyDelay ?? 1000;\n this.keyRotationGracePeriodMs = joinConfig?.keyRotationGracePeriodMs ?? 10_000;\n\n this.transport.on(KeyTransportEvents.ReceivedKeys, this.onNewKeyReceived);\n void this.getOwnRtcBackendIdentity(); // precompute own identity\n\n this.logger?.info(`Joining room`);\n this.transport.start();\n }\n\n public leave(): void {\n this.transport.off(KeyTransportEvents.ReceivedKeys, this.onNewKeyReceived);\n this.transport.stop();\n this.participantKeyRings.clear();\n }\n\n /**\n * Will ensure that a new key is distributed and used to encrypt our media.\n * If there is already a key distribution in progress, it will schedule a new distribution round just after the current one is completed.\n * If this function is called repeatedly while a distribution is in progress,\n * the calls will be coalesced to a single new distribution (that will start just after the current one has completed).\n */\n private ensureKeyDistribution(): void {\n // `manageMediaKeys` is a stop-gap solution for now. The preferred way to handle this case would be instead\n // to create a NoOpEncryptionManager that does nothing and use it for the session.\n // This will be done when removing the legacy EncryptionManager.\n if (!this.manageMediaKeys) return;\n if (this.currentKeyDistributionPromise == null) {\n this.logger?.debug(`No active rollout, start a new one`);\n // start a rollout\n this.currentKeyDistributionPromise = this.rolloutOutboundKey().then(() => {\n this.logger?.debug(`Rollout completed`);\n this.currentKeyDistributionPromise = null;\n if (this.needToEnsureKeyAgain) {\n this.logger?.debug(`New Rollout needed`);\n this.needToEnsureKeyAgain = false;\n // rollout a new one\n this.ensureKeyDistribution();\n }\n });\n } else {\n // There is a rollout in progress, but a key rotation is requested (could be caused by a ownMembership change)\n // Remember that a new rotation is needed after the current one.\n this.logger?.debug(`Rollout in progress, a new rollout will be started after the current one`);\n this.needToEnsureKeyAgain = true;\n }\n }\n\n public onNewKeyReceived: KeyTransportEventListener = (membership, keyBase64Encoded, index, timestamp) => {\n // `manageMediaKeys` is a stop-gap solution for now. The preferred way to handle this case would be instead\n // to create a NoOpEncryptionManager that does nothing and use it for the session.\n // This will be done when removing the legacy EncryptionManager.\n if (!this.manageMediaKeys) {\n this.logger?.warn(\n `Received key over transport ${membership.userId}:${membership.deviceId} at index ${index} but media keys are disabled`,\n );\n return;\n }\n this.logger?.debug(`Received key over transport ${membership.userId}:${membership.deviceId} at index ${index}`);\n\n // We received a new key, notify the video layer of this new key so that it can decrypt the frames properly.\n const keyBin = decodeBase64(keyBase64Encoded);\n const candidateInboundSession: InboundEncryptionSession = {\n key: keyBin,\n membership,\n keyIndex: index,\n creationTS: timestamp,\n };\n\n const outdated = this.keyBuffer.isOutdated(membership, candidateInboundSession);\n if (!outdated) {\n this.addKeyToParticipant(\n candidateInboundSession.key,\n candidateInboundSession.keyIndex,\n candidateInboundSession.membership,\n );\n } else {\n this.logger?.info(\n `Received an out of order key for ${membership.userId}:${membership.deviceId}, dropping it`,\n );\n }\n };\n\n /**\n * Called when the ownMembership of the call changes.\n * This encryption manager is very basic, it will rotate the key everytime this is called.\n * @param oldMemberships - This parameter is not used here, but it is kept for compatibility with the interface.\n */\n public onMembershipsUpdate(oldMemberships: CallMembership[] = []): void {\n this.logger?.trace(`onMembershipsUpdate`);\n\n // Ensure the key is distributed. This will be no-op if the key is already being distributed to everyone.\n // If there is an ongoing distribution, it will be completed before a new one is started.\n this.ensureKeyDistribution();\n // ensure key emission to the rtc backend\n this.checkKeysWithoutMatchingRTCMembership();\n }\n\n private async rolloutOutboundKey(): Promise<void> {\n const isFirstKey = this.outboundSession == null;\n if (isFirstKey) {\n // create the first key\n const firstKey = {\n key: this.generateRandomKey(),\n creationTS: Date.now(),\n sharedWith: [],\n keyId: 0,\n };\n this.outboundSession = firstKey;\n this.addKeyToParticipantWithBackendIdentity(\n firstKey.key,\n firstKey.keyId,\n this.ownMembership,\n await this.getOwnRtcBackendIdentity(),\n );\n }\n // get current memberships\n const toShareWith: ParticipantDeviceInfo[] = this.getMemberships()\n .filter((membership) => {\n return membership.sender != undefined;\n })\n .map((membership) => {\n return {\n userId: membership.sender!,\n deviceId: membership.deviceId,\n membershipTs: membership.createdTs(),\n };\n });\n\n let alreadySharedWith = this.outboundSession?.sharedWith ?? [];\n\n // Some users might have rotate their ownMembership event (formally called fingerprint) meaning they might have\n // clear their key. Reset the `alreadySharedWith` flag for them.\n alreadySharedWith = alreadySharedWith.filter(\n (x) =>\n // If there was a member with same userId and deviceId but different membershipTs, we need to clear it\n !toShareWith.some(\n (o) => x.userId == o.userId && x.deviceId == o.deviceId && x.membershipTs != o.membershipTs,\n ),\n );\n\n const anyLeft = alreadySharedWith.filter(\n (x) =>\n !toShareWith.some(\n (o) => x.userId == o.userId && x.deviceId == o.deviceId && x.membershipTs == o.membershipTs,\n ),\n );\n const anyJoined = toShareWith.filter(\n (x) =>\n !alreadySharedWith.some(\n (o) => x.userId == o.userId && x.deviceId == o.deviceId && x.membershipTs == o.membershipTs,\n ),\n );\n\n let toDistributeTo: ParticipantDeviceInfo[] = [];\n let outboundKey: OutboundEncryptionSession;\n let hasKeyChanged = false;\n if (anyLeft.length > 0) {\n // We need to rotate the key\n const newOutboundKey = this.createNewOutboundSession();\n hasKeyChanged = true;\n toDistributeTo = toShareWith;\n outboundKey = newOutboundKey;\n } else if (anyJoined.length > 0) {\n const now = Date.now();\n const keyAge = now - this.outboundSession!.creationTS;\n // If the current key is recently created (less than `keyRotationGracePeriodMs`), we can keep it and just distribute it to the new joiners.\n if (keyAge < this.keyRotationGracePeriodMs) {\n // keep the same key\n // XXX In the future we want to distribute a ratcheted key, not the current one\n this.logger?.debug(`New joiners detected, but the key is recent enough (age:${keyAge}), keeping it`);\n toDistributeTo = anyJoined;\n outboundKey = this.outboundSession!;\n } else {\n // We need to rotate the key\n this.logger?.debug(`New joiners detected, rotating the key`);\n const newOutboundKey = this.createNewOutboundSession();\n hasKeyChanged = true;\n toDistributeTo = toShareWith;\n outboundKey = newOutboundKey;\n }\n } else {\n // no changes\n return;\n }\n\n try {\n this.logger?.trace(`Sending key...`);\n await this.transport.sendKey(encodeBase64(outboundKey.key), outboundKey.keyId, toDistributeTo);\n outboundKey.sharedWith.push(...toDistributeTo);\n this.logger?.trace(\n `key index:${outboundKey.keyId} sent to ${outboundKey.sharedWith.map((m) => `${m.userId}:${m.deviceId}`).join(\",\")}`,\n );\n if (hasKeyChanged) {\n // Delay a bit before using this key\n // It is recommended not to start using a key immediately but instead wait for a short time to make sure it is delivered.\n this.logger?.trace(`Delay Rollout for key:${outboundKey.keyId}...`);\n await sleep(this.useKeyDelay);\n this.logger?.trace(`...Delayed rollout of index:${outboundKey.keyId} `);\n this.addKeyToParticipantWithBackendIdentity(\n outboundKey.key,\n outboundKey.keyId,\n this.ownMembership,\n await this.getOwnRtcBackendIdentity(),\n );\n }\n } catch (err) {\n this.logger?.error(`Failed to rollout key`, err);\n }\n }\n\n private createNewOutboundSession(): OutboundEncryptionSession {\n const newOutboundKey: OutboundEncryptionSession = {\n key: this.generateRandomKey(),\n creationTS: Date.now(),\n sharedWith: [],\n keyId: this.nextKeyIndex(),\n };\n\n this.logger?.info(`creating new outbound key index:${newOutboundKey.keyId}`);\n // Set this new key as the current one\n this.outboundSession = newOutboundKey;\n return newOutboundKey;\n }\n\n private nextKeyIndex(): number {\n if (this.outboundSession) {\n return (this.outboundSession!.keyId + 1) % 256;\n }\n return 0;\n }\n\n private generateRandomKey(): Uint8Array<ArrayBuffer> {\n const key = new Uint8Array(16);\n globalThis.crypto.getRandomValues(key);\n return key;\n }\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAEIA,sBAAsB,QAEnB,wBAAwB;AAG/B,SAASC,YAAY,EAAEC,YAAY,QAAQ,cAAc;AACzD,SAA6DC,kBAAkB,QAAQ,oBAAoB;AAE3G,SAASC,KAAK,QAAQ,aAAa;AAOnC,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,qBAAqB,QAAQ,yBAAyB;;AAE/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,CAA+B;EAqE5D;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACWC,WAAWA,CACGC,aAA0C,EACnDC,cAAsC,EACtCC,SAAwB;EAChC;EACQC,uBAKC,EACTC,YAAqB,EACrBC,oBAA8F,EAChG;IAAA,KAZmBL,aAA0C,GAA1CA,aAA0C;IAAA,KACnDC,cAAsC,GAAtCA,cAAsC;IAAA,KACtCC,SAAwB,GAAxBA,SAAwB;IAAA,KAExBC,uBAKC,GALDA,uBAKC;IAxFb;IACA;IACA;IAAAG,eAAA,0BAC0B,KAAK;IAAAA,eAAA,sCAEO,KAAK;IAAAA,eAAA;IAG3C;AACJ;AACA;AACA;AACA;IAJIA,eAAA,8BAKuC,IAAIC,GAAG,CAQ5C,CAAC;IAEH;IAAAD,eAAA,0BAC4D,IAAI;IAEhE;AACJ;AACA;IAFIA,eAAA,wCAG8D,IAAI;IAElE;AACJ;AACA;AACA;AACA;IAJIA,e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4
4
|
export * from "./MatrixRTCSessionManager.ts";
|
|
5
5
|
export type * from "./types.ts";
|
|
6
|
+
export { type SessionMembershipData, type RtcMembershipData } from "./membershipData/index.ts";
|
|
6
7
|
export { Status, parseCallNotificationContent, isMyMembership } from "./types.ts";
|
|
7
8
|
export { MembershipManagerEvent } from "./IMembershipManager.ts";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/matrixrtc/index.ts"],"names":[],"mappings":"AAgBA,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,mBAAmB,YAAY,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/matrixrtc/index.ts"],"names":[],"mappings":"AAgBA,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,mBAAmB,YAAY,CAAC;AAChC,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC/F,OAAO,EAAE,MAAM,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Status","parseCallNotificationContent","isMyMembership","MembershipManagerEvent"],"sources":["../../src/matrixrtc/index.ts"],"sourcesContent":["/*\nCopyright 2024 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport * from \"./CallMembership.ts\";\nexport * from \"./LivekitTransport.ts\";\nexport * from \"./MatrixRTCSession.ts\";\nexport * from \"./MatrixRTCSessionManager.ts\";\nexport type * from \"./types.ts\";\nexport { Status, parseCallNotificationContent, isMyMembership } from \"./types.ts\";\nexport { MembershipManagerEvent } from \"./IMembershipManager.ts\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,uBAAuB;AACrC,cAAc,8BAA8B;
|
|
1
|
+
{"version":3,"file":"index.js","names":["Status","parseCallNotificationContent","isMyMembership","MembershipManagerEvent"],"sources":["../../src/matrixrtc/index.ts"],"sourcesContent":["/*\nCopyright 2024 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport * from \"./CallMembership.ts\";\nexport * from \"./LivekitTransport.ts\";\nexport * from \"./MatrixRTCSession.ts\";\nexport * from \"./MatrixRTCSessionManager.ts\";\nexport type * from \"./types.ts\";\nexport { type SessionMembershipData, type RtcMembershipData } from \"./membershipData/index.ts\";\nexport { Status, parseCallNotificationContent, isMyMembership } from \"./types.ts\";\nexport { MembershipManagerEvent } from \"./IMembershipManager.ts\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,uBAAuB;AACrC,cAAc,8BAA8B;AAG5C,SAASA,MAAM,EAAEC,4BAA4B,EAAEC,cAAc,QAAQ,YAAY;AACjF,SAASC,sBAAsB,QAAQ,yBAAyB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/matrixrtc/membershipData/common.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,cAAc;aAEzC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EAC5B,MAAM,EAAE,MAAM,EAAE;CAIvB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 The Matrix.org Foundation C.I.C.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when an event is not valid for use with MatrixRTC.
|
|
19
|
+
*/
|
|
20
|
+
export class MatrixRTCMembershipParseError extends AggregateError {
|
|
21
|
+
constructor(type, errors) {
|
|
22
|
+
super(errors, "Does not match ".concat(type, ":\n").concat(errors.join("\n")));
|
|
23
|
+
this.type = type;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","names":["MatrixRTCMembershipParseError","AggregateError","constructor","type","errors","concat","join"],"sources":["../../../src/matrixrtc/membershipData/common.ts"],"sourcesContent":["/*\nCopyright 2026 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/**\n * Thrown when an event is not valid for use with MatrixRTC.\n */\nexport class MatrixRTCMembershipParseError extends AggregateError {\n public constructor(\n public readonly type: string,\n errors: string[],\n ) {\n super(errors, `Does not match ${type}:\\n${errors.join(\"\\n\")}`);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,6BAA6B,SAASC,cAAc,CAAC;EACvDC,WAAWA,CACEC,IAAY,EAC5BC,MAAgB,EAClB;IACE,KAAK,CAACA,MAAM,oBAAAC,MAAA,CAAoBF,IAAI,SAAAE,MAAA,CAAMD,MAAM,CAACE,IAAI,CAAC,IAAI,CAAC,CAAE,CAAC;IAAC,KAH/CH,IAAY,GAAZA,IAAY;EAIhC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { type SessionMembershipData, checkSessionsMembershipData } from "./session.ts";
|
|
2
|
+
export { type RtcMembershipData, computeRtcIdentityRaw, checkRtcMembershipData } from "./rtc.ts";
|
|
3
|
+
export { MatrixRTCMembershipParseError } from "./common.ts";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/matrixrtc/membershipData/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACjG,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 The Matrix.org Foundation C.I.C.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export { checkSessionsMembershipData } from "./session.js";
|
|
18
|
+
export { computeRtcIdentityRaw, checkRtcMembershipData } from "./rtc.js";
|
|
19
|
+
export { MatrixRTCMembershipParseError } from "./common.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["checkSessionsMembershipData","computeRtcIdentityRaw","checkRtcMembershipData","MatrixRTCMembershipParseError"],"sources":["../../../src/matrixrtc/membershipData/index.ts"],"sourcesContent":["/*\nCopyright 2026 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport { type SessionMembershipData, checkSessionsMembershipData } from \"./session.ts\";\nexport { type RtcMembershipData, computeRtcIdentityRaw, checkRtcMembershipData } from \"./rtc.ts\";\nexport { MatrixRTCMembershipParseError } from \"./common.ts\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAqCA,2BAA2B,QAAQ,cAAc;AACtF,SAAiCC,qBAAqB,EAAEC,sBAAsB,QAAQ,UAAU;AAChG,SAASC,6BAA6B,QAAQ,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IContent } from "../../models/event.ts";
|
|
2
|
+
import type { RelationType } from "../../types.ts";
|
|
3
|
+
import { type RtcSlotEventContent, type Transport } from "../types.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Represents the current form of MSC4143, which uses sticky events to store membership.
|
|
6
|
+
*/
|
|
7
|
+
export interface RtcMembershipData {
|
|
8
|
+
"slot_id": string;
|
|
9
|
+
"member": {
|
|
10
|
+
user_id: string;
|
|
11
|
+
device_id: string;
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
"m.relates_to"?: {
|
|
15
|
+
event_id: string;
|
|
16
|
+
rel_type: RelationType.Reference;
|
|
17
|
+
};
|
|
18
|
+
"application": RtcSlotEventContent["application"];
|
|
19
|
+
"rtc_transports": Transport[];
|
|
20
|
+
"versions": string[];
|
|
21
|
+
"msc4354_sticky_key"?: string;
|
|
22
|
+
"sticky_key"?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates that `data` matches the format expected by MSC4143.
|
|
26
|
+
* @param data The event content.
|
|
27
|
+
* @param sender The sender of the event.
|
|
28
|
+
* @returns true if `data` is valid RtcMembershipData
|
|
29
|
+
* @throws {MatrixRTCMembershipParseError} if the content is not valid
|
|
30
|
+
*/
|
|
31
|
+
export declare const checkRtcMembershipData: (data: IContent, sender: string) => data is RtcMembershipData;
|
|
32
|
+
export declare function computeRtcIdentityRaw(userId: string, deviceId: string, memberId: string): Promise<string>;
|
|
33
|
+
//# sourceMappingURL=rtc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rtc.d.ts","sourceRoot":"","sources":["../../../src/matrixrtc/membershipData/rtc.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAMvE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,EAAE,EAAE,MAAM,CAAC;KACd,CAAC;IACF,cAAc,CAAC,EAAE;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,YAAY,CAAC,SAAS,CAAC;KACpC,CAAC;IACF,aAAa,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAClD,gBAAgB,EAAE,SAAS,EAAE,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GAAI,MAAM,QAAQ,EAAE,QAAQ,MAAM,KAAG,IAAI,IAAI,iBA+F/E,CAAC;AAEF,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK/G"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2026 The Matrix.org Foundation C.I.C.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { MXID_PATTERN } from "../../models/room-member.js";
|
|
19
|
+
import { MatrixRTCMembershipParseError } from "./common.js";
|
|
20
|
+
import { sha256 } from "../../digest.js";
|
|
21
|
+
import { encodeUnpaddedBase64Url } from "../../base64.js";
|
|
22
|
+
import { slotIdToDescription } from "../utils.js";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Represents the current form of MSC4143, which uses sticky events to store membership.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Validates that `data` matches the format expected by MSC4143.
|
|
30
|
+
* @param data The event content.
|
|
31
|
+
* @param sender The sender of the event.
|
|
32
|
+
* @returns true if `data` is valid RtcMembershipData
|
|
33
|
+
* @throws {MatrixRTCMembershipParseError} if the content is not valid
|
|
34
|
+
*/
|
|
35
|
+
export var checkRtcMembershipData = (data, sender) => {
|
|
36
|
+
var _data$application, _data$sticky_key;
|
|
37
|
+
var errors = [];
|
|
38
|
+
var prefix = " - ";
|
|
39
|
+
var expectedSlotPrefix = "".concat(data === null || data === void 0 || (_data$application = data.application) === null || _data$application === void 0 ? void 0 : _data$application.type, "#");
|
|
40
|
+
|
|
41
|
+
// required fields
|
|
42
|
+
if (typeof data.slot_id !== "string") {
|
|
43
|
+
errors.push(prefix + "slot_id must be string");
|
|
44
|
+
} else if (!data.slot_id.startsWith(expectedSlotPrefix)) {
|
|
45
|
+
errors.push(prefix + "slot_id must start with ".concat(expectedSlotPrefix));
|
|
46
|
+
} else {
|
|
47
|
+
try {
|
|
48
|
+
slotIdToDescription(data.slot_id);
|
|
49
|
+
} catch (ex) {
|
|
50
|
+
errors.push(prefix + "slot_id was badly formed".concat(ex instanceof Error ? ": ".concat(ex.message) : ""));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (typeof data.member !== "object" || data.member === null) {
|
|
54
|
+
errors.push(prefix + "member must be an object");
|
|
55
|
+
} else {
|
|
56
|
+
if (typeof data.member.user_id !== "string") {
|
|
57
|
+
errors.push(prefix + "member.user_id must be string");
|
|
58
|
+
} else if (!MXID_PATTERN.test(data.member.user_id)) {
|
|
59
|
+
errors.push(prefix + "member.user_id must be a valid mxid");
|
|
60
|
+
}
|
|
61
|
+
// This is not what the spec enforces but there currently are no rules what power levels are required to
|
|
62
|
+
// send a m.rtc.member event for a other user. So we add this check for simplicity and to avoid possible attacks until there
|
|
63
|
+
// is a proper definition when this is allowed.
|
|
64
|
+
else if (data.member.user_id !== sender) {
|
|
65
|
+
errors.push(prefix + "member.user_id must match the sender");
|
|
66
|
+
}
|
|
67
|
+
if (typeof data.member.device_id !== "string") {
|
|
68
|
+
errors.push(prefix + "member.device_id must be string");
|
|
69
|
+
}
|
|
70
|
+
if (typeof data.member.id !== "string") errors.push(prefix + "member.id must be string");
|
|
71
|
+
}
|
|
72
|
+
if (typeof data.application !== "object" || data.application === null) {
|
|
73
|
+
errors.push(prefix + "application must be an object");
|
|
74
|
+
} else {
|
|
75
|
+
if (typeof data.application.type !== "string") {
|
|
76
|
+
errors.push(prefix + "application.type must be a string");
|
|
77
|
+
} else {
|
|
78
|
+
if (data.application.type.includes("#")) errors.push(prefix + 'application.type must not include "#"');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (data.rtc_transports === undefined || !Array.isArray(data.rtc_transports)) {
|
|
82
|
+
errors.push(prefix + "rtc_transports must be an array");
|
|
83
|
+
} else {
|
|
84
|
+
// validate that each transport has at least a string 'type'
|
|
85
|
+
for (var t of data.rtc_transports) {
|
|
86
|
+
if (typeof t !== "object" || t === null || typeof t.type !== "string") {
|
|
87
|
+
errors.push(prefix + "rtc_transports entries must be objects with a string type");
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (data.versions === undefined || !Array.isArray(data.versions)) {
|
|
93
|
+
errors.push(prefix + "versions must be an array");
|
|
94
|
+
} else if (!data.versions.every(v => typeof v === "string")) {
|
|
95
|
+
errors.push(prefix + "versions must be an array of strings");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// optional fields
|
|
99
|
+
if (((_data$sticky_key = data.sticky_key) !== null && _data$sticky_key !== void 0 ? _data$sticky_key : data.msc4354_sticky_key) === undefined) {
|
|
100
|
+
errors.push(prefix + "sticky_key or msc4354_sticky_key must be a defined");
|
|
101
|
+
}
|
|
102
|
+
if (data.sticky_key !== undefined && typeof data.sticky_key !== "string") {
|
|
103
|
+
errors.push(prefix + "sticky_key must be a string");
|
|
104
|
+
}
|
|
105
|
+
if (data.msc4354_sticky_key !== undefined && typeof data.msc4354_sticky_key !== "string") {
|
|
106
|
+
errors.push(prefix + "msc4354_sticky_key must be a string");
|
|
107
|
+
}
|
|
108
|
+
if (data.sticky_key !== undefined && data.msc4354_sticky_key !== undefined && data.sticky_key !== data.msc4354_sticky_key) {
|
|
109
|
+
errors.push(prefix + "sticky_key and msc4354_sticky_key must be equal if both are defined");
|
|
110
|
+
}
|
|
111
|
+
if (data["m.relates_to"] !== undefined) {
|
|
112
|
+
var rel = data["m.relates_to"];
|
|
113
|
+
if (typeof rel !== "object" || rel === null) {
|
|
114
|
+
errors.push(prefix + "m.relates_to must be an object if provided");
|
|
115
|
+
} else {
|
|
116
|
+
if (typeof rel.event_id !== "string") errors.push(prefix + "m.relates_to.event_id must be a string");
|
|
117
|
+
if (rel.rel_type !== "m.reference") errors.push(prefix + "m.relates_to.rel_type must be m.reference");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (errors.length) {
|
|
121
|
+
throw new MatrixRTCMembershipParseError("RtcMembership", errors);
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
};
|
|
125
|
+
export function computeRtcIdentityRaw(_x, _x2, _x3) {
|
|
126
|
+
return _computeRtcIdentityRaw.apply(this, arguments);
|
|
127
|
+
}
|
|
128
|
+
function _computeRtcIdentityRaw() {
|
|
129
|
+
_computeRtcIdentityRaw = _asyncToGenerator(function* (userId, deviceId, memberId) {
|
|
130
|
+
var hashInput = "".concat(userId, "|").concat(deviceId, "|").concat(memberId);
|
|
131
|
+
var hashBuffer = yield sha256(hashInput);
|
|
132
|
+
var hashedString = encodeUnpaddedBase64Url(hashBuffer);
|
|
133
|
+
return hashedString;
|
|
134
|
+
});
|
|
135
|
+
return _computeRtcIdentityRaw.apply(this, arguments);
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=rtc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rtc.js","names":["MXID_PATTERN","MatrixRTCMembershipParseError","sha256","encodeUnpaddedBase64Url","slotIdToDescription","checkRtcMembershipData","data","sender","_data$application","_data$sticky_key","errors","prefix","expectedSlotPrefix","concat","application","type","slot_id","push","startsWith","ex","Error","message","member","user_id","test","device_id","id","includes","rtc_transports","undefined","Array","isArray","t","versions","every","v","sticky_key","msc4354_sticky_key","rel","event_id","rel_type","length","computeRtcIdentityRaw","_x","_x2","_x3","_computeRtcIdentityRaw","apply","arguments","_asyncToGenerator","userId","deviceId","memberId","hashInput","hashBuffer","hashedString"],"sources":["../../../src/matrixrtc/membershipData/rtc.ts"],"sourcesContent":["/*\nCopyright 2026 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { MXID_PATTERN } from \"../../models/room-member.ts\";\nimport type { IContent } from \"../../models/event.ts\";\nimport type { RelationType } from \"../../types.ts\";\nimport { type RtcSlotEventContent, type Transport } from \"../types.ts\";\nimport { MatrixRTCMembershipParseError } from \"./common.ts\";\nimport { sha256 } from \"../../digest.ts\";\nimport { encodeUnpaddedBase64Url } from \"../../base64.ts\";\nimport { slotIdToDescription } from \"../utils.ts\";\n\n/**\n * Represents the current form of MSC4143, which uses sticky events to store membership.\n */\nexport interface RtcMembershipData {\n \"slot_id\": string;\n \"member\": {\n user_id: string;\n device_id: string;\n id: string;\n };\n \"m.relates_to\"?: {\n event_id: string;\n rel_type: RelationType.Reference;\n };\n \"application\": RtcSlotEventContent[\"application\"];\n \"rtc_transports\": Transport[];\n \"versions\": string[];\n \"msc4354_sticky_key\"?: string;\n \"sticky_key\"?: string;\n}\n\n/**\n * Validates that `data` matches the format expected by MSC4143.\n * @param data The event content.\n * @param sender The sender of the event.\n * @returns true if `data` is valid RtcMembershipData\n * @throws {MatrixRTCMembershipParseError} if the content is not valid\n */\nexport const checkRtcMembershipData = (data: IContent, sender: string): data is RtcMembershipData => {\n const errors: string[] = [];\n const prefix = \" - \";\n const expectedSlotPrefix = `${data?.application?.type}#`;\n\n // required fields\n if (typeof data.slot_id !== \"string\") {\n errors.push(prefix + \"slot_id must be string\");\n } else if (!data.slot_id.startsWith(expectedSlotPrefix)) {\n errors.push(prefix + `slot_id must start with ${expectedSlotPrefix}`);\n } else {\n try {\n slotIdToDescription(data.slot_id);\n } catch (ex) {\n errors.push(prefix + `slot_id was badly formed${ex instanceof Error ? `: ${ex.message}` : \"\"}`);\n }\n }\n\n if (typeof data.member !== \"object\" || data.member === null) {\n errors.push(prefix + \"member must be an object\");\n } else {\n if (typeof data.member.user_id !== \"string\") {\n errors.push(prefix + \"member.user_id must be string\");\n } else if (!MXID_PATTERN.test(data.member.user_id)) {\n errors.push(prefix + \"member.user_id must be a valid mxid\");\n }\n // This is not what the spec enforces but there currently are no rules what power levels are required to\n // send a m.rtc.member event for a other user. So we add this check for simplicity and to avoid possible attacks until there\n // is a proper definition when this is allowed.\n else if (data.member.user_id !== sender) {\n errors.push(prefix + \"member.user_id must match the sender\");\n }\n if (typeof data.member.device_id !== \"string\") {\n errors.push(prefix + \"member.device_id must be string\");\n }\n if (typeof data.member.id !== \"string\") errors.push(prefix + \"member.id must be string\");\n }\n if (typeof data.application !== \"object\" || data.application === null) {\n errors.push(prefix + \"application must be an object\");\n } else {\n if (typeof data.application.type !== \"string\") {\n errors.push(prefix + \"application.type must be a string\");\n } else {\n if (data.application.type.includes(\"#\")) errors.push(prefix + 'application.type must not include \"#\"');\n }\n }\n if (data.rtc_transports === undefined || !Array.isArray(data.rtc_transports)) {\n errors.push(prefix + \"rtc_transports must be an array\");\n } else {\n // validate that each transport has at least a string 'type'\n for (const t of data.rtc_transports) {\n if (typeof t !== \"object\" || t === null || typeof (t as any).type !== \"string\") {\n errors.push(prefix + \"rtc_transports entries must be objects with a string type\");\n break;\n }\n }\n }\n if (data.versions === undefined || !Array.isArray(data.versions)) {\n errors.push(prefix + \"versions must be an array\");\n } else if (!data.versions.every((v) => typeof v === \"string\")) {\n errors.push(prefix + \"versions must be an array of strings\");\n }\n\n // optional fields\n if ((data.sticky_key ?? data.msc4354_sticky_key) === undefined) {\n errors.push(prefix + \"sticky_key or msc4354_sticky_key must be a defined\");\n }\n if (data.sticky_key !== undefined && typeof data.sticky_key !== \"string\") {\n errors.push(prefix + \"sticky_key must be a string\");\n }\n if (data.msc4354_sticky_key !== undefined && typeof data.msc4354_sticky_key !== \"string\") {\n errors.push(prefix + \"msc4354_sticky_key must be a string\");\n }\n if (\n data.sticky_key !== undefined &&\n data.msc4354_sticky_key !== undefined &&\n data.sticky_key !== data.msc4354_sticky_key\n ) {\n errors.push(prefix + \"sticky_key and msc4354_sticky_key must be equal if both are defined\");\n }\n if (data[\"m.relates_to\"] !== undefined) {\n const rel = data[\"m.relates_to\"] as RtcMembershipData[\"m.relates_to\"];\n if (typeof rel !== \"object\" || rel === null) {\n errors.push(prefix + \"m.relates_to must be an object if provided\");\n } else {\n if (typeof rel.event_id !== \"string\") errors.push(prefix + \"m.relates_to.event_id must be a string\");\n if (rel.rel_type !== \"m.reference\") errors.push(prefix + \"m.relates_to.rel_type must be m.reference\");\n }\n }\n\n if (errors.length) {\n throw new MatrixRTCMembershipParseError(\"RtcMembership\", errors);\n }\n\n return true;\n};\n\nexport async function computeRtcIdentityRaw(userId: string, deviceId: string, memberId: string): Promise<string> {\n const hashInput = `${userId}|${deviceId}|${memberId}`;\n const hashBuffer = await sha256(hashInput);\n const hashedString = encodeUnpaddedBase64Url(hashBuffer);\n return hashedString;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAAQ,6BAA6B;AAI1D,SAASC,6BAA6B,QAAQ,aAAa;AAC3D,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,uBAAuB,QAAQ,iBAAiB;AACzD,SAASC,mBAAmB,QAAQ,aAAa;;AAEjD;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMC,sBAAsB,G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]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type IContent } from "../../matrix.ts";
|
|
2
|
+
import { type RTCCallIntent, type Transport } from "../types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* (MatrixRTC) session membership data.
|
|
5
|
+
* This represents the *OLD* form of MSC4143, which uses state events to store membership.
|
|
6
|
+
* Represents the `session` in the memberships section of an m.call.member event as it is on the wire.
|
|
7
|
+
**/
|
|
8
|
+
export type SessionMembershipData = {
|
|
9
|
+
/**
|
|
10
|
+
* The RTC application defines the type of the RTC session.
|
|
11
|
+
*/
|
|
12
|
+
"application": string;
|
|
13
|
+
/**
|
|
14
|
+
* The id of this session.
|
|
15
|
+
* A session can never span over multiple rooms so this id is to distinguish between
|
|
16
|
+
* multiple session in one room. A room wide session that is not associated with a user,
|
|
17
|
+
* and therefore immune to creation race conflicts, uses the `call_id: ""`.
|
|
18
|
+
*/
|
|
19
|
+
"call_id": string;
|
|
20
|
+
/**
|
|
21
|
+
* The Matrix device ID of this session. A single user can have multiple sessions on different devices.
|
|
22
|
+
*/
|
|
23
|
+
"device_id": string;
|
|
24
|
+
/**
|
|
25
|
+
* The focus selection system this user/membership is using.
|
|
26
|
+
* NOTE: This is still included for legacy reasons, but not consumed by the SDK.
|
|
27
|
+
*/
|
|
28
|
+
"focus_active": {
|
|
29
|
+
type: "livekit" | string;
|
|
30
|
+
focus_selection: "oldest_membership" | "multi_sfu" | string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A list of possible foci this user knows about. One of them might be used based on the focus_active
|
|
34
|
+
* selection system.
|
|
35
|
+
*/
|
|
36
|
+
"foci_preferred": Transport[];
|
|
37
|
+
/**
|
|
38
|
+
* Optional field that contains the creation of the session. If it is undefined the creation
|
|
39
|
+
* is the `origin_server_ts` of the event itself. For updates to the event this property tracks
|
|
40
|
+
* the `origin_server_ts` of the initial join event.
|
|
41
|
+
* - If it is undefined it can be interpreted as a "Join".
|
|
42
|
+
* - If it is defined it can be interpreted as an "Update"
|
|
43
|
+
*/
|
|
44
|
+
"created_ts"?: number;
|
|
45
|
+
/**
|
|
46
|
+
* If the `application` = `"m.call"` this defines if it is a room or user owned call.
|
|
47
|
+
* There can always be one room scoped call but multiple user owned calls (breakout sessions)
|
|
48
|
+
*/
|
|
49
|
+
"scope"?: "m.room" | "m.user";
|
|
50
|
+
/**
|
|
51
|
+
* Optionally we allow to define a delta to the `created_ts` that defines when the event is expired/invalid.
|
|
52
|
+
* This should be set to multiple hours. The only reason it exist is to deal with failed delayed events.
|
|
53
|
+
* (for example caused by a homeserver crashes)
|
|
54
|
+
**/
|
|
55
|
+
"expires"?: number;
|
|
56
|
+
/**
|
|
57
|
+
* The intent of the call from the perspective of this user. This may be an audio call, video call or
|
|
58
|
+
* something else.
|
|
59
|
+
*/
|
|
60
|
+
"m.call.intent"?: RTCCallIntent;
|
|
61
|
+
/**
|
|
62
|
+
* The id used on the media backend.
|
|
63
|
+
* (With livekit this is the participant identity on the LK SFU)
|
|
64
|
+
* This can be a UUID but right now it is `${this.matrixEventData.sender}:${data.device_id}`.
|
|
65
|
+
*
|
|
66
|
+
* It is compleatly valid to not set this field. Other clients will treat `undefined` as `${this.matrixEventData.sender}:${data.device_id}`
|
|
67
|
+
*/
|
|
68
|
+
"membershipID"?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Validates that `data` matches the format expected by the legacy form of MSC4143.
|
|
72
|
+
* @param data The event content.
|
|
73
|
+
* @returns true if `data` is valid SessionMembershipData
|
|
74
|
+
* @throws {MatrixRTCMembershipParseError} if the content is not valid
|
|
75
|
+
*/
|
|
76
|
+
export declare const checkSessionsMembershipData: (data: IContent) => data is SessionMembershipData;
|
|
77
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/matrixrtc/membershipData/session.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAGjE;;;;IAII;AACJ,MAAM,MAAM,qBAAqB,GAAG;IAChC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,cAAc,EAAE;QACZ,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;QACzB,eAAe,EAAE,mBAAmB,GAAG,WAAW,GAAG,MAAM,CAAC;KAC/D,CAAC;IAEF;;;OAGG;IACH,gBAAgB,EAAE,SAAS,EAAE,CAAC;IAE9B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAItB;;;OAGG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAE9B;;;;QAII;IACJ,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,eAAe,CAAC,EAAE,aAAa,CAAC;IAEhC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,QAAQ,KAAG,IAAI,IAAI,qBAwCpE,CAAC"}
|