Skip to content
58 changes: 7 additions & 51 deletions src/__tests__/api/enclaved/signMpcTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('signMpcTransaction', () => {
source: 'user',
pub: 'DSqMPMsMAbEJVNuPKv1ZFdzt6YvJaDPDddfeW7ajtqds',
txRequest: mockTxRequest,
bitgoGpgPubKey: bitgoGpgPubKey,
bitgoPublicGpgKey: bitgoGpgPubKey,
};

const mockDataKeyResponse = {
Expand Down Expand Up @@ -275,46 +275,19 @@ describe('signMpcTransaction', () => {
});

it('should fail for unsupported share type', async () => {
const user = MPC.keyShare(1, 2, 3);
const backup = MPC.keyShare(2, 2, 3);
const bitgo = MPC.keyShare(3, 2, 3);

const userSigningMaterial = {
uShare: user.uShare,
bitgoYShare: bitgo.yShares[1],
backupYShare: backup.yShares[1],
};

const mockKmsResponse = {
prv: JSON.stringify(userSigningMaterial),
pub: 'DSqMPMsMAbEJVNuPKv1ZFdzt6YvJaDPDddfeW7ajtqds',
source: 'user',
type: 'independent',
};

const input = {
source: 'user',
pub: 'DSqMPMsMAbEJVNuPKv1ZFdzt6YvJaDPDddfeW7ajtqds',
txRequest: mockTxRequest,
};

const kmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: false })
.reply(200, mockKmsResponse);

const response = await agent
.post(`/api/${coin}/mpc/sign/invalid`)
.set('Authorization', `Bearer ${accessToken}`)
.send(input);

response.status.should.equal(500);
response.status.should.equal(400);
response.body.should.have.property('error');
response.body.details.should.equal(
'Share type invalid not supported for EDDSA, only commitment, G and R share generation is supported.',
);

kmsNock.done();
});

it('should fail when required fields are missing', async () => {
Expand Down Expand Up @@ -343,7 +316,7 @@ describe('signMpcTransaction', () => {
const derivationPath = 'm/0';

const [userShare, backupShare, bitgoShare] = await DklsUtils.generateDKGKeyShares();
assert(backupShare, 'backupShare is not defined');
assert(backupShare, 'Backup share is not defined');

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

Expand Down Expand Up @@ -389,7 +362,7 @@ describe('signMpcTransaction', () => {
source: 'user',
pub: 'mock-ecdsa-public-key',
txRequest: mockTxRequest,
bitgoGpgPubKey: bitgoGpgKey.public,
bitgoPublicGpgKey: bitgoGpgKey.public,
};

const mockDataKeyResponse = {
Expand Down Expand Up @@ -449,7 +422,7 @@ describe('signMpcTransaction', () => {
source: 'user',
pub: 'mock-ecdsa-public-key',
txRequest: txRequestRound1,
bitgoGpgPubKey: bitgoGpgKey.public,
bitgoPublicGpgKey: bitgoGpgKey.public,
encryptedDataKey,
encryptedUserGpgPrvKey,
encryptedRound1Session,
Expand Down Expand Up @@ -501,7 +474,7 @@ describe('signMpcTransaction', () => {
source: 'user',
pub: 'mock-ecdsa-public-key',
txRequest: txRequestRound2,
bitgoGpgPubKey: bitgoGpgKey.public,
bitgoPublicGpgKey: bitgoGpgKey.public,
encryptedDataKey,
encryptedUserGpgPrvKey,
encryptedRound2Session,
Expand Down Expand Up @@ -643,36 +616,19 @@ describe('signMpcTransaction', () => {
});

it('should fail for unsupported share type', async () => {
const mockKmsResponse = {
prv: 'mock-ecdsa-private-key',
pub: 'mock-ecdsa-public-key',
source: 'user',
type: 'independent',
};

const input = {
source: 'user',
pub: 'mock-ecdsa-public-key',
txRequest: mockTxRequest,
};

const kmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: true })
.reply(200, mockKmsResponse);

const response = await agent
.post(`/api/${coin}/mpc/sign/invalid`)
.set('Authorization', `Bearer ${accessToken}`)
.send(input);

response.status.should.equal(500);
response.status.should.equal(400);
response.body.should.have.property('error');
response.body.details.should.equal(
'Share type invalid not supported for MPCv2, only MPCv2Round1, MPCv2Round2 and MPCv2Round3 is supported.',
);

kmsNock.done();
});
});
});
39 changes: 13 additions & 26 deletions src/__tests__/api/master/ecdsa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Wallet,
TxRequest,
IRequestTracer,
TxRequestVersion,
Environments,
RequestTracer,
EcdsaMPCv2Utils,
Expand All @@ -16,7 +15,7 @@ import {
TransactionState,
} from '@bitgo/sdk-core';
import { EnclavedExpressClient } from '../../../../src/api/master/clients/enclavedExpressClient';
import { handleEcdsaSigning } from '../../../../src/api/master/handlers/ecdsa';
import { signAndSendEcdsaMPCv2FromTxRequest } from '../../../api/master/handlers/ecdsaMPCv2';
import { BitGo } from 'bitgo';
import { readKey } from 'openpgp';

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

// Mock getTxRequest call
const getTxRequestNock = nock(bitgoApiUrl)
.get(`/api/v2/wallet/${walletId}/txrequests`)
.query({ txRequestIds: 'test-tx-request-id', latest: true })
.matchHeader('any', () => true)
.reply(200, {
txRequests: [txRequest],
});

// Mock sendSignatureShareV2 calls for each round
const round1SignatureShare: SignatureShareRecord = {
from: SignatureShareType.USER,
Expand Down Expand Up @@ -132,7 +122,7 @@ describe('Ecdsa Signing Handler', () => {
.post(`/api/v2/wallet/${walletId}/txrequests/test-tx-request-id/transactions/0/sign`)
.matchHeader('any', () => true)
.reply(200, {
txRequest: round1TxRequest,
...round1TxRequest,
});

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

const round3SignatureShare: SignatureShareRecord = {
Expand All @@ -194,15 +184,13 @@ describe('Ecdsa Signing Handler', () => {
.post(`/api/v2/wallet/${walletId}/txrequests/test-tx-request-id/transactions/0/sign`)
.matchHeader('any', () => true)
.reply(200, {
txRequest: {
...round2TxRequest,
transactions: [
{
...round2TxRequest.transactions![0],
signatureShares: [round1SignatureShare, round2SignatureShare, round3SignatureShare],
},
],
},
...round2TxRequest,
transactions: [
{
...round2TxRequest.transactions![0],
signatureShares: [round1SignatureShare, round2SignatureShare, round3SignatureShare],
},
],
});

// Mock sendTxRequest call
Expand Down Expand Up @@ -240,10 +228,10 @@ describe('Ecdsa Signing Handler', () => {
signatureShareRound3: round3SignatureShare,
});

const result = await handleEcdsaSigning(
const result = await signAndSendEcdsaMPCv2FromTxRequest(
bitgo,
wallet,
txRequest.txRequestId,
txRequest,
enclavedExpressClient,
'user',
userPubKey,
Expand All @@ -255,7 +243,6 @@ describe('Ecdsa Signing Handler', () => {
state: 'signed',
});

getTxRequestNock.done();
sendSignatureShareV2Round1Nock.done();
sendSignatureShareV2Round2Nock.done();
sendSignatureShareV2Round3Nock.done();
Expand Down
31 changes: 26 additions & 5 deletions src/__tests__/api/master/eddsa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Wallet,
TxRequest,
IRequestTracer,
TxRequestVersion,
Environments,
RequestTracer,
EddsaUtils,
Expand All @@ -17,7 +16,8 @@ import { handleEddsaSigning } from '../../../../src/api/master/handlers/eddsa';
import { BitGo } from 'bitgo';
import { readKey } from 'openpgp';

describe('Eddsa Signing Handler', () => {
// TODO: Re-enable once using EDDSA Custom signing fns
xdescribe('Eddsa Signing Handler', () => {
let bitgo: BitGoBase;
let wallet: Wallet;
let enclavedExpressClient: EnclavedExpressClient;
Expand Down Expand Up @@ -62,9 +62,30 @@ describe('Eddsa Signing Handler', () => {
it('should successfully sign an Eddsa transaction', async () => {
const txRequest: TxRequest = {
txRequestId: 'test-tx-request-id',
apiVersion: '2.0.0' as TxRequestVersion,
apiVersion: 'full',
enterpriseId: 'test-enterprise-id',
transactions: [],
transactions: [
{
state: 'pendingSignature',
unsignedTx: {
derivationPath: 'm/0',
signableHex: 'testMessage',
serializedTxHex: 'testSerializedTxHex',
},
signatureShares: [
{
share: 'bitgo-to-user-r-share',
from: 'bitgo',
to: 'user',
},
{
share: 'user-to-bitgo-r-share',
from: 'user',
to: 'bitgo',
},
],
},
],
state: 'pendingUserSignature',
walletId: 'test-wallet-id',
walletType: 'hot',
Expand Down Expand Up @@ -234,7 +255,7 @@ describe('Eddsa Signing Handler', () => {
const result = await handleEddsaSigning(
bitgo,
wallet,
txRequest.txRequestId,
txRequest,
enclavedExpressClient,
userPubKey,
reqId,
Expand Down
Loading