Skip to content

Commit 0bc73f5

Browse files
committed
chore(advanced-wallets): use bitgoPublicGpgKey consistently
Ticket: WP-5232
1 parent b34b387 commit 0bc73f5

File tree

6 files changed

+33
-72
lines changed

6 files changed

+33
-72
lines changed

src/__tests__/api/enclaved/signMpcTransaction.test.ts

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('signMpcTransaction', () => {
122122
source: 'user',
123123
pub: 'DSqMPMsMAbEJVNuPKv1ZFdzt6YvJaDPDddfeW7ajtqds',
124124
txRequest: mockTxRequest,
125-
bitgoGpgPubKey: bitgoGpgPubKey,
125+
bitgoPublicGpgKey: bitgoGpgPubKey,
126126
};
127127

128128
const mockDataKeyResponse = {
@@ -275,46 +275,19 @@ describe('signMpcTransaction', () => {
275275
});
276276

277277
it('should fail for unsupported share type', async () => {
278-
const user = MPC.keyShare(1, 2, 3);
279-
const backup = MPC.keyShare(2, 2, 3);
280-
const bitgo = MPC.keyShare(3, 2, 3);
281-
282-
const userSigningMaterial = {
283-
uShare: user.uShare,
284-
bitgoYShare: bitgo.yShares[1],
285-
backupYShare: backup.yShares[1],
286-
};
287-
288-
const mockKmsResponse = {
289-
prv: JSON.stringify(userSigningMaterial),
290-
pub: 'DSqMPMsMAbEJVNuPKv1ZFdzt6YvJaDPDddfeW7ajtqds',
291-
source: 'user',
292-
type: 'independent',
293-
};
294-
295278
const input = {
296279
source: 'user',
297280
pub: 'DSqMPMsMAbEJVNuPKv1ZFdzt6YvJaDPDddfeW7ajtqds',
298281
txRequest: mockTxRequest,
299282
};
300283

301-
const kmsNock = nock(kmsUrl)
302-
.get(`/key/${input.pub}`)
303-
.query({ source: 'user', useLocalEncipherment: false })
304-
.reply(200, mockKmsResponse);
305-
306284
const response = await agent
307285
.post(`/api/${coin}/mpc/sign/invalid`)
308286
.set('Authorization', `Bearer ${accessToken}`)
309287
.send(input);
310288

311-
response.status.should.equal(500);
289+
response.status.should.equal(400);
312290
response.body.should.have.property('error');
313-
response.body.details.should.equal(
314-
'Share type invalid not supported for EDDSA, only commitment, G and R share generation is supported.',
315-
);
316-
317-
kmsNock.done();
318291
});
319292

320293
it('should fail when required fields are missing', async () => {
@@ -389,7 +362,7 @@ describe('signMpcTransaction', () => {
389362
source: 'user',
390363
pub: 'mock-ecdsa-public-key',
391364
txRequest: mockTxRequest,
392-
bitgoGpgPubKey: bitgoGpgKey.public,
365+
bitgoPublicGpgKey: bitgoGpgKey.public,
393366
};
394367

395368
const mockDataKeyResponse = {
@@ -449,7 +422,7 @@ describe('signMpcTransaction', () => {
449422
source: 'user',
450423
pub: 'mock-ecdsa-public-key',
451424
txRequest: txRequestRound1,
452-
bitgoGpgPubKey: bitgoGpgKey.public,
425+
bitgoPublicGpgKey: bitgoGpgKey.public,
453426
encryptedDataKey,
454427
encryptedUserGpgPrvKey,
455428
encryptedRound1Session,
@@ -501,7 +474,7 @@ describe('signMpcTransaction', () => {
501474
source: 'user',
502475
pub: 'mock-ecdsa-public-key',
503476
txRequest: txRequestRound2,
504-
bitgoGpgPubKey: bitgoGpgKey.public,
477+
bitgoPublicGpgKey: bitgoGpgKey.public,
505478
encryptedDataKey,
506479
encryptedUserGpgPrvKey,
507480
encryptedRound2Session,
@@ -643,36 +616,19 @@ describe('signMpcTransaction', () => {
643616
});
644617

645618
it('should fail for unsupported share type', async () => {
646-
const mockKmsResponse = {
647-
prv: 'mock-ecdsa-private-key',
648-
pub: 'mock-ecdsa-public-key',
649-
source: 'user',
650-
type: 'independent',
651-
};
652-
653619
const input = {
654620
source: 'user',
655621
pub: 'mock-ecdsa-public-key',
656622
txRequest: mockTxRequest,
657623
};
658624

659-
const kmsNock = nock(kmsUrl)
660-
.get(`/key/${input.pub}`)
661-
.query({ source: 'user', useLocalEncipherment: true })
662-
.reply(200, mockKmsResponse);
663-
664625
const response = await agent
665626
.post(`/api/${coin}/mpc/sign/invalid`)
666627
.set('Authorization', `Bearer ${accessToken}`)
667628
.send(input);
668629

669-
response.status.should.equal(500);
630+
response.status.should.equal(400);
670631
response.body.should.have.property('error');
671-
response.body.details.should.equal(
672-
'Share type invalid not supported for MPCv2, only MPCv2Round1, MPCv2Round2 and MPCv2Round3 is supported.',
673-
);
674-
675-
kmsNock.done();
676632
});
677633
});
678634
});

src/api/enclaved/handlers/signMpcTransaction.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ interface EddsaSigningParams {
6868
userToBitgoRShare?: SignShare;
6969
encryptedUserToBitgoRShare?: EncryptedSignerShareRecord;
7070
bitgoToUserCommitment?: CommitmentShareRecord;
71-
bitgoGpgPubKey?: string;
71+
bitgoPublicGpgKey?: string;
7272
}
7373

7474
// Unified parameters for handleEcdsaSigning - includes all possible fields
@@ -77,7 +77,7 @@ interface EcdsaSigningParams {
7777
shareType: ShareType;
7878
txRequest: TxRequest;
7979
prv: string;
80-
bitgoGpgPubKey?: string;
80+
bitgoPublicGpgKey?: string;
8181
encryptedDataKey?: string;
8282
encryptedUserGpgPrvKey?: string;
8383
encryptedRound1Session?: string;
@@ -119,15 +119,15 @@ export async function signMpcTransaction(req: EnclavedApiSpecRouteRequest<'v1.mp
119119
userToBitgoRShare: req.decoded.userToBitgoRShare,
120120
encryptedUserToBitgoRShare: req.decoded.encryptedUserToBitgoRShare,
121121
bitgoToUserCommitment: req.decoded.bitgoToUserCommitment,
122-
bitgoGpgPubKey: req.decoded.bitgoGpgPubKey,
122+
bitgoPublicGpgKey: req.decoded.bitgoPublicGpgKey,
123123
});
124124
} else if (mpcAlgorithm === MPCType.ECDSA) {
125125
return await handleEcdsaMpcV2Signing(req.bitgo, req.config, {
126126
coin: coinInstance,
127-
shareType,
127+
shareType: shareType as ShareType,
128128
txRequest: req.decoded.txRequest,
129129
prv,
130-
bitgoGpgPubKey: req.decoded.bitgoGpgPubKey,
130+
bitgoPublicGpgKey: req.decoded.bitgoPublicGpgKey,
131131
encryptedDataKey: req.decoded.encryptedDataKey,
132132
encryptedUserGpgPrvKey: req.decoded.encryptedUserGpgPrvKey,
133133
encryptedRound1Session: req.decoded.encryptedRound1Session,
@@ -164,23 +164,23 @@ async function handleEddsaSigning(
164164
userToBitgoRShare,
165165
encryptedUserToBitgoRShare,
166166
bitgoToUserCommitment,
167-
bitgoGpgPubKey,
167+
bitgoPublicGpgKey,
168168
} = params;
169169

170170
// Create EddsaUtils instance using the coin's bitgo instance
171171
const eddsaUtils = new EddsaUtils(bitgo, coin);
172172

173173
switch (shareType.toLowerCase()) {
174174
case ShareType.Commitment: {
175-
if (!bitgoGpgPubKey) {
176-
throw new Error('bitgoGpgPubKey is required for commitment share generation');
175+
if (!bitgoPublicGpgKey) {
176+
throw new Error('bitgoPublicGpgKey is required for commitment share generation');
177177
}
178178
const dataKey = await generateDataKey({ keyType: 'AES-256', cfg });
179179
const commitmentParams: CommitmentShareParams = {
180180
txRequest,
181181
prv,
182182
walletPassphrase: dataKey.plaintextKey,
183-
bitgoGpgPubKey,
183+
bitgoGpgPubKey: bitgoPublicGpgKey,
184184
};
185185
return {
186186
...(await eddsaUtils.createCommitmentShareFromTxRequest(commitmentParams)),
@@ -257,8 +257,8 @@ async function handleEcdsaMpcV2Signing(
257257
if (!params.encryptedDataKey) {
258258
throw new Error('encryptedDataKey from Round 1 is required for MPCv2 Round 2');
259259
}
260-
if (!params.bitgoGpgPubKey) {
261-
throw new Error('bitgoGpgPubKey is required for MPCv2 Round 2');
260+
if (!params.bitgoPublicGpgKey) {
261+
throw new Error('bitgoPublicGpgKey is required for MPCv2 Round 2');
262262
}
263263
if (!params.encryptedUserGpgPrvKey) {
264264
throw new Error('encryptedUserGpgPrvKey is required for MPCv2 Round 2');
@@ -274,7 +274,7 @@ async function handleEcdsaMpcV2Signing(
274274
txRequest: params.txRequest,
275275
prv: params.prv,
276276
walletPassphrase: plaintextDataKey,
277-
bitgoPublicGpgKey: params.bitgoGpgPubKey,
277+
bitgoPublicGpgKey: params.bitgoPublicGpgKey,
278278
encryptedUserGpgPrvKey: params.encryptedUserGpgPrvKey,
279279
encryptedRound1Session: params.encryptedRound1Session,
280280
});
@@ -283,7 +283,7 @@ async function handleEcdsaMpcV2Signing(
283283
if (!params.encryptedDataKey) {
284284
throw new Error('encryptedDataKey from Round 1 is required for MPCv2 Round 3');
285285
}
286-
if (!params.bitgoGpgPubKey) {
286+
if (!params.bitgoPublicGpgKey) {
287287
throw new Error('bitgoGpgPubKey is required for MPCv2 Round 3');
288288
}
289289
if (!params.encryptedUserGpgPrvKey) {
@@ -300,7 +300,7 @@ async function handleEcdsaMpcV2Signing(
300300
txRequest: params.txRequest,
301301
prv: params.prv,
302302
walletPassphrase: plaintextDataKey,
303-
bitgoPublicGpgKey: params.bitgoGpgPubKey,
303+
bitgoPublicGpgKey: params.bitgoPublicGpgKey,
304304
encryptedUserGpgPrvKey: params.encryptedUserGpgPrvKey,
305305
encryptedRound2Session: params.encryptedRound2Session,
306306
});

src/api/master/clients/enclavedExpressClient.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ interface RecoveryMultisigOptions {
9090

9191
interface SignMpcCommitmentParams {
9292
txRequest: TxRequest;
93-
bitgoGpgPubKey: string;
93+
bitgoPublicGpgKey: string;
9494
source: 'user' | 'backup';
9595
pub: string;
9696
}
@@ -146,7 +146,6 @@ interface SignMpcV2Round2Params {
146146
encryptedRound1Session: string;
147147
encryptedDataKey: string;
148148
bitgoPublicGpgKey: string;
149-
bitgoGpgPubKey: string;
150149
}
151150

152151
export interface SignMpcV2Round2Response {
@@ -160,7 +159,6 @@ interface SignMpcV2Round3Params {
160159
encryptedRound2Session: string;
161160
encryptedDataKey: string;
162161
bitgoPublicGpgKey: string;
163-
bitgoGpgPubKey: string;
164162
}
165163

166164
export interface SignMpcV2Round3Response {

src/api/master/handlers/ecdsa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function handleEcdsaSigning(
5959
encryptedDataKey: round1Response.encryptedDataKey,
6060
encryptedRound1Session: round1Response.encryptedRound1Session,
6161
encryptedUserGpgPrvKey: round1Response.encryptedUserGpgPrvKey,
62-
bitgoGpgPubKey: params.bitgoPublicGpgKey,
62+
bitgoPublicGpgKey: params.bitgoPublicGpgKey,
6363
});
6464
round2Response = response;
6565
return response;
@@ -83,7 +83,7 @@ export async function handleEcdsaSigning(
8383
encryptedDataKey: round1Response.encryptedDataKey,
8484
encryptedRound2Session: round2Response.encryptedRound2Session,
8585
encryptedUserGpgPrvKey: round1Response.encryptedUserGpgPrvKey,
86-
bitgoGpgPubKey: params.bitgoPublicGpgKey,
86+
bitgoPublicGpgKey: params.bitgoPublicGpgKey,
8787
});
8888
};
8989

src/api/master/handlers/eddsa.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function handleEddsaSigning(
3535
encryptedDataKey,
3636
} = await enclavedExpressClient.signMpcCommitment({
3737
txRequest,
38-
bitgoGpgPubKey: bitgoGpgKey.armor(),
38+
bitgoPublicGpgKey: bitgoGpgKey.armor(),
3939
source: 'user',
4040
pub: commonKeychain,
4141
});

src/enclavedBitgoExpress/routers/enclavedApiSpec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const SignMpcRequest = {
9191
userToBitgoRShare: t.union([t.undefined, t.any]),
9292
encryptedUserToBitgoRShare: t.union([t.undefined, t.any]),
9393
bitgoToUserCommitment: t.union([t.undefined, t.any]),
94-
bitgoGpgPubKey: t.union([t.undefined, t.string]),
94+
bitgoPublicGpgKey: t.union([t.undefined, t.string]),
9595
encryptedDataKey: t.union([t.undefined, t.string]),
9696

9797
// ECDSA MPCv2 specific fields
@@ -337,7 +337,14 @@ export const EnclavedAPiSpec = apiSpec({
337337
request: httpRequest({
338338
params: {
339339
coin: t.string,
340-
shareType: t.string,
340+
shareType: t.union([
341+
t.literal('commitment'),
342+
t.literal('r'),
343+
t.literal('g'),
344+
t.literal('mpcv2round1'),
345+
t.literal('mpcv2round2'),
346+
t.literal('mpcv2round3'),
347+
]),
341348
},
342349
body: SignMpcRequest,
343350
}),

0 commit comments

Comments
 (0)