fix(mpc/backup): add accountSequence to backup share storage
- mpc-service: add accountSequence param to StoreBackupShareParams - mpc-service: pass accountSequence when calling backup-service - backup-service: add logging for store request success/failure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
300fe211c8
commit
41af5ef3a3
|
|
@ -9,7 +9,11 @@
|
||||||
"Bash(cat:*)",
|
"Bash(cat:*)",
|
||||||
"Bash(git add:*)",
|
"Bash(git add:*)",
|
||||||
"Bash(git commit:*)",
|
"Bash(git commit:*)",
|
||||||
"Bash(git push)"
|
"Bash(git push)",
|
||||||
|
"Bash(find:*)",
|
||||||
|
"Bash(npm run build:*)",
|
||||||
|
"Bash(npx prisma generate:*)",
|
||||||
|
"Bash(npx tsc:*)"
|
||||||
],
|
],
|
||||||
"deny": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import {
|
||||||
HttpCode,
|
HttpCode,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Req,
|
Req,
|
||||||
|
Logger,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { BackupShareApplicationService } from '../../application/services/backup-share-application.service';
|
import { BackupShareApplicationService } from '../../application/services/backup-share-application.service';
|
||||||
import { StoreBackupShareCommand } from '../../application/commands/store-backup-share/store-backup-share.command';
|
import { StoreBackupShareCommand } from '../../application/commands/store-backup-share/store-backup-share.command';
|
||||||
|
|
@ -24,6 +25,8 @@ import {
|
||||||
@Controller('backup-share')
|
@Controller('backup-share')
|
||||||
@UseGuards(ServiceAuthGuard)
|
@UseGuards(ServiceAuthGuard)
|
||||||
export class BackupShareController {
|
export class BackupShareController {
|
||||||
|
private readonly logger = new Logger(BackupShareController.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly backupShareService: BackupShareApplicationService,
|
private readonly backupShareService: BackupShareApplicationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
@ -34,24 +37,33 @@ export class BackupShareController {
|
||||||
@Body() dto: StoreShareDto,
|
@Body() dto: StoreShareDto,
|
||||||
@Req() request: any,
|
@Req() request: any,
|
||||||
): Promise<StoreShareResponseDto> {
|
): Promise<StoreShareResponseDto> {
|
||||||
const command = new StoreBackupShareCommand(
|
this.logger.log(`[STORE] Received store request: userId=${dto.userId}, accountSequence=${dto.accountSequence}, publicKey=${dto.publicKey?.substring(0, 20)}...`);
|
||||||
dto.userId,
|
|
||||||
dto.accountSequence,
|
|
||||||
dto.publicKey,
|
|
||||||
dto.encryptedShareData,
|
|
||||||
request.sourceService,
|
|
||||||
request.sourceIp,
|
|
||||||
dto.threshold,
|
|
||||||
dto.totalParties,
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await this.backupShareService.storeBackupShare(command);
|
try {
|
||||||
|
const command = new StoreBackupShareCommand(
|
||||||
|
dto.userId,
|
||||||
|
dto.accountSequence,
|
||||||
|
dto.publicKey,
|
||||||
|
dto.encryptedShareData,
|
||||||
|
request.sourceService,
|
||||||
|
request.sourceIp,
|
||||||
|
dto.threshold,
|
||||||
|
dto.totalParties,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
const result = await this.backupShareService.storeBackupShare(command);
|
||||||
success: true,
|
|
||||||
shareId: result.shareId,
|
this.logger.log(`[STORE] SUCCESS: shareId=${result.shareId}, userId=${dto.userId}, accountSequence=${dto.accountSequence}`);
|
||||||
message: 'Backup share stored successfully',
|
|
||||||
};
|
return {
|
||||||
|
success: true,
|
||||||
|
shareId: result.shareId,
|
||||||
|
message: 'Backup share stored successfully',
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`[STORE] FAILED: userId=${dto.userId}, accountSequence=${dto.accountSequence}, error=${error.message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('retrieve')
|
@Post('retrieve')
|
||||||
|
|
|
||||||
|
|
@ -105,13 +105,14 @@ export class KeygenRequestedHandler implements OnModuleInit {
|
||||||
try {
|
try {
|
||||||
await this.backupClient.storeBackupShare({
|
await this.backupClient.storeBackupShare({
|
||||||
userId,
|
userId,
|
||||||
|
accountSequence,
|
||||||
username,
|
username,
|
||||||
publicKey: result.publicKey,
|
publicKey: result.publicKey,
|
||||||
partyId: result.delegateShare.partyId,
|
partyId: result.delegateShare.partyId,
|
||||||
partyIndex: result.delegateShare.partyIndex,
|
partyIndex: result.delegateShare.partyIndex,
|
||||||
encryptedShare: result.delegateShare.encryptedShare,
|
encryptedShare: result.delegateShare.encryptedShare,
|
||||||
});
|
});
|
||||||
this.logger.log(`Delegate share stored to backup-service: userId=${userId}`);
|
this.logger.log(`Delegate share stored to backup-service: userId=${userId}, accountSequence=${accountSequence}`);
|
||||||
} catch (backupError) {
|
} catch (backupError) {
|
||||||
// 备份失败不阻塞主流程,但记录错误
|
// 备份失败不阻塞主流程,但记录错误
|
||||||
this.logger.error(`Failed to store delegate share to backup-service: userId=${userId}`, backupError);
|
this.logger.error(`Failed to store delegate share to backup-service: userId=${userId}`, backupError);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import * as jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
export interface StoreBackupShareParams {
|
export interface StoreBackupShareParams {
|
||||||
userId: string;
|
userId: string;
|
||||||
|
accountSequence: number;
|
||||||
username: string;
|
username: string;
|
||||||
publicKey: string;
|
publicKey: string;
|
||||||
partyId: string;
|
partyId: string;
|
||||||
|
|
@ -77,10 +78,8 @@ export class BackupClientService {
|
||||||
`${this.backupServiceUrl}/backup-share/store`,
|
`${this.backupServiceUrl}/backup-share/store`,
|
||||||
{
|
{
|
||||||
userId: params.userId,
|
userId: params.userId,
|
||||||
username: params.username,
|
accountSequence: params.accountSequence,
|
||||||
publicKey: params.publicKey,
|
publicKey: params.publicKey,
|
||||||
partyId: params.partyId,
|
|
||||||
partyIndex: params.partyIndex,
|
|
||||||
encryptedShareData: params.encryptedShare,
|
encryptedShareData: params.encryptedShare,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue