Skip to content

Commit b186053

Browse files
authored
Merge pull request #500 from zkLinkProtocol/fix-check-password
fix: check password before claiming
2 parents 3b1760c + d63fe18 commit b186053

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

libs/red-envelope/src/red-envelope.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,16 +440,24 @@ export class RedEnvelopeService extends ActionDto<FieldTypes> {
440440
public async preCheckTransaction(
441441
data: GenerateTransactionParams<FieldTypes>,
442442
) {
443-
const { additionalData } = data;
443+
const { additionalData, formData } = data;
444+
const { password } = formData;
444445
const { code, account } = additionalData;
445446
if (!code) {
446447
throw new Error('missing code');
447448
}
448449
const packetId = this.getPacketIDByCode(code);
450+
const packetInfo = await this.envelopContract.redPackets(packetId);
451+
const passwordHash = ethers.keccak256(ethers.toUtf8Bytes(password));
449452
const hasClaimed = await this.envelopContract.isClaimed(packetId, account);
450453
if (hasClaimed) {
451454
return 'User has already received';
452455
}
456+
457+
if ([...packetInfo].pop() !== passwordHash) {
458+
return 'Wrong Password';
459+
}
460+
453461
const hasUnclaimedPacket =
454462
await this.envelopContract.getRedPacketBalance(packetId);
455463
if (hasUnclaimedPacket.unClaimedCount === 0n) {

libs/shared-red-packet/src/shared-red-packet.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,27 @@ export class SharedRedPacketService extends ActionDto<FieldTypes> {
376376
public async preCheckTransaction(
377377
data: GenerateTransactionParams<FieldTypes>,
378378
) {
379-
const { additionalData } = data;
379+
const { additionalData, formData } = data;
380+
const { password } = formData;
380381
const { code, account } = additionalData;
381382
if (!code) {
382383
throw new Error('missing code');
383384
}
384385
const packetId = this.getPacketIDByCode(code);
386+
const packetInfo = await this.redPacketContract.redPackets(packetId);
387+
const passwordHash = ethers.keccak256(ethers.toUtf8Bytes(password));
385388
const hasClaimed = await this.redPacketContract.isClaimed(
386389
packetId,
387390
account,
388391
);
389392
if (hasClaimed) {
390393
return 'User has already received';
391394
}
395+
396+
if ([...packetInfo].pop() !== passwordHash) {
397+
return 'Wrong Password';
398+
}
399+
392400
const hasUnclaimedPacket =
393401
await this.redPacketContract.getRedPacketBalance(packetId);
394402
if (hasUnclaimedPacket.unClaimedCount === 0n) {

0 commit comments

Comments
 (0)