@@ -11,14 +11,27 @@ import {
1111} from '@bitgo/public-types' ;
1212import assert from 'assert' ;
1313
14+ function partyIdToSignatureShareType ( partyId : 0 | 1 | 2 ) : SignatureShareType {
15+ assert ( partyId === 0 || partyId === 1 || partyId === 2 , 'Invalid partyId for MPCv2 signing' ) ;
16+ switch ( partyId ) {
17+ case 0 :
18+ return SignatureShareType . USER ;
19+ case 1 :
20+ return SignatureShareType . BACKUP ;
21+ case 2 :
22+ return SignatureShareType . BITGO ;
23+ }
24+ }
25+
1426/**
1527 Helpers in this take care of all interaction with WP API's
1628**/
1729
1830export async function getSignatureShareRoundOne (
1931 round1Message : DklsTypes . DeserializedBroadcastMessage ,
2032 userGpgKey : openpgp . SerializedKeyPair < string > ,
21- partyId : 0 | 1 = 0
33+ partyId : 0 | 1 = 0 ,
34+ otherSignerPartyId : 0 | 1 | 2 = 2
2235) : Promise < SignatureShareRecord > {
2336 const serializedMessages = DklsTypes . serializeMessages ( {
2437 broadcastMessages : [ round1Message ] ,
@@ -45,8 +58,8 @@ export async function getSignatureShareRoundOne(
4558 } ;
4659 const serializedShare = JSON . stringify ( share ) ;
4760 return {
48- from : partyId === 0 ? SignatureShareType . USER : SignatureShareType . BACKUP ,
49- to : SignatureShareType . BITGO ,
61+ from : partyIdToSignatureShareType ( partyId ) ,
62+ to : partyIdToSignatureShareType ( otherSignerPartyId ) ,
5063 share : serializedShare ,
5164 } ;
5265}
@@ -55,18 +68,19 @@ export async function getSignatureShareRoundTwo(
5568 userToBitGoMessages2 : DklsTypes . DeserializedMessages ,
5669 userToBitGoMessages3 : DklsTypes . DeserializedMessages ,
5770 userGpgKey : openpgp . SerializedKeyPair < string > ,
58- bitgoGpgKey : openpgp . Key ,
59- partyId : 0 | 1 = 0
71+ otherPartyGpgKey : openpgp . Key ,
72+ partyId : 0 | 1 = 0 ,
73+ otherSignerPartyId : 0 | 1 | 2 = 2
6074) : Promise < SignatureShareRecord > {
6175 const userToBitGoEncryptedMsg2 = await DklsComms . encryptAndAuthOutgoingMessages (
6276 DklsTypes . serializeMessages ( userToBitGoMessages2 ) ,
63- [ getBitGoPartyGpgKey ( bitgoGpgKey ) ] ,
77+ [ getBitGoPartyGpgKey ( otherPartyGpgKey , otherSignerPartyId ) ] ,
6478 [ getUserPartyGpgKey ( userGpgKey , partyId ) ]
6579 ) ;
6680
6781 const userToBitGoEncryptedMsg3 = await DklsComms . encryptAndAuthOutgoingMessages (
6882 DklsTypes . serializeMessages ( userToBitGoMessages3 ) ,
69- [ getBitGoPartyGpgKey ( bitgoGpgKey ) ] ,
83+ [ getBitGoPartyGpgKey ( otherPartyGpgKey , otherSignerPartyId ) ] ,
7084 [ getUserPartyGpgKey ( userGpgKey , partyId ) ]
7185 ) ;
7286 assert ( userToBitGoEncryptedMsg2 . p2pMessages . length , 'User to BitGo messages 2 not present.' ) ;
@@ -93,8 +107,8 @@ export async function getSignatureShareRoundTwo(
93107 } ,
94108 } ;
95109 return {
96- from : partyId === 0 ? SignatureShareType . USER : SignatureShareType . BACKUP ,
97- to : SignatureShareType . BITGO ,
110+ from : partyIdToSignatureShareType ( partyId ) ,
111+ to : partyIdToSignatureShareType ( otherSignerPartyId ) ,
98112 share : JSON . stringify ( share ) ,
99113 } ;
100114}
@@ -103,11 +117,12 @@ export async function getSignatureShareRoundThree(
103117 userToBitGoMessages4 : DklsTypes . DeserializedMessages ,
104118 userGpgKey : openpgp . SerializedKeyPair < string > ,
105119 bitgoGpgKey : openpgp . Key ,
106- partyId : 0 | 1 = 0
120+ partyId : 0 | 1 = 0 ,
121+ otherSignerPartyId : 0 | 1 | 2 = 2
107122) : Promise < SignatureShareRecord > {
108123 const userToBitGoEncryptedMsg4 = await DklsComms . encryptAndAuthOutgoingMessages (
109124 DklsTypes . serializeMessages ( userToBitGoMessages4 ) ,
110- [ getBitGoPartyGpgKey ( bitgoGpgKey ) ] ,
125+ [ getBitGoPartyGpgKey ( bitgoGpgKey , otherSignerPartyId ) ] ,
111126 [ getUserPartyGpgKey ( userGpgKey , partyId ) ]
112127 ) ;
113128 assert ( MPCv2PartyFromStringOrNumber . is ( userToBitGoEncryptedMsg4 . broadcastMessages [ 0 ] . from ) ) ;
@@ -126,8 +141,8 @@ export async function getSignatureShareRoundThree(
126141 } ,
127142 } ;
128143 return {
129- from : partyId === 0 ? SignatureShareType . USER : SignatureShareType . BACKUP ,
130- to : SignatureShareType . BITGO ,
144+ from : partyIdToSignatureShareType ( partyId ) ,
145+ to : partyIdToSignatureShareType ( otherSignerPartyId ) ,
131146 share : JSON . stringify ( share ) ,
132147 } ;
133148}
@@ -190,9 +205,9 @@ export async function verifyBitGoMessagesAndSignaturesRoundTwo(
190205 ) ;
191206}
192207
193- export function getBitGoPartyGpgKey ( key : openpgp . Key ) : DklsTypes . PartyGpgKey {
208+ export function getBitGoPartyGpgKey ( key : openpgp . Key , partyId : 0 | 1 | 2 = 2 ) : DklsTypes . PartyGpgKey {
194209 return {
195- partyId : 2 ,
210+ partyId : partyId ,
196211 gpgKey : key . armor ( ) ,
197212 } ;
198213}
0 commit comments