diff --git a/web/grpc/identity-service-client-wrapper.js b/web/grpc/identity-service-client-wrapper.js --- a/web/grpc/identity-service-client-wrapper.js +++ b/web/grpc/identity-service-client-wrapper.js @@ -533,29 +533,60 @@ notifOneTimeKeys, } = uploadData; - const contentOneTimeKeysArray = [...contentOneTimeKeys]; - const notifOneTimeKeysArray = [...notifOneTimeKeys]; + const identityKeyInfo = createIdentityKeyInfo( + keyPayload, + keyPayloadSignature, + ); + + const contentPrekeyUpload = createPrekey( + contentPrekey, + contentPrekeySignature, + ); + + const notifPrekeyUpload = createPrekey(notifPrekey, notifPrekeySignature); + + const deviceKeyUpload = createDeviceKeyUpload( + identityKeyInfo, + contentPrekeyUpload, + notifPrekeyUpload, + contentOneTimeKeys, + notifOneTimeKeys, + ); + return deviceKeyUpload; +} + +function createIdentityKeyInfo( + keyPayload: string, + keyPayloadSignature: string, +): IdentityKeyInfo { const identityKeyInfo = new IdentityKeyInfo(); identityKeyInfo.setPayload(keyPayload); identityKeyInfo.setPayloadSignature(keyPayloadSignature); + return identityKeyInfo; +} - const contentPrekeyUpload = new Prekey(); - contentPrekeyUpload.setPrekey(contentPrekey); - contentPrekeyUpload.setPrekeySignature(contentPrekeySignature); - - const notifPrekeyUpload = new Prekey(); - notifPrekeyUpload.setPrekey(notifPrekey); - notifPrekeyUpload.setPrekeySignature(notifPrekeySignature); +function createPrekey(prekey: string, prekeySignature: string): Prekey { + const prekeyUpload = new Prekey(); + prekeyUpload.setPrekey(prekey); + prekeyUpload.setPrekeySignature(prekeySignature); + return prekeyUpload; +} +function createDeviceKeyUpload( + identityKeyInfo: IdentityKeyInfo, + contentPrekeyUpload: Prekey, + notifPrekeyUpload: Prekey, + contentOneTimeKeys: $ReadOnlyArray = [], + notifOneTimeKeys: $ReadOnlyArray = [], +): DeviceKeyUpload { const deviceKeyUpload = new DeviceKeyUpload(); deviceKeyUpload.setDeviceKeyInfo(identityKeyInfo); deviceKeyUpload.setContentUpload(contentPrekeyUpload); deviceKeyUpload.setNotifUpload(notifPrekeyUpload); - deviceKeyUpload.setOneTimeContentPrekeysList(contentOneTimeKeysArray); - deviceKeyUpload.setOneTimeNotifPrekeysList(notifOneTimeKeysArray); + deviceKeyUpload.setOneTimeContentPrekeysList([...contentOneTimeKeys]); + deviceKeyUpload.setOneTimeNotifPrekeysList([...notifOneTimeKeys]); deviceKeyUpload.setDeviceType(identityDeviceTypes.WEB); - return deviceKeyUpload; }