diff options
Diffstat (limited to 'includes/external/matrix/node_modules/matrix-js-sdk/lib/rendezvous/MSC3906Rendezvous.js.map')
-rw-r--r-- | includes/external/matrix/node_modules/matrix-js-sdk/lib/rendezvous/MSC3906Rendezvous.js.map | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rendezvous/MSC3906Rendezvous.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rendezvous/MSC3906Rendezvous.js.map new file mode 100644 index 0000000..4c0b657 --- /dev/null +++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rendezvous/MSC3906Rendezvous.js.map @@ -0,0 +1 @@ +{"version":3,"file":"MSC3906Rendezvous.js","names":["_matrixEventsSdk","require","_","_feature","_logger","_utils","PayloadType","Outcome","LOGIN_TOKEN_PROTOCOL","UnstableValue","MSC3906Rendezvous","constructor","channel","client","onFailure","_defineProperty2","default","RendezvousIntent","RECIPROCATE_LOGIN_ON_EXISTING_DEVICE","code","_code","generateCode","JSON","stringify","ourIntent","startAfterShowingCode","checksum","connect","logger","info","features","buildFeatureSupportMap","getVersions","get","Feature","LoginTokenRequest","ServerSupport","Unsupported","send","type","Finish","outcome","cancel","RendezvousFailureReason","HomeserverLacksSupport","undefined","Progress","protocols","name","protocol","receive","UnsupportedAlgorithm","Unknown","matches","payload","declineLoginOnExistingDevice","Declined","approveLoginOnExistingDevice","loginToken","login_token","homeserver","baseUrl","res","device_id","deviceId","device_key","deviceKey","Error","newDeviceId","newDeviceKey","verifyAndCrossSignDevice","deviceInfo","crypto","getFingerprint","userId","getUserId","setDeviceVerification","masterPublicKey","crossSigningInfo","getId","Verified","verifying_device_id","getDeviceId","verifying_device_key","getDeviceEd25519Key","master_key","verifyNewDeviceOnExistingDevice","timeout","getStoredDevice","sleep","reason","_this$onFailure","call","close","exports"],"sources":["../../src/rendezvous/MSC3906Rendezvous.ts"],"sourcesContent":["/*\nCopyright 2022 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 { UnstableValue } from \"matrix-events-sdk\";\n\nimport { RendezvousChannel, RendezvousFailureListener, RendezvousFailureReason, RendezvousIntent } from \".\";\nimport { MatrixClient } from \"../client\";\nimport { CrossSigningInfo } from \"../crypto/CrossSigning\";\nimport { DeviceInfo } from \"../crypto/deviceinfo\";\nimport { buildFeatureSupportMap, Feature, ServerSupport } from \"../feature\";\nimport { logger } from \"../logger\";\nimport { sleep } from \"../utils\";\n\nenum PayloadType {\n Start = \"m.login.start\",\n Finish = \"m.login.finish\",\n Progress = \"m.login.progress\",\n}\n\nenum Outcome {\n Success = \"success\",\n Failure = \"failure\",\n Verified = \"verified\",\n Declined = \"declined\",\n Unsupported = \"unsupported\",\n}\n\nexport interface MSC3906RendezvousPayload {\n type: PayloadType;\n intent?: RendezvousIntent;\n outcome?: Outcome;\n device_id?: string;\n device_key?: string;\n verifying_device_id?: string;\n verifying_device_key?: string;\n master_key?: string;\n protocols?: string[];\n protocol?: string;\n login_token?: string;\n homeserver?: string;\n}\n\nconst LOGIN_TOKEN_PROTOCOL = new UnstableValue(\"login_token\", \"org.matrix.msc3906.login_token\");\n\n/**\n * Implements MSC3906 to allow a user to sign in on a new device using QR code.\n * This implementation only supports generating a QR code on a device that is already signed in.\n * Note that this is UNSTABLE and may have breaking changes without notice.\n */\nexport class MSC3906Rendezvous {\n private newDeviceId?: string;\n private newDeviceKey?: string;\n private ourIntent: RendezvousIntent = RendezvousIntent.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE;\n private _code?: string;\n\n /**\n * @param channel - The secure channel used for communication\n * @param client - The Matrix client in used on the device already logged in\n * @param onFailure - Callback for when the rendezvous fails\n */\n public constructor(\n private channel: RendezvousChannel<MSC3906RendezvousPayload>,\n private client: MatrixClient,\n public onFailure?: RendezvousFailureListener,\n ) {}\n\n /**\n * Returns the code representing the rendezvous suitable for rendering in a QR code or undefined if not generated yet.\n */\n public get code(): string | undefined {\n return this._code;\n }\n\n /**\n * Generate the code including doing partial set up of the channel where required.\n */\n public async generateCode(): Promise<void> {\n if (this._code) {\n return;\n }\n\n this._code = JSON.stringify(await this.channel.generateCode(this.ourIntent));\n }\n\n public async startAfterShowingCode(): Promise<string | undefined> {\n const checksum = await this.channel.connect();\n\n logger.info(`Connected to secure channel with checksum: ${checksum} our intent is ${this.ourIntent}`);\n\n const features = await buildFeatureSupportMap(await this.client.getVersions());\n // determine available protocols\n if (features.get(Feature.LoginTokenRequest) === ServerSupport.Unsupported) {\n logger.info(\"Server doesn't support MSC3882\");\n await this.send({ type: PayloadType.Finish, outcome: Outcome.Unsupported });\n await this.cancel(RendezvousFailureReason.HomeserverLacksSupport);\n return undefined;\n }\n\n await this.send({ type: PayloadType.Progress, protocols: [LOGIN_TOKEN_PROTOCOL.name] });\n\n logger.info(\"Waiting for other device to chose protocol\");\n const { type, protocol, outcome } = await this.receive();\n\n if (type === PayloadType.Finish) {\n // new device decided not to complete\n switch (outcome ?? \"\") {\n case \"unsupported\":\n await this.cancel(RendezvousFailureReason.UnsupportedAlgorithm);\n break;\n default:\n await this.cancel(RendezvousFailureReason.Unknown);\n }\n return undefined;\n }\n\n if (type !== PayloadType.Progress) {\n await this.cancel(RendezvousFailureReason.Unknown);\n return undefined;\n }\n\n if (!protocol || !LOGIN_TOKEN_PROTOCOL.matches(protocol)) {\n await this.cancel(RendezvousFailureReason.UnsupportedAlgorithm);\n return undefined;\n }\n\n return checksum;\n }\n\n private async receive(): Promise<MSC3906RendezvousPayload> {\n return (await this.channel.receive()) as MSC3906RendezvousPayload;\n }\n\n private async send(payload: MSC3906RendezvousPayload): Promise<void> {\n await this.channel.send(payload);\n }\n\n public async declineLoginOnExistingDevice(): Promise<void> {\n logger.info(\"User declined sign in\");\n await this.send({ type: PayloadType.Finish, outcome: Outcome.Declined });\n }\n\n public async approveLoginOnExistingDevice(loginToken: string): Promise<string | undefined> {\n // eslint-disable-next-line camelcase\n await this.send({ type: PayloadType.Progress, login_token: loginToken, homeserver: this.client.baseUrl });\n\n logger.info(\"Waiting for outcome\");\n const res = await this.receive();\n if (!res) {\n return undefined;\n }\n const { outcome, device_id: deviceId, device_key: deviceKey } = res;\n\n if (outcome !== \"success\") {\n throw new Error(\"Linking failed\");\n }\n\n this.newDeviceId = deviceId;\n this.newDeviceKey = deviceKey;\n\n return deviceId;\n }\n\n private async verifyAndCrossSignDevice(deviceInfo: DeviceInfo): Promise<CrossSigningInfo | DeviceInfo> {\n if (!this.client.crypto) {\n throw new Error(\"Crypto not available on client\");\n }\n\n if (!this.newDeviceId) {\n throw new Error(\"No new device ID set\");\n }\n\n // check that keys received from the server for the new device match those received from the device itself\n if (deviceInfo.getFingerprint() !== this.newDeviceKey) {\n throw new Error(\n `New device has different keys than expected: ${this.newDeviceKey} vs ${deviceInfo.getFingerprint()}`,\n );\n }\n\n const userId = this.client.getUserId();\n\n if (!userId) {\n throw new Error(\"No user ID set\");\n }\n // mark the device as verified locally + cross sign\n logger.info(`Marking device ${this.newDeviceId} as verified`);\n const info = await this.client.crypto.setDeviceVerification(userId, this.newDeviceId, true, false, true);\n\n const masterPublicKey = this.client.crypto.crossSigningInfo.getId(\"master\")!;\n\n await this.send({\n type: PayloadType.Finish,\n outcome: Outcome.Verified,\n verifying_device_id: this.client.getDeviceId()!,\n verifying_device_key: this.client.getDeviceEd25519Key()!,\n master_key: masterPublicKey,\n });\n\n return info;\n }\n\n /**\n * Verify the device and cross-sign it.\n * @param timeout - time in milliseconds to wait for device to come online\n * @returns the new device info if the device was verified\n */\n public async verifyNewDeviceOnExistingDevice(\n timeout = 10 * 1000,\n ): Promise<DeviceInfo | CrossSigningInfo | undefined> {\n if (!this.newDeviceId) {\n throw new Error(\"No new device to sign\");\n }\n\n if (!this.newDeviceKey) {\n logger.info(\"No new device key to sign\");\n return undefined;\n }\n\n if (!this.client.crypto) {\n throw new Error(\"Crypto not available on client\");\n }\n\n const userId = this.client.getUserId();\n\n if (!userId) {\n throw new Error(\"No user ID set\");\n }\n\n let deviceInfo = this.client.crypto.getStoredDevice(userId, this.newDeviceId);\n\n if (!deviceInfo) {\n logger.info(\"Going to wait for new device to be online\");\n await sleep(timeout);\n deviceInfo = this.client.crypto.getStoredDevice(userId, this.newDeviceId);\n }\n\n if (deviceInfo) {\n return await this.verifyAndCrossSignDevice(deviceInfo);\n }\n\n throw new Error(\"Device not online within timeout\");\n }\n\n public async cancel(reason: RendezvousFailureReason): Promise<void> {\n this.onFailure?.(reason);\n await this.channel.cancel(reason);\n }\n\n public async close(): Promise<void> {\n await this.channel.close();\n }\n}\n"],"mappings":";;;;;;;;AAgBA,IAAAA,gBAAA,GAAAC,OAAA;AAEA,IAAAC,CAAA,GAAAD,OAAA;AAIA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAdA,IA0BKK,WAAW;AAAA,WAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;AAAA,GAAXA,WAAW,KAAXA,WAAW;AAAA,IAMXC,OAAO;AAAA,WAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;AAAA,GAAPA,OAAO,KAAPA,OAAO;AAuBZ,MAAMC,oBAAoB,GAAG,IAAIC,8BAAa,CAAC,aAAa,EAAE,gCAAgC,CAAC;;AAE/F;AACA;AACA;AACA;AACA;AACO,MAAMC,iBAAiB,CAAC;EAM3B;AACJ;AACA;AACA;AACA;EACWC,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