diff --git a/native/profile/secondary-device-qr-code-scanner.react.js b/native/profile/secondary-device-qr-code-scanner.react.js --- a/native/profile/secondary-device-qr-code-scanner.react.js +++ b/native/profile/secondary-device-qr-code-scanner.react.js @@ -49,6 +49,34 @@ const aes256Key = React.useRef(null); const secondaryDeviceID = React.useRef(null); + const broadcastDeviceListUpdate = React.useCallback(async () => { + invariant(identityContext, 'identity context not set'); + const { getAuthMetadata, identityClient } = identityContext; + const { userID } = await getAuthMetadata(); + if (!userID) { + throw new Error('missing auth metadata'); + } + + const deviceLists = + await identityClient.getDeviceListHistoryForUser(userID); + const lastSignedDeviceList = deviceLists[deviceLists.length - 1]; + const deviceList: RawDeviceList = JSON.parse( + lastSignedDeviceList.rawDeviceList, + ); + + const promises = deviceList.devices.map(recipient => + tunnelbrokerContext.sendMessage({ + deviceID: recipient, + payload: JSON.stringify({ + type: peerToPeerMessageTypes.DEVICCE_LIST_UPDATED, + userID, + signedDeviceList: JSON.stringify(lastSignedDeviceList), + }), + }), + ); + await Promise.all(promises); + }, [identityContext, tunnelbrokerContext]); + const addDeviceToList = React.useCallback( async (newDeviceID: string) => { invariant(identityContext, 'identity context not set'); @@ -115,11 +143,23 @@ ) { return; } + + void broadcastDeviceListUpdate(); + + const backupKeyMessage = createQRAuthTunnelbrokerMessage(encryptionKey, { + type: qrCodeAuthMessageTypes.BACKUP_DATA_KEY_MESSAGE, + backupDataKey: 'stub', + }); + await tunnelbrokerContext.sendMessage({ + deviceID: targetDeviceID, + payload: JSON.stringify(backupKeyMessage), + }); + Alert.alert('Device added', 'Device registered successfully', [ { text: 'OK' }, ]); }, - [tunnelbrokerContext], + [tunnelbrokerContext, broadcastDeviceListUpdate], ); React.useEffect(() => { diff --git a/native/qr-code/qr-code-screen.react.js b/native/qr-code/qr-code-screen.react.js --- a/native/qr-code/qr-code-screen.react.js +++ b/native/qr-code/qr-code-screen.react.js @@ -95,6 +95,15 @@ deviceKeys.aesKey, innerMessage, ); + + if ( + qrCodeAuthMessage?.type === + qrCodeAuthMessageTypes.BACKUP_DATA_KEY_MESSAGE + ) { + console.log('Received backup data key:', qrCodeAuthMessage); + return; + } + if ( !qrCodeAuthMessage || qrCodeAuthMessage.type !==