|
9 | 9 | EddsaUtils, |
10 | 10 | BaseCoin, |
11 | 11 | ApiKeyShare, |
| 12 | + CustomRShareGeneratingFunction, |
| 13 | + CustomGShareGeneratingFunction, |
| 14 | + CustomCommitmentGeneratingFunction, |
12 | 15 | } from '@bitgo/sdk-core'; |
13 | 16 | import { EnclavedExpressClient } from '../clients/enclavedExpressClient'; |
14 | 17 | import { exchangeEddsaCommitments } from '@bitgo/sdk-core/dist/src/bitgo/tss/common'; |
@@ -198,3 +201,70 @@ export async function orchestrateEddsaKeyGen({ |
198 | 201 | walletParams.keys = [userMpcKey.id, backupMpcKey.id, bitgoKeychain.id]; |
199 | 202 | return { walletParams, keychains }; |
200 | 203 | } |
| 204 | + |
| 205 | +// Commitment |
| 206 | +export function createCustomCommitmentGenerator( |
| 207 | + bitgo: BitGoBase, |
| 208 | + wallet: Wallet, |
| 209 | + enclavedExpressClient: EnclavedExpressClient, |
| 210 | + source: 'user' | 'backup', |
| 211 | + pub: string, |
| 212 | +): CustomCommitmentGeneratingFunction { |
| 213 | + return async function customCommitmentGeneratingFunction(params) { |
| 214 | + const eddsaUtils = new EddsaUtils(bitgo, wallet.baseCoin); |
| 215 | + const bitgoGpgKey = await eddsaUtils.getBitgoPublicGpgKey(); |
| 216 | + const { txRequest } = params; |
| 217 | + const response = await enclavedExpressClient.signMpcCommitment({ |
| 218 | + txRequest, |
| 219 | + bitgoGpgPubKey: bitgoGpgKey.armor(), |
| 220 | + source, |
| 221 | + pub, |
| 222 | + }); |
| 223 | + return { |
| 224 | + ...response, |
| 225 | + encryptedUserToBitgoRShare: { |
| 226 | + ...response.encryptedUserToBitgoRShare, |
| 227 | + encryptedDataKey: response.encryptedDataKey, |
| 228 | + }, |
| 229 | + }; |
| 230 | + }; |
| 231 | +} |
| 232 | + |
| 233 | +// RShare |
| 234 | +export function createCustomRShareGenerator( |
| 235 | + enclavedExpressClient: EnclavedExpressClient, |
| 236 | + source: 'user' | 'backup', |
| 237 | + pub: string, |
| 238 | +): CustomRShareGeneratingFunction { |
| 239 | + return async function customRShareGeneratingFunction(params) { |
| 240 | + const { txRequest, encryptedUserToBitgoRShare } = params; |
| 241 | + const encryptedDataKey = (encryptedUserToBitgoRShare as any).encryptedDataKey; |
| 242 | + return await enclavedExpressClient.signMpcRShare({ |
| 243 | + txRequest, |
| 244 | + encryptedUserToBitgoRShare, |
| 245 | + encryptedDataKey, |
| 246 | + source, |
| 247 | + pub, |
| 248 | + }); |
| 249 | + }; |
| 250 | +} |
| 251 | + |
| 252 | +// GShare |
| 253 | +export function createCustomGShareGenerator( |
| 254 | + enclavedExpressClient: EnclavedExpressClient, |
| 255 | + source: 'user' | 'backup', |
| 256 | + pub: string, |
| 257 | +): CustomGShareGeneratingFunction { |
| 258 | + return async function customGShareGeneratingFunction(params) { |
| 259 | + const { txRequest, bitgoToUserRShare, userToBitgoRShare, bitgoToUserCommitment } = params; |
| 260 | + const response = await enclavedExpressClient.signMpcGShare({ |
| 261 | + txRequest, |
| 262 | + bitgoToUserRShare, |
| 263 | + userToBitgoRShare, |
| 264 | + bitgoToUserCommitment, |
| 265 | + source, |
| 266 | + pub, |
| 267 | + }); |
| 268 | + return response.gShare; |
| 269 | + }; |
| 270 | +} |
0 commit comments