diff --git a/src/routes/notifications/v1/entities/__tests__/create-registration-v2.dto.builder.ts b/src/routes/notifications/v1/entities/__tests__/create-registration-v2.dto.builder.ts index 41c3a747f1..fc22100313 100644 --- a/src/routes/notifications/v1/entities/__tests__/create-registration-v2.dto.builder.ts +++ b/src/routes/notifications/v1/entities/__tests__/create-registration-v2.dto.builder.ts @@ -3,7 +3,14 @@ import { AuthPayload } from '@/domain/auth/entities/auth-payload.entity'; import { NotificationType } from '@/domain/notifications/v2/entities/notification.entity'; import type { RegisterDeviceDto } from '@/routes/notifications/v1/entities/register-device.dto.entity'; import type { UUID } from 'crypto'; -import { getAddress, keccak256, recoverMessageAddress, toBytes } from 'viem'; +import { + getAddress, + keccak256, + recoverAddress, + recoverMessageAddress, + toBytes, +} from 'viem'; +import { DeviceType } from '@/domain/notifications/v1/entities/device.entity'; export const createV2RegisterDtoBuilder = async ( args: RegisterDeviceDto, @@ -46,18 +53,32 @@ export const createV2RegisterDtoBuilder = async ( } for (const [index, safeV2] of safeV2Array.entries()) { - const safeAddresses = args.safeRegistrations.flatMap((safe) => safe.safes); + const safeAddresses = safeV2.upsertSubscriptionsDto.safes.map( + (safeV2Safes) => safeV2Safes.address, + ); - const recoveredAddress = await recoverMessageAddress({ - message: { - raw: keccak256( + let recoveredAddress: `0x${string}`; + if (args.deviceType === DeviceType.Web) { + recoveredAddress = await recoverMessageAddress({ + message: { + raw: keccak256( + toBytes( + `gnosis-safe${args.timestamp}${args.uuid}${args.cloudMessagingToken}${safeAddresses.sort().join('')}`, + ), + ), + }, + signature: safeV2.upsertSubscriptionsDto.signature, + }); + } else { + recoveredAddress = await recoverAddress({ + hash: keccak256( toBytes( `gnosis-safe${args.timestamp}${args.uuid}${args.cloudMessagingToken}${safeAddresses.sort().join('')}`, ), ), - }, - signature: safeV2.upsertSubscriptionsDto.signature, - }); + signature: safeV2.upsertSubscriptionsDto.signature, + }); + } safeV2.authPayload.chain_id = safeV2.upsertSubscriptionsDto.safes[0].chainId;