Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PooyaRaki committed Dec 23, 2024
1 parent 7d9addb commit 8b4eb22
Showing 1 changed file with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8b4eb22

Please sign in to comment.