@@ -11,14 +11,27 @@ import {
11
11
} from '@bitgo/public-types' ;
12
12
import assert from 'assert' ;
13
13
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
+
14
26
/**
15
27
Helpers in this take care of all interaction with WP API's
16
28
**/
17
29
18
30
export async function getSignatureShareRoundOne (
19
31
round1Message : DklsTypes . DeserializedBroadcastMessage ,
20
32
userGpgKey : openpgp . SerializedKeyPair < string > ,
21
- partyId : 0 | 1 = 0
33
+ partyId : 0 | 1 = 0 ,
34
+ otherSignerPartyId : 0 | 1 | 2 = 2
22
35
) : Promise < SignatureShareRecord > {
23
36
const serializedMessages = DklsTypes . serializeMessages ( {
24
37
broadcastMessages : [ round1Message ] ,
@@ -45,8 +58,8 @@ export async function getSignatureShareRoundOne(
45
58
} ;
46
59
const serializedShare = JSON . stringify ( share ) ;
47
60
return {
48
- from : partyId === 0 ? SignatureShareType . USER : SignatureShareType . BACKUP ,
49
- to : SignatureShareType . BITGO ,
61
+ from : partyIdToSignatureShareType ( partyId ) ,
62
+ to : partyIdToSignatureShareType ( otherSignerPartyId ) ,
50
63
share : serializedShare ,
51
64
} ;
52
65
}
@@ -55,18 +68,19 @@ export async function getSignatureShareRoundTwo(
55
68
userToBitGoMessages2 : DklsTypes . DeserializedMessages ,
56
69
userToBitGoMessages3 : DklsTypes . DeserializedMessages ,
57
70
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
60
74
) : Promise < SignatureShareRecord > {
61
75
const userToBitGoEncryptedMsg2 = await DklsComms . encryptAndAuthOutgoingMessages (
62
76
DklsTypes . serializeMessages ( userToBitGoMessages2 ) ,
63
- [ getBitGoPartyGpgKey ( bitgoGpgKey ) ] ,
77
+ [ getBitGoPartyGpgKey ( otherPartyGpgKey , otherSignerPartyId ) ] ,
64
78
[ getUserPartyGpgKey ( userGpgKey , partyId ) ]
65
79
) ;
66
80
67
81
const userToBitGoEncryptedMsg3 = await DklsComms . encryptAndAuthOutgoingMessages (
68
82
DklsTypes . serializeMessages ( userToBitGoMessages3 ) ,
69
- [ getBitGoPartyGpgKey ( bitgoGpgKey ) ] ,
83
+ [ getBitGoPartyGpgKey ( otherPartyGpgKey , otherSignerPartyId ) ] ,
70
84
[ getUserPartyGpgKey ( userGpgKey , partyId ) ]
71
85
) ;
72
86
assert ( userToBitGoEncryptedMsg2 . p2pMessages . length , 'User to BitGo messages 2 not present.' ) ;
@@ -93,8 +107,8 @@ export async function getSignatureShareRoundTwo(
93
107
} ,
94
108
} ;
95
109
return {
96
- from : partyId === 0 ? SignatureShareType . USER : SignatureShareType . BACKUP ,
97
- to : SignatureShareType . BITGO ,
110
+ from : partyIdToSignatureShareType ( partyId ) ,
111
+ to : partyIdToSignatureShareType ( otherSignerPartyId ) ,
98
112
share : JSON . stringify ( share ) ,
99
113
} ;
100
114
}
@@ -103,11 +117,12 @@ export async function getSignatureShareRoundThree(
103
117
userToBitGoMessages4 : DklsTypes . DeserializedMessages ,
104
118
userGpgKey : openpgp . SerializedKeyPair < string > ,
105
119
bitgoGpgKey : openpgp . Key ,
106
- partyId : 0 | 1 = 0
120
+ partyId : 0 | 1 = 0 ,
121
+ otherSignerPartyId : 0 | 1 | 2 = 2
107
122
) : Promise < SignatureShareRecord > {
108
123
const userToBitGoEncryptedMsg4 = await DklsComms . encryptAndAuthOutgoingMessages (
109
124
DklsTypes . serializeMessages ( userToBitGoMessages4 ) ,
110
- [ getBitGoPartyGpgKey ( bitgoGpgKey ) ] ,
125
+ [ getBitGoPartyGpgKey ( bitgoGpgKey , otherSignerPartyId ) ] ,
111
126
[ getUserPartyGpgKey ( userGpgKey , partyId ) ]
112
127
) ;
113
128
assert ( MPCv2PartyFromStringOrNumber . is ( userToBitGoEncryptedMsg4 . broadcastMessages [ 0 ] . from ) ) ;
@@ -126,8 +141,8 @@ export async function getSignatureShareRoundThree(
126
141
} ,
127
142
} ;
128
143
return {
129
- from : partyId === 0 ? SignatureShareType . USER : SignatureShareType . BACKUP ,
130
- to : SignatureShareType . BITGO ,
144
+ from : partyIdToSignatureShareType ( partyId ) ,
145
+ to : partyIdToSignatureShareType ( otherSignerPartyId ) ,
131
146
share : JSON . stringify ( share ) ,
132
147
} ;
133
148
}
@@ -190,9 +205,9 @@ export async function verifyBitGoMessagesAndSignaturesRoundTwo(
190
205
) ;
191
206
}
192
207
193
- export function getBitGoPartyGpgKey ( key : openpgp . Key ) : DklsTypes . PartyGpgKey {
208
+ export function getBitGoPartyGpgKey ( key : openpgp . Key , partyId : 0 | 1 | 2 = 2 ) : DklsTypes . PartyGpgKey {
194
209
return {
195
- partyId : 2 ,
210
+ partyId : partyId ,
196
211
gpgKey : key . armor ( ) ,
197
212
} ;
198
213
}
0 commit comments