Skip to content

Commit 4dc5161

Browse files
committed
fix(mbe): fix/tested mpcv2 signing with custom fns
Ticket: WP-5232
1 parent c02a2d6 commit 4dc5161

File tree

2 files changed

+67
-65
lines changed

2 files changed

+67
-65
lines changed

src/api/master/clients/enclavedExpressClient.ts

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -597,22 +597,22 @@ export class EnclavedExpressClient {
597597
}
598598
}
599599

600-
/**
601-
* Create custom MPCv2 Round 1 signing function for enclaved express client
602-
*/
603-
export function signMPCv2Round1(
604-
enclavedExpressClient: EnclavedExpressClient,
605-
source: 'user' | 'backup',
606-
pub: string,
607-
): (params: SignMpcV2Round1Params) => Promise<SignMpcV2Round1Response> {
608-
return async function (params): Promise<SignMpcV2Round1Response> {
609-
if (!enclavedExpressClient['coin']) {
600+
/**
601+
* Sign MPCv2 Round 1
602+
*/
603+
async signMPCv2Round1(
604+
enclavedExpressClient: EnclavedExpressClient,
605+
source: 'user' | 'backup',
606+
pub: string,
607+
params: SignMpcV2Round1Params,
608+
): Promise<SignMpcV2Round1Response> {
609+
if (!this['coin']) {
610610
throw new Error('Coin must be specified to sign an MPCv2 Round 1');
611611
}
612612

613613
try {
614-
let request = enclavedExpressClient['apiClient']['v1.mpc.sign'].post({
615-
coin: enclavedExpressClient['coin'],
614+
let request = this['apiClient']['v1.mpc.sign'].post({
615+
coin: this['coin'],
616616
shareType: 'mpcv2round1',
617617
...params,
618618
source,
@@ -629,33 +629,32 @@ export function signMPCv2Round1(
629629
debugLogger('Failed to sign mpcv2 round 1: %s', err.message);
630630
throw err;
631631
}
632-
};
633-
}
632+
}
634633

635-
/**
636-
* Create custom MPCv2 Round 2 signing function for enclaved express client
637-
*/
638-
export function signMPCv2Round2(
639-
enclavedExpressClient: EnclavedExpressClient,
640-
source: 'user' | 'backup',
641-
pub: string,
642-
): (params: SignMpcV2Round2Params) => Promise<SignMpcV2Round2Response> {
643-
return async function (params): Promise<SignMpcV2Round2Response> {
644-
if (!enclavedExpressClient['coin']) {
634+
/**
635+
* Sign MPCv2 Round 2
636+
*/
637+
async signMPCv2Round2(
638+
enclavedExpressClient: EnclavedExpressClient,
639+
source: 'user' | 'backup',
640+
pub: string,
641+
params: SignMpcV2Round2Params,
642+
): Promise<SignMpcV2Round2Response> {
643+
if (!this['coin']) {
645644
throw new Error('Coin must be specified to sign an MPCv2 Round 2');
646645
}
647646

648647
try {
649-
let request = enclavedExpressClient['apiClient']['v1.mpc.sign'].post({
650-
coin: enclavedExpressClient['coin'],
648+
let request = this['apiClient']['v1.mpc.sign'].post({
649+
coin: this['coin'],
651650
shareType: 'mpcv2round2',
652651
...params,
653652
source,
654653
pub,
655654
});
656655

657-
if (enclavedExpressClient['tlsMode'] === TlsMode.MTLS) {
658-
request = request.agent(enclavedExpressClient['createHttpsAgent']());
656+
if (this['tlsMode'] === TlsMode.MTLS) {
657+
request = request.agent(this['createHttpsAgent']());
659658
}
660659
const response = await request.decodeExpecting(200);
661660
return response.body;
@@ -664,33 +663,32 @@ export function signMPCv2Round2(
664663
debugLogger('Failed to sign mpcv2 round 2: %s', err.message);
665664
throw err;
666665
}
667-
};
668-
}
666+
}
669667

670-
/**
671-
* Create custom MPCv2 Round 3 signing function for enclaved express client
672-
*/
673-
export function signMPCv2Round3(
674-
enclavedExpressClient: EnclavedExpressClient,
675-
source: 'user' | 'backup',
676-
pub: string,
677-
): (params: SignMpcV2Round3Params) => Promise<SignMpcV2Round3Response> {
678-
return async function (params): Promise<SignMpcV2Round3Response> {
679-
if (!enclavedExpressClient['coin']) {
668+
/**
669+
* Sign MPCv2 Round 3
670+
*/
671+
async signMPCv2Round3(
672+
enclavedExpressClient: EnclavedExpressClient,
673+
source: 'user' | 'backup',
674+
pub: string,
675+
params: SignMpcV2Round3Params,
676+
): Promise<SignMpcV2Round3Response> {
677+
if (!this['coin']) {
680678
throw new Error('Coin must be specified to sign an MPCv2 Round 3');
681679
}
682680

683681
try {
684-
let request = enclavedExpressClient['apiClient']['v1.mpc.sign'].post({
685-
coin: enclavedExpressClient['coin'],
682+
let request = this['apiClient']['v1.mpc.sign'].post({
683+
coin: this['coin'],
686684
shareType: 'mpcv2round3',
687685
...params,
688686
source,
689687
pub,
690688
});
691689

692-
if (enclavedExpressClient['tlsMode'] === TlsMode.MTLS) {
693-
request = request.agent(enclavedExpressClient['createHttpsAgent']());
690+
if (this['tlsMode'] === TlsMode.MTLS) {
691+
request = request.agent(this['createHttpsAgent']());
694692
}
695693
const response = await request.decodeExpecting(200);
696694
return response.body;
@@ -699,7 +697,7 @@ export function signMPCv2Round3(
699697
debugLogger('Failed to sign mpcv2 round 3: %s', err.message);
700698
throw err;
701699
}
702-
};
700+
}
703701
}
704702

705703
/**

src/api/master/handlers/ecdsa.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import {
1111
EnclavedExpressClient,
1212
SignMpcV2Round1Response,
1313
SignMpcV2Round2Response,
14-
signMPCv2Round1,
15-
signMPCv2Round2,
16-
signMPCv2Round3,
1714
} from '../clients/enclavedExpressClient';
1815

1916
export async function handleEcdsaSigning(
@@ -34,7 +31,12 @@ export async function handleEcdsaSigning(
3431

3532
// Create custom signing methods that maintain state
3633
const customRound1Signer = async (params: { txRequest: TxRequest }) => {
37-
const response = await signMPCv2Round1(enclavedExpressClient, source, commonKeychain)(params);
34+
const response = await enclavedExpressClient.signMPCv2Round1(
35+
enclavedExpressClient,
36+
source,
37+
commonKeychain,
38+
params,
39+
);
3840
round1Response = response;
3941
return response;
4042
};
@@ -48,17 +50,18 @@ export async function handleEcdsaSigning(
4850
if (!round1Response) {
4951
throw new Error('Round 1 must be completed before Round 2');
5052
}
51-
const response = await signMPCv2Round2(
53+
const response = await enclavedExpressClient.signMPCv2Round2(
5254
enclavedExpressClient,
5355
source,
5456
commonKeychain,
55-
)({
56-
...params,
57-
encryptedDataKey: round1Response.encryptedDataKey,
58-
encryptedRound1Session: round1Response.encryptedRound1Session,
59-
encryptedUserGpgPrvKey: round1Response.encryptedUserGpgPrvKey,
60-
bitgoPublicGpgKey: params.bitgoPublicGpgKey,
61-
});
57+
{
58+
...params,
59+
encryptedDataKey: round1Response.encryptedDataKey,
60+
encryptedRound1Session: round1Response.encryptedRound1Session,
61+
encryptedUserGpgPrvKey: round1Response.encryptedUserGpgPrvKey,
62+
bitgoPublicGpgKey: params.bitgoPublicGpgKey,
63+
},
64+
);
6265
round2Response = response;
6366
return response;
6467
};
@@ -72,17 +75,18 @@ export async function handleEcdsaSigning(
7275
if (!round2Response) {
7376
throw new Error('Round 1 must be completed before Round 3');
7477
}
75-
return await signMPCv2Round3(
78+
return await enclavedExpressClient.signMPCv2Round3(
7679
enclavedExpressClient,
7780
source,
7881
commonKeychain,
79-
)({
80-
...params,
81-
encryptedDataKey: round1Response.encryptedDataKey,
82-
encryptedRound2Session: round2Response.encryptedRound2Session,
83-
encryptedUserGpgPrvKey: round1Response.encryptedUserGpgPrvKey,
84-
bitgoPublicGpgKey: params.bitgoPublicGpgKey,
85-
});
82+
{
83+
...params,
84+
encryptedDataKey: round1Response.encryptedDataKey,
85+
encryptedRound2Session: round2Response.encryptedRound2Session,
86+
encryptedUserGpgPrvKey: round1Response.encryptedUserGpgPrvKey,
87+
bitgoPublicGpgKey: params.bitgoPublicGpgKey,
88+
},
89+
);
8690
};
8791

8892
// Use the existing signEcdsaMPCv2TssUsingExternalSigner method with our custom signers

0 commit comments

Comments
 (0)