Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Socket/socket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Boom } from '@hapi/boom'

Check failure on line 1 in src/Socket/socket.ts

View workflow job for this annotation

GitHub Actions / check-lint

Run autofix to sort these imports!
import { randomBytes } from 'crypto'
import { URL } from 'url'
import { promisify } from 'util'
Expand All @@ -21,12 +21,14 @@
aesEncryptCTR,
bindWaitForConnectionUpdate,
bytesToCrockford,
buildPairingQRData,
configureSuccessfulPairing,
Curve,
derivePairingCodeKey,
generateLoginNode,
generateMdTagPrefix,
generateRegistrationNode,
getCompanionPlatformId,
Comment thread
purpshell marked this conversation as resolved.
Outdated
getCodeFromWSError,
getErrorCodeFromStreamError,
getNextPreKeysNode,
Expand All @@ -36,7 +38,6 @@
signedKeyPair,
xmppSignedPreKey
} from '../Utils'
import { getPlatformId } from '../Utils/browser-utils'
import {
assertNodeErrorFree,
type BinaryNode,
Expand Down Expand Up @@ -206,7 +207,7 @@

const msgId = node.attrs.id

const result = await promiseTimeout<any>(timeoutMs, async (resolve, reject) => {

Check warning on line 210 in src/Socket/socket.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
const result = waitForMessage(msgId, timeoutMs).catch(reject)
sendNode(node)
.then(async () => resolve(await result))
Expand Down Expand Up @@ -790,7 +791,7 @@
{
tag: 'companion_platform_id',
attrs: {},
content: getPlatformId(browser[1])
content: getCompanionPlatformId(browser)
},
{
tag: 'companion_platform_display',
Expand Down Expand Up @@ -840,7 +841,7 @@
ws.on('open', async () => {
try {
await validateConnection()
} catch (err: any) {

Check warning on line 844 in src/Socket/socket.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
logger.error({ err }, 'error in validating connection')
void end(err)
}
Expand Down Expand Up @@ -883,7 +884,7 @@
}

const ref = (refNode.content as Buffer).toString('utf-8')
const qr = [ref, noiseKeyB64, identityKeyB64, advB64].join(',')
const qr = buildPairingQRData(ref, noiseKeyB64, identityKeyB64, advB64, browser)

ev.emit('connection.update', { qr })

Expand Down Expand Up @@ -911,7 +912,7 @@

await sendNode(reply)
void sendUnifiedSession()
} catch (error: any) {

Check warning on line 915 in src/Socket/socket.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
logger.info({ trace: error.stack }, 'error in pairing')
void end(error)
}
Expand Down
45 changes: 45 additions & 0 deletions src/Utils/companion-reg-client-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { WABrowserDescription } from '../Types'

export enum CompanionWebClientType {
UNKNOWN = 0,
CHROME = 1,
EDGE = 2,
FIREFOX = 3,
IE = 4,
OPERA = 5,
SAFARI = 6,
ELECTRON = 7,
UWP = 8,
OTHER_WEB_CLIENT = 9
}

const BROWSER_TO_COMPANION_WEB_CLIENT: Record<string, CompanionWebClientType> = {
Chrome: CompanionWebClientType.CHROME,
Edge: CompanionWebClientType.EDGE,
Firefox: CompanionWebClientType.FIREFOX,
IE: CompanionWebClientType.IE,
Opera: CompanionWebClientType.OPERA,
Safari: CompanionWebClientType.SAFARI
}

export const getCompanionWebClientType = ([os, browserName]: WABrowserDescription): CompanionWebClientType => {
if (browserName === 'Desktop') {
return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON
}

return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT
}

export const getCompanionPlatformId = (browser: WABrowserDescription): string => {
return getCompanionWebClientType(browser).toString()
}

export const buildPairingQRData = (
ref: string,
noiseKeyB64: string,
identityKeyB64: string,
advB64: string,
browser: WABrowserDescription
): string => {
return [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',')
Comment thread
purpshell marked this conversation as resolved.
Outdated
}
1 change: 1 addition & 0 deletions src/Utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export * from './event-buffer'
export * from './process-message'
export * from './message-retry-manager'
export * from './browser-utils'
export * from './companion-reg-client-utils'
export * from './identity-change-handler'
export * from './stanza-ack'
Loading