Skip to content

Commit 15c27bd

Browse files
authored
Merge pull request #61 from BitGo/WP-5232-mpcv2-signing-custom-fns
feat(mbe): use custom signing fns for mpcv2 signing/sendmany
2 parents 8154e4a + a69a9a4 commit 15c27bd

File tree

12 files changed

+428
-385
lines changed

12 files changed

+428
-385
lines changed

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

Lines changed: 7 additions & 51 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 () => {
@@ -343,7 +316,7 @@ describe('signMpcTransaction', () => {
343316
const derivationPath = 'm/0';
344317

345318
const [userShare, backupShare, bitgoShare] = await DklsUtils.generateDKGKeyShares();
346-
assert(backupShare, 'backupShare is not defined');
319+
assert(backupShare, 'Backup share is not defined');
347320

348321
const userKeyShare = userShare.getKeyShare().toString('base64');
349322

@@ -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/__tests__/api/master/ecdsa.test.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Wallet,
77
TxRequest,
88
IRequestTracer,
9-
TxRequestVersion,
109
Environments,
1110
RequestTracer,
1211
EcdsaMPCv2Utils,
@@ -16,7 +15,7 @@ import {
1615
TransactionState,
1716
} from '@bitgo/sdk-core';
1817
import { EnclavedExpressClient } from '../../../../src/api/master/clients/enclavedExpressClient';
19-
import { handleEcdsaSigning } from '../../../../src/api/master/handlers/ecdsa';
18+
import { signAndSendEcdsaMPCv2FromTxRequest } from '../../../api/master/handlers/ecdsaMPCv2';
2019
import { BitGo } from 'bitgo';
2120
import { readKey } from 'openpgp';
2221

@@ -69,7 +68,7 @@ describe('Ecdsa Signing Handler', () => {
6968
it('should successfully sign an ECDSA MPCv2 transaction', async () => {
7069
const txRequest: TxRequest = {
7170
txRequestId: 'test-tx-request-id',
72-
apiVersion: '2.0.0' as TxRequestVersion,
71+
apiVersion: 'full',
7372
enterpriseId: 'test-enterprise-id',
7473
transactions: [],
7574
state: 'pendingUserSignature',
@@ -89,15 +88,6 @@ describe('Ecdsa Signing Handler', () => {
8988
const pgpKey = await readKey({ armoredKey: bitgoGpgKey.publicKey });
9089
sinon.stub(EcdsaMPCv2Utils.prototype, 'getBitgoMpcv2PublicGpgKey').resolves(pgpKey);
9190

92-
// Mock getTxRequest call
93-
const getTxRequestNock = nock(bitgoApiUrl)
94-
.get(`/api/v2/wallet/${walletId}/txrequests`)
95-
.query({ txRequestIds: 'test-tx-request-id', latest: true })
96-
.matchHeader('any', () => true)
97-
.reply(200, {
98-
txRequests: [txRequest],
99-
});
100-
10191
// Mock sendSignatureShareV2 calls for each round
10292
const round1SignatureShare: SignatureShareRecord = {
10393
from: SignatureShareType.USER,
@@ -132,7 +122,7 @@ describe('Ecdsa Signing Handler', () => {
132122
.post(`/api/v2/wallet/${walletId}/txrequests/test-tx-request-id/transactions/0/sign`)
133123
.matchHeader('any', () => true)
134124
.reply(200, {
135-
txRequest: round1TxRequest,
125+
...round1TxRequest,
136126
});
137127

138128
const round2SignatureShare: SignatureShareRecord = {
@@ -171,7 +161,7 @@ describe('Ecdsa Signing Handler', () => {
171161
.post(`/api/v2/wallet/${walletId}/txrequests/test-tx-request-id/transactions/0/sign`)
172162
.matchHeader('any', () => true)
173163
.reply(200, {
174-
txRequest: round2TxRequest,
164+
...round2TxRequest,
175165
});
176166

177167
const round3SignatureShare: SignatureShareRecord = {
@@ -194,15 +184,13 @@ describe('Ecdsa Signing Handler', () => {
194184
.post(`/api/v2/wallet/${walletId}/txrequests/test-tx-request-id/transactions/0/sign`)
195185
.matchHeader('any', () => true)
196186
.reply(200, {
197-
txRequest: {
198-
...round2TxRequest,
199-
transactions: [
200-
{
201-
...round2TxRequest.transactions![0],
202-
signatureShares: [round1SignatureShare, round2SignatureShare, round3SignatureShare],
203-
},
204-
],
205-
},
187+
...round2TxRequest,
188+
transactions: [
189+
{
190+
...round2TxRequest.transactions![0],
191+
signatureShares: [round1SignatureShare, round2SignatureShare, round3SignatureShare],
192+
},
193+
],
206194
});
207195

208196
// Mock sendTxRequest call
@@ -240,10 +228,10 @@ describe('Ecdsa Signing Handler', () => {
240228
signatureShareRound3: round3SignatureShare,
241229
});
242230

243-
const result = await handleEcdsaSigning(
231+
const result = await signAndSendEcdsaMPCv2FromTxRequest(
244232
bitgo,
245233
wallet,
246-
txRequest.txRequestId,
234+
txRequest,
247235
enclavedExpressClient,
248236
'user',
249237
userPubKey,
@@ -255,7 +243,6 @@ describe('Ecdsa Signing Handler', () => {
255243
state: 'signed',
256244
});
257245

258-
getTxRequestNock.done();
259246
sendSignatureShareV2Round1Nock.done();
260247
sendSignatureShareV2Round2Nock.done();
261248
sendSignatureShareV2Round3Nock.done();

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Wallet,
77
TxRequest,
88
IRequestTracer,
9-
TxRequestVersion,
109
Environments,
1110
RequestTracer,
1211
EddsaUtils,
@@ -17,7 +16,8 @@ import { handleEddsaSigning } from '../../../../src/api/master/handlers/eddsa';
1716
import { BitGo } from 'bitgo';
1817
import { readKey } from 'openpgp';
1918

20-
describe('Eddsa Signing Handler', () => {
19+
// TODO: Re-enable once using EDDSA Custom signing fns
20+
xdescribe('Eddsa Signing Handler', () => {
2121
let bitgo: BitGoBase;
2222
let wallet: Wallet;
2323
let enclavedExpressClient: EnclavedExpressClient;
@@ -62,9 +62,30 @@ describe('Eddsa Signing Handler', () => {
6262
it('should successfully sign an Eddsa transaction', async () => {
6363
const txRequest: TxRequest = {
6464
txRequestId: 'test-tx-request-id',
65-
apiVersion: '2.0.0' as TxRequestVersion,
65+
apiVersion: 'full',
6666
enterpriseId: 'test-enterprise-id',
67-
transactions: [],
67+
transactions: [
68+
{
69+
state: 'pendingSignature',
70+
unsignedTx: {
71+
derivationPath: 'm/0',
72+
signableHex: 'testMessage',
73+
serializedTxHex: 'testSerializedTxHex',
74+
},
75+
signatureShares: [
76+
{
77+
share: 'bitgo-to-user-r-share',
78+
from: 'bitgo',
79+
to: 'user',
80+
},
81+
{
82+
share: 'user-to-bitgo-r-share',
83+
from: 'user',
84+
to: 'bitgo',
85+
},
86+
],
87+
},
88+
],
6889
state: 'pendingUserSignature',
6990
walletId: 'test-wallet-id',
7091
walletType: 'hot',
@@ -234,7 +255,7 @@ describe('Eddsa Signing Handler', () => {
234255
const result = await handleEddsaSigning(
235256
bitgo,
236257
wallet,
237-
txRequest.txRequestId,
258+
txRequest,
238259
enclavedExpressClient,
239260
userPubKey,
240261
reqId,

0 commit comments

Comments
 (0)