Skip to content

Commit 4030a48

Browse files
committed
chore(mbe): check for required params instead of other coin params
Ticket: WP-5454
1 parent a98af04 commit 4030a48

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

src/__tests__/api/master/recoveryWallet.test.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ describe('Recovery Tests', () => {
232232
response.status.should.equal(422);
233233
response.body.should.have.property('error');
234234
response.body.should.have.property('details');
235-
response.body.details.should.containEql('Invalid parameters provided for UTXO coin recovery');
235+
response.body.details.should.containEql(
236+
'UTXO recovery options are required for UTXO coin recovery',
237+
);
236238
});
237239

238240
it('should reject incorrect Solana parameters for a UTXO coin', async () => {
@@ -267,7 +269,9 @@ describe('Recovery Tests', () => {
267269
response.status.should.equal(422);
268270
response.body.should.have.property('error');
269271
response.body.should.have.property('details');
270-
response.body.details.should.containEql('Invalid parameters provided for UTXO coin recovery');
272+
response.body.details.should.containEql(
273+
'UTXO recovery options are required for UTXO coin recovery',
274+
);
271275
});
272276

273277
it('should reject using legacy coinSpecificParams format', async () => {
@@ -294,9 +298,12 @@ describe('Recovery Tests', () => {
294298
},
295299
});
296300

297-
response.status.should.equal(500);
298-
// Since we test that the incorrect format doesn't work anymore
301+
response.status.should.equal(422);
299302
response.body.should.have.property('error');
303+
response.body.should.have.property('details');
304+
response.body.details.should.containEql(
305+
'UTXO recovery options are required for UTXO coin recovery',
306+
);
300307
});
301308
});
302309

@@ -355,7 +362,7 @@ describe('Recovery Tests', () => {
355362
response.body.should.have.property('error');
356363
response.body.should.have.property('details');
357364
response.body.details.should.containEql(
358-
'Invalid parameters provided for ETH-like coin recovery',
365+
'EVM recovery options are required for ETH-like coin recovery',
359366
);
360367
});
361368

@@ -393,7 +400,7 @@ describe('Recovery Tests', () => {
393400
response.body.should.have.property('error');
394401
response.body.should.have.property('details');
395402
response.body.details.should.containEql(
396-
'Invalid parameters provided for ETH-like coin recovery',
403+
'EVM recovery options are required for ETH-like coin recovery',
397404
);
398405
});
399406
});
@@ -448,7 +455,7 @@ describe('Recovery Tests', () => {
448455
response.body.should.have.property('error');
449456
response.body.should.have.property('details');
450457
response.body.details.should.containEql(
451-
'Invalid parameters provided for Solana coin recovery',
458+
'Solana recovery options are required for EdDSA coin recovery',
452459
);
453460
});
454461

@@ -479,7 +486,7 @@ describe('Recovery Tests', () => {
479486
response.body.should.have.property('error');
480487
response.body.should.have.property('details');
481488
response.body.details.should.containEql(
482-
'Invalid parameters provided for Solana coin recovery',
489+
'Solana recovery options are required for EdDSA coin recovery',
483490
);
484491
});
485492
});

src/api/master/handlers/recoveryWallet.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,52 +63,48 @@ function validateRecoveryParams(
6363
}
6464

6565
if (isUtxoCoin(sdkCoin)) {
66-
if (params.solanaRecoveryOptions || params.evmRecoveryOptions) {
67-
throw new ValidationError('Invalid parameters provided for UTXO coin recovery');
68-
}
69-
return;
70-
}
71-
72-
if (!isMpcRecovery && isEthLikeCoin(sdkCoin)) {
73-
if (params.solanaRecoveryOptions || params.utxoRecoveryOptions) {
74-
throw new ValidationError('Invalid parameters provided for ETH-like coin recovery');
66+
// UTXO coins need utxoRecoveryOptions for standard recovery
67+
if (!isMpcRecovery && !params.utxoRecoveryOptions) {
68+
throw new ValidationError('UTXO recovery options are required for UTXO coin recovery');
7569
}
7670
return;
7771
}
7872

7973
if (isEddsaCoin(sdkCoin)) {
80-
if (params.evmRecoveryOptions || params.utxoRecoveryOptions) {
81-
throw new ValidationError('Invalid parameters provided for Solana coin recovery');
74+
// EdDSA coins (like Solana) need solanaRecoveryOptions for standard recovery
75+
if (!params.solanaRecoveryOptions) {
76+
throw new ValidationError('Solana recovery options are required for EdDSA coin recovery');
8277
}
8378
return;
8479
}
8580

86-
if (isEcdsaCoin(sdkCoin)) {
81+
if (isEcdsaCoin(sdkCoin) && isMpcRecovery) {
8782
if (isEthLikeCoin(sdkCoin)) {
88-
if (isMpcRecovery) {
89-
if (!params.ecdsaEthLikeRecoverySpecificParams) {
90-
throw new ValidationError(
91-
'Invalid parameters provided for ETH-like MPC V2 coin recovery',
92-
);
93-
}
83+
if (!params.ecdsaEthLikeRecoverySpecificParams) {
84+
throw new ValidationError(
85+
'ECDSA ETH-like recovery specific parameters are required for MPC recovery',
86+
);
9487
}
95-
return;
9688
} else if (isCosmosLikeCoin(sdkCoin)) {
97-
if (isMpcRecovery) {
98-
if (!params.ecdsaCosmosLikeRecoverySpecificParams) {
99-
throw new ValidationError(
100-
'Invalid parameters provided for Cosmos-like MPC V2 coin recovery',
101-
);
102-
}
89+
// ECDSA Cosmos-like MPC recovery needs ecdsaCosmosLikeRecoverySpecificParams
90+
if (!params.ecdsaCosmosLikeRecoverySpecificParams) {
91+
throw new ValidationError(
92+
'ECDSA Cosmos-like recovery specific parameters are required for MPC recovery',
93+
);
10394
}
10495
} else {
10596
throw new NotImplementedError(
10697
`MPC V2 recovery is not supported for coin family: ${sdkCoin.getFamily()}`,
10798
);
10899
}
100+
}
101+
if (!isMpcRecovery && isEthLikeCoin(sdkCoin)) {
102+
// Non-ECDSA ETH-like coins need evmRecoveryOptions for standard recovery
103+
if (!params.evmRecoveryOptions) {
104+
throw new ValidationError('EVM recovery options are required for ETH-like coin recovery');
105+
}
109106
return;
110107
}
111-
throw new ValidationError('Recovery parameters are not valid');
112108
}
113109

114110
async function handleEthLikeRecovery(

0 commit comments

Comments
 (0)